aboutsummaryrefslogtreecommitdiff
path: root/api/social/destroy_relation.py
blob: 4b61ecd24e3feaff7480dd9916527a27e780be24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from flask import Blueprint, request
from db import cursor
from social.create_relation import remove_relation, two_person_endpoint
from user.info import get_relation_to
from socket_io import io
import time

remove = Blueprint('remove', __name__)

@remove.route('/remove', methods = ['POST'])
@two_person_endpoint
def index(user_1_id, user_2_id):
    relation = get_relation_to(user_1_id, user_2_id)
    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__)

@unblock.route('/unblock', methods = ['POST'])
@two_person_endpoint
def index(user_1_id, user_2_id):
    if get_relation_to(user_1_id, user_2_id) != "blocked": return "", 403

    remove_relation(user_1_id, user_2_id)
    return "", 200

dynamic_routes = [
        ["/social", remove],
        ["/social", unblock]
        ]