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