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

Commit af3db1e

Browse files
committed
Restore contact presence events
Fixes #130.
1 parent 8e62dda commit af3db1e

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

skpy/conn.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,10 @@ class SkypeEndpoint(SkypeObj):
841841

842842
attrs = ("id",)
843843

844+
resources = ["/v1/users/ME/conversations/ALL/properties",
845+
"/v1/users/ME/conversations/ALL/messages",
846+
"/v1/threads/ALL"]
847+
844848
def __init__(self, conn, id):
845849
"""
846850
Create a new instance based on a newly-created endpoint identifier.
@@ -853,6 +857,7 @@ def __init__(self, conn, id):
853857
self.conn = conn
854858
self.id = id
855859
self.subscribed = False
860+
self.subscribedPresence = False
856861

857862
def config(self, name="skype"):
858863
"""
@@ -890,14 +895,29 @@ def subscribe(self):
890895
"""
891896
self.conn("POST", "{0}/users/ME/endpoints/{1}/subscriptions".format(self.conn.msgsHost, self.id),
892897
auth=SkypeConnection.Auth.RegToken,
893-
json={"interestedResources": ["/v1/threads/ALL",
894-
"/v1/users/ME/contacts/ALL",
895-
"/v1/users/ME/conversations/ALL/messages",
896-
"/v1/users/ME/conversations/ALL/properties"],
897-
"template": "raw",
898-
"channelType": "httpLongPoll"})
898+
json={"interestedResources": self.resources,
899+
"channelType": "HttpLongPoll",
900+
"conversationType": 2047})
899901
self.subscribed = True
900902

903+
def subscribePresence(self, contacts):
904+
"""
905+
Enable presence subscriptions for the authenticated user's contacts.
906+
907+
Args:
908+
contacts (.SkypeContacts): contact list to select user IDs
909+
"""
910+
if not self.subscribed:
911+
self.subscribe()
912+
resources = list(self.resources)
913+
for contact in contacts:
914+
resources.append("/v1/users/ME/contacts/8:{}".format(contact.id))
915+
self.conn("PUT", "{0}/users/ME/endpoints/{1}/subscriptions/0".format(self.conn.msgsHost, self.id),
916+
auth=SkypeConnection.Auth.RegToken,
917+
params={"name": "interestedResources"},
918+
json={"interestedResources": resources})
919+
self.subscribedPresence = True
920+
901921
def getEvents(self):
902922
"""
903923
Retrieve a list of events since the last poll. Multiple calls may be needed to retrieve all events.

skpy/main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ def services(self):
8989
return self.conn("GET", "{0}/users/{1}/services".format(SkypeConnection.API_ENTITLEMENT, self.userId),
9090
auth=SkypeConnection.Auth.SkypeToken, headers={"Accept": "application/json; ver=3.0"}).json()
9191

92+
def subscribePresence(self):
93+
"""
94+
Subscribe to contact presence events.
95+
"""
96+
self.conn.endpoints["self"].subscribePresence(self.contacts)
97+
9298
@SkypeConnection.handle(404, regToken=True)
9399
@SkypeConnection.handle(404, subscribe="self")
94100
def getEvents(self):

0 commit comments

Comments
 (0)