diff options
author | Blake DeMarcy <ofunknowndescent@gmail.com> | 2017-04-26 14:51:03 -0500 |
---|---|---|
committer | Blake DeMarcy <ofunknowndescent@gmail.com> | 2017-04-26 14:51:03 -0500 |
commit | 33b591293750db1de93c2c372706cf2e3b134dee (patch) | |
tree | 6114beb9dbabe7495885fb57adf7c2cb92947aed /src | |
parent | c4f04173c44ec79c80de1eed47892e28fde2d704 (diff) | |
download | bbj-33b591293750db1de93c2c372706cf2e3b134dee.tar.gz |
add message feeds
Diffstat (limited to 'src')
-rw-r--r-- | src/db.py | 48 |
1 files changed, 48 insertions, 0 deletions
@@ -30,6 +30,54 @@ import os anon = None + +def message_feed(connection, time): + """ + Returns a special object representing all activity on the board since + the argument `time`, a unix/epoch timestamp. + + { + "threads": { + "thread_id": { + ...thread object + }, + ...more thread_id/object pairs + }, + "messages": [...standard message object array sorted by date] + } + + The message objects in "messages" are the same objects returned + in threads normally. They each have a thread_id parameter, and + you can access metadata for these threads by the "threads" object + which is also provided. + + The "messages" array is already sorted by submission time, newest + first. The order in the threads object is undefined and you should + instead use their `last_mod` attribute if you intend to list them + out visually. + """ + threads = { + obj[0]: schema.thread(*obj) for obj in + connection.execute( + "SELECT * FROM threads WHERE last_mod > ?", (time,)) + } + + messages = list() + for thread in threads.values(): + messages += [ + schema.message(*obj) for obj in + connection.execute(""" + SELECT * FROM messages WHERE thread_id = ? + AND created > ? """, (thread["thread_id"], time)) + ] + + return { + "threads": threads, + "messages": sorted(messages, key=lambda m: m["created"]) + } + + + ### THREADS ### def thread_get(connection, thread_id, messages=True): |