Rename .uid -> .id everywhere

This commit is contained in:
Mads Marquart
2020-01-08 23:09:51 +01:00
parent 45c0a4772d
commit a5abb05ab3
35 changed files with 171 additions and 180 deletions

View File

@@ -43,14 +43,6 @@ class Client:
useful while listening).
"""
@property
def uid(self):
"""The ID of the client.
Can be used as ``thread_id``. See :ref:`intro_threads` for more info.
"""
return self._uid
def __init__(self, session):
"""Initialize and log in the client.
@@ -68,7 +60,6 @@ class Client:
self._mark_alive = True
self._buddylist = dict()
self._session = session
self._uid = session.user_id
"""
INTERNAL REQUEST METHODS
@@ -192,12 +183,12 @@ class Client:
users_to_fetch = [] # It's more efficient to fetch all users in one request
for thread in threads:
if thread.type == ThreadType.USER:
if thread.uid not in [user.uid for user in users]:
if thread.id not in [user.id for user in users]:
users.append(thread)
elif thread.type == ThreadType.GROUP:
for user_id in thread.participants:
if (
user_id not in [user.uid for user in users]
user_id not in [user.id for user in users]
and user_id not in users_to_fetch
):
users_to_fetch.append(user_id)
@@ -214,7 +205,7 @@ class Client:
Raises:
FBchatException: If request failed
"""
data = {"viewer": self._uid}
data = {"viewer": self._session.user_id}
j = self._payload_post("/chat/user_info_all", data)
users = []
@@ -837,7 +828,7 @@ class Client:
elif i["node"].get("__typename") == "MessageVideo":
yield VideoAttachment._from_list(i)
else:
yield Attachment(uid=i["node"].get("legacy_attachment_id"))
yield Attachment(id=i["node"].get("legacy_attachment_id"))
del j[thread_id]["message_shared_media"]["edges"][0]
"""
@@ -873,7 +864,7 @@ class Client:
Raises:
FBchatException: If request failed
"""
thread = thread_type._to_class()(uid=thread_id)
thread = thread_type._to_class()(id=thread_id)
data = thread._to_send_data()
data.update(message._to_send_data())
return self._do_send_request(data)
@@ -892,7 +883,7 @@ class Client:
Raises:
FBchatException: If request failed
"""
thread = thread_type._to_class()(uid=thread_id)
thread = thread_type._to_class()(id=thread_id)
data = thread._to_send_data()
data["action_type"] = "ma-type:user-generated-message"
data["lightweight_action_attachment[lwa_state]"] = (
@@ -965,7 +956,7 @@ class Client:
def _send_location(
self, location, current=True, message=None, thread_id=None, thread_type=None
):
thread = thread_type._to_class()(uid=thread_id)
thread = thread_type._to_class()(id=thread_id)
data = thread._to_send_data()
if message is not None:
data.update(message._to_send_data())
@@ -1033,7 +1024,7 @@ class Client:
`files` should be a list of tuples, with a file's ID and mimetype.
"""
thread = thread_type._to_class()(uid=thread_id)
thread = thread_type._to_class()(id=thread_id)
data = thread._to_send_data()
data.update(self._old_message(message)._to_send_data())
data["action_type"] = "ma-type:user-generated-message"
@@ -1179,7 +1170,7 @@ class Client:
if len(user_ids) < 2:
raise ValueError("Error when creating group: Not enough participants")
for i, user_id in enumerate(user_ids + [self._uid]):
for i, user_id in enumerate(user_ids + [self._session.user_id]):
data["specific_to_list[{}]".format(i)] = "fbid:{}".format(user_id)
message_id, thread_id = self._do_send_request(data, get_thread_id=True)
@@ -1199,7 +1190,7 @@ class Client:
Raises:
FBchatException: If request failed
"""
data = Group(uid=thread_id)._to_send_data()
data = Group(id=thread_id)._to_send_data()
data["action_type"] = "ma-type:log-message"
data["log_message_type"] = "log:subscribe"
@@ -1207,7 +1198,7 @@ class Client:
user_ids = _util.require_list(user_ids)
for i, user_id in enumerate(user_ids):
if user_id == self._uid:
if user_id == self._session.user_id:
raise ValueError(
"Error when adding users: Cannot add self to group thread"
)
@@ -1283,7 +1274,7 @@ class Client:
data = {
"client_mutation_id": "0",
"actor_id": self._uid,
"actor_id": self._session.user_id,
"thread_fbid": thread_id,
"user_ids": user_ids,
"response": "ACCEPT" if approve else "DENY",
@@ -1456,7 +1447,7 @@ class Client:
data = {
"action": "ADD_REACTION" if reaction else "REMOVE_REACTION",
"client_mutation_id": "1",
"actor_id": self._uid,
"actor_id": self._session.user_id,
"message_id": str(message_id),
"reaction": reaction.value if reaction else None,
}
@@ -1501,7 +1492,7 @@ class Client:
FBchatException: If request failed
"""
data = {
"event_reminder_id": plan.uid,
"event_reminder_id": plan.id,
"delete": "false",
"date": _util.datetime_to_seconds(new_plan.time),
"location_name": new_plan.location or "",
@@ -1520,7 +1511,7 @@ class Client:
Raises:
FBchatException: If request failed
"""
data = {"event_reminder_id": plan.uid, "delete": "true", "acontext": ACONTEXT}
data = {"event_reminder_id": plan.id, "delete": "true", "acontext": ACONTEXT}
j = self._payload_post("/ajax/eventreminder/submit", data)
def change_plan_participation(self, plan, take_part=True):
@@ -1534,7 +1525,7 @@ class Client:
FBchatException: If request failed
"""
data = {
"event_reminder_id": plan.uid,
"event_reminder_id": plan.id,
"guest_state": "GOING" if take_part else "DECLINED",
"acontext": ACONTEXT,
}
@@ -1913,14 +1904,14 @@ class Client:
def _ping(self):
data = {
"seq": self._seq,
"channel": "p_" + self._uid,
"channel": "p_" + self._session.user_id,
"clientid": self._session._client_id,
"partition": -2,
"cap": 0,
"uid": self._uid,
"uid": self._session.user_id,
"sticky_token": self._sticky,
"sticky_pool": self._pool,
"viewer_uid": self._uid,
"viewer_uid": self._session.user_id,
"state": "active",
}
j = self._get(
@@ -2461,7 +2452,7 @@ class Client:
replied_to = Message._from_reply(i["repliedToMessage"])
message = Message._from_reply(i["message"], replied_to)
self.on_message(
mid=message.uid,
mid=message.id,
author_id=message.author,
message_object=message,
thread_id=thread_id,
@@ -2537,7 +2528,7 @@ class Client:
thread_id = str(thread_id)
else:
thread_type = ThreadType.USER
if author_id == self._uid:
if author_id == self._session.user_id:
thread_id = m.get("to")
else:
thread_id = author_id