Remove Thread.type
This commit is contained in:
@@ -186,10 +186,10 @@ class Client:
|
|||||||
users = []
|
users = []
|
||||||
users_to_fetch = [] # It's more efficient to fetch all users in one request
|
users_to_fetch = [] # It's more efficient to fetch all users in one request
|
||||||
for thread in threads:
|
for thread in threads:
|
||||||
if thread.type == ThreadType.USER:
|
if isinstance(thread, User):
|
||||||
if thread.id not in [user.id for user in users]:
|
if thread.id not in [user.id for user in users]:
|
||||||
users.append(thread)
|
users.append(thread)
|
||||||
elif thread.type == ThreadType.GROUP:
|
elif isinstance(thread, Group):
|
||||||
for user_id in thread.participants:
|
for user_id in thread.participants:
|
||||||
if (
|
if (
|
||||||
user_id not in [user.id for user in users]
|
user_id not in [user.id for user in users]
|
||||||
@@ -458,7 +458,7 @@ class Client:
|
|||||||
threads = self.fetch_thread_info(*user_ids)
|
threads = self.fetch_thread_info(*user_ids)
|
||||||
users = {}
|
users = {}
|
||||||
for id_, thread in threads.items():
|
for id_, thread in threads.items():
|
||||||
if thread.type == ThreadType.USER:
|
if isinstance(thread, User):
|
||||||
users[id_] = thread
|
users[id_] = thread
|
||||||
else:
|
else:
|
||||||
raise ValueError("Thread {} was not a user".format(thread))
|
raise ValueError("Thread {} was not a user".format(thread))
|
||||||
@@ -483,7 +483,7 @@ class Client:
|
|||||||
threads = self.fetch_thread_info(*page_ids)
|
threads = self.fetch_thread_info(*page_ids)
|
||||||
pages = {}
|
pages = {}
|
||||||
for id_, thread in threads.items():
|
for id_, thread in threads.items():
|
||||||
if thread.type == ThreadType.PAGE:
|
if isinstance(thread, Page):
|
||||||
pages[id_] = thread
|
pages[id_] = thread
|
||||||
else:
|
else:
|
||||||
raise ValueError("Thread {} was not a page".format(thread))
|
raise ValueError("Thread {} was not a page".format(thread))
|
||||||
@@ -505,7 +505,7 @@ class Client:
|
|||||||
threads = self.fetch_thread_info(*group_ids)
|
threads = self.fetch_thread_info(*group_ids)
|
||||||
groups = {}
|
groups = {}
|
||||||
for id_, thread in threads.items():
|
for id_, thread in threads.items():
|
||||||
if thread.type == ThreadType.GROUP:
|
if isinstance(thread, Group):
|
||||||
groups[id_] = thread
|
groups[id_] = thread
|
||||||
else:
|
else:
|
||||||
raise ValueError("Thread {} was not a group".format(thread))
|
raise ValueError("Thread {} was not a group".format(thread))
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import attr
|
import attr
|
||||||
from ._core import attrs_default, Image
|
from ._core import attrs_default, Image
|
||||||
from . import _util, _session, _plan
|
from . import _util, _session, _plan
|
||||||
from ._thread import ThreadType, Thread
|
from ._thread import Thread
|
||||||
from typing import Iterable
|
from typing import Iterable
|
||||||
|
|
||||||
|
|
||||||
@@ -9,8 +9,6 @@ from typing import Iterable
|
|||||||
class Group(Thread):
|
class Group(Thread):
|
||||||
"""Represents a Facebook group. Inherits `Thread`."""
|
"""Represents a Facebook group. Inherits `Thread`."""
|
||||||
|
|
||||||
type = ThreadType.GROUP
|
|
||||||
|
|
||||||
#: The session to use when making requests.
|
#: The session to use when making requests.
|
||||||
session = attr.ib(type=_session.Session)
|
session = attr.ib(type=_session.Session)
|
||||||
#: The group's unique identifier.
|
#: The group's unique identifier.
|
||||||
|
@@ -1,15 +1,13 @@
|
|||||||
import attr
|
import attr
|
||||||
from ._core import attrs_default, Image
|
from ._core import attrs_default, Image
|
||||||
from . import _session, _plan
|
from . import _session, _plan
|
||||||
from ._thread import ThreadType, Thread
|
from ._thread import Thread
|
||||||
|
|
||||||
|
|
||||||
@attrs_default
|
@attrs_default
|
||||||
class Page(Thread):
|
class Page(Thread):
|
||||||
"""Represents a Facebook page. Inherits `Thread`."""
|
"""Represents a Facebook page. Inherits `Thread`."""
|
||||||
|
|
||||||
type = ThreadType.PAGE
|
|
||||||
|
|
||||||
#: The session to use when making requests.
|
#: The session to use when making requests.
|
||||||
session = attr.ib(type=_session.Session)
|
session = attr.ib(type=_session.Session)
|
||||||
#: The unique identifier of the page.
|
#: The unique identifier of the page.
|
||||||
|
@@ -76,8 +76,6 @@ class Thread:
|
|||||||
session = attr.ib(type=_session.Session)
|
session = attr.ib(type=_session.Session)
|
||||||
#: The unique identifier of the thread.
|
#: The unique identifier of the thread.
|
||||||
id = attr.ib(converter=str)
|
id = attr.ib(converter=str)
|
||||||
#: Specifies the type of thread. Can be used a ``thread_type``. See :ref:`intro_threads` for more info
|
|
||||||
type = None
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _parse_customization_info(data):
|
def _parse_customization_info(data):
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import attr
|
import attr
|
||||||
from ._core import attrs_default, Enum, Image
|
from ._core import attrs_default, Enum, Image
|
||||||
from . import _util, _session, _plan
|
from . import _util, _session, _plan
|
||||||
from ._thread import ThreadType, Thread
|
from ._thread import Thread
|
||||||
|
|
||||||
|
|
||||||
GENDERS = {
|
GENDERS = {
|
||||||
@@ -45,8 +45,6 @@ class TypingStatus(Enum):
|
|||||||
class User(Thread):
|
class User(Thread):
|
||||||
"""Represents a Facebook user. Inherits `Thread`."""
|
"""Represents a Facebook user. Inherits `Thread`."""
|
||||||
|
|
||||||
type = ThreadType.USER
|
|
||||||
|
|
||||||
#: The session to use when making requests.
|
#: The session to use when making requests.
|
||||||
session = attr.ib(type=_session.Session)
|
session = attr.ib(type=_session.Session)
|
||||||
#: The user's unique identifier.
|
#: The user's unique identifier.
|
||||||
|
@@ -89,7 +89,6 @@ def test_fetch_info(client1, group):
|
|||||||
assert info.name == "Mark Zuckerberg"
|
assert info.name == "Mark Zuckerberg"
|
||||||
|
|
||||||
info = client1.fetch_group_info(group["id"])[group["id"]]
|
info = client1.fetch_group_info(group["id"])[group["id"]]
|
||||||
assert info.type == ThreadType.GROUP
|
|
||||||
|
|
||||||
|
|
||||||
def test_fetch_image_url(client):
|
def test_fetch_image_url(client):
|
||||||
|
@@ -11,7 +11,6 @@ def test_search_for(client1):
|
|||||||
u = users[0]
|
u = users[0]
|
||||||
|
|
||||||
assert u.id == "4"
|
assert u.id == "4"
|
||||||
assert u.type == ThreadType.USER
|
|
||||||
assert u.photo[:4] == "http"
|
assert u.photo[:4] == "http"
|
||||||
assert u.url[:4] == "http"
|
assert u.url[:4] == "http"
|
||||||
assert u.name == "Mark Zuckerberg"
|
assert u.name == "Mark Zuckerberg"
|
||||||
|
Reference in New Issue
Block a user