@@ -95,15 +95,13 @@ def _update_friend(self, newUser, id):
9595 for user in self .me .onlineFriends :
9696 if user .id == id :
9797 oldUser = user
98- print ("Updating %s" % user .displayName )
9998 self .me .onlineFriends .remove (user )
10099 break
101100
102101 if oldUser is None :
103102 for user in self .me .offlineFriends :
104103 if user .id == id :
105104 oldUser = user
106- print ("Updating %s" % user .displayName )
107105 self .me .offlineFriends .remove (user )
108106 break
109107
@@ -156,10 +154,14 @@ def on_connect(self):
156154 # WS handles
157155
158156 def _ws_friend_online (self , content ):
159- self .on_friend_online (objects .User (self , content ["user" ]))
157+ user = objects .User (self , content ["user" ])
158+ self ._update_friend (user , user .id )
159+ self .on_friend_online (user )
160160
161161 def _ws_friend_active (self , content ):
162- self .on_friend_active (objects .User (self , content ["user" ]))
162+ user = objects .User (self , content ["user" ])
163+ self ._update_friend (user , user .id )
164+ self .on_friend_active (user )
163165
164166 def _ws_friend_location (self , content ):
165167 user = objects .User (self , content ["user" ])
@@ -176,19 +178,27 @@ def _ws_friend_location(self, content):
176178 instance = world .fetch_instance (content ["instance" ])
177179 location = objects .Location (self , content ["location" ])
178180
181+ self ._update_friend (user , user .id )
179182 self .on_friend_location (user , world , location , instance )
180183
181184 def _ws_friend_offline (self , content ):
182- self .on_friend_offline (self .fetch_user_by_id (content ["userId" ]))
185+ user = self .fetch_user_by_id (content ["userId" ])
186+ self ._update_friend (user , user .id )
187+ self .on_friend_offline (user )
183188
184189 def _ws_friend_add (self , content ):
185- self .on_friend_add (objects .User (self , content ["user" ]))
190+ user = objects .User (self , content ["user" ])
191+ self ._update_friend (user , user .id )
192+ self .on_friend_add (user )
186193
187194 def _ws_friend_delete (self , content ):
188- self .on_friend_delete (self .fetch_user_by_id (content ["userId" ]))
195+ user = self ._update_friend (None , content ["userId" ])
196+ self .on_friend_delete (user )
189197
190198 def _ws_friend_update (self , content ):
191- self .on_friend_update (objects .User (self , content ["user" ]))
199+ user = objects .User (self , content ["user" ])
200+ self ._update_friend (user , user .id )
201+ self .on_friend_update (user )
192202
193203 def _ws_notification (self , content ):
194204 self .on_notification (objects .Notification (self , content ))
@@ -265,10 +275,14 @@ async def on_connect(self):
265275 # WS handles
266276
267277 async def _ws_friend_online (self , content ):
268- await self .on_friend_online (aobjects .User (self , content ["user" ]))
278+ user = aobjects .User (self , content ["user" ])
279+ self ._update_friend (user , user .id )
280+ await self .on_friend_online (user )
269281
270282 async def _ws_friend_active (self , content ):
271- await self .on_friend_active (aobjects .User (self , content ["user" ]))
283+ user = aobjects .User (self , content ["user" ])
284+ self ._update_friend (user , user .id )
285+ await self .on_friend_active (user )
272286
273287 async def _ws_friend_location (self , content ):
274288 user = aobjects .User (self , content ["user" ])
@@ -285,19 +299,27 @@ async def _ws_friend_location(self, content):
285299 instance = await world .fetch_instance (content ["instance" ])
286300 location = aobjects .Location (self , content ["location" ])
287301
302+ self ._update_friend (user , user .id )
288303 await self .on_friend_location (user , world , location , instance )
289304
290305 async def _ws_friend_offline (self , content ):
291- await self .on_friend_offline (await self .fetch_user_by_id (content ["userId" ]))
306+ user = await self .fetch_user_by_id (content ["userId" ])
307+ self ._update_friend (user , user .id )
308+ await self .on_friend_offline (user )
292309
293310 async def _ws_friend_add (self , content ):
294- await self .on_friend_add (aobjects .User (self , content ["user" ]))
311+ user = aobjects .User (self , content ["user" ])
312+ self ._update_friend (user , user .id )
313+ await self .on_friend_add (user )
295314
296315 async def _ws_friend_delete (self , content ):
297- await self .on_friend_delete (await self .fetch_user_by_id (content ["userId" ]))
316+ user = self ._update_friend (None , content ["userId" ])
317+ await self .on_friend_delete (user )
298318
299319 async def _ws_friend_update (self , content ):
300- await self .on_friend_update (aobjects .User (self , content ["user" ]))
320+ user = aobjects .User (self , content ["user" ])
321+ self ._update_friend (user , user .id )
322+ await self .on_friend_update (user )
301323
302324 async def _ws_notification (self , content ):
303325 await self .on_notification (aobjects .Notification (self , content ))
0 commit comments