Skip to content

Commit

Permalink
Command /m [name] to mark messages as read
Browse files Browse the repository at this point in the history
/m marks all messages as read, /m <name> marks all messages in group <name> as
read.
  • Loading branch information
vlasovskikh committed Mar 11, 2011
1 parent 6cad338 commit feb8a03
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
1 change: 0 additions & 1 deletion TODO.rst
Expand Up @@ -7,5 +7,4 @@ TODO List
- Colorize the output
- Group/topic autocompletion for ``/t``
- ``@username`` autocompletion
- A command to mark messages in topics/groups as read

17 changes: 17 additions & 0 deletions convoread/console.py
Expand Up @@ -148,12 +148,29 @@ def cmd_t(self, topic_id=None):
output(_format_message(message))


def cmd_m(self, group_slug=None):
try:
if group_slug:
groups = [g for g in self.convore.get_groups().values()
if g.get('slug') == group_slug]
if not groups:
error('group "{0}" not found'.format(group_slug))
return
group = groups[0]
self.convore.mark_group_read(group.get('id'))
else:
self.convore.mark_all_read()
except NetworkError, e:
error(unicode(e))


def cmd_help(self):
output('''\
commands:
/ts [name] list unread topics or topics in group <name>
/t [num] set the posting topic to <num> and list recent messages
/m [name] mark messages as read (all or in group <name>)
/help show help on commands
/q quit
<text> post a new message to the selected topic
Expand Down
17 changes: 17 additions & 0 deletions convoread/convore.py
Expand Up @@ -119,6 +119,23 @@ def close(self):
self._live.close()


@synchronized
def mark_all_read(self):
url = '/api/account/mark_read.json'
self._connection.request('POST', url)
for topic in self.get_topics().values():
topic['unread'] = 0


@synchronized
def mark_group_read(self, group_id):
url = '/api/groups/{0}/mark_read.json'.format(group_id)
self._connection.request('POST', url)
for topic in self.get_topics().values():
if topic.get('group') == group_id:
topic['unread'] = 0


@synchronized
def _handle_live_update(self, message):
if message.get('kind') != 'message':
Expand Down

0 comments on commit feb8a03

Please sign in to comment.