Skip to content

Commit 9508a8b

Browse files
Add is_snoozed for notification and fix is_snoozed wrong value assignment
1 parent a004824 commit 9508a8b

File tree

4 files changed

+36
-38
lines changed

4 files changed

+36
-38
lines changed

README.md

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -106,26 +106,6 @@ You can use <kbd>ctrl d</kbd> (or your custom shortcut) to set snooze time.
106106

107107
Focus on message and press <kbd>r</kbd> (or your custom shortcut) to get permalink (Quote message) and it will be put into your chat box.
108108

109-
110-
### Enable features
111-
112-
There are some features available, you can adjust them by change the config file
113-
114-
115-
```json
116-
{
117-
"features": {
118-
"emoji": true,
119-
"markdown": true,
120-
"pictures": true,
121-
"notification": ""
122-
},
123-
}
124-
```
125-
126-
* notification: How we send notification for you (*MacOS* supported now): `none` Disable notification / `mentioned` Direct message or mentioned in channel / `all` Receive all notifications
127-
128-
129109
### Default keybindings
130110
```json
131111
{

app.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
from sclack.widgets.set_snooze import SetSnoozeWidget
3131
from sclack.utils.channel import is_dm, is_group, is_channel
32+
from sclack.utils.message import get_mentioned_patterns
3233

3334
loop = asyncio.get_event_loop()
3435

@@ -97,30 +98,20 @@ def __init__(self, config):
9798
self.mentioned_patterns = None
9899

99100
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'])
115102

116103
def should_notify_me(self, message_obj):
117104
"""
118105
Checking whether notify to user
119106
:param message_obj:
120107
:return:
121108
"""
109+
# Snoozzzzzed or disabled
110+
if self.store.state.is_snoozed or self.config['features']['notification'] in ['', 'none']:
111+
return False
112+
122113
# 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']:
124115
return False
125116

126117
if self.config['features']['notification'] == 'all':
@@ -879,8 +870,8 @@ def stop_typing(*args):
879870
pass
880871
# print(json.dumps(event, indent=2))
881872
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)
884875
elif event.get('ok', False):
885876
if not self.is_chatbox_rendered:
886877
return

sclack/utils/message.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import re
2+
13
from datetime import datetime
24

35

@@ -17,3 +19,27 @@ def format_date_time(ts):
1719
date_text = message_datetime.strftime('%b %d, %Y at %I:%M%p')
1820

1921
return date_text
22+
23+
24+
def get_mentioned_patterns(user_id):
25+
"""
26+
All possible pattern in message which mention me
27+
:param user_id:
28+
:type user_id: str
29+
:return:
30+
"""
31+
slack_mentions = [
32+
'<!everyone>',
33+
'<!here>',
34+
'<!channel>',
35+
'<@{}>'.format(user_id),
36+
]
37+
38+
patterns = []
39+
40+
for mention in slack_mentions:
41+
patterns.append('^{}[ ]+'.format(mention))
42+
patterns.append('^{}$'.format(mention))
43+
patterns.append('[ ]+{}'.format(mention))
44+
45+
return re.compile('|'.join(patterns))

tests/test_quick_switcher.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from sclack.quick_switcher import remove_diacritic
22

3+
34
def test_remove_diacritic():
45
assert remove_diacritic("sábado") == "sabado"

0 commit comments

Comments
 (0)