Skip to content

Commit 4aa76b6

Browse files
apawlowskijgoggalaxy
authored andcommitted
SDK-3137: friends and presence updates
1 parent c03465e commit 4aa76b6

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

src/galaxy/api/plugin.py

+21
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,13 @@ def remove_friend(self, user_id: str) -> None:
397397
params = {"user_id": user_id}
398398
self._connection.send_notification("friend_removed", params)
399399

400+
def update_friend_info(self, user: UserInfo) -> None:
401+
"""Notify the client about the updated friend information.
402+
403+
:param user: UserInfo of a friend whose info was updated
404+
"""
405+
self._connection.send_notification("friend_updated", params={"friend_info": user})
406+
400407
def update_game_time(self, game_time: GameTime) -> None:
401408
"""Notify the client to update game time for a game.
402409
@@ -405,6 +412,20 @@ def update_game_time(self, game_time: GameTime) -> None:
405412
params = {"game_time": game_time}
406413
self._connection.send_notification("game_time_updated", params)
407414

415+
def update_user_presence(self, user_id: str, user_presence: UserPresence) -> None:
416+
"""Notify the client about the updated user presence information.
417+
418+
:param user_id: the id of the user whose presence information is updated
419+
:param user_presence: presence information of the specified user
420+
"""
421+
self._connection.send_notification(
422+
"user_presence_updated",
423+
{
424+
"user_id": user_id,
425+
"presence": user_presence
426+
}
427+
)
428+
408429
def _game_time_import_success(self, game_time: GameTime) -> None:
409430
params = {"game_time": game_time}
410431
self._connection.send_notification("game_time_import_success", params)

tests/test_friends.py

+23
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,26 @@ async def test_remove_friend(plugin, write):
9999
}
100100
}
101101
]
102+
103+
104+
@pytest.mark.asyncio
105+
async def test_update_friend_info(plugin, write):
106+
plugin.update_friend_info(
107+
UserInfo("7", "Jakub", avatar_url="https://new-avatar.url/kuba2.jpg", profile_url="https://profile.url/kuba")
108+
)
109+
await skip_loop()
110+
111+
assert get_messages(write) == [
112+
{
113+
"jsonrpc": "2.0",
114+
"method": "friend_updated",
115+
"params": {
116+
"friend_info": {
117+
"user_id": "7",
118+
"user_name": "Jakub",
119+
"avatar_url": "https://new-avatar.url/kuba2.jpg",
120+
"profile_url": "https://profile.url/kuba"
121+
}
122+
}
123+
}
124+
]

tests/test_user_presence.py

+23-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from galaxy.api.consts import PresenceState
66
from galaxy.api.errors import BackendError
77
from galaxy.api.types import UserPresence
8-
from galaxy.unittest.mock import async_return_value
8+
from galaxy.unittest.mock import async_return_value, skip_loop
99
from tests import create_message, get_messages
1010

1111

@@ -229,3 +229,25 @@ async def test_import_already_in_progress_error(plugin, read, write):
229229
"message": "Import already in progress"
230230
}
231231
} in responses
232+
233+
234+
@pytest.mark.asyncio
235+
async def test_update_user_presence(plugin, write):
236+
plugin.update_user_presence("42", UserPresence(PresenceState.Online, "game-id", "game-title", "Pew pew"))
237+
await skip_loop()
238+
239+
assert get_messages(write) == [
240+
{
241+
"jsonrpc": "2.0",
242+
"method": "user_presence_updated",
243+
"params": {
244+
"user_id": "42",
245+
"presence": {
246+
"presence_state": PresenceState.Online.value,
247+
"game_id": "game-id",
248+
"game_title": "game-title",
249+
"presence_status": "Pew pew"
250+
}
251+
}
252+
}
253+
]

0 commit comments

Comments
 (0)