Allow admins to set server pins from client.

This commit is contained in:
desvox 2018-08-05 22:25:02 -05:00
parent cba92412a8
commit 1c296cc500
4 changed files with 27 additions and 20 deletions

View File

@ -592,15 +592,14 @@ class BBJ(object):
return response["data"]
def set_thread_pin(self, thread_id, new_status):
def thread_set_pin(self, thread_id, new_status):
"""
Set whether a thread should be pinned or not. new_status
is evaluated as a boolean, and given that the logged in
user is an admin, the thread is set to this status on
the server, and the boolean is returned.
"""
assert self.get_me()["is_admin"]
response = self("set_thread_pin", thread_id=pinned, pinned=new_status)
response = self("thread_set_pin", thread_id=thread_id, value=new_status)
return response["data"]

View File

@ -668,6 +668,8 @@ class App(object):
"Enable Formatting" if raw else "Disable Formatting",
self.toggle_formatting, message))
buttons.insert(0, urwid.Button("Edit Post", self.edit_post, message))
if network.user["is_admin"]:
buttons.insert(0, urwid.Text(("20", "Reminder: You're an admin!")))
if not buttons:
return
@ -823,19 +825,22 @@ class App(object):
self.usermap.update(usermap)
self.walker.clear()
server_pin_counter = 0
server_pins = []
client_pin_counter = 0
for thread in threads:
if thread["pinned"]:
self.walker.insert(server_pin_counter, self.make_thread_body(thread, pinned="server"))
server_pin_counter += 1
server_pins.append(thread)
elif thread["thread_id"] in self.client_pinned_threads:
self.walker.insert(client_pin_counter, self.make_thread_body(thread, pinned="client"))
client_pin_counter += 1
else:
self.walker.append(self.make_thread_body(thread))
# make sure these are always up top
for index, thread in enumerate(server_pins):
self.walker.insert(index, self.make_thread_body(thread, pinned="server"))
self.set_bars(True)
if self.last_index_pos:
@ -882,6 +887,14 @@ class App(object):
self.index()
def toggle_server_pin(self):
if self.mode != "index" or not network.user["is_admin"]:
return
thread = self.walker.get_focus()[0].thread
network.thread_set_pin(thread["thread_id"], not thread["pinned"])
self.index()
def search_index_callback(self, query):
simple_query = query.lower().strip()
threads, usermap = network.thread_index()
@ -2233,6 +2246,9 @@ class ActionBox(urwid.ListBox):
elif key == "*":
app.toggle_client_pin()
elif key == "\\":
app.toggle_server_pin()
elif key == "~":
# sssssshhhhhhhh
app.loop.stop()
@ -2240,13 +2256,12 @@ class ActionBox(urwid.ListBox):
except: pass
app.loop.start()
elif keyl == "f12":
elif keyl == "$":
app.loop.stop()
call("clear", shell=True)
motherfucking_rainbows(obnoxious_logo)
readline.set_completer(rlcompleter.Completer().complete)
readline.parse_and_bind("tab: complete")
interact(banner=version + "\n(BBJ Interactive Console)", local=globals())
interact(banner="Python " + version + "\nBBJ Interactive Console\nCtrl-D exits.", local=globals())
app.loop.start()
elif app.mode == "thread" and not app.window_split and not overlay:

View File

@ -1,7 +0,0 @@
File "server.py", line 64, in wrapper
value = function(self, body, connection, user)
File "server.py", line 380, in format_message
formatting.apply_formatting(message, formatter)
File "/home/desvox/BBJ/src/formatting.py", line 183, in apply_formatting
if not msg_obj[x]["send_raw"]:
KeyError('send_raw',)

View File

@ -600,7 +600,7 @@ class API(object):
)
@api_method
def set_thread_pin(self, args, database, user, **kwargs):
def thread_set_pin(self, args, database, user, **kwargs):
"""
Requires the arguments `thread_id` and `value`. `value`
must be a boolean of what the pinned status should be.
@ -612,9 +612,9 @@ class API(object):
validate(args, ["thread_id", "value"])
if not user["is_admin"]:
raise BBJUserError("Only admins can set thread pins")
return db.set_thread_pin(database, args["thread_id"], args["value"])
set_thread_pin.doctype = "Threads & Messages"
set_thread_pin.arglist = (
return db.thread_set_pin(database, args["thread_id"], args["value"])
thread_set_pin.doctype = "Threads & Messages"
thread_set_pin.arglist = (
("thread_id", "string: the id of the thread to modify."),
("value", "boolean: `true` to pin thread, `false` otherwise.")
)