blueprints.relationships: sub/unsub friends on friend request changes

This commit is contained in:
Luna Mendes 2018-10-15 15:43:00 -03:00
parent 1d3520876d
commit 151715943b
1 changed files with 22 additions and 0 deletions

View File

@ -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