add new parameter to threads: last_author
parent
90b5573f84
commit
0f6846c360
|
@ -594,17 +594,23 @@ class App(object):
|
||||||
]
|
]
|
||||||
|
|
||||||
infoline = "%d replies; active %s" % (
|
infoline = "%d replies; active %s" % (
|
||||||
thread["reply_count"], self.timestring(thread["last_mod"], "delta"))
|
thread["reply_count"],
|
||||||
|
self.timestring(thread["last_mod"], "delta"))
|
||||||
|
|
||||||
|
last_author = self.usermap[thread["last_author"]]
|
||||||
pile = [
|
pile = [
|
||||||
urwid.Columns([(3, urwid.AttrMap(button, "button", "hover")), title]),
|
urwid.Columns([(3, urwid.AttrMap(button, "button", "hover")), title]),
|
||||||
urwid.Text(dateline),
|
urwid.Text(dateline),
|
||||||
urwid.AttrMap(urwid.Text(infoline), "dim"),
|
urwid.Text(("dim", infoline)),
|
||||||
|
urwid.Text([
|
||||||
|
("dim", "last post by "),
|
||||||
|
(str(last_author["color"]), "~" + last_author["user_name"])
|
||||||
|
]),
|
||||||
urwid.AttrMap(urwid.Divider("-"), "dim")
|
urwid.AttrMap(urwid.Divider("-"), "dim")
|
||||||
]
|
]
|
||||||
|
|
||||||
if self.prefs["index_spacing"]:
|
if self.prefs["index_spacing"]:
|
||||||
pile.insert(3, urwid.Divider())
|
pile.insert(4, urwid.Divider())
|
||||||
|
|
||||||
pile = urwid.Pile(pile)
|
pile = urwid.Pile(pile)
|
||||||
pile.thread = thread
|
pile.thread = thread
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
import sqlite3
|
||||||
|
|
||||||
|
with sqlite3.connect("data.sqlite") as _con:
|
||||||
|
_con.execute('ALTER TABLE threads ADD COLUMN last_author text DEFAULT ""')
|
||||||
|
_con.commit()
|
||||||
|
for tid in _con.execute("SELECT thread_id FROM threads"):
|
||||||
|
author = _con.execute("SELECT author FROM messages WHERE thread_id = ? ORDER BY post_id", tid).fetchall()[-1]
|
||||||
|
_con.execute("UPDATE threads SET last_author = ? WHERE thread_id = ?", author + tid)
|
||||||
|
_con.commit()
|
|
@ -22,7 +22,8 @@ create table threads (
|
||||||
last_mod real, -- floating point unix timestamp (of last post or post edit)
|
last_mod real, -- floating point unix timestamp (of last post or post edit)
|
||||||
created real, -- floating point unix timestamp (when thread was made)
|
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
|
pinned int, -- boolean
|
||||||
|
last_author text -- uuid string
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
11
server.py
11
server.py
|
@ -87,24 +87,25 @@ def api_method(function):
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
def create_usermap(connection, obj):
|
def create_usermap(connection, obj, index=False):
|
||||||
"""
|
"""
|
||||||
Creates a mapping of all the user_ids that occur in OBJ to
|
Creates a mapping of all the user_ids that occur in OBJ to
|
||||||
their full user objects (names, profile info, etc). Can
|
their full user objects (names, profile info, etc). Can
|
||||||
be a thread_index or a messages object from one.
|
be a thread_index or a messages object from one.
|
||||||
"""
|
"""
|
||||||
|
user_set = {item["author"] for item in obj}
|
||||||
|
if index:
|
||||||
|
[user_set.add(item["last_author"]) for item in obj]
|
||||||
return {
|
return {
|
||||||
user_id: db.user_resolve(
|
user_id: db.user_resolve(
|
||||||
connection,
|
connection,
|
||||||
user_id,
|
user_id,
|
||||||
externalize=True,
|
externalize=True,
|
||||||
return_false=False)
|
return_false=False)
|
||||||
for user_id in {item["author"] for item in obj}
|
for user_id in user_set
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def validate(json, args):
|
def validate(json, args):
|
||||||
"""
|
"""
|
||||||
Ensure the json object contains all the keys needed to satisfy
|
Ensure the json object contains all the keys needed to satisfy
|
||||||
|
@ -206,7 +207,7 @@ class API(object):
|
||||||
Requires no arguments.
|
Requires no arguments.
|
||||||
"""
|
"""
|
||||||
threads = db.thread_index(database)
|
threads = db.thread_index(database)
|
||||||
cherrypy.thread_data.usermap = create_usermap(database, threads)
|
cherrypy.thread_data.usermap = create_usermap(database, threads, True)
|
||||||
return threads
|
return threads
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -106,11 +106,12 @@ def thread_create(connection, author_id, body, title, send_raw=False):
|
||||||
thread_id = uuid1().hex
|
thread_id = uuid1().hex
|
||||||
scheme = schema.thread(
|
scheme = schema.thread(
|
||||||
thread_id, author_id, title,
|
thread_id, author_id, title,
|
||||||
now, now, -1, False) # see below for why i set -1 instead of 0
|
now, now, -1, # see below for why i set -1 instead of 0
|
||||||
|
False, author_id)
|
||||||
|
|
||||||
connection.execute("""
|
connection.execute("""
|
||||||
INSERT INTO threads
|
INSERT INTO threads
|
||||||
VALUES (?,?,?,?,?,?,?)
|
VALUES (?,?,?,?,?,?,?,?)
|
||||||
""", schema_values("thread", scheme))
|
""", schema_values("thread", scheme))
|
||||||
connection.commit()
|
connection.commit()
|
||||||
# the thread is initially commited with reply_count -1 so that i can
|
# the thread is initially commited with reply_count -1 so that i can
|
||||||
|
@ -147,9 +148,10 @@ def thread_reply(connection, author_id, thread_id, body, send_raw=False, time_ov
|
||||||
connection.execute("""
|
connection.execute("""
|
||||||
UPDATE threads SET
|
UPDATE threads SET
|
||||||
reply_count = ?,
|
reply_count = ?,
|
||||||
|
last_author = ?,
|
||||||
last_mod = ?
|
last_mod = ?
|
||||||
WHERE thread_id = ?
|
WHERE thread_id = ?
|
||||||
""", (count, now, thread_id))
|
""", (count, author_id, now, thread_id))
|
||||||
|
|
||||||
connection.commit()
|
connection.commit()
|
||||||
return scheme
|
return scheme
|
||||||
|
|
|
@ -128,7 +128,8 @@ def thread(
|
||||||
last_mod, # floating point unix timestamp (of last post or post edit)
|
last_mod, # floating point unix timestamp (of last post or post edit)
|
||||||
created, # floating point unix timestamp (when thread was made)
|
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
|
pinned, # boolean
|
||||||
|
last_author): # uuid string
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"thread_id": thread_id,
|
"thread_id": thread_id,
|
||||||
|
@ -137,7 +138,8 @@ def thread(
|
||||||
"last_mod": last_mod,
|
"last_mod": last_mod,
|
||||||
"created": created,
|
"created": created,
|
||||||
"reply_count": reply_count,
|
"reply_count": reply_count,
|
||||||
"pinned": bool(pinned)
|
"pinned": bool(pinned),
|
||||||
|
"last_author": last_author
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,8 @@ def schema_values(scheme, obj):
|
||||||
elif scheme == "thread":
|
elif scheme == "thread":
|
||||||
return ordered_keys(obj,
|
return ordered_keys(obj,
|
||||||
"thread_id", "author", "title",
|
"thread_id", "author", "title",
|
||||||
"last_mod", "created", "reply_count", "pinned")
|
"last_mod", "created", "reply_count",
|
||||||
|
"pinned", "last_author")
|
||||||
|
|
||||||
elif scheme == "message":
|
elif scheme == "message":
|
||||||
return ordered_keys(obj,
|
return ordered_keys(obj,
|
||||||
|
|
Loading…
Reference in New Issue