From 39079ea816e0c1547a372d9e557f556a92d45bd7 Mon Sep 17 00:00:00 2001 From: Ollie Terrance Date: Sat, 16 Apr 2016 12:02:12 +0100 Subject: [PATCH] Mark messages as read via consumption horizon --- skpy/chat.py | 13 +++++++++++++ skpy/event.py | 2 +- skpy/msg.py | 6 ++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/skpy/chat.py b/skpy/chat.py index f080d26..783a57b 100644 --- a/skpy/chat.py +++ b/skpy/chat.py @@ -192,6 +192,19 @@ def sendContacts(self, *contacts): content = """{0}""".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 ``,,`` + """ + 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. diff --git a/skpy/event.py b/skpy/event.py index 4ec4409..30e868e 100644 --- a/skpy/event.py +++ b/skpy/event.py @@ -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 ``,,``. """ attrs = SkypeEvent.attrs + ("chatId", "horizon") diff --git a/skpy/msg.py b/skpy/msg.py index 450eadd..d6dd2b1 100644 --- a/skpy/msg.py +++ b/skpy/msg.py @@ -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`.