aboutsummaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
Diffstat (limited to 'api')
-rw-r--r--api/readme.md1
-rw-r--r--api/social/destroy_relation.py7
-rw-r--r--api/social/friend_accept.py4
3 files changed, 11 insertions, 1 deletions
diff --git a/api/readme.md b/api/readme.md
index 48e9b14..26ef02b 100644
--- a/api/readme.md
+++ b/api/readme.md
@@ -50,6 +50,7 @@ resign|send to resign, is then forwarded to all subscribed clients|`none`|`s <->
newMove|send a new move|`{ move: int, game_id: string }`|`s <- c`|game
registerGameListener|listen to events for a game|`{ id: string }`|`s <- c`|game
incomingFriendRequest|get notified of friend request|`none`|`s -> c`|global
+changedRelation|get notified of a different relation to someone|`{ id: string }`|`s -> c`|global
## How to test API endpoints
```sh
diff --git a/api/social/destroy_relation.py b/api/social/destroy_relation.py
index 09b42f0..a08175f 100644
--- a/api/social/destroy_relation.py
+++ b/api/social/destroy_relation.py
@@ -3,6 +3,7 @@ from db import cursor
from auth.login_token import token_login
from social.create_relation import remove_relation
from user.info import get_relation_to
+from socket_io import io
import time
remove = Blueprint('remove', __name__)
@@ -22,10 +23,14 @@ def index():
return "", 403
relation = get_relation_to(user_1_id, user_2_id)
- if relation == "none": return 403
+ if relation == "none": return "", 403
remove_relation(user_1_id, user_2_id)
remove_relation(user_2_id, user_1_id)
+
+ io.emit("changedRelation", { "id": user_2_id }, room="user-"+user_1_id)
+ io.emit("changedRelation", { "id": user_1_id }, room="user-"+user_2_id)
+
return "", 200
unblock = Blueprint('unblock', __name__)
diff --git a/api/social/friend_accept.py b/api/social/friend_accept.py
index bc850d2..8340274 100644
--- a/api/social/friend_accept.py
+++ b/api/social/friend_accept.py
@@ -1,6 +1,7 @@
from flask import Blueprint, request
from db import cursor, connection
from auth.login_token import token_login
+from socket_io import io
import time
accept = Blueprint('accept', __name__)
@@ -23,6 +24,9 @@ def route():
[user_1_id, user_2_id])
connection.commit()
+ io.emit("changedRelation", { "id": user_2_id }, room="user-"+user_1_id)
+ io.emit("changedRelation", { "id": user_1_id }, room="user-"+user_2_id)
+
return "", 200
dynamic_route = ["/social", accept]