add message feeds
This commit is contained in:
parent
c4f04173c4
commit
33b5912937
@ -1532,7 +1532,6 @@ class JumpPrompt(Prompt, urwid.IntEdit):
|
|||||||
self.set_edit_pos(len(value))
|
self.set_edit_pos(len(value))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def keypress(self, size, key):
|
def keypress(self, size, key):
|
||||||
keyl = key.lower()
|
keyl = key.lower()
|
||||||
if key == "enter":
|
if key == "enter":
|
||||||
|
37
server.py
37
server.py
@ -211,6 +211,37 @@ class API(object):
|
|||||||
return threads
|
return threads
|
||||||
|
|
||||||
|
|
||||||
|
@api_method
|
||||||
|
def message_feed(self, args, database, user, **kwargs):
|
||||||
|
"""
|
||||||
|
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.
|
||||||
|
"""
|
||||||
|
validate(args, ["time"])
|
||||||
|
return db.message_feed(database, args["time"])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@api_method
|
@api_method
|
||||||
def thread_create(self, args, database, user, **kwargs):
|
def thread_create(self, args, database, user, **kwargs):
|
||||||
"""
|
"""
|
||||||
@ -435,12 +466,6 @@ class API(object):
|
|||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
def test(self, **kwargs):
|
|
||||||
print(cherrypy.request.body.read())
|
|
||||||
return "{\"wow\": \"jolly good show!\"}"
|
|
||||||
test.exposed = True
|
|
||||||
|
|
||||||
|
|
||||||
def api_http_error(status, message, traceback, version):
|
def api_http_error(status, message, traceback, version):
|
||||||
return json.dumps(schema.error(2, "HTTP error {}: {}".format(status, message)))
|
return json.dumps(schema.error(2, "HTTP error {}: {}".format(status, message)))
|
||||||
|
|
||||||
|
48
src/db.py
48
src/db.py
@ -30,6 +30,54 @@ import os
|
|||||||
|
|
||||||
anon = None
|
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 ###
|
### THREADS ###
|
||||||
|
|
||||||
def thread_get(connection, thread_id, messages=True):
|
def thread_get(connection, thread_id, messages=True):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user