From 0d930b0cbd41b4625eff3b8c5900ed52f4e7c1ed Mon Sep 17 00:00:00 2001 From: 2FWAH <36737818+2FWAH@users.noreply.github.com> Date: Fri, 23 Mar 2018 19:29:42 +0100 Subject: [PATCH 1/2] Add UserStatus class --- fbchat/models.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fbchat/models.py b/fbchat/models.py index 947d943d..4cdd9d36 100644 --- a/fbchat/models.py +++ b/fbchat/models.py @@ -494,3 +494,10 @@ class MessageReaction(Enum): ANGRY = '😠' YES = '👍' NO = '👎' + +class UserStatus(Enum): + """Define possible status for FB user""" + OFFLINE = 0 + IDLE = 1 + ACTIVE = 2 + MOBILE = 3 From a5480ca685b2572306d9fad680bfc8ec7d95aeb8 Mon Sep 17 00:00:00 2001 From: 2FWAH <36737818+2FWAH@users.noreply.github.com> Date: Fri, 23 Mar 2018 19:33:34 +0100 Subject: [PATCH 2/2] Add onBuddylistOverlay method --- fbchat/client.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/fbchat/client.py b/fbchat/client.py index 46981550..9f34a69d 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -1550,6 +1550,13 @@ def getThreadIdAndThreadType(msg_metadata): buddylist[_id] = payload.get('lat') self.onChatTimestamp(buddylist=buddylist, msg=m) + # Buddylist Overlay + elif mtype == "buddylist_overlay": + for user_id in m.get('overlay', {}): + status = UserStatus(m['overlay'][user_id]['a']) + last_active = m['overlay'][user_id]['la'] + self.onBuddylistOverlay(user_id=user_id, status=status, last_active=last_active, msg=m) + # Unknown message type else: self.onUnknownMesssageType(msg=m) @@ -1873,6 +1880,17 @@ def onChatTimestamp(self, buddylist=None, msg=None): """ log.debug('Chat Timestamps received: {}'.format(buddylist)) + def onBuddylistOverlay(self, user_id=None, status=None, last_active=None, msg=None): + """ + Called when the client receives a Buddylist Overlay message + + :param user_id: friend id + :param status: friend status + :param last_active: last seen timestamp + :param msg: A full set of the data recieved + """ + log.debug('Buddylist Overlay received: user_id = {}, status = {} and last_active = {}'.format(user_id, status, last_active)) + def onUnknownMesssageType(self, msg=None): """ Called when the client is listening, and some unknown data was recieved