summary refs log tree commit diff
path: root/db.py
diff options
context:
space:
mode:
Diffstat (limited to 'db.py')
-rw-r--r--db.py44
1 files changed, 43 insertions, 1 deletions
diff --git a/db.py b/db.py
index 88dc79b..6750e47 100644
--- a/db.py
+++ b/db.py
@@ -94,4 +94,46 @@ class acc:
         user = usersd.find_one({"username": username})
         if not user:
             return "notExists"
-        return user["permissions"]
\ No newline at end of file
+        return user["permissions"]
+
+class posts:
+    def get_recent(amount=75):
+        posts = list(postsd.find().sort("created", -1).limit(amount))
+        for i in posts:
+            data = acc.get(i["author"])
+            if type(data) != dict:
+                data = {}
+            else:
+                del data["secure"]
+                del data["profile"]
+            i["author"] = data
+            incr = -1
+            for j in i["replies"]:
+                incr += 1
+                data = acc.get(j["author"])
+                if type(data) != dict:
+                    data = {}
+                else:
+                    del data["secure"]
+                    del data["profile"]
+                i["replies"][incr]["author"] = data
+        return posts
+    
+    def get_by_id(post_id):
+        post = postsd.find_one({"_id": post_id})
+        if not post:
+            return "notExists"
+        else:
+            return post
+
+    def add(data):
+        try:
+            postsd.insert_one(data)
+        except Exception as e:
+            return "fail"
+        return True
+
+class inbox:
+    def get_recent(amount=75):
+        posts = list(inboxd.find().sort("created", -1).limit(amount))
+        return posts
\ No newline at end of file