Changed deleted to unsent

This commit is contained in:
Kacper Ziubryniewicz
2019-01-04 20:02:00 +01:00
parent 95989b6da7
commit 7b8ecf8fe3
3 changed files with 19 additions and 18 deletions

View File

@@ -2366,7 +2366,7 @@ class Client(object):
mid = i['messageID'] mid = i['messageID']
ts = i['deletionTimestamp'] ts = i['deletionTimestamp']
author_id = str(i['senderID']) author_id = str(i['senderID'])
self.onMessageDeleted(mid=mid, author_id=author_id, thread_id=thread_id, thread_type=thread_type, self.onMessageUnsent(mid=mid, author_id=author_id, thread_id=thread_id, thread_type=thread_type,
ts=ts, msg=m) ts=ts, msg=m)
# New message # New message
@@ -2380,7 +2380,7 @@ class Client(object):
sticker = None sticker = None
attachments = [] attachments = []
deleted = False unsent = False
if delta.get('attachments'): if delta.get('attachments'):
try: try:
for a in delta['attachments']: for a in delta['attachments']:
@@ -2400,8 +2400,8 @@ class Client(object):
elif mercury.get('extensible_attachment'): elif mercury.get('extensible_attachment'):
attachment = graphql_to_extensible_attachment(mercury['extensible_attachment']) attachment = graphql_to_extensible_attachment(mercury['extensible_attachment'])
if isinstance(attachment, DeletedMessage): if isinstance(attachment, UnsentMessage):
deleted = True unsent = True
elif attachment: elif attachment:
attachments.append(attachment) attachments.append(attachment)
@@ -2422,7 +2422,7 @@ class Client(object):
message.author = author_id message.author = author_id
message.timestamp = ts message.timestamp = ts
#message.reactions = {} #message.reactions = {}
message.deleted = deleted message.unsent = unsent
thread_id, thread_type = getThreadIdAndThreadType(metadata) thread_id, thread_type = getThreadIdAndThreadType(metadata)
self.onMessage(mid=mid, author_id=author_id, message=delta.get('body', ''), message_object=message, self.onMessage(mid=mid, author_id=author_id, message=delta.get('body', ''), message_object=message,
thread_id=thread_id, thread_type=thread_type, ts=ts, metadata=metadata, msg=m) thread_id=thread_id, thread_type=thread_type, ts=ts, metadata=metadata, msg=m)
@@ -2778,19 +2778,19 @@ class Client(object):
""" """
log.info("Marked messages as seen in threads {} at {}s".format([(x[0], x[1].name) for x in threads], seen_ts/1000)) log.info("Marked messages as seen in threads {} at {}s".format([(x[0], x[1].name) for x in threads], seen_ts/1000))
def onMessageDeleted(self, mid=None, author_id=None, thread_id=None, thread_type=None, ts=None, msg=None): def onMessageUnsent(self, mid=None, author_id=None, thread_id=None, thread_type=None, ts=None, msg=None):
""" """
Called when the client is listening, and someone unsends (deleted for everyone) a message Called when the client is listening, and someone unsends (deletes for everyone) a message
:param mid: ID of the deleted message :param mid: ID of the unsent message
:param author_id: The ID of the person who deleted the message :param author_id: The ID of the person who unsent the message
:param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads` :param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
:param thread_type: Type of thread that the action was sent to. See :ref:`intro_threads` :param thread_type: Type of thread that the action was sent to. See :ref:`intro_threads`
:param ts: A timestamp of the action :param ts: A timestamp of the action
:param msg: A full set of the data recieved :param msg: A full set of the data recieved
:type thread_type: models.ThreadType :type thread_type: models.ThreadType
""" """
log.info("{} unsended the message {} in {} ({}) at {}s".format(author_id, repr(mid), thread_id, thread_type.name, ts/1000)) log.info("{} unsent the message {} in {} ({}) at {}s".format(author_id, repr(mid), thread_id, thread_type.name, ts/1000))
def onPeopleAdded(self, mid=None, added_ids=None, author_id=None, thread_id=None, ts=None, msg=None): def onPeopleAdded(self, mid=None, added_ids=None, author_id=None, thread_id=None, ts=None, msg=None):
""" """

View File

@@ -178,7 +178,7 @@ def graphql_to_extensible_attachment(a):
attachments=[graphql_to_subattachment(attachment) for attachment in story.get('subattachments')], attachments=[graphql_to_subattachment(attachment) for attachment in story.get('subattachments')],
) )
else: else:
return DeletedMessage( return UnsentMessage(
uid=a.get('legacy_attachment_id'), uid=a.get('legacy_attachment_id'),
) )
@@ -282,6 +282,7 @@ def graphql_to_message(message):
rtn.uid = str(message.get('message_id')) rtn.uid = str(message.get('message_id'))
rtn.author = str(message.get('message_sender').get('id')) rtn.author = str(message.get('message_sender').get('id'))
rtn.timestamp = message.get('timestamp_precise') rtn.timestamp = message.get('timestamp_precise')
rtn.unsent = False
if message.get('unread') is not None: if message.get('unread') is not None:
rtn.is_read = not message['unread'] rtn.is_read = not message['unread']
rtn.reactions = {str(r['user']['id']):MessageReaction(r['reaction']) for r in message.get('message_reactions')} rtn.reactions = {str(r['user']['id']):MessageReaction(r['reaction']) for r in message.get('message_reactions')}
@@ -289,8 +290,8 @@ def graphql_to_message(message):
rtn.attachments = [graphql_to_attachment(attachment) for attachment in message['blob_attachments']] rtn.attachments = [graphql_to_attachment(attachment) for attachment in message['blob_attachments']]
if message.get('extensible_attachment') is not None: if message.get('extensible_attachment') is not None:
attachment = graphql_to_extensible_attachment(message['extensible_attachment']) attachment = graphql_to_extensible_attachment(message['extensible_attachment'])
if isinstance(attachment, DeletedMessage): if isinstance(attachment, UnsentMessage):
rtn.deleted = True rtn.unsent = True
elif attachment: elif attachment:
rtn.attachments.append(attachment) rtn.attachments.append(attachment)
return rtn return rtn

View File

@@ -190,8 +190,8 @@ class Message(object):
sticker = None sticker = None
#: A list of attachments #: A list of attachments
attachments = None attachments = None
#: Whether the message is deleted (unsended) #: Whether the message is unsent (deleted for everyone)
deleted = None unsent = None
def __init__(self, text=None, mentions=None, emoji_size=None, sticker=None, attachments=None): def __init__(self, text=None, mentions=None, emoji_size=None, sticker=None, attachments=None):
"""Represents a Facebook message""" """Represents a Facebook message"""
@@ -222,11 +222,11 @@ class Attachment(object):
"""Represents a Facebook attachment""" """Represents a Facebook attachment"""
self.uid = uid self.uid = uid
class DeletedMessage(Attachment): class UnsentMessage(Attachment):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
"""Represents a deleted message""" """Represents an unsent message attachment"""
super(DeletedMessage, self).__init__(*args, **kwargs) super(UnsentMessage, self).__init__(*args, **kwargs)
class Sticker(Attachment): class Sticker(Attachment):
#: The sticker-pack's ID #: The sticker-pack's ID