diff --git a/fbchat/client.py b/fbchat/client.py index 2b20d69b..0d095ddd 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -1566,6 +1566,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) @@ -1889,6 +1896,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 diff --git a/fbchat/models.py b/fbchat/models.py index a3805991..b942b962 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