Skip to content

Commit

Permalink
Allow apps to submit filters
Browse files Browse the repository at this point in the history
  • Loading branch information
crysxd committed Jan 27, 2024
1 parent 52a80dc commit ce35d7d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 5 additions & 1 deletion octoapp/appsstorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def __init__(
appLanguage:str,
lastSeenAt:float,
expireAt:float,
excludeNotifications:list,
):
self.FcmToken = fcmToken
self.FcmFallbackToken = fcmFallbackToken
Expand All @@ -30,6 +31,7 @@ def __init__(
self.AppLanguage = appLanguage
self.LastSeenAt = lastSeenAt
self.ExpireAt = expireAt
self.ExcludeNotifications = excludeNotifications


def ToDict(self):
Expand All @@ -44,7 +46,8 @@ def ToDict(self):
appBuild=self.AppBuild,
appLanguage=self.AppLanguage,
lastSeenAt=self.LastSeenAt,
expireAt=self.ExpireAt
expireAt=self.ExpireAt,
excludeNotifications=self.ExcludeNotifications
)

@staticmethod
Expand All @@ -61,6 +64,7 @@ def FromDict(dict:dict):
appLanguage=dict.get("appLanguage", "en"),
lastSeenAt=dict.get("lastSeenAt", 0),
expireAt=dict.get("expireAt", 0),
excludeNotifications=dict.get("excludeNotifications", []),
)


Expand Down
13 changes: 12 additions & 1 deletion octoapp/notificationsender.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ def SendNotification(self, event, state=None):
if not targets:
Sentry.Debug("SENDER", "No targets, skipping notification")
return


targets = self._processFilters(targets=targets, event=event)
ios_targets = helper.GetIosApps(targets)
activity_targets = helper.GetActivities(targets)
android_targets = helper.GetAndroidApps(targets)
Expand Down Expand Up @@ -132,6 +133,16 @@ def _shouldSendOnlyActivities(self, event, state):
Sentry.Debug("SENDER", "Skipping progress update, only %s seconds passed since last" % int(time_since_last))
return True

def _processFilters(self, targets, event):
filterName = None
if event == self.EVENT_FIRST_LAYER_DONE:
filterName = "layer_1"
elif event == self.EVENT_THIRD_LAYER_DONE:
filterName = "layer_3"
else:
return targets

return list(filter(lambda target: filterName not in target.ExcludeNotifications, targets))

def _doSendNotification(self, targets, highProiroty, apnsData, androidData):
try:
Expand Down

0 comments on commit ce35d7d

Please sign in to comment.