aboutsummaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
authorlonkaars <l.leblansch@gmail.com>2021-03-14 15:07:51 +0100
committerlonkaars <l.leblansch@gmail.com>2021-03-14 15:07:51 +0100
commit8a9060d5dcdc67d14fb5b1b6e856d9ea39ffb618 (patch)
treeeeaf0178fdc2e90e85f3f0f89d4272618ab0f4db /api
parentf6e46892723059efe3ad7666f94d476c7d350c2c (diff)
friend count + dutch grammar on /user
Diffstat (limited to 'api')
-rw-r--r--api/api.ts1
-rw-r--r--api/user/info.py5
2 files changed, 6 insertions, 0 deletions
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)