@@ -37,13 +37,14 @@ class Client(object):
3737 """Verify ssl certificate, set to False to allow debugging with a proxy"""
3838 listening = False
3939 """Whether the client is listening. Used when creating an external event loop to determine when to stop listening"""
40- uid = None
41- """
42- The ID of the client.
43- Can be used as `thread_id`. See :ref:`intro_threads` for more info.
4440
45- Note: Modifying this results in undefined behaviour
46- """
41+ @property
42+ def uid (self ):
43+ """The ID of the client.
44+
45+ Can be used as `thread_id`. See :ref:`intro_threads` for more info.
46+ """
47+ return self ._uid
4748
4849 def __init__ (
4950 self ,
@@ -299,15 +300,15 @@ def _resetValues(self):
299300 self ._session = requests .session ()
300301 self .req_counter = 1
301302 self .seq = "0"
302- self .uid = None
303+ self ._uid = None
303304
304305 def _postLogin (self ):
305306 self .payloadDefault = OrderedDict ()
306307 self ._client_id = hex (int (random () * 2147483648 ))[2 :]
307- self .uid = self ._session .cookies .get_dict ().get ("c_user" )
308- if self .uid is None :
308+ self ._uid = self ._session .cookies .get_dict ().get ("c_user" )
309+ if self ._uid is None :
309310 raise FBchatException ("Could not find c_user cookie" )
310- self .uid = str (self .uid )
311+ self ._uid = str (self ._uid )
311312
312313 r = self ._get (self .req_url .BASE )
313314 soup = bs (r .text , "html.parser" )
@@ -330,7 +331,7 @@ def _postLogin(self):
330331 self .payloadDefault ["__rev" ] = int (
331332 r .text .split ('"client_revision":' , 1 )[1 ].split ("," , 1 )[0 ]
332333 )
333- self .payloadDefault ["__user" ] = self .uid
334+ self .payloadDefault ["__user" ] = self ._uid
334335 self .payloadDefault ["__a" ] = "1"
335336 self .payloadDefault ["ttstamp" ] = ttstamp
336337 self .payloadDefault ["fb_dtsg" ] = fb_dtsg
@@ -660,7 +661,7 @@ def fetchAllUsers(self):
660661 :rtype: list
661662 :raises: FBchatException if request failed
662663 """
663- data = {"viewer" : self .uid }
664+ data = {"viewer" : self ._uid }
664665 j = self ._post (
665666 self .req_url .ALL_USERS , query = data , fix_request = True , as_json = True
666667 )
@@ -1249,7 +1250,7 @@ def _getSendData(self, message=None, thread_id=None, thread_type=ThreadType.USER
12491250 timestamp = now ()
12501251 data = {
12511252 "client" : "mercury" ,
1252- "author" : "fbid:{}" .format (self .uid ),
1253+ "author" : "fbid:{}" .format (self ._uid ),
12531254 "timestamp" : timestamp ,
12541255 "source" : "source:chat:web" ,
12551256 "offline_threading_id" : messageAndOTID ,
@@ -1709,7 +1710,7 @@ def createGroup(self, message, user_ids):
17091710 if len (user_ids ) < 2 :
17101711 raise FBchatUserError ("Error when creating group: Not enough participants" )
17111712
1712- for i , user_id in enumerate (user_ids + [self .uid ]):
1713+ for i , user_id in enumerate (user_ids + [self ._uid ]):
17131714 data ["specific_to_list[{}]" .format (i )] = "fbid:{}" .format (user_id )
17141715
17151716 message_id , thread_id = self ._doSendRequest (data , get_thread_id = True )
@@ -1737,7 +1738,7 @@ def addUsersToGroup(self, user_ids, thread_id=None):
17371738 user_ids = require_list (user_ids )
17381739
17391740 for i , user_id in enumerate (user_ids ):
1740- if user_id == self .uid :
1741+ if user_id == self ._uid :
17411742 raise FBchatUserError (
17421743 "Error when adding users: Cannot add self to group thread"
17431744 )
@@ -1813,7 +1814,7 @@ def _usersApproval(self, user_ids, approve, thread_id=None):
18131814
18141815 data = {
18151816 "client_mutation_id" : "0" ,
1816- "actor_id" : self .uid ,
1817+ "actor_id" : self ._uid ,
18171818 "thread_fbid" : thread_id ,
18181819 "user_ids" : user_ids ,
18191820 "response" : "ACCEPT" if approve else "DENY" ,
@@ -1972,7 +1973,7 @@ def reactToMessage(self, message_id, reaction):
19721973 data = {
19731974 "action" : "ADD_REACTION" if reaction else "REMOVE_REACTION" ,
19741975 "client_mutation_id" : "1" ,
1975- "actor_id" : self .uid ,
1976+ "actor_id" : self ._uid ,
19761977 "message_id" : str (message_id ),
19771978 "reaction" : reaction .value if reaction else None ,
19781979 }
@@ -2376,14 +2377,14 @@ def unmuteThreadMentions(self, thread_id=None):
23762377
23772378 def _ping (self ):
23782379 data = {
2379- "channel" : "p_" + self .uid ,
2380+ "channel" : "p_" + self ._uid ,
23802381 "clientid" : self ._client_id ,
23812382 "partition" : - 2 ,
23822383 "cap" : 0 ,
2383- "uid" : self .uid ,
2384+ "uid" : self ._uid ,
23842385 "sticky_token" : self .sticky ,
23852386 "sticky_pool" : self .pool ,
2386- "viewer_uid" : self .uid ,
2387+ "viewer_uid" : self ._uid ,
23872388 "state" : "active" ,
23882389 }
23892390 self ._get (self .req_url .PING , data , fix_request = True , as_json = False )
@@ -2984,7 +2985,7 @@ def _parseMessage(self, content):
29842985 thread_id = str (thread_id )
29852986 else :
29862987 thread_type = ThreadType .USER
2987- if author_id == self .uid :
2988+ if author_id == self ._uid :
29882989 thread_id = m .get ("to" )
29892990 else :
29902991 thread_id = author_id
0 commit comments