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!
|
# 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
|
# 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:
|
def wave(self, first: bool = True) -> str:
|
||||||
"""Wave hello to the thread.
|
"""Wave hello to the thread.
|
||||||
|
|
||||||
@@ -289,9 +299,7 @@ class ThreadABC(metaclass=abc.ABCMeta):
|
|||||||
if not result:
|
if not result:
|
||||||
return (0, [])
|
return (0, [])
|
||||||
|
|
||||||
# TODO: May or may not be a good idea to attach the current thread?
|
thread = self._copy()
|
||||||
# For now, we just create a new thread:
|
|
||||||
thread = self.__class__(session=self.session, id=self.id)
|
|
||||||
snippets = [
|
snippets = [
|
||||||
_models.MessageSnippet._parse(thread, snippet)
|
_models.MessageSnippet._parse(thread, snippet)
|
||||||
for snippet in result["snippets"]
|
for snippet in result["snippets"]
|
||||||
@@ -351,9 +359,7 @@ class ThreadABC(metaclass=abc.ABCMeta):
|
|||||||
|
|
||||||
read_receipts = j["message_thread"]["read_receipts"]["nodes"]
|
read_receipts = j["message_thread"]["read_receipts"]["nodes"]
|
||||||
|
|
||||||
# TODO: May or may not be a good idea to attach the current thread?
|
thread = self._copy()
|
||||||
# For now, we just create a new thread:
|
|
||||||
thread = self.__class__(session=self.session, id=self.id)
|
|
||||||
return [
|
return [
|
||||||
_models.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"]
|
||||||
@@ -779,3 +785,6 @@ class Thread(ThreadABC):
|
|||||||
"The method you called is not supported on raw Thread objects."
|
"The method you called is not supported on raw Thread objects."
|
||||||
" Please use an appropriate User/Group/Page object instead!"
|
" 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):
|
def _to_send_data(self):
|
||||||
return {"thread_fbid": self.id}
|
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]):
|
def add_participants(self, user_ids: Iterable[str]):
|
||||||
"""Add users to the group.
|
"""Add users to the group.
|
||||||
|
|
||||||
|
@@ -23,6 +23,9 @@ class Page(ThreadABC):
|
|||||||
def _to_send_data(self):
|
def _to_send_data(self):
|
||||||
return {"other_user_fbid": self.id}
|
return {"other_user_fbid": self.id}
|
||||||
|
|
||||||
|
def _copy(self) -> "Page":
|
||||||
|
return Page(session=self.session, id=self.id)
|
||||||
|
|
||||||
|
|
||||||
@attrs_default
|
@attrs_default
|
||||||
class PageData(Page):
|
class PageData(Page):
|
||||||
|
@@ -55,6 +55,9 @@ class User(ThreadABC):
|
|||||||
"specific_to_list[0]": "fbid:{}".format(self.id),
|
"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):
|
def confirm_friend_request(self):
|
||||||
"""Confirm a friend request, adding the user to your friend list.
|
"""Confirm a friend request, adding the user to your friend list.
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user