From aca9176f7f3121ae356fd6b9361da20a97666602 Mon Sep 17 00:00:00 2001 From: Jarbas Date: Thu, 29 Jun 2017 17:56:14 +0100 Subject: [PATCH] Add on chat presence event Last_seen time stamps were handled in unknown message type, this info is freely available and potentially useful --- fbchat/client.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/fbchat/client.py b/fbchat/client.py index 4eb9360..4957a92 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -1355,7 +1355,7 @@ class Client(object): thread_id, thread_type = getThreadIdAndThreadType(metadata) self.onMessage(mid=mid, author_id=author_id, message=message, thread_id=thread_id, thread_type=thread_type, ts=ts, metadata=metadata, msg=m) - + # Unknown message type else: self.onUnknownMesssageType(msg=m) @@ -1388,7 +1388,16 @@ class Client(object): # Is sent before any other message elif mtype == "deltaflow": pass - + + # Chat timestamp + elif mtype == "chatproxy-presence": + buddyList = [] + for id in m.get("buddyList", {}).keys(): + payload = m["buddyList"][id] + timestamp = payload["lat"] + buddyList.append({id:timestamp}) + self.onChatTimestamp(buddylist=buddyList, msg=m) + # Unknown message type else: self.onUnknownMesssageType(msg=m) @@ -1676,7 +1685,15 @@ class Client(object): """ pass + def onChatTimestamp(self, buddylist={), msg={}): + """ + Called when the client receives chat online presence update + :param buddylist: A list of dicts with friend id and last seen timestamp + :param msg: A full set of the data recieved + """ + log.debug('Chat Timestamps received: {}'.format(buddylist)) + def onUnknownMesssageType(self, msg={}): """ Called when the client is listening, and some unknown data was recieved