@@ -29,6 +29,25 @@ def rawToFields(cls, raw={}):
29
29
return {"id" : raw .get ("id" ),
30
30
"alerts" : False if raw .get ("properties" , {}).get ("alerts" ) == "false" else True }
31
31
32
+ @classmethod
33
+ def fromRaw (cls , skype = None , raw = {}):
34
+ id = raw .get ("id" )
35
+ if "threadProperties" in raw :
36
+ active = True
37
+ try :
38
+ info = skype .conn ("GET" , "{0}/threads/{1}" .format (skype .conn .msgsHost , raw .get ("id" )),
39
+ auth = SkypeConnection .Auth .RegToken ,
40
+ params = {"view" : "msnp24Equivalent" }).json ()
41
+ except SkypeApiException as e :
42
+ if e .args [1 ].status_code != 404 :
43
+ raise
44
+ active = False
45
+ else :
46
+ raw .update (info )
47
+ return SkypeGroupChat (skype , raw , ** SkypeGroupChat .rawToFields (raw , active = active ))
48
+ else :
49
+ return SkypeSingleChat (skype , raw , ** SkypeSingleChat .rawToFields (raw ))
50
+
32
51
def getMsgs (self ):
33
52
"""
34
53
Retrieve a batch of messages from the conversation.
@@ -315,12 +334,15 @@ class SkypeGroupChat(SkypeChat):
315
334
URL to retrieve the conversation picture.
316
335
joinUrl (str):
317
336
Public ``join.skype.com`` URL for any other users to access the conversation.
337
+ active (bool):
338
+ Whether the full group chat was retrieved from the server. This may be ``False`` if a group conversation
339
+ still appears in the recent list despite being left or deleted.
318
340
"""
319
341
320
- attrs = SkypeChat .attrs + ("topic" , "creatorId" , "userIds" , "adminIds" , "open" , "history" , "picture" )
342
+ attrs = SkypeChat .attrs + ("topic" , "creatorId" , "userIds" , "adminIds" , "open" , "history" , "picture" , "active" )
321
343
322
344
@classmethod
323
- def rawToFields (cls , raw = {}):
345
+ def rawToFields (cls , raw = {}, active = False ):
324
346
fields = super (SkypeGroupChat , cls ).rawToFields (raw )
325
347
props = raw .get ("properties" , {})
326
348
userIds = []
@@ -336,7 +358,8 @@ def rawToFields(cls, raw={}):
336
358
"adminIds" : adminIds ,
337
359
"open" : props .get ("joiningenabled" , "" ) == "true" ,
338
360
"history" : props .get ("historydisclosed" , "" ) == "true" ,
339
- "picture" : props .get ("picture" , "" )[4 :] or None })
361
+ "picture" : props .get ("picture" , "" )[4 :] or None ,
362
+ "active" : active })
340
363
return fields
341
364
342
365
@property
@@ -450,14 +473,8 @@ def recent(self):
450
473
resp = self .skype .conn .syncStateCall ("GET" , url , params , auth = SkypeConnection .Auth .RegToken ).json ()
451
474
chats = {}
452
475
for json in resp .get ("conversations" , []):
453
- cls = SkypeSingleChat
454
- if "threadProperties" in json :
455
- info = self .skype .conn ("GET" , "{0}/threads/{1}" .format (self .skype .conn .msgsHost , json .get ("id" )),
456
- auth = SkypeConnection .Auth .RegToken ,
457
- params = {"view" : "msnp24Equivalent" }).json ()
458
- json .update (info )
459
- cls = SkypeGroupChat
460
- chats [json .get ("id" )] = self .merge (cls .fromRaw (self .skype , json ))
476
+ chat = SkypeChat .fromRaw (self .skype , json )
477
+ chats [chat .id ] = self .merge (chat )
461
478
return chats
462
479
463
480
def chat (self , id ):
@@ -466,16 +483,13 @@ def chat(self, id):
466
483
467
484
Args:
468
485
id (str): single or group chat identifier
486
+
487
+ Returns:
488
+ :class:`SkypeChat`: retrieved conversation
469
489
"""
470
490
json = self .skype .conn ("GET" , "{0}/users/ME/conversations/{1}" .format (self .skype .conn .msgsHost , id ),
471
491
auth = SkypeConnection .Auth .RegToken , params = {"view" : "msnp24Equivalent" }).json ()
472
- cls = SkypeSingleChat
473
- if "threadProperties" in json :
474
- info = self .skype .conn ("GET" , "{0}/threads/{1}" .format (self .skype .conn .msgsHost , json .get ("id" )),
475
- auth = SkypeConnection .Auth .RegToken , params = {"view" : "msnp24Equivalent" }).json ()
476
- json .update (info )
477
- cls = SkypeGroupChat
478
- return self .merge (cls .fromRaw (self .skype , json ))
492
+ return self .merge (SkypeChat .fromRaw (self .skype , json ))
479
493
480
494
def create (self , members = (), admins = ()):
481
495
"""
@@ -487,6 +501,9 @@ def create(self, members=(), admins=()):
487
501
Args:
488
502
members (str list): user identifiers to initially join the conversation
489
503
admins (str list): user identifiers to gain admin privileges
504
+
505
+ Returns:
506
+ :class:`SkypeGroupChat`: newly created group conversation
490
507
"""
491
508
memberObjs = [{"id" : "8:{0}" .format (self .skype .userId ), "role" : "Admin" }]
492
509
for id in members :
0 commit comments