Rename Client.fetch_all_users -> .fetch_users, and document it better
This commit is contained in:
@@ -3,7 +3,7 @@ import time
|
|||||||
import requests
|
import requests
|
||||||
|
|
||||||
from ._core import log
|
from ._core import log
|
||||||
from . import _util, _graphql, _session, _poll
|
from . import _util, _graphql, _session, _poll, _user
|
||||||
|
|
||||||
from ._exception import FBchatException, FBchatFacebookError
|
from ._exception import FBchatException, FBchatFacebookError
|
||||||
from ._thread import ThreadLocation
|
from ._thread import ThreadLocation
|
||||||
@@ -24,6 +24,8 @@ from ._quick_reply import (
|
|||||||
)
|
)
|
||||||
from ._plan import PlanData
|
from ._plan import PlanData
|
||||||
|
|
||||||
|
from typing import Sequence
|
||||||
|
|
||||||
|
|
||||||
class Client:
|
class Client:
|
||||||
"""A client for the Facebook Chat (Messenger).
|
"""A client for the Facebook Chat (Messenger).
|
||||||
@@ -184,25 +186,26 @@ class Client:
|
|||||||
users.append(user)
|
users.append(user)
|
||||||
return users
|
return users
|
||||||
|
|
||||||
def fetch_all_users(self):
|
def fetch_users(self) -> Sequence[_user.UserData]:
|
||||||
"""Fetch all users the client is currently chatting with.
|
"""Fetch users the client is currently chatting with.
|
||||||
|
|
||||||
Returns:
|
This is very close to your friend list, with the follow differences:
|
||||||
list: `User` objects
|
|
||||||
|
|
||||||
Raises:
|
It differs by including users that you're not friends with, but have chatted
|
||||||
FBchatException: If request failed
|
with before, and by including accounts that are "Messenger Only".
|
||||||
|
|
||||||
|
But does not include deactivated, deleted or memorialized users (logically,
|
||||||
|
since you can't chat with those).
|
||||||
"""
|
"""
|
||||||
data = {"viewer": self._session.user_id}
|
data = {"viewer": self.session.user_id}
|
||||||
j = self._payload_post("/chat/user_info_all", data)
|
j = self.session._payload_post("/chat/user_info_all", data)
|
||||||
|
|
||||||
users = []
|
users = []
|
||||||
for data in j.values():
|
for data in j.values():
|
||||||
if data["type"] in ["user", "friend"]:
|
if data["type"] not in ["user", "friend"] or data["id"] in ["0", 0]:
|
||||||
if data["id"] in ["0", 0]:
|
log.warning("Invalid user data %s", data)
|
||||||
# Skip invalid users
|
continue # Skip invalid users
|
||||||
continue
|
users.append(_user.UserData._from_all_fetch(self.session, data))
|
||||||
users.append(UserData._from_all_fetch(self.session, data))
|
|
||||||
return users
|
return users
|
||||||
|
|
||||||
def search_for_users(self, name, limit=10):
|
def search_for_users(self, name, limit=10):
|
||||||
|
Reference in New Issue
Block a user