Skip to content

Reading user "do not disturb" status #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down Expand Up @@ -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([{
Expand Down
1 change: 1 addition & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"private_channel": "\uF023",
"skype": "\uF17E",
"square": "\uF445",
"snooze": "\uF9B1",
"status": "\uF075",
"timezone": "\uF0AC"
}
Expand Down
24 changes: 20 additions & 4 deletions sclack/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions sclack/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand Down