Skip to content

Commit

Permalink
Mark messages as read via consumption horizon
Browse files Browse the repository at this point in the history
  • Loading branch information
Terrance committed Apr 16, 2016
1 parent 2364d93 commit 39079ea
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
13 changes: 13 additions & 0 deletions skpy/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,19 @@ def sendContacts(self, *contacts):
content = """<contacts>{0}</contacts>""".format("".join(contactTags))
return self.sendRaw(content=content, messagetype="RichText/Contacts")

def setConsumption(self, horizon):
"""
Update the user's consumption horizon for this conversation, i.e. where it has been read up to.
To consume up to a given message, call :meth:`.SkypeMsg.read` instead.
Args:
horizon (str): new horizon string, of the form ``<id>,<timestamp>,<id>``
"""
self.skype.conn("PUT", "{0}/users/ME/conversations/{1}/properties".format(self.skype.conn.msgsHost, self.id),
auth=SkypeConnection.Auth.RegToken, params={"name": "consumptionhorizon"},
json={"consumptionhorizon": horizon})

def delete(self):
"""
Delete the conversation and all message history.
Expand Down
2 changes: 1 addition & 1 deletion skpy/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ class SkypeChatUpdateEvent(SkypeEvent):
chat (:class:`.SkypeChat`):
Conversation that emitted an update.
horizon (str):
Raw list of timestamps, as provided by the API.
Updated horizon string, in the form ``<id>,<timestamp>,<id>``.
"""

attrs = SkypeEvent.attrs + ("chatId", "horizon")
Expand Down
6 changes: 6 additions & 0 deletions skpy/msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,12 @@ def plain(self, entities=False):
# It's already plain, or it's something we can't handle.
return self.content

def read(self):
"""
Mark this message as read by sending an updated consumption horizon.
"""
self.chat.setConsumption("{0};{1};{0}".format(self.clientId, int(time.time() * 1000)))

def edit(self, content, me=False, rich=False):
"""
Send an edit of this message. Arguments are passed to :meth:`.SkypeChat.sendMsg`.
Expand Down

0 comments on commit 39079ea

Please sign in to comment.