diff --git a/src/galaxy/api/plugin.py b/src/galaxy/api/plugin.py index 65d408b..1d934f7 100644 --- a/src/galaxy/api/plugin.py +++ b/src/galaxy/api/plugin.py @@ -397,6 +397,13 @@ class Plugin: params = {"user_id": user_id} self._connection.send_notification("friend_removed", params) + def update_friend_info(self, user: UserInfo) -> None: + """Notify the client about the updated friend information. + + :param user: UserInfo of a friend whose info was updated + """ + self._connection.send_notification("friend_updated", params={"friend_info": user}) + def update_game_time(self, game_time: GameTime) -> None: """Notify the client to update game time for a game. @@ -405,6 +412,20 @@ class Plugin: params = {"game_time": game_time} self._connection.send_notification("game_time_updated", params) + def update_user_presence(self, user_id: str, user_presence: UserPresence) -> None: + """Notify the client about the updated user presence information. + + :param user_id: the id of the user whose presence information is updated + :param user_presence: presence information of the specified user + """ + self._connection.send_notification( + "user_presence_updated", + { + "user_id": user_id, + "presence": user_presence + } + ) + def _game_time_import_success(self, game_time: GameTime) -> None: params = {"game_time": game_time} self._connection.send_notification("game_time_import_success", params) diff --git a/tests/test_friends.py b/tests/test_friends.py index c52ced1..9ce07db 100644 --- a/tests/test_friends.py +++ b/tests/test_friends.py @@ -99,3 +99,26 @@ async def test_remove_friend(plugin, write): } } ] + + +@pytest.mark.asyncio +async def test_update_friend_info(plugin, write): + plugin.update_friend_info( + UserInfo("7", "Jakub", avatar_url="https://new-avatar.url/kuba2.jpg", profile_url="https://profile.url/kuba") + ) + await skip_loop() + + assert get_messages(write) == [ + { + "jsonrpc": "2.0", + "method": "friend_updated", + "params": { + "friend_info": { + "user_id": "7", + "user_name": "Jakub", + "avatar_url": "https://new-avatar.url/kuba2.jpg", + "profile_url": "https://profile.url/kuba" + } + } + } + ] diff --git a/tests/test_user_presence.py b/tests/test_user_presence.py index 67163e7..20f8a2f 100644 --- a/tests/test_user_presence.py +++ b/tests/test_user_presence.py @@ -5,7 +5,7 @@ import pytest from galaxy.api.consts import PresenceState from galaxy.api.errors import BackendError from galaxy.api.types import UserPresence -from galaxy.unittest.mock import async_return_value +from galaxy.unittest.mock import async_return_value, skip_loop from tests import create_message, get_messages @@ -229,3 +229,25 @@ async def test_import_already_in_progress_error(plugin, read, write): "message": "Import already in progress" } } in responses + + +@pytest.mark.asyncio +async def test_update_user_presence(plugin, write): + plugin.update_user_presence("42", UserPresence(PresenceState.Online, "game-id", "game-title", "Pew pew")) + await skip_loop() + + assert get_messages(write) == [ + { + "jsonrpc": "2.0", + "method": "user_presence_updated", + "params": { + "user_id": "42", + "presence": { + "presence_state": PresenceState.Online.value, + "game_id": "game-id", + "game_title": "game-title", + "presence_status": "Pew pew" + } + } + } + ]