aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBlake DeMarcy <ofunknowndescent@gmail.com>2017-04-08 02:14:45 -0500
committerBlake DeMarcy <ofunknowndescent@gmail.com>2017-04-08 02:14:45 -0500
commit054c197534c38fcfd39f57089d23af65f8458dd4 (patch)
treead274ae4d15d2506d7d94f8821ddf41f1e325067 /src
parent2cd7c5d37cb6c68de9e449d4b7a731744ff3407f (diff)
downloadbbj-054c197534c38fcfd39f57089d23af65f8458dd4.tar.gz
add pinned parameter to threads
Diffstat (limited to 'src')
-rw-r--r--src/db.py22
-rw-r--r--src/schema.py4
-rw-r--r--src/utils.py2
3 files changed, 24 insertions, 4 deletions
diff --git a/src/db.py b/src/db.py
index f77a647..38d8cb0 100644
--- a/src/db.py
+++ b/src/db.py
@@ -78,6 +78,21 @@ def thread_index(connection):
return threads
+def thread_set_pin(connection, thread_id, pin_bool):
+ """
+ Set the pinned status of thread_id to pin_bool.
+ """
+ # can never be too sure :^)
+ pin_bool = bool(pin_bool)
+ connection.execute("""
+ UPDATE threads SET
+ pinned = ?
+ WHERE thread_id = ?
+ """, (pin_bool, thread_id))
+ connection.commit()
+ return pin_bool
+
+
def thread_create(connection, author_id, body, title):
"""
Create a new thread and return it.
@@ -91,13 +106,16 @@ def thread_create(connection, author_id, body, title):
thread_id = uuid1().hex
scheme = schema.thread(
thread_id, author_id, title,
- now, now, -1) # see below for why i set -1 instead of 0
+ now, now, -1, False) # see below for why i set -1 instead of 0
connection.execute("""
INSERT INTO threads
- VALUES (?,?,?,?,?,?)
+ VALUES (?,?,?,?,?,?,?)
""", schema_values("thread", scheme))
connection.commit()
+ # the thread is initially commited with reply_count -1 so that i can
+ # just pass the message to the reply method, instead of duplicating
+ # its code here. It then increments to 0.
thread_reply(connection, author_id, thread_id, body, time_override=now)
# fetch the new thread out of the database instead of reusing the returned
# objects, just to be 100% sure what is returned is what was committed
diff --git a/src/schema.py b/src/schema.py
index a6b6d5f..7529c46 100644
--- a/src/schema.py
+++ b/src/schema.py
@@ -127,7 +127,8 @@ def thread(
title, # string
last_mod, # floating point unix timestamp (of last post or post edit)
created, # floating point unix timestamp (when thread was made)
- reply_count): # integer (incremental, starting with 0)
+ reply_count, # integer (incremental, starting with 0)
+ pinned): # boolean
return {
"thread_id": thread_id,
@@ -136,6 +137,7 @@ def thread(
"last_mod": last_mod,
"created": created,
"reply_count": reply_count,
+ "pinned": bool(pinned)
}
diff --git a/src/utils.py b/src/utils.py
index 4f4ad0b..a193cb4 100644
--- a/src/utils.py
+++ b/src/utils.py
@@ -22,7 +22,7 @@ def schema_values(scheme, obj):
elif scheme == "thread":
return ordered_keys(obj,
"thread_id", "author", "title",
- "last_mod", "created", "reply_count")
+ "last_mod", "created", "reply_count", "pinned")
elif scheme == "message":
return ordered_keys(obj,
Un proyecto texto-plano.xyz