Skip to content

Commit

Permalink
Add is_snoozed for notification and fix is_snoozed wrong value assign…
Browse files Browse the repository at this point in the history
…ment
  • Loading branch information
duynguyenhoang committed Sep 12, 2018
1 parent a004824 commit ab44d8f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 40 deletions.
20 changes: 0 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,26 +106,6 @@ You can use <kbd>ctrl d</kbd> (or your custom shortcut) to set snooze time.

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.


### Enable features

There are some features available, you can adjust them by change the config file


```json
{
"features": {
"emoji": true,
"markdown": true,
"pictures": true,
"notification": ""
},
}
```

* notification: How we send notification for you (*MacOS* supported now): `none` Disable notification / `mentioned` Direct message or mentioned in channel / `all` Receive all notifications


### Default keybindings
```json
{
Expand Down
4 changes: 2 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
- [x] Show indicator when a message is edited
- [x] Live events
- [x] Post message
- [x] 'Do not disturb' status
- [ ] Header for direct message
- [ ] Load more on up
- [ ] Unread messages indicator
- [ ] Navigate throught users and conversations I don't belong to.
- [ ] Navigate thought users and conversations I don't belong to.
- [ ] Publish on PIP
- [ ] Group messages
- [ ] Update documentation and screenshots

# Good to have

- React to a message
- 'Do not disturb' status
- Integration with reminders
- Handle slash commands
- RTM events (see https://api.slack.com/rtm)
27 changes: 9 additions & 18 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

from sclack.widgets.set_snooze import SetSnoozeWidget
from sclack.utils.channel import is_dm, is_group, is_channel
from sclack.utils.message import get_mentioned_patterns

loop = asyncio.get_event_loop()

Expand Down Expand Up @@ -97,30 +98,20 @@ def __init__(self, config):
self.mentioned_patterns = None

def get_mentioned_patterns(self):
slack_mentions = [
'<!everyone>',
'<!here>',
'<!channel>',
'<@{}>'.format(self.store.state.auth['user_id']),
]

patterns = []

for mention in slack_mentions:
patterns.append('^{}[ ]+'.format(mention))
patterns.append('^{}$'.format(mention))
patterns.append('[ ]+{}'.format(mention))

return re.compile('|'.join(patterns))
return get_mentioned_patterns(self.store.state.auth['user_id'])

def should_notify_me(self, message_obj):
"""
Checking whether notify to user
:param message_obj:
:return:
"""
# Snoozzzzzed or disabled
if self.store.state.is_snoozed or self.config['features']['notification'] in ['', 'none']:
return False

# You send message, don't need notification
if self.config['features']['notification'] in ['', 'none'] or message_obj.get('user') == self.store.state.auth['user_id']:
if message_obj.get('user') == self.store.state.auth['user_id']:
return False

if self.config['features']['notification'] == 'all':
Expand Down Expand Up @@ -879,8 +870,8 @@ def stop_typing(*args):
pass
# print(json.dumps(event, indent=2))
elif event.get('type') == 'dnd_updated' and 'dnd_status' in event:
self.store.is_snoozed = event['dnd_status']['snooze_enabled']
self.sidebar.profile.set_snooze(self.store.is_snoozed)
self.store.state.is_snoozed = event['dnd_status']['snooze_enabled']
self.sidebar.profile.set_snooze(self.store.state.is_snoozed)
elif event.get('ok', False):
if not self.is_chatbox_rendered:
return
Expand Down
26 changes: 26 additions & 0 deletions sclack/utils/message.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re

from datetime import datetime


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

return date_text


def get_mentioned_patterns(user_id):
"""
All possible pattern in message which mention me
:param user_id:
:type user_id: str
:return:
"""
slack_mentions = [
'<!everyone>',
'<!here>',
'<!channel>',
'<@{}>'.format(user_id),
]

patterns = []

for mention in slack_mentions:
patterns.append('^{}[ ]+'.format(mention))
patterns.append('^{}$'.format(mention))
patterns.append('[ ]+{}'.format(mention))

return re.compile('|'.join(patterns))
1 change: 1 addition & 0 deletions tests/test_quick_switcher.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from sclack.quick_switcher import remove_diacritic


def test_remove_diacritic():
assert remove_diacritic("sábado") == "sabado"

0 comments on commit ab44d8f

Please sign in to comment.