diff --git a/app.py b/app.py index f0f6779..e0e4082 100755 --- a/app.py +++ b/app.py @@ -132,9 +132,10 @@ def mount_sidebar(self, executor): loop.run_in_executor(executor, self.store.load_auth), loop.run_in_executor(executor, self.store.load_channels), loop.run_in_executor(executor, self.store.load_groups), - loop.run_in_executor(executor, self.store.load_users) + loop.run_in_executor(executor, self.store.load_users), + loop.run_in_executor(executor, self.store.load_user_dnd), ) - profile = Profile(name=self.store.state.auth['user']) + profile = Profile(name=self.store.state.auth['user'], is_snoozed=self.store.state.is_snoozed) channels = [ Channel( id=channel['id'], @@ -564,6 +565,9 @@ def stop_typing(*args): else: 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) elif event.get('ok', False): # Message was sent, Slack confirmed it. self.chatbox.body.body.extend(self.render_messages([{ diff --git a/config.json b/config.json index 6f83024..5657fe7 100644 --- a/config.json +++ b/config.json @@ -48,6 +48,7 @@ "private_channel": "\uF023", "skype": "\uF17E", "square": "\uF445", + "snooze": "\uF9B1", "status": "\uF075", "timezone": "\uF0AC" } diff --git a/sclack/components.py b/sclack/components.py index 7cfa321..3510a22 100644 --- a/sclack/components.py +++ b/sclack/components.py @@ -564,13 +564,28 @@ def keypress(self, size, key): return super(MessagePrompt, self).keypress(size, key) class Profile(urwid.Text): - def __init__(self, name, is_online=False): - if is_online: + def __init__(self, name, is_online=False, is_snoozed=False): + self.name = name + self.is_online = is_online + self.is_snoozed = is_snoozed + super(Profile, self).__init__(self.body) + + @property + def body(self): + if self.is_snoozed: + presence_icon = ('presence_active', ' {} '.format(get_icon('snooze'))) + elif self.is_online: presence_icon = ('presence_active', ' {} '.format(get_icon('online'))) else: presence_icon = ('presence_away', ' {} '.format(get_icon('offline'))) - body = [presence_icon, name] - super(Profile, self).__init__(body) + + snooze_str = ' (snoozed) ' if self.is_snoozed else '' + + return [presence_icon, self.name, snooze_str] + + def set_snooze(self, is_snoozed): + self.is_snoozed = is_snoozed + self.set_text(self.body) class ProfileSideBar(urwid.AttrWrap): def format_row(self, icon, text): @@ -622,6 +637,7 @@ class SideBar(urwid.Frame): signals = ['go_to_channel'] def __init__(self, profile, channels=[], dms=[], title=''): + self.profile = profile self.channels = channels self.dms = dms # Subcribe to receive message from channels to select them diff --git a/sclack/store.py b/sclack/store.py index 80b2a96..215bfb5 100644 --- a/sclack/store.py +++ b/sclack/store.py @@ -16,6 +16,7 @@ def __init__(self): self.last_date = None self.did_render_new_messages = False self.online_users = set() + self.is_snoozed = False class Cache: def __init__(self): @@ -112,6 +113,9 @@ def load_users(self): self._users_dict[user['profile']['bot_id']] = user self._users_dict[user['id']] = user + def load_user_dnd(self): + self.state.is_snoozed = self.slack.api_call('dnd.info').get('snooze_enabled') + def set_topic(self, channel_id, topic): return self.slack.api_call('conversations.setTopic', channel=channel_id, topic=topic)