Check on watched notification states before adding to the queue

This commit is contained in:
JonnyWong16 2018-02-15 15:16:50 -08:00
parent d94a1efe75
commit 16f270691d
3 changed files with 42 additions and 14 deletions

View file

@ -82,11 +82,6 @@ def add_notifier_each(notifier_id=None, notify_action=None, stream_data=None, ti
# Check if any notification agents have notifications enabled for the action
notifiers_enabled = notifiers.get_notifiers(notify_action=notify_action)
# Check if the watched notifications has already been sent
if stream_data and notify_action == 'on_watched':
watched_notifiers = [d['notifier_id'] for d in get_notify_state(session=stream_data)]
notifiers_enabled = [n for n in notifiers_enabled if n['id'] not in watched_notifiers]
if notifiers_enabled and not manual_trigger:
# Check if notification conditions are satisfied
conditions = notify_conditions(notify_action=notify_action,
@ -390,6 +385,28 @@ def get_notify_state(session):
return notify_states
def get_notify_state_enabled(session, notify_action, notified=True):
if notified:
timestamp_where = 'AND timestamp IS NOT NULL'
else:
timestamp_where = 'AND timestamp IS NULL'
monitor_db = database.MonitorDatabase()
result = monitor_db.select('SELECT id AS notifier_id, timestamp '
'FROM notifiers '
'LEFT OUTER JOIN ('
'SELECT timestamp, notifier_id '
'FROM notify_log '
'WHERE session_key = ? '
'AND rating_key = ? '
'AND user_id = ? '
'AND notify_action = ?) AS t ON notifiers.id = t.notifier_id '
'WHERE %s = 1 %s' % (notify_action, timestamp_where),
args=[session['session_key'], session['rating_key'], session['user_id'], notify_action])
return result
def set_notify_state(notifier, notify_action, subject='', body='', script_args='', session=None):
if notifier and notify_action: