Add ThreadABC copy helper
This commit is contained in:
@@ -65,6 +65,16 @@ class ThreadABC(metaclass=abc.ABCMeta):
|
||||
# We won't support those use cases, it'll make for a confusing API!
|
||||
# If we absolutely need to in the future, we can always add extra functionality
|
||||
|
||||
@abc.abstractmethod
|
||||
def _copy(self) -> "ThreadABC":
|
||||
"""It may or may not be a good idea to attach the current thread to new objects.
|
||||
|
||||
So for now, we use this method to create a new thread.
|
||||
|
||||
This should return the minimal representation of the thread (e.g. not UserData).
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def wave(self, first: bool = True) -> str:
|
||||
"""Wave hello to the thread.
|
||||
|
||||
@@ -289,9 +299,7 @@ class ThreadABC(metaclass=abc.ABCMeta):
|
||||
if not result:
|
||||
return (0, [])
|
||||
|
||||
# TODO: May or may not be a good idea to attach the current thread?
|
||||
# For now, we just create a new thread:
|
||||
thread = self.__class__(session=self.session, id=self.id)
|
||||
thread = self._copy()
|
||||
snippets = [
|
||||
_models.MessageSnippet._parse(thread, snippet)
|
||||
for snippet in result["snippets"]
|
||||
@@ -351,9 +359,7 @@ class ThreadABC(metaclass=abc.ABCMeta):
|
||||
|
||||
read_receipts = j["message_thread"]["read_receipts"]["nodes"]
|
||||
|
||||
# TODO: May or may not be a good idea to attach the current thread?
|
||||
# For now, we just create a new thread:
|
||||
thread = self.__class__(session=self.session, id=self.id)
|
||||
thread = self._copy()
|
||||
return [
|
||||
_models.MessageData._from_graphql(thread, message, read_receipts)
|
||||
for message in j["message_thread"]["messages"]["nodes"]
|
||||
@@ -779,3 +785,6 @@ class Thread(ThreadABC):
|
||||
"The method you called is not supported on raw Thread objects."
|
||||
" Please use an appropriate User/Group/Page object instead!"
|
||||
)
|
||||
|
||||
def _copy(self) -> "Thread":
|
||||
return Thread(session=self.session, id=self.id)
|
||||
|
@@ -23,6 +23,9 @@ class Group(ThreadABC):
|
||||
def _to_send_data(self):
|
||||
return {"thread_fbid": self.id}
|
||||
|
||||
def _copy(self) -> "Group":
|
||||
return Group(session=self.session, id=self.id)
|
||||
|
||||
def add_participants(self, user_ids: Iterable[str]):
|
||||
"""Add users to the group.
|
||||
|
||||
|
@@ -23,6 +23,9 @@ class Page(ThreadABC):
|
||||
def _to_send_data(self):
|
||||
return {"other_user_fbid": self.id}
|
||||
|
||||
def _copy(self) -> "Page":
|
||||
return Page(session=self.session, id=self.id)
|
||||
|
||||
|
||||
@attrs_default
|
||||
class PageData(Page):
|
||||
|
@@ -55,6 +55,9 @@ class User(ThreadABC):
|
||||
"specific_to_list[0]": "fbid:{}".format(self.id),
|
||||
}
|
||||
|
||||
def _copy(self) -> "User":
|
||||
return User(session=self.session, id=self.id)
|
||||
|
||||
def confirm_friend_request(self):
|
||||
"""Confirm a friend request, adding the user to your friend list.
|
||||
|
||||
|
Reference in New Issue
Block a user