Remove MessageReaction
This commit is contained in:
@@ -28,8 +28,6 @@ Messages
|
|||||||
.. autoclass:: Mention
|
.. autoclass:: Mention
|
||||||
.. autoclass:: EmojiSize(Enum)
|
.. autoclass:: EmojiSize(Enum)
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
.. autoclass:: MessageReaction(Enum)
|
|
||||||
:undoc-members:
|
|
||||||
|
|
||||||
Exceptions
|
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,
|
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.
|
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::
|
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'))
|
message = thread.send_text("A message!")
|
||||||
client.react_to_message(message_id, MessageReaction.LOVE)
|
message.react("😍")
|
||||||
|
|
||||||
|
|
||||||
.. _intro_interacting:
|
.. _intro_interacting:
|
||||||
|
@@ -63,4 +63,4 @@ thread.set_emoji("👍")
|
|||||||
message = fbchat.Message(session=session, id="<message id>")
|
message = fbchat.Message(session=session, id="<message id>")
|
||||||
|
|
||||||
# Will react to a message with a 😍 emoji
|
# 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 ._user import TypingStatus, User, UserData, ActiveStatus
|
||||||
from ._group import Group, GroupData
|
from ._group import Group, GroupData
|
||||||
from ._page import Page, PageData
|
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 ._attachment import Attachment, UnsentMessage, ShareAttachment
|
||||||
from ._sticker import Sticker
|
from ._sticker import Sticker
|
||||||
from ._location import LocationAttachment, LiveLocationAttachment
|
from ._location import LocationAttachment, LiveLocationAttachment
|
||||||
|
@@ -10,7 +10,7 @@ from ._thread import ThreadLocation, ThreadColor
|
|||||||
from ._user import TypingStatus, User, UserData, ActiveStatus
|
from ._user import TypingStatus, User, UserData, ActiveStatus
|
||||||
from ._group import Group, GroupData
|
from ._group import Group, GroupData
|
||||||
from ._page import Page, PageData
|
from ._page import Page, PageData
|
||||||
from ._message import EmojiSize, MessageReaction, Mention, Message
|
from ._message import EmojiSize, Mention, Message
|
||||||
from ._attachment import Attachment
|
from ._attachment import Attachment
|
||||||
from ._sticker import Sticker
|
from ._sticker import Sticker
|
||||||
from ._location import LocationAttachment, LiveLocationAttachment
|
from ._location import LocationAttachment, LiveLocationAttachment
|
||||||
@@ -1259,14 +1259,11 @@ class Client:
|
|||||||
i = d["deltaMessageReaction"]
|
i = d["deltaMessageReaction"]
|
||||||
mid = i["messageId"]
|
mid = i["messageId"]
|
||||||
author_id = str(i["userId"])
|
author_id = str(i["userId"])
|
||||||
reaction = (
|
|
||||||
MessageReaction(i["reaction"]) if i.get("reaction") else None
|
|
||||||
)
|
|
||||||
add_reaction = not bool(i["action"])
|
add_reaction = not bool(i["action"])
|
||||||
if add_reaction:
|
if add_reaction:
|
||||||
self.on_reaction_added(
|
self.on_reaction_added(
|
||||||
mid=mid,
|
mid=mid,
|
||||||
reaction=reaction,
|
reaction=i.get("reaction"),
|
||||||
author_id=author_id,
|
author_id=author_id,
|
||||||
thread=get_thread(metadata),
|
thread=get_thread(metadata),
|
||||||
at=at,
|
at=at,
|
||||||
@@ -1855,7 +1852,7 @@ class Client:
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
mid: Message ID, that user reacted to
|
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
|
add_reaction: Whether user added or removed reaction
|
||||||
author_id: The ID of the person who reacted to the message
|
author_id: The ID of the person who reacted to the message
|
||||||
thread: Thread that the action was sent to. See :ref:`intro_threads`
|
thread: Thread that the action was sent to. See :ref:`intro_threads`
|
||||||
@@ -1863,7 +1860,7 @@ class Client:
|
|||||||
"""
|
"""
|
||||||
log.info(
|
log.info(
|
||||||
"{} reacted to message {} with {} in {}".format(
|
"{} 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
|
return None
|
||||||
|
|
||||||
|
|
||||||
class MessageReaction(Enum):
|
|
||||||
"""Used to specify a message reaction."""
|
|
||||||
|
|
||||||
HEART = "❤"
|
|
||||||
LOVE = "😍"
|
|
||||||
SMILE = "😆"
|
|
||||||
WOW = "😮"
|
|
||||||
SAD = "😢"
|
|
||||||
ANGRY = "😠"
|
|
||||||
YES = "👍"
|
|
||||||
NO = "👎"
|
|
||||||
|
|
||||||
|
|
||||||
@attrs_default
|
@attrs_default
|
||||||
class Mention:
|
class Mention:
|
||||||
"""Represents a ``@mention``."""
|
"""Represents a ``@mention``."""
|
||||||
@@ -74,6 +61,9 @@ class Mention:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SENDABLE_REACTIONS = ("❤", "😍", "😆", "😮", "😢", "😠", "👍", "👎")
|
||||||
|
|
||||||
|
|
||||||
@attrs_default
|
@attrs_default
|
||||||
class Message:
|
class Message:
|
||||||
"""Represents a Facebook message."""
|
"""Represents a Facebook message."""
|
||||||
@@ -93,18 +83,26 @@ class Message:
|
|||||||
data = {"message_id": self.id}
|
data = {"message_id": self.id}
|
||||||
j = self.session._payload_post("/messaging/unsend_message/?dpr=1", data)
|
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.
|
"""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:
|
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 = {
|
data = {
|
||||||
"action": "ADD_REACTION" if reaction else "REMOVE_REACTION",
|
"action": "ADD_REACTION" if reaction else "REMOVE_REACTION",
|
||||||
"client_mutation_id": "1",
|
"client_mutation_id": "1",
|
||||||
"actor_id": self.session.user_id,
|
"actor_id": self.session.user_id,
|
||||||
"message_id": self.id,
|
"message_id": self.id,
|
||||||
"reaction": reaction.value if reaction else None,
|
"reaction": reaction,
|
||||||
}
|
}
|
||||||
data = {
|
data = {
|
||||||
"doc_id": 1491398900900362,
|
"doc_id": 1491398900900362,
|
||||||
@@ -190,7 +188,7 @@ class MessageData(Message):
|
|||||||
is_read = attr.ib(None)
|
is_read = attr.ib(None)
|
||||||
#: A list of people IDs who read the message, works only with `Client.fetch_thread_messages`
|
#: A list of people IDs who read the message, works only with `Client.fetch_thread_messages`
|
||||||
read_by = attr.ib(factory=list)
|
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)
|
reactions = attr.ib(factory=dict)
|
||||||
#: A `Sticker`
|
#: A `Sticker`
|
||||||
sticker = attr.ib(None)
|
sticker = attr.ib(None)
|
||||||
@@ -266,8 +264,7 @@ class MessageData(Message):
|
|||||||
if _util.millis_to_datetime(int(receipt["watermark"])) >= created_at
|
if _util.millis_to_datetime(int(receipt["watermark"])) >= created_at
|
||||||
],
|
],
|
||||||
reactions={
|
reactions={
|
||||||
str(r["user"]["id"]): MessageReaction._extend_if_invalid(r["reaction"])
|
str(r["user"]["id"]): r["reaction"] for r in data["message_reactions"]
|
||||||
for r in data["message_reactions"]
|
|
||||||
},
|
},
|
||||||
sticker=_sticker.Sticker._from_graphql(data.get("sticker")),
|
sticker=_sticker.Sticker._from_graphql(data.get("sticker")),
|
||||||
attachments=attachments,
|
attachments=attachments,
|
||||||
|
@@ -1,16 +1,11 @@
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from fbchat import Message, MessageReaction
|
from fbchat import Message
|
||||||
from utils import subset
|
from utils import subset
|
||||||
|
|
||||||
pytestmark = pytest.mark.online
|
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):
|
def test_delete_messages(client):
|
||||||
text1 = "This message will stay"
|
text1 = "This message will stay"
|
||||||
text2 = "This message will be removed"
|
text2 = "This message will be removed"
|
||||||
|
Reference in New Issue
Block a user