From 8a9060d5dcdc67d14fb5b1b6e856d9ea39ffb618 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Sun, 14 Mar 2021 15:07:51 +0100 Subject: friend count + dutch grammar on /user --- api/api.ts | 1 + api/user/info.py | 5 +++++ 2 files changed, 6 insertions(+) (limited to 'api') diff --git a/api/api.ts b/api/api.ts index 0902d53..2acc4ea 100644 --- a/api/api.ts +++ b/api/api.ts @@ -6,6 +6,7 @@ export interface userInfo { registered?: number, type?: string, username?: string, + friends: number, relation?: "none"|"friends"|"incoming"|"outgoing"|"blocked", }; diff --git a/api/user/info.py b/api/user/info.py index e720e56..b60593e 100644 --- a/api/user/info.py +++ b/api/user/info.py @@ -18,6 +18,10 @@ def get_relation_to(user_1_id, user_2_id): if relation[2] == "block" and relation[0] == user_1_id: return "blocked" return "none" +def count_friends(user_id): + query = cursor.execute("select type from social where (user_1_id = ? or user_2_id = ?) and type = \"friendship\"", [user_id, user_id]).fetchall() + return len(query) + def format_user(user_id, viewer = ''): user = cursor.execute("select " + ", ".join([ "username", @@ -34,6 +38,7 @@ def format_user(user_id, viewer = ''): "registered": user[3], "avatar": user[4], "status": user[5], + "friends": count_friends(user_id) } if viewer: formatted_user["relation"] = get_relation_to(viewer, user_id) -- cgit v1.2.3