Refactor models file structure
This commit is contained in:
@@ -39,20 +39,34 @@ from ._threads import (
|
|||||||
Page,
|
Page,
|
||||||
PageData,
|
PageData,
|
||||||
)
|
)
|
||||||
from ._message import EmojiSize, Mention, Message, MessageData
|
|
||||||
from ._attachment import Attachment, UnsentMessage, ShareAttachment
|
# Models
|
||||||
from ._sticker import Sticker
|
from ._models import (
|
||||||
from ._location import LocationAttachment, LiveLocationAttachment
|
Attachment,
|
||||||
from ._file import FileAttachment, AudioAttachment, ImageAttachment, VideoAttachment
|
UnsentMessage,
|
||||||
from ._quick_reply import (
|
ShareAttachment,
|
||||||
|
LocationAttachment,
|
||||||
|
LiveLocationAttachment,
|
||||||
|
Sticker,
|
||||||
|
FileAttachment,
|
||||||
|
AudioAttachment,
|
||||||
|
ImageAttachment,
|
||||||
|
VideoAttachment,
|
||||||
|
Poll,
|
||||||
|
PollOption,
|
||||||
|
GuestStatus,
|
||||||
|
Plan,
|
||||||
|
PlanData,
|
||||||
QuickReply,
|
QuickReply,
|
||||||
QuickReplyText,
|
QuickReplyText,
|
||||||
QuickReplyLocation,
|
QuickReplyLocation,
|
||||||
QuickReplyPhoneNumber,
|
QuickReplyPhoneNumber,
|
||||||
QuickReplyEmail,
|
QuickReplyEmail,
|
||||||
|
EmojiSize,
|
||||||
|
Mention,
|
||||||
|
Message,
|
||||||
|
MessageData,
|
||||||
)
|
)
|
||||||
from ._poll import Poll, PollOption
|
|
||||||
from ._plan import GuestStatus, Plan, PlanData
|
|
||||||
|
|
||||||
# Events
|
# Events
|
||||||
from ._events import (
|
from ._events import (
|
||||||
|
@@ -2,7 +2,7 @@ import attr
|
|||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from ._common import log, attrs_default
|
from ._common import log, attrs_default
|
||||||
from . import _exception, _util, _graphql, _session, _threads, _message
|
from . import _exception, _util, _graphql, _session, _threads, _models
|
||||||
|
|
||||||
from typing import Sequence, Iterable, Tuple, Optional, Set
|
from typing import Sequence, Iterable, Tuple, Optional, Set
|
||||||
|
|
||||||
@@ -495,7 +495,7 @@ class Client:
|
|||||||
data = self._get_private_data()
|
data = self._get_private_data()
|
||||||
return [j["display_email"] for j in data["all_emails"]]
|
return [j["display_email"] for j in data["all_emails"]]
|
||||||
|
|
||||||
def mark_as_delivered(self, message: _message.Message):
|
def mark_as_delivered(self, message: _models.Message):
|
||||||
"""Mark a message as delivered.
|
"""Mark a message as delivered.
|
||||||
|
|
||||||
Warning:
|
Warning:
|
||||||
@@ -605,7 +605,7 @@ class Client:
|
|||||||
"/ajax/mercury/delete_threads.php?dpr=1", data_delete
|
"/ajax/mercury/delete_threads.php?dpr=1", data_delete
|
||||||
)
|
)
|
||||||
|
|
||||||
def delete_messages(self, messages: Iterable[_message.Message]):
|
def delete_messages(self, messages: Iterable[_models.Message]):
|
||||||
"""Bulk delete specified messages.
|
"""Bulk delete specified messages.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
@@ -6,7 +6,7 @@ from ._client_payload import *
|
|||||||
from ._delta_class import *
|
from ._delta_class import *
|
||||||
from ._delta_type import *
|
from ._delta_type import *
|
||||||
|
|
||||||
from .. import _exception, _util, _threads
|
from .. import _exception, _threads
|
||||||
|
|
||||||
from typing import Mapping
|
from typing import Mapping
|
||||||
|
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import attr
|
import attr
|
||||||
import datetime
|
import datetime
|
||||||
from ._common import attrs_event, UnknownEvent, ThreadEvent
|
from ._common import attrs_event, UnknownEvent, ThreadEvent
|
||||||
from .. import _exception, _util, _threads, _message
|
from .. import _exception, _util, _threads, _models
|
||||||
|
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ class ReactionEvent(ThreadEvent):
|
|||||||
"""Somebody reacted to a message."""
|
"""Somebody reacted to a message."""
|
||||||
|
|
||||||
#: Message that the user reacted to
|
#: Message that the user reacted to
|
||||||
message = attr.ib(type=_message.Message)
|
message = attr.ib(type="_models.Message")
|
||||||
|
|
||||||
reaction = attr.ib(type=Optional[str])
|
reaction = attr.ib(type=Optional[str])
|
||||||
"""The reaction.
|
"""The reaction.
|
||||||
@@ -27,7 +27,7 @@ class ReactionEvent(ThreadEvent):
|
|||||||
return cls(
|
return cls(
|
||||||
author=_threads.User(session=session, id=str(data["userId"])),
|
author=_threads.User(session=session, id=str(data["userId"])),
|
||||||
thread=thread,
|
thread=thread,
|
||||||
message=_message.Message(thread=thread, id=data["messageId"]),
|
message=_models.Message(thread=thread, id=data["messageId"]),
|
||||||
reaction=data["reaction"] if data["action"] == 0 else None,
|
reaction=data["reaction"] if data["action"] == 0 else None,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ class LiveLocationEvent(ThreadEvent):
|
|||||||
|
|
||||||
thread = cls._get_thread(session, data)
|
thread = cls._get_thread(session, data)
|
||||||
for location_data in data["messageLiveLocations"]:
|
for location_data in data["messageLiveLocations"]:
|
||||||
message = _message.Message(thread=thread, id=data["messageId"])
|
message = _models.Message(thread=thread, id=data["messageId"])
|
||||||
author = _threads.User(session=session, id=str(location_data["senderId"]))
|
author = _threads.User(session=session, id=str(location_data["senderId"]))
|
||||||
location = _location.LiveLocationAttachment._from_pull(location_data)
|
location = _location.LiveLocationAttachment._from_pull(location_data)
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@ class UnsendEvent(ThreadEvent):
|
|||||||
"""Somebody unsent a message (which deletes it for everyone)."""
|
"""Somebody unsent a message (which deletes it for everyone)."""
|
||||||
|
|
||||||
#: The unsent message
|
#: The unsent message
|
||||||
message = attr.ib(type=_message.Message)
|
message = attr.ib(type="_models.Message")
|
||||||
#: When the message was unsent
|
#: When the message was unsent
|
||||||
at = attr.ib(type=datetime.datetime)
|
at = attr.ib(type=datetime.datetime)
|
||||||
|
|
||||||
@@ -80,7 +80,7 @@ class UnsendEvent(ThreadEvent):
|
|||||||
return cls(
|
return cls(
|
||||||
author=_threads.User(session=session, id=str(data["senderID"])),
|
author=_threads.User(session=session, id=str(data["senderID"])),
|
||||||
thread=thread,
|
thread=thread,
|
||||||
message=_message.Message(thread=thread, id=data["messageID"]),
|
message=_models.Message(thread=thread, id=data["messageID"]),
|
||||||
at=_util.millis_to_datetime(data["deletionTimestamp"]),
|
at=_util.millis_to_datetime(data["deletionTimestamp"]),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -90,9 +90,9 @@ class MessageReplyEvent(ThreadEvent):
|
|||||||
"""Somebody replied to a message."""
|
"""Somebody replied to a message."""
|
||||||
|
|
||||||
#: The sent message
|
#: The sent message
|
||||||
message = attr.ib(type=_message.MessageData)
|
message = attr.ib(type="_models.MessageData")
|
||||||
#: The message that was replied to
|
#: The message that was replied to
|
||||||
replied_to = attr.ib(type=_message.MessageData)
|
replied_to = attr.ib(type="_models.MessageData")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _parse(cls, session, data):
|
def _parse(cls, session, data):
|
||||||
@@ -101,8 +101,8 @@ class MessageReplyEvent(ThreadEvent):
|
|||||||
return cls(
|
return cls(
|
||||||
author=_threads.User(session=session, id=str(metadata["actorFbId"])),
|
author=_threads.User(session=session, id=str(metadata["actorFbId"])),
|
||||||
thread=thread,
|
thread=thread,
|
||||||
message=_message.MessageData._from_reply(thread, data["message"]),
|
message=_models.MessageData._from_reply(thread, data["message"]),
|
||||||
replied_to=_message.MessageData._from_reply(
|
replied_to=_models.MessageData._from_reply(
|
||||||
thread, data["repliedToMessage"]
|
thread, data["repliedToMessage"]
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import attr
|
import attr
|
||||||
import abc
|
import abc
|
||||||
from .._common import kw_only
|
from .._common import kw_only
|
||||||
from .. import _exception, _util, _threads, _message
|
from .. import _exception, _util, _threads
|
||||||
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import attr
|
import attr
|
||||||
import datetime
|
import datetime
|
||||||
from ._common import attrs_event, Event, UnknownEvent, ThreadEvent
|
from ._common import attrs_event, Event, UnknownEvent, ThreadEvent
|
||||||
from .. import _util, _threads, _message
|
from .. import _util, _threads, _models
|
||||||
|
|
||||||
from typing import Sequence, Optional
|
from typing import Sequence, Optional
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ class PersonRemoved(ThreadEvent):
|
|||||||
|
|
||||||
thread = attr.ib(type="_threads.Group") # Set the correct type
|
thread = attr.ib(type="_threads.Group") # Set the correct type
|
||||||
#: Person who got removed
|
#: Person who got removed
|
||||||
removed = attr.ib(type=_message.Message)
|
removed = attr.ib(type="_models.Message")
|
||||||
#: When the person were removed
|
#: When the person were removed
|
||||||
at = attr.ib(type=datetime.datetime)
|
at = attr.ib(type=datetime.datetime)
|
||||||
|
|
||||||
@@ -79,14 +79,14 @@ class UnfetchedThreadEvent(Event):
|
|||||||
#: The thread the message was sent to
|
#: The thread the message was sent to
|
||||||
thread = attr.ib(type="_threads.ThreadABC")
|
thread = attr.ib(type="_threads.ThreadABC")
|
||||||
#: The message
|
#: The message
|
||||||
message = attr.ib(type=Optional[_message.Message])
|
message = attr.ib(type=Optional["_models.Message"])
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _parse(cls, session, data):
|
def _parse(cls, session, data):
|
||||||
thread = ThreadEvent._get_thread(session, data)
|
thread = ThreadEvent._get_thread(session, data)
|
||||||
message = None
|
message = None
|
||||||
if "messageId" in data:
|
if "messageId" in data:
|
||||||
message = _message.Message(thread=thread, id=data["messageId"])
|
message = _models.Message(thread=thread, id=data["messageId"])
|
||||||
return cls(thread=thread, message=message)
|
return cls(thread=thread, message=message)
|
||||||
|
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ class MessagesDelivered(ThreadEvent):
|
|||||||
"""Somebody marked messages as delivered in a thread."""
|
"""Somebody marked messages as delivered in a thread."""
|
||||||
|
|
||||||
#: The messages that were marked as delivered
|
#: The messages that were marked as delivered
|
||||||
messages = attr.ib(type=Sequence[_message.Message])
|
messages = attr.ib(type=Sequence["_models.Message"])
|
||||||
#: When the messages were delivered
|
#: When the messages were delivered
|
||||||
at = attr.ib(type=datetime.datetime)
|
at = attr.ib(type=datetime.datetime)
|
||||||
|
|
||||||
@@ -106,7 +106,7 @@ class MessagesDelivered(ThreadEvent):
|
|||||||
author = _threads.User(session=session, id=data["actorFbId"])
|
author = _threads.User(session=session, id=data["actorFbId"])
|
||||||
else:
|
else:
|
||||||
author = thread
|
author = thread
|
||||||
messages = [_message.Message(thread=thread, id=x) for x in data["messageIds"]]
|
messages = [_models.Message(thread=thread, id=x) for x in data["messageIds"]]
|
||||||
at = _util.millis_to_datetime(int(data["deliveredWatermarkTimestampMs"]))
|
at = _util.millis_to_datetime(int(data["deliveredWatermarkTimestampMs"]))
|
||||||
return cls(author=author, thread=thread, messages=messages, at=at)
|
return cls(author=author, thread=thread, messages=messages, at=at)
|
||||||
|
|
||||||
@@ -145,14 +145,14 @@ class MessageEvent(ThreadEvent):
|
|||||||
"""Somebody sent a message to a thread."""
|
"""Somebody sent a message to a thread."""
|
||||||
|
|
||||||
#: The sent message
|
#: The sent message
|
||||||
message = attr.ib(type=_message.Message)
|
message = attr.ib(type="_models.Message")
|
||||||
#: When the threads were read
|
#: When the threads were read
|
||||||
at = attr.ib(type=datetime.datetime)
|
at = attr.ib(type=datetime.datetime)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _parse(cls, session, data):
|
def _parse(cls, session, data):
|
||||||
author, thread, at = cls._parse_metadata(session, data)
|
author, thread, at = cls._parse_metadata(session, data)
|
||||||
message = _message.MessageData._from_pull(
|
message = _models.MessageData._from_pull(
|
||||||
thread, data, author=author.id, created_at=at,
|
thread, data, author=author.id, created_at=at,
|
||||||
)
|
)
|
||||||
return cls(author=author, thread=thread, message=message, at=at)
|
return cls(author=author, thread=thread, message=message, at=at)
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import attr
|
import attr
|
||||||
import datetime
|
import datetime
|
||||||
from ._common import attrs_event, Event, UnknownEvent, ThreadEvent
|
from ._common import attrs_event, Event, UnknownEvent, ThreadEvent
|
||||||
from .. import _util, _threads, _poll, _plan
|
from .. import _util, _threads, _models
|
||||||
|
|
||||||
from typing import Sequence, Optional
|
from typing import Sequence, Optional
|
||||||
|
|
||||||
@@ -155,7 +155,7 @@ class PollCreated(ThreadEvent):
|
|||||||
"""Somebody created a group poll."""
|
"""Somebody created a group poll."""
|
||||||
|
|
||||||
#: The new poll
|
#: The new poll
|
||||||
poll = attr.ib(type=_poll.Poll)
|
poll = attr.ib(type="_models.Poll")
|
||||||
#: When the poll was created
|
#: When the poll was created
|
||||||
at = attr.ib(type=datetime.datetime)
|
at = attr.ib(type=datetime.datetime)
|
||||||
|
|
||||||
@@ -163,7 +163,7 @@ class PollCreated(ThreadEvent):
|
|||||||
def _parse(cls, session, data):
|
def _parse(cls, session, data):
|
||||||
author, thread, at = cls._parse_metadata(session, data)
|
author, thread, at = cls._parse_metadata(session, data)
|
||||||
poll_data = _util.parse_json(data["untypedData"]["question_json"])
|
poll_data = _util.parse_json(data["untypedData"]["question_json"])
|
||||||
poll = _poll.Poll._from_graphql(session, poll_data)
|
poll = _models.Poll._from_graphql(session, poll_data)
|
||||||
return cls(author=author, thread=thread, poll=poll, at=at)
|
return cls(author=author, thread=thread, poll=poll, at=at)
|
||||||
|
|
||||||
|
|
||||||
@@ -172,7 +172,7 @@ class PollVoted(ThreadEvent):
|
|||||||
"""Somebody voted in a group poll."""
|
"""Somebody voted in a group poll."""
|
||||||
|
|
||||||
#: The updated poll
|
#: The updated poll
|
||||||
poll = attr.ib(type=_poll.Poll)
|
poll = attr.ib(type="_models.Poll")
|
||||||
#: Ids of the voted options
|
#: Ids of the voted options
|
||||||
added_ids = attr.ib(type=Sequence[str])
|
added_ids = attr.ib(type=Sequence[str])
|
||||||
#: Ids of the un-voted options
|
#: Ids of the un-voted options
|
||||||
@@ -184,7 +184,7 @@ class PollVoted(ThreadEvent):
|
|||||||
def _parse(cls, session, data):
|
def _parse(cls, session, data):
|
||||||
author, thread, at = cls._parse_metadata(session, data)
|
author, thread, at = cls._parse_metadata(session, data)
|
||||||
poll_data = _util.parse_json(data["untypedData"]["question_json"])
|
poll_data = _util.parse_json(data["untypedData"]["question_json"])
|
||||||
poll = _poll.Poll._from_graphql(session, poll_data)
|
poll = _models.Poll._from_graphql(session, poll_data)
|
||||||
added_ids = _util.parse_json(data["untypedData"]["added_option_ids"])
|
added_ids = _util.parse_json(data["untypedData"]["added_option_ids"])
|
||||||
removed_ids = _util.parse_json(data["untypedData"]["removed_option_ids"])
|
removed_ids = _util.parse_json(data["untypedData"]["removed_option_ids"])
|
||||||
return cls(
|
return cls(
|
||||||
@@ -202,14 +202,14 @@ class PlanCreated(ThreadEvent):
|
|||||||
"""Somebody created a plan in a group."""
|
"""Somebody created a plan in a group."""
|
||||||
|
|
||||||
#: The new plan
|
#: The new plan
|
||||||
plan = attr.ib(type=_plan.PlanData)
|
plan = attr.ib(type="_models.PlanData")
|
||||||
#: When the plan was created
|
#: When the plan was created
|
||||||
at = attr.ib(type=datetime.datetime)
|
at = attr.ib(type=datetime.datetime)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _parse(cls, session, data):
|
def _parse(cls, session, data):
|
||||||
author, thread, at = cls._parse_metadata(session, data)
|
author, thread, at = cls._parse_metadata(session, data)
|
||||||
plan = _plan.PlanData._from_pull(session, data["untypedData"])
|
plan = _models.PlanData._from_pull(session, data["untypedData"])
|
||||||
return cls(author=author, thread=thread, plan=plan, at=at)
|
return cls(author=author, thread=thread, plan=plan, at=at)
|
||||||
|
|
||||||
|
|
||||||
@@ -218,14 +218,14 @@ class PlanEnded(ThreadEvent):
|
|||||||
"""A plan ended."""
|
"""A plan ended."""
|
||||||
|
|
||||||
#: The ended plan
|
#: The ended plan
|
||||||
plan = attr.ib(type=_plan.PlanData)
|
plan = attr.ib(type="_models.PlanData")
|
||||||
#: When the plan ended
|
#: When the plan ended
|
||||||
at = attr.ib(type=datetime.datetime)
|
at = attr.ib(type=datetime.datetime)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _parse(cls, session, data):
|
def _parse(cls, session, data):
|
||||||
author, thread, at = cls._parse_metadata(session, data)
|
author, thread, at = cls._parse_metadata(session, data)
|
||||||
plan = _plan.PlanData._from_pull(session, data["untypedData"])
|
plan = _models.PlanData._from_pull(session, data["untypedData"])
|
||||||
return cls(author=author, thread=thread, plan=plan, at=at)
|
return cls(author=author, thread=thread, plan=plan, at=at)
|
||||||
|
|
||||||
|
|
||||||
@@ -234,14 +234,14 @@ class PlanEdited(ThreadEvent):
|
|||||||
"""Somebody changed a plan in a group."""
|
"""Somebody changed a plan in a group."""
|
||||||
|
|
||||||
#: The updated plan
|
#: The updated plan
|
||||||
plan = attr.ib(type=_plan.PlanData)
|
plan = attr.ib(type="_models.PlanData")
|
||||||
#: When the plan was updated
|
#: When the plan was updated
|
||||||
at = attr.ib(type=datetime.datetime)
|
at = attr.ib(type=datetime.datetime)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _parse(cls, session, data):
|
def _parse(cls, session, data):
|
||||||
author, thread, at = cls._parse_metadata(session, data)
|
author, thread, at = cls._parse_metadata(session, data)
|
||||||
plan = _plan.PlanData._from_pull(session, data["untypedData"])
|
plan = _models.PlanData._from_pull(session, data["untypedData"])
|
||||||
return cls(author=author, thread=thread, plan=plan, at=at)
|
return cls(author=author, thread=thread, plan=plan, at=at)
|
||||||
|
|
||||||
|
|
||||||
@@ -250,14 +250,14 @@ class PlanDeleted(ThreadEvent):
|
|||||||
"""Somebody removed a plan in a group."""
|
"""Somebody removed a plan in a group."""
|
||||||
|
|
||||||
#: The removed plan
|
#: The removed plan
|
||||||
plan = attr.ib(type=_plan.PlanData)
|
plan = attr.ib(type="_models.PlanData")
|
||||||
#: When the plan was removed
|
#: When the plan was removed
|
||||||
at = attr.ib(type=datetime.datetime)
|
at = attr.ib(type=datetime.datetime)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _parse(cls, session, data):
|
def _parse(cls, session, data):
|
||||||
author, thread, at = cls._parse_metadata(session, data)
|
author, thread, at = cls._parse_metadata(session, data)
|
||||||
plan = _plan.PlanData._from_pull(session, data["untypedData"])
|
plan = _models.PlanData._from_pull(session, data["untypedData"])
|
||||||
return cls(author=author, thread=thread, plan=plan, at=at)
|
return cls(author=author, thread=thread, plan=plan, at=at)
|
||||||
|
|
||||||
|
|
||||||
@@ -266,7 +266,7 @@ class PlanResponded(ThreadEvent):
|
|||||||
"""Somebody responded to a plan in a group."""
|
"""Somebody responded to a plan in a group."""
|
||||||
|
|
||||||
#: The plan that was responded to
|
#: The plan that was responded to
|
||||||
plan = attr.ib(type=_plan.PlanData)
|
plan = attr.ib(type="_models.PlanData")
|
||||||
#: Whether the author will go to the plan or not
|
#: Whether the author will go to the plan or not
|
||||||
take_part = attr.ib(type=bool)
|
take_part = attr.ib(type=bool)
|
||||||
#: When the plan was removed
|
#: When the plan was removed
|
||||||
@@ -275,7 +275,7 @@ class PlanResponded(ThreadEvent):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def _parse(cls, session, data):
|
def _parse(cls, session, data):
|
||||||
author, thread, at = cls._parse_metadata(session, data)
|
author, thread, at = cls._parse_metadata(session, data)
|
||||||
plan = _plan.PlanData._from_pull(session, data["untypedData"])
|
plan = _models.PlanData._from_pull(session, data["untypedData"])
|
||||||
take_part = data["untypedData"]["guest_status"] == "GOING"
|
take_part = data["untypedData"]["guest_status"] == "GOING"
|
||||||
return cls(author=author, thread=thread, plan=plan, take_part=take_part, at=at)
|
return cls(author=author, thread=thread, plan=plan, take_part=take_part, at=at)
|
||||||
|
|
||||||
|
8
fbchat/_models/__init__.py
Normal file
8
fbchat/_models/__init__.py
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
from ._attachment import *
|
||||||
|
from ._file import *
|
||||||
|
from ._location import *
|
||||||
|
from ._plan import *
|
||||||
|
from ._poll import *
|
||||||
|
from ._quick_reply import *
|
||||||
|
from ._sticker import *
|
||||||
|
from ._message import *
|
@@ -1,6 +1,6 @@
|
|||||||
import attr
|
import attr
|
||||||
from ._common import attrs_default, Image
|
from .._common import attrs_default, Image
|
||||||
from . import _util
|
from .. import _util
|
||||||
|
|
||||||
from typing import Sequence
|
from typing import Sequence
|
||||||
|
|
@@ -1,8 +1,8 @@
|
|||||||
import attr
|
import attr
|
||||||
import datetime
|
import datetime
|
||||||
from ._common import attrs_default, Image
|
|
||||||
from . import _util
|
|
||||||
from ._attachment import Attachment
|
from ._attachment import Attachment
|
||||||
|
from .._common import attrs_default, Image
|
||||||
|
from .. import _util
|
||||||
|
|
||||||
from typing import Set
|
from typing import Set
|
||||||
|
|
@@ -1,7 +1,7 @@
|
|||||||
import attr
|
import attr
|
||||||
from ._common import attrs_default, Image
|
|
||||||
from ._attachment import Attachment
|
from ._attachment import Attachment
|
||||||
from . import _util
|
from .._common import attrs_default, Image
|
||||||
|
from .. import _util
|
||||||
|
|
||||||
|
|
||||||
@attrs_default
|
@attrs_default
|
@@ -2,18 +2,9 @@ import attr
|
|||||||
import datetime
|
import datetime
|
||||||
import enum
|
import enum
|
||||||
from string import Formatter
|
from string import Formatter
|
||||||
from ._common import log, attrs_default
|
from . import _attachment, _location, _file, _quick_reply, _sticker
|
||||||
from . import (
|
from .._common import log, attrs_default
|
||||||
_exception,
|
from .. import _exception, _util, _session, _threads
|
||||||
_util,
|
|
||||||
_session,
|
|
||||||
_attachment,
|
|
||||||
_location,
|
|
||||||
_file,
|
|
||||||
_quick_reply,
|
|
||||||
_sticker,
|
|
||||||
_threads,
|
|
||||||
)
|
|
||||||
from typing import Optional, Mapping, Sequence
|
from typing import Optional, Mapping, Sequence
|
||||||
|
|
||||||
|
|
@@ -1,8 +1,8 @@
|
|||||||
import attr
|
import attr
|
||||||
import datetime
|
import datetime
|
||||||
import enum
|
import enum
|
||||||
from ._common import attrs_default
|
from .._common import attrs_default
|
||||||
from . import _exception, _util, _session
|
from .. import _exception, _util, _session
|
||||||
|
|
||||||
from typing import Mapping, Sequence
|
from typing import Mapping, Sequence
|
||||||
|
|
@@ -1,6 +1,6 @@
|
|||||||
import attr
|
import attr
|
||||||
from ._common import attrs_default
|
from .._common import attrs_default
|
||||||
from . import _exception, _session
|
from .. import _exception, _session
|
||||||
from typing import Iterable, Sequence
|
from typing import Iterable, Sequence
|
||||||
|
|
||||||
|
|
@@ -1,6 +1,6 @@
|
|||||||
import attr
|
import attr
|
||||||
from ._common import attrs_default
|
|
||||||
from ._attachment import Attachment
|
from ._attachment import Attachment
|
||||||
|
from .._common import attrs_default
|
||||||
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
@@ -1,6 +1,6 @@
|
|||||||
import attr
|
import attr
|
||||||
from ._common import attrs_default, Image
|
|
||||||
from ._attachment import Attachment
|
from ._attachment import Attachment
|
||||||
|
from .._common import attrs_default, Image
|
||||||
|
|
||||||
|
|
||||||
@attrs_default
|
@attrs_default
|
@@ -4,16 +4,7 @@ import collections
|
|||||||
import datetime
|
import datetime
|
||||||
import enum
|
import enum
|
||||||
from .._common import log, attrs_default, Image
|
from .._common import log, attrs_default, Image
|
||||||
from .. import (
|
from .. import _util, _exception, _session, _graphql, _models
|
||||||
_util,
|
|
||||||
_exception,
|
|
||||||
_session,
|
|
||||||
_graphql,
|
|
||||||
_attachment,
|
|
||||||
_file,
|
|
||||||
_plan,
|
|
||||||
_message,
|
|
||||||
)
|
|
||||||
from typing import MutableMapping, Mapping, Any, Iterable, Tuple, Optional
|
from typing import MutableMapping, Mapping, Any, Iterable, Tuple, Optional
|
||||||
|
|
||||||
|
|
||||||
@@ -111,7 +102,7 @@ class ThreadABC(metaclass=abc.ABCMeta):
|
|||||||
def send_text(
|
def send_text(
|
||||||
self,
|
self,
|
||||||
text: str,
|
text: str,
|
||||||
mentions: Iterable["_message.Mention"] = None,
|
mentions: Iterable["_models.Mention"] = None,
|
||||||
files: Iterable[Tuple[str, str]] = None,
|
files: Iterable[Tuple[str, str]] = None,
|
||||||
reply_to_id: str = None,
|
reply_to_id: str = None,
|
||||||
) -> str:
|
) -> str:
|
||||||
@@ -149,7 +140,7 @@ class ThreadABC(metaclass=abc.ABCMeta):
|
|||||||
|
|
||||||
return self.session._do_send_request(data)
|
return self.session._do_send_request(data)
|
||||||
|
|
||||||
def send_emoji(self, emoji: str, size: "_message.EmojiSize") -> str:
|
def send_emoji(self, emoji: str, size: "_models.EmojiSize") -> str:
|
||||||
"""Send an emoji to the thread.
|
"""Send an emoji to the thread.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -316,14 +307,14 @@ class ThreadABC(metaclass=abc.ABCMeta):
|
|||||||
# For now, we just create a new thread:
|
# For now, we just create a new thread:
|
||||||
thread = self.__class__(session=self.session, id=self.id)
|
thread = self.__class__(session=self.session, id=self.id)
|
||||||
snippets = [
|
snippets = [
|
||||||
_message.MessageSnippet._parse(thread, snippet)
|
_models.MessageSnippet._parse(thread, snippet)
|
||||||
for snippet in result["snippets"]
|
for snippet in result["snippets"]
|
||||||
]
|
]
|
||||||
return (result["num_total_snippets"], snippets)
|
return (result["num_total_snippets"], snippets)
|
||||||
|
|
||||||
def search_messages(
|
def search_messages(
|
||||||
self, query: str, limit: int
|
self, query: str, limit: int
|
||||||
) -> Iterable["_message.MessageSnippet"]:
|
) -> Iterable["_models.MessageSnippet"]:
|
||||||
"""Find and get message IDs by query.
|
"""Find and get message IDs by query.
|
||||||
|
|
||||||
Warning! If someone send a message to the thread that matches the query, while
|
Warning! If someone send a message to the thread that matches the query, while
|
||||||
@@ -378,11 +369,11 @@ class ThreadABC(metaclass=abc.ABCMeta):
|
|||||||
# For now, we just create a new thread:
|
# For now, we just create a new thread:
|
||||||
thread = self.__class__(session=self.session, id=self.id)
|
thread = self.__class__(session=self.session, id=self.id)
|
||||||
return [
|
return [
|
||||||
_message.MessageData._from_graphql(thread, message, read_receipts)
|
_models.MessageData._from_graphql(thread, message, read_receipts)
|
||||||
for message in j["message_thread"]["messages"]["nodes"]
|
for message in j["message_thread"]["messages"]["nodes"]
|
||||||
]
|
]
|
||||||
|
|
||||||
def fetch_messages(self, limit: Optional[int]) -> Iterable["_message.Message"]:
|
def fetch_messages(self, limit: Optional[int]) -> Iterable["_models.Message"]:
|
||||||
"""Fetch messages in a thread.
|
"""Fetch messages in a thread.
|
||||||
|
|
||||||
The returned messages are ordered by most recent first.
|
The returned messages are ordered by most recent first.
|
||||||
@@ -437,9 +428,9 @@ class ThreadABC(metaclass=abc.ABCMeta):
|
|||||||
node = edge["node"]
|
node = edge["node"]
|
||||||
type_ = node["__typename"]
|
type_ = node["__typename"]
|
||||||
if type_ == "MessageImage":
|
if type_ == "MessageImage":
|
||||||
rtn.append(_file.ImageAttachment._from_list(node))
|
rtn.append(_models.ImageAttachment._from_list(node))
|
||||||
elif type_ == "MessageVideo":
|
elif type_ == "MessageVideo":
|
||||||
rtn.append(_file.VideoAttachment._from_list(node))
|
rtn.append(_models.VideoAttachment._from_list(node))
|
||||||
else:
|
else:
|
||||||
log.warning("Unknown image type %s, data: %s", type_, edge)
|
log.warning("Unknown image type %s, data: %s", type_, edge)
|
||||||
rtn.append(None)
|
rtn.append(None)
|
||||||
@@ -447,7 +438,7 @@ class ThreadABC(metaclass=abc.ABCMeta):
|
|||||||
# result["page_info"]["has_next_page"] is not correct when limit > 12
|
# result["page_info"]["has_next_page"] is not correct when limit > 12
|
||||||
return (result["page_info"]["end_cursor"], rtn)
|
return (result["page_info"]["end_cursor"], rtn)
|
||||||
|
|
||||||
def fetch_images(self, limit: Optional[int]) -> Iterable[_attachment.Attachment]:
|
def fetch_images(self, limit: Optional[int]) -> Iterable["_models.Attachment"]:
|
||||||
"""Fetch images/videos posted in the thread.
|
"""Fetch images/videos posted in the thread.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -618,7 +609,7 @@ class ThreadABC(metaclass=abc.ABCMeta):
|
|||||||
Example:
|
Example:
|
||||||
>>> thread.create_plan(...)
|
>>> thread.create_plan(...)
|
||||||
"""
|
"""
|
||||||
return _plan.Plan._create(self, name, at, location_name, location_id)
|
return _models.Plan._create(self, name, at, location_name, location_id)
|
||||||
|
|
||||||
def create_poll(self, question: str, options=Mapping[str, bool]):
|
def create_poll(self, question: str, options=Mapping[str, bool]):
|
||||||
"""Create poll in a thread.
|
"""Create poll in a thread.
|
||||||
|
@@ -3,7 +3,7 @@ import datetime
|
|||||||
from ._abc import ThreadABC
|
from ._abc import ThreadABC
|
||||||
from . import _user
|
from . import _user
|
||||||
from .._common import attrs_default, Image
|
from .._common import attrs_default, Image
|
||||||
from .. import _util, _session, _graphql, _plan
|
from .. import _util, _session, _graphql, _models
|
||||||
from typing import Sequence, Iterable, Set, Mapping
|
from typing import Sequence, Iterable, Set, Mapping
|
||||||
|
|
||||||
|
|
||||||
@@ -184,7 +184,7 @@ class GroupData(Group):
|
|||||||
#: Number of messages in the group
|
#: Number of messages in the group
|
||||||
message_count = attr.ib(None, type=int)
|
message_count = attr.ib(None, type=int)
|
||||||
#: Set `Plan`
|
#: Set `Plan`
|
||||||
plan = attr.ib(None, type=_plan.PlanData)
|
plan = attr.ib(None, type="_models.PlanData")
|
||||||
#: The group thread's participant user ids
|
#: The group thread's participant user ids
|
||||||
participants = attr.ib(factory=set, type=Set[str])
|
participants = attr.ib(factory=set, type=Set[str])
|
||||||
#: A dictionary, containing user nicknames mapped to their IDs
|
#: A dictionary, containing user nicknames mapped to their IDs
|
||||||
@@ -214,7 +214,7 @@ class GroupData(Group):
|
|||||||
)
|
)
|
||||||
plan = None
|
plan = None
|
||||||
if data.get("event_reminders") and data["event_reminders"].get("nodes"):
|
if data.get("event_reminders") and data["event_reminders"].get("nodes"):
|
||||||
plan = _plan.PlanData._from_graphql(
|
plan = _models.PlanData._from_graphql(
|
||||||
session, data["event_reminders"]["nodes"][0]
|
session, data["event_reminders"]["nodes"][0]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@@ -2,7 +2,7 @@ import attr
|
|||||||
import datetime
|
import datetime
|
||||||
from ._abc import ThreadABC
|
from ._abc import ThreadABC
|
||||||
from .._common import attrs_default, Image
|
from .._common import attrs_default, Image
|
||||||
from .. import _session, _plan
|
from .. import _session, _models
|
||||||
|
|
||||||
|
|
||||||
@attrs_default
|
@attrs_default
|
||||||
@@ -40,7 +40,7 @@ class PageData(Page):
|
|||||||
#: Number of messages in the thread
|
#: Number of messages in the thread
|
||||||
message_count = attr.ib(None, type=int)
|
message_count = attr.ib(None, type=int)
|
||||||
#: Set `Plan`
|
#: Set `Plan`
|
||||||
plan = attr.ib(None, type=_plan.PlanData)
|
plan = attr.ib(None, type="_models.PlanData")
|
||||||
#: The page's custom URL
|
#: The page's custom URL
|
||||||
url = attr.ib(None, type=str)
|
url = attr.ib(None, type=str)
|
||||||
#: The name of the page's location city
|
#: The name of the page's location city
|
||||||
@@ -60,7 +60,7 @@ class PageData(Page):
|
|||||||
data["city"] = {}
|
data["city"] = {}
|
||||||
plan = None
|
plan = None
|
||||||
if data.get("event_reminders") and data["event_reminders"].get("nodes"):
|
if data.get("event_reminders") and data["event_reminders"].get("nodes"):
|
||||||
plan = _plan.PlanData._from_graphql(
|
plan = _models.PlanData._from_graphql(
|
||||||
session, data["event_reminders"]["nodes"][0]
|
session, data["event_reminders"]["nodes"][0]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@@ -2,7 +2,7 @@ import attr
|
|||||||
import datetime
|
import datetime
|
||||||
from ._abc import ThreadABC
|
from ._abc import ThreadABC
|
||||||
from .._common import log, attrs_default, Image
|
from .._common import log, attrs_default, Image
|
||||||
from .. import _util, _session, _plan
|
from .. import _util, _session, _models
|
||||||
|
|
||||||
|
|
||||||
GENDERS = {
|
GENDERS = {
|
||||||
@@ -114,7 +114,7 @@ class UserData(User):
|
|||||||
#: Number of messages in the thread
|
#: Number of messages in the thread
|
||||||
message_count = attr.ib(None, type=int)
|
message_count = attr.ib(None, type=int)
|
||||||
#: Set `Plan`
|
#: Set `Plan`
|
||||||
plan = attr.ib(None, type=_plan.PlanData)
|
plan = attr.ib(None, type="_models.PlanData")
|
||||||
#: The profile URL. ``None`` for Messenger-only users
|
#: The profile URL. ``None`` for Messenger-only users
|
||||||
url = attr.ib(None, type=str)
|
url = attr.ib(None, type=str)
|
||||||
#: The user's gender
|
#: The user's gender
|
||||||
@@ -145,7 +145,7 @@ class UserData(User):
|
|||||||
|
|
||||||
plan = None
|
plan = None
|
||||||
if data.get("event_reminders") and data["event_reminders"].get("nodes"):
|
if data.get("event_reminders") and data["event_reminders"].get("nodes"):
|
||||||
plan = _plan.PlanData._from_graphql(
|
plan = _models.PlanData._from_graphql(
|
||||||
session, data["event_reminders"]["nodes"][0]
|
session, data["event_reminders"]["nodes"][0]
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -180,7 +180,7 @@ class UserData(User):
|
|||||||
|
|
||||||
plan = None
|
plan = None
|
||||||
if data["event_reminders"]["nodes"]:
|
if data["event_reminders"]["nodes"]:
|
||||||
plan = _plan.PlanData._from_graphql(
|
plan = _models.PlanData._from_graphql(
|
||||||
session, data["event_reminders"]["nodes"][0]
|
session, data["event_reminders"]["nodes"][0]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@@ -1,7 +1,8 @@
|
|||||||
import pytest
|
import pytest
|
||||||
import datetime
|
import datetime
|
||||||
import fbchat
|
import fbchat
|
||||||
from fbchat._attachment import UnsentMessage, ShareAttachment
|
from fbchat import UnsentMessage, ShareAttachment
|
||||||
|
from fbchat._models._message import graphql_to_extensible_attachment
|
||||||
|
|
||||||
|
|
||||||
def test_parse_unsent_message():
|
def test_parse_unsent_message():
|
||||||
@@ -25,9 +26,7 @@ def test_parse_unsent_message():
|
|||||||
},
|
},
|
||||||
"genie_attachment": {"genie_message": None},
|
"genie_attachment": {"genie_message": None},
|
||||||
}
|
}
|
||||||
assert UnsentMessage(
|
assert UnsentMessage(id="ee.mid.$xyz") == graphql_to_extensible_attachment(data)
|
||||||
id="ee.mid.$xyz"
|
|
||||||
) == fbchat._message.graphql_to_extensible_attachment(data)
|
|
||||||
|
|
||||||
|
|
||||||
def test_share_from_graphql_minimal():
|
def test_share_from_graphql_minimal():
|
@@ -1,13 +1,7 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import fbchat
|
import fbchat
|
||||||
from fbchat._file import (
|
from fbchat import FileAttachment, AudioAttachment, ImageAttachment, VideoAttachment
|
||||||
FileAttachment,
|
from fbchat._models._file import graphql_to_attachment, graphql_to_subattachment
|
||||||
AudioAttachment,
|
|
||||||
ImageAttachment,
|
|
||||||
VideoAttachment,
|
|
||||||
graphql_to_attachment,
|
|
||||||
graphql_to_subattachment,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_imageattachment_from_list():
|
def test_imageattachment_from_list():
|
@@ -1,7 +1,7 @@
|
|||||||
import pytest
|
import pytest
|
||||||
import datetime
|
import datetime
|
||||||
import fbchat
|
import fbchat
|
||||||
from fbchat._location import LocationAttachment, LiveLocationAttachment
|
from fbchat import LocationAttachment, LiveLocationAttachment
|
||||||
|
|
||||||
|
|
||||||
def test_location_attachment_from_graphql():
|
def test_location_attachment_from_graphql():
|
@@ -1,7 +1,7 @@
|
|||||||
import pytest
|
import pytest
|
||||||
import fbchat
|
import fbchat
|
||||||
from fbchat import EmojiSize, Mention, Message, MessageData
|
from fbchat import EmojiSize, Mention, Message, MessageData
|
||||||
from fbchat._message import graphql_to_extensible_attachment
|
from fbchat._models._message import graphql_to_extensible_attachment
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
@@ -1,5 +1,5 @@
|
|||||||
import datetime
|
import datetime
|
||||||
from fbchat._plan import GuestStatus, PlanData
|
from fbchat import GuestStatus, PlanData
|
||||||
|
|
||||||
|
|
||||||
def test_plan_properties(session):
|
def test_plan_properties(session):
|
@@ -1,4 +1,4 @@
|
|||||||
from fbchat._poll import Poll, PollOption
|
from fbchat import Poll, PollOption
|
||||||
|
|
||||||
|
|
||||||
def test_poll_option_from_graphql_unvoted():
|
def test_poll_option_from_graphql_unvoted():
|
@@ -1,10 +1,10 @@
|
|||||||
from fbchat._quick_reply import (
|
from fbchat import (
|
||||||
QuickReplyText,
|
QuickReplyText,
|
||||||
QuickReplyLocation,
|
QuickReplyLocation,
|
||||||
QuickReplyPhoneNumber,
|
QuickReplyPhoneNumber,
|
||||||
QuickReplyEmail,
|
QuickReplyEmail,
|
||||||
graphql_to_quick_reply,
|
|
||||||
)
|
)
|
||||||
|
from fbchat._models._quick_reply import graphql_to_quick_reply
|
||||||
|
|
||||||
|
|
||||||
def test_parse_minimal():
|
def test_parse_minimal():
|
@@ -1,6 +1,6 @@
|
|||||||
import pytest
|
import pytest
|
||||||
import fbchat
|
import fbchat
|
||||||
from fbchat._sticker import Sticker
|
from fbchat import Sticker
|
||||||
|
|
||||||
|
|
||||||
def test_from_graphql_none():
|
def test_from_graphql_none():
|
Reference in New Issue
Block a user