add pinned parameter to threads
parent
2cd7c5d37c
commit
054c197534
|
@ -21,7 +21,8 @@ create table threads (
|
|||
title text, -- string
|
||||
last_mod real, -- floating point unix timestamp (of last post or post edit)
|
||||
created real, -- floating point unix timestamp (when thread was made)
|
||||
reply_count int -- integer (incremental, starting with 0)
|
||||
reply_count int, -- integer (incremental, starting with 0)
|
||||
pinned int -- boolean
|
||||
);
|
||||
|
||||
|
||||
|
|
22
src/db.py
22
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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue