Skip to content
This repository was archived by the owner on Jun 11, 2025. It is now read-only.

Commit 7db8f54

Browse files
committed
Merge branch leandr92:master (PR #181)
2 parents 1a1480a + 225f2f3 commit 7db8f54

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

skpy/chat.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,12 @@ class SkypeGroupChat(SkypeChat):
338338
active (bool):
339339
Whether the full group chat was retrieved from the server. This may be ``False`` if a group conversation
340340
still appears in the recent list despite being left or deleted.
341+
moderated (bool):
342+
Whether the group chat is a Skype Moderated Group.
341343
"""
342344

343-
attrs = SkypeChat.attrs + ("topic", "creatorId", "userIds", "adminIds", "open", "history", "picture", "active")
345+
attrs = SkypeChat.attrs + ("topic", "creatorId", "userIds", "adminIds", "open", "history", "picture", "active",
346+
"moderated")
344347

345348
@classmethod
346349
def rawToFields(cls, raw={}, active=False):
@@ -357,6 +360,7 @@ def rawToFields(cls, raw={}, active=False):
357360
"creatorId": SkypeUtils.noPrefix(props.get("creator")),
358361
"userIds": userIds,
359362
"adminIds": adminIds,
363+
"moderated": props.get("moderatedthread") == "true",
360364
"open": props.get("joiningenabled", "") == "true",
361365
"history": props.get("historydisclosed", "") == "true",
362366
"picture": props.get("picture", "")[4:] or None,
@@ -381,6 +385,18 @@ def setTopic(self, topic):
381385
auth=SkypeConnection.Auth.RegToken, params={"name": "topic"}, json={"topic": topic})
382386
self.topic = topic
383387

388+
def setModerated(self, moderated=True):
389+
"""
390+
Update the chat type, and make chat moderated.
391+
392+
Args:
393+
moderated (bool): whether to enable moderation restrictions
394+
"""
395+
self.skype.conn("PUT", "{0}/threads/{1}/properties".format(self.skype.conn.msgsHost, self.id),
396+
auth=SkypeConnection.Auth.RegToken, params={"name": "moderatedthread"},
397+
json={"moderatedthread": moderated})
398+
self.moderated = moderated
399+
384400
def setOpen(self, open):
385401
"""
386402
Enable or disable joining by URL. This does not affect current participants inviting others.
@@ -492,7 +508,7 @@ def chat(self, id):
492508
auth=SkypeConnection.Auth.RegToken, params={"view": "msnp24Equivalent"}).json()
493509
return self.merge(SkypeChat.fromRaw(self.skype, json))
494510

495-
def create(self, members=(), admins=()):
511+
def create(self, members=(), admins=(), moderated=False):
496512
"""
497513
Create a new group chat with the given users.
498514
@@ -502,17 +518,19 @@ def create(self, members=(), admins=()):
502518
Args:
503519
members (str list): user identifiers to initially join the conversation
504520
admins (str list): user identifiers to gain admin privileges
521+
moderate (bool): whether to enable moderation restrictions
505522
506523
Returns:
507524
:class:`SkypeGroupChat`: newly created group conversation
508525
"""
509526
memberObjs = [{"id": "8:{0}".format(self.skype.userId), "role": "Admin"}]
527+
props = {"moderatedthread": moderated}
510528
for id in members:
511529
if id == self.skype.userId:
512530
continue
513531
memberObjs.append({"id": "8:{0}".format(id), "role": "Admin" if id in admins else "User"})
514532
resp = self.skype.conn("POST", "{0}/threads".format(self.skype.conn.msgsHost),
515-
auth=SkypeConnection.Auth.RegToken, json={"members": memberObjs})
533+
auth=SkypeConnection.Auth.RegToken, json={"members": memberObjs, "properties": props})
516534
return self.chat(resp.headers["Location"].rsplit("/", 1)[1])
517535

518536
@staticmethod

0 commit comments

Comments
 (0)