Remove MessageReaction
This commit is contained in:
@@ -28,8 +28,6 @@ Messages
|
||||
.. autoclass:: Mention
|
||||
.. autoclass:: EmojiSize(Enum)
|
||||
:undoc-members:
|
||||
.. autoclass:: MessageReaction(Enum)
|
||||
:undoc-members:
|
||||
|
||||
Exceptions
|
||||
----------
|
||||
|
@@ -82,12 +82,10 @@ Message IDs
|
||||
Every message you send on Facebook has a unique ID, and every action you do in a thread,
|
||||
like changing a nickname or adding a person, has a unique ID too.
|
||||
|
||||
Some of ``fbchat``'s functions require these ID's, like `Client.react_to_message`,
|
||||
and some of then provide this ID, like `Client.send`.
|
||||
This snippet shows how to send a message, and then use the returned ID to react to that message with a 😍 emoji::
|
||||
|
||||
message_id = thread.send(Message(text='message'))
|
||||
client.react_to_message(message_id, MessageReaction.LOVE)
|
||||
message = thread.send_text("A message!")
|
||||
message.react("😍")
|
||||
|
||||
|
||||
.. _intro_interacting:
|
||||
|
@@ -63,4 +63,4 @@ thread.set_emoji("👍")
|
||||
message = fbchat.Message(session=session, id="<message id>")
|
||||
|
||||
# Will react to a message with a 😍 emoji
|
||||
message.react(fbchat.MessageReaction.LOVE)
|
||||
message.react("😍")
|
||||
|
@@ -18,7 +18,7 @@ from ._thread import ThreadLocation, ThreadColor, ThreadABC, Thread
|
||||
from ._user import TypingStatus, User, UserData, ActiveStatus
|
||||
from ._group import Group, GroupData
|
||||
from ._page import Page, PageData
|
||||
from ._message import EmojiSize, MessageReaction, Mention, Message
|
||||
from ._message import EmojiSize, Mention, Message
|
||||
from ._attachment import Attachment, UnsentMessage, ShareAttachment
|
||||
from ._sticker import Sticker
|
||||
from ._location import LocationAttachment, LiveLocationAttachment
|
||||
|
@@ -10,7 +10,7 @@ from ._thread import ThreadLocation, ThreadColor
|
||||
from ._user import TypingStatus, User, UserData, ActiveStatus
|
||||
from ._group import Group, GroupData
|
||||
from ._page import Page, PageData
|
||||
from ._message import EmojiSize, MessageReaction, Mention, Message
|
||||
from ._message import EmojiSize, Mention, Message
|
||||
from ._attachment import Attachment
|
||||
from ._sticker import Sticker
|
||||
from ._location import LocationAttachment, LiveLocationAttachment
|
||||
@@ -1259,14 +1259,11 @@ class Client:
|
||||
i = d["deltaMessageReaction"]
|
||||
mid = i["messageId"]
|
||||
author_id = str(i["userId"])
|
||||
reaction = (
|
||||
MessageReaction(i["reaction"]) if i.get("reaction") else None
|
||||
)
|
||||
add_reaction = not bool(i["action"])
|
||||
if add_reaction:
|
||||
self.on_reaction_added(
|
||||
mid=mid,
|
||||
reaction=reaction,
|
||||
reaction=i.get("reaction"),
|
||||
author_id=author_id,
|
||||
thread=get_thread(metadata),
|
||||
at=at,
|
||||
@@ -1855,7 +1852,7 @@ class Client:
|
||||
|
||||
Args:
|
||||
mid: Message ID, that user reacted to
|
||||
reaction (MessageReaction): Reaction
|
||||
reaction: The added reaction. Not limited to the ones in `Message.react`
|
||||
add_reaction: Whether user added or removed reaction
|
||||
author_id: The ID of the person who reacted to the message
|
||||
thread: Thread that the action was sent to. See :ref:`intro_threads`
|
||||
@@ -1863,7 +1860,7 @@ class Client:
|
||||
"""
|
||||
log.info(
|
||||
"{} reacted to message {} with {} in {}".format(
|
||||
author_id, mid, reaction.name, thread
|
||||
author_id, mid, reaction, thread
|
||||
)
|
||||
)
|
||||
|
||||
|
@@ -29,19 +29,6 @@ class EmojiSize(Enum):
|
||||
return None
|
||||
|
||||
|
||||
class MessageReaction(Enum):
|
||||
"""Used to specify a message reaction."""
|
||||
|
||||
HEART = "❤"
|
||||
LOVE = "😍"
|
||||
SMILE = "😆"
|
||||
WOW = "😮"
|
||||
SAD = "😢"
|
||||
ANGRY = "😠"
|
||||
YES = "👍"
|
||||
NO = "👎"
|
||||
|
||||
|
||||
@attrs_default
|
||||
class Mention:
|
||||
"""Represents a ``@mention``."""
|
||||
@@ -74,6 +61,9 @@ class Mention:
|
||||
}
|
||||
|
||||
|
||||
SENDABLE_REACTIONS = ("❤", "😍", "😆", "😮", "😢", "😠", "👍", "👎")
|
||||
|
||||
|
||||
@attrs_default
|
||||
class Message:
|
||||
"""Represents a Facebook message."""
|
||||
@@ -93,18 +83,26 @@ class Message:
|
||||
data = {"message_id": self.id}
|
||||
j = self.session._payload_post("/messaging/unsend_message/?dpr=1", data)
|
||||
|
||||
def react(self, reaction: Optional[MessageReaction]):
|
||||
def react(self, reaction: Optional[str]):
|
||||
"""React to the message, or removes reaction.
|
||||
|
||||
Currently, you can use "❤", "😍", "😆", "😮", "😢", "😠", "👍" or "👎". It
|
||||
should be possible to add support for more, but we haven't figured that out yet.
|
||||
|
||||
Args:
|
||||
reaction: Reaction emoji to use, if ``None`` removes reaction
|
||||
reaction: Reaction emoji to use, or if ``None``, removes reaction.
|
||||
"""
|
||||
if reaction and reaction not in SENDABLE_REACTIONS:
|
||||
raise ValueError(
|
||||
"Invalid reaction! Please use one of: {}".format(SENDABLE_REACTIONS)
|
||||
)
|
||||
|
||||
data = {
|
||||
"action": "ADD_REACTION" if reaction else "REMOVE_REACTION",
|
||||
"client_mutation_id": "1",
|
||||
"actor_id": self.session.user_id,
|
||||
"message_id": self.id,
|
||||
"reaction": reaction.value if reaction else None,
|
||||
"reaction": reaction,
|
||||
}
|
||||
data = {
|
||||
"doc_id": 1491398900900362,
|
||||
@@ -190,7 +188,7 @@ class MessageData(Message):
|
||||
is_read = attr.ib(None)
|
||||
#: A list of people IDs who read the message, works only with `Client.fetch_thread_messages`
|
||||
read_by = attr.ib(factory=list)
|
||||
#: A dictionary with user's IDs as keys, and their `MessageReaction` as values
|
||||
#: A dictionary with user's IDs as keys, and their reaction as values
|
||||
reactions = attr.ib(factory=dict)
|
||||
#: A `Sticker`
|
||||
sticker = attr.ib(None)
|
||||
@@ -266,8 +264,7 @@ class MessageData(Message):
|
||||
if _util.millis_to_datetime(int(receipt["watermark"])) >= created_at
|
||||
],
|
||||
reactions={
|
||||
str(r["user"]["id"]): MessageReaction._extend_if_invalid(r["reaction"])
|
||||
for r in data["message_reactions"]
|
||||
str(r["user"]["id"]): r["reaction"] for r in data["message_reactions"]
|
||||
},
|
||||
sticker=_sticker.Sticker._from_graphql(data.get("sticker")),
|
||||
attachments=attachments,
|
||||
|
@@ -1,16 +1,11 @@
|
||||
import pytest
|
||||
|
||||
from fbchat import Message, MessageReaction
|
||||
from fbchat import Message
|
||||
from utils import subset
|
||||
|
||||
pytestmark = pytest.mark.online
|
||||
|
||||
|
||||
def test_set_reaction(client):
|
||||
mid = client.send(Message(text="This message will be reacted to"))
|
||||
client.react_to_message(mid, MessageReaction.LOVE)
|
||||
|
||||
|
||||
def test_delete_messages(client):
|
||||
text1 = "This message will stay"
|
||||
text2 = "This message will be removed"
|
||||
|
Reference in New Issue
Block a user