Skip to content

Commit

Permalink
Fixed dcai#238 issue that can't send broadcast message due to device …
Browse files Browse the repository at this point in the history
…type check for ios-fcm
  • Loading branch information
sanlinnaing committed Oct 8, 2024
1 parent 5843876 commit f581e66
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
10 changes: 6 additions & 4 deletions controllers/broadcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import tornado.web

from controllers.base import *
from routes import route
from controllers.base import WebBaseHandler


@route(r"/applications/([^/]+)/broadcast")
Expand All @@ -41,16 +41,18 @@ def get(self, appname):
raise tornado.web.HTTPError(500)
self.render("app_broadcast.html", app=app, sent=False)

# TODO: to check and implement for performance in case there are much devices
# to send the broadcast message.
@tornado.web.authenticated
def post(self, appname):
async def post(self, appname):
self.appname = appname
app = self.masterdb.applications.find_one({"shortname": appname})
if not app:
raise tornado.web.HTTPError(500)
alert = self.get_argument("notification").strip()
sound = "default"
channel = "default"
self.application.send_broadcast(
await self.application.send_broadcast(
self.appname, self.db, channel=channel, alert=alert, sound=sound
)
self.render("app_broadcast.html", app=app, sent=True)
Expand Down
19 changes: 12 additions & 7 deletions web.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
RELEASE,
VERSION,
)
from uimodules import *
from uimodules import (
AppSideBar,
NavBar,
TabBar
)
import datetime
import os
import logging
Expand Down Expand Up @@ -117,15 +121,16 @@ async def send_broadcast(self, appname, appdb, **kwargs):
extra=extra,
apns=kwargs.get("apns", {}),
)
elif token["device"] == DEVICE_TYPE_FCM or token["device"] == DEVICE_TYPE_ANDROID:
elif (token["device"].endswith(DEVICE_TYPE_FCM) or
token["device"] == DEVICE_TYPE_ANDROID):
await fcm.process(
token=t, alert=alert, extra=extra, fcm=kwargs.get("fcm", {})
)
elif token["device"] == DEVICE_TYPE_WNS:
if wns is not None:
wns.process(
token=t, alert=alert, extra=extra, wns=kwargs.get("wns", {})
)
elif (token["device"] == DEVICE_TYPE_WNS and
wns is not None):
wns.process(
token=t, alert=alert, extra=extra, wns=kwargs.get("wns", {})
)
except Exception as ex:
logging.error(ex)

Expand Down

0 comments on commit f581e66

Please sign in to comment.