From 151715943bf7dac48965babeffc5668cf328ee3a Mon Sep 17 00:00:00 2001 From: Luna Mendes Date: Mon, 15 Oct 2018 15:43:00 -0300 Subject: [PATCH] blueprints.relationships: sub/unsub friends on friend request changes --- litecord/blueprints/relationships.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/litecord/blueprints/relationships.py b/litecord/blueprints/relationships.py index 46e3b03..80985dd 100644 --- a/litecord/blueprints/relationships.py +++ b/litecord/blueprints/relationships.py @@ -15,6 +15,17 @@ async def get_me_relationships(): return jsonify(await app.storage.get_relationships(user_id)) +async def _unsub_friend(user_id, peer_id): + await app.dispatcher.unsub('friend', user_id, peer_id) + await app.dispatcher.unsub('friend', peer_id, user_id) + + +async def _sub_friend(user_id, peer_id): + await app.dispatcher.sub('friend', user_id, peer_id) + await app.dispatcher.sub('friend', peer_id, user_id) + + + async def make_friend(user_id: int, peer_id: int, rel_type=RelationshipType.FRIEND.value): _friend = RelationshipType.FRIEND.value @@ -54,6 +65,8 @@ async def make_friend(user_id: int, peer_id: int, 'user': await app.storage.get_user(user_id) }) + await _sub_friend(user_id, peer_id) + return '', 204 # check if friend AND not acceptance of fr @@ -70,6 +83,9 @@ async def make_friend(user_id: int, peer_id: int, 'user': await app.storage.get_user(user_id) }) + # we don't make the pubsub link + # until the peer accepts the friend request + return '', 204 return @@ -116,6 +132,8 @@ async def add_relationship(peer_id: int): 'user': await app.storage.get_user(peer_id) }) + await _unsub_friend(user_id, peer_id) + return '', 204 @@ -169,6 +187,8 @@ async def remove_relationship(peer_id: int): 'type': peer_del_type, }) + await _unsub_friend(user_id, peer_id) + return '', 204 # was a block! @@ -182,4 +202,6 @@ async def remove_relationship(peer_id: int): 'type': _block, }) + await _unsub_friend(user_id, peer_id) + return '', 204