|
29 | 29 |
|
30 | 30 | from sclack.widgets.set_snooze import SetSnoozeWidget
|
31 | 31 | from sclack.utils.channel import is_dm, is_group, is_channel
|
| 32 | +from sclack.utils.message import get_mentioned_patterns |
32 | 33 |
|
33 | 34 | loop = asyncio.get_event_loop()
|
34 | 35 |
|
@@ -97,30 +98,20 @@ def __init__(self, config):
|
97 | 98 | self.mentioned_patterns = None
|
98 | 99 |
|
99 | 100 | def get_mentioned_patterns(self):
|
100 |
| - slack_mentions = [ |
101 |
| - '<!everyone>', |
102 |
| - '<!here>', |
103 |
| - '<!channel>', |
104 |
| - '<@{}>'.format(self.store.state.auth['user_id']), |
105 |
| - ] |
106 |
| - |
107 |
| - patterns = [] |
108 |
| - |
109 |
| - for mention in slack_mentions: |
110 |
| - patterns.append('^{}[ ]+'.format(mention)) |
111 |
| - patterns.append('^{}$'.format(mention)) |
112 |
| - patterns.append('[ ]+{}'.format(mention)) |
113 |
| - |
114 |
| - return re.compile('|'.join(patterns)) |
| 101 | + return get_mentioned_patterns(self.store.state.auth['user_id']) |
115 | 102 |
|
116 | 103 | def should_notify_me(self, message_obj):
|
117 | 104 | """
|
118 | 105 | Checking whether notify to user
|
119 | 106 | :param message_obj:
|
120 | 107 | :return:
|
121 | 108 | """
|
| 109 | + # Snoozzzzzed or disabled |
| 110 | + if self.store.state.is_snoozed or self.config['features']['notification'] in ['', 'none']: |
| 111 | + return False |
| 112 | + |
122 | 113 | # You send message, don't need notification
|
123 |
| - if self.config['features']['notification'] in ['', 'none'] or message_obj.get('user') == self.store.state.auth['user_id']: |
| 114 | + if message_obj.get('user') == self.store.state.auth['user_id']: |
124 | 115 | return False
|
125 | 116 |
|
126 | 117 | if self.config['features']['notification'] == 'all':
|
@@ -879,8 +870,8 @@ def stop_typing(*args):
|
879 | 870 | pass
|
880 | 871 | # print(json.dumps(event, indent=2))
|
881 | 872 | elif event.get('type') == 'dnd_updated' and 'dnd_status' in event:
|
882 |
| - self.store.is_snoozed = event['dnd_status']['snooze_enabled'] |
883 |
| - self.sidebar.profile.set_snooze(self.store.is_snoozed) |
| 873 | + self.store.state.is_snoozed = event['dnd_status']['snooze_enabled'] |
| 874 | + self.sidebar.profile.set_snooze(self.store.state.is_snoozed) |
884 | 875 | elif event.get('ok', False):
|
885 | 876 | if not self.is_chatbox_rendered:
|
886 | 877 | return
|
|
0 commit comments