Skip to content

Commit adb0023

Browse files
Merge pull request #60 from Mazuh/do_not_disturb_read
Reading user "do not disturb" status
2 parents 08cf8c5 + aafc3c6 commit adb0023

File tree

4 files changed

+31
-6
lines changed

4 files changed

+31
-6
lines changed

app.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,10 @@ def mount_sidebar(self, executor):
132132
loop.run_in_executor(executor, self.store.load_auth),
133133
loop.run_in_executor(executor, self.store.load_channels),
134134
loop.run_in_executor(executor, self.store.load_groups),
135-
loop.run_in_executor(executor, self.store.load_users)
135+
loop.run_in_executor(executor, self.store.load_users),
136+
loop.run_in_executor(executor, self.store.load_user_dnd),
136137
)
137-
profile = Profile(name=self.store.state.auth['user'])
138+
profile = Profile(name=self.store.state.auth['user'], is_snoozed=self.store.state.is_snoozed)
138139
channels = [
139140
Channel(
140141
id=channel['id'],
@@ -564,6 +565,9 @@ def stop_typing(*args):
564565
else:
565566
pass
566567
# print(json.dumps(event, indent=2))
568+
elif event.get('type') == 'dnd_updated' and 'dnd_status' in event:
569+
self.store.is_snoozed = event['dnd_status']['snooze_enabled']
570+
self.sidebar.profile.set_snooze(self.store.is_snoozed)
567571
elif event.get('ok', False):
568572
# Message was sent, Slack confirmed it.
569573
self.chatbox.body.body.extend(self.render_messages([{

config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"private_channel": "\uF023",
4949
"skype": "\uF17E",
5050
"square": "\uF445",
51+
"snooze": "\uF9B1",
5152
"status": "\uF075",
5253
"timezone": "\uF0AC"
5354
}

sclack/components.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -564,13 +564,28 @@ def keypress(self, size, key):
564564
return super(MessagePrompt, self).keypress(size, key)
565565

566566
class Profile(urwid.Text):
567-
def __init__(self, name, is_online=False):
568-
if is_online:
567+
def __init__(self, name, is_online=False, is_snoozed=False):
568+
self.name = name
569+
self.is_online = is_online
570+
self.is_snoozed = is_snoozed
571+
super(Profile, self).__init__(self.body)
572+
573+
@property
574+
def body(self):
575+
if self.is_snoozed:
576+
presence_icon = ('presence_active', ' {} '.format(get_icon('snooze')))
577+
elif self.is_online:
569578
presence_icon = ('presence_active', ' {} '.format(get_icon('online')))
570579
else:
571580
presence_icon = ('presence_away', ' {} '.format(get_icon('offline')))
572-
body = [presence_icon, name]
573-
super(Profile, self).__init__(body)
581+
582+
snooze_str = ' (snoozed) ' if self.is_snoozed else ''
583+
584+
return [presence_icon, self.name, snooze_str]
585+
586+
def set_snooze(self, is_snoozed):
587+
self.is_snoozed = is_snoozed
588+
self.set_text(self.body)
574589

575590
class ProfileSideBar(urwid.AttrWrap):
576591
def format_row(self, icon, text):
@@ -622,6 +637,7 @@ class SideBar(urwid.Frame):
622637
signals = ['go_to_channel']
623638

624639
def __init__(self, profile, channels=[], dms=[], title=''):
640+
self.profile = profile
625641
self.channels = channels
626642
self.dms = dms
627643
# Subcribe to receive message from channels to select them

sclack/store.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def __init__(self):
1616
self.last_date = None
1717
self.did_render_new_messages = False
1818
self.online_users = set()
19+
self.is_snoozed = False
1920

2021
class Cache:
2122
def __init__(self):
@@ -112,6 +113,9 @@ def load_users(self):
112113
self._users_dict[user['profile']['bot_id']] = user
113114
self._users_dict[user['id']] = user
114115

116+
def load_user_dnd(self):
117+
self.state.is_snoozed = self.slack.api_call('dnd.info').get('snooze_enabled')
118+
115119
def set_topic(self, channel_id, topic):
116120
return self.slack.api_call('conversations.setTopic', channel=channel_id, topic=topic)
117121

0 commit comments

Comments
 (0)