Allow admins to set server pins from client.
parent
cba92412a8
commit
1c296cc500
|
@ -592,15 +592,14 @@ class BBJ(object):
|
||||||
return response["data"]
|
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
|
Set whether a thread should be pinned or not. new_status
|
||||||
is evaluated as a boolean, and given that the logged in
|
is evaluated as a boolean, and given that the logged in
|
||||||
user is an admin, the thread is set to this status on
|
user is an admin, the thread is set to this status on
|
||||||
the server, and the boolean is returned.
|
the server, and the boolean is returned.
|
||||||
"""
|
"""
|
||||||
assert self.get_me()["is_admin"]
|
response = self("thread_set_pin", thread_id=thread_id, value=new_status)
|
||||||
response = self("set_thread_pin", thread_id=pinned, pinned=new_status)
|
|
||||||
return response["data"]
|
return response["data"]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -668,6 +668,8 @@ class App(object):
|
||||||
"Enable Formatting" if raw else "Disable Formatting",
|
"Enable Formatting" if raw else "Disable Formatting",
|
||||||
self.toggle_formatting, message))
|
self.toggle_formatting, message))
|
||||||
buttons.insert(0, urwid.Button("Edit Post", self.edit_post, 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:
|
if not buttons:
|
||||||
return
|
return
|
||||||
|
@ -823,19 +825,22 @@ class App(object):
|
||||||
self.usermap.update(usermap)
|
self.usermap.update(usermap)
|
||||||
self.walker.clear()
|
self.walker.clear()
|
||||||
|
|
||||||
server_pin_counter = 0
|
server_pins = []
|
||||||
client_pin_counter = 0
|
client_pin_counter = 0
|
||||||
|
|
||||||
for thread in threads:
|
for thread in threads:
|
||||||
if thread["pinned"]:
|
if thread["pinned"]:
|
||||||
self.walker.insert(server_pin_counter, self.make_thread_body(thread, pinned="server"))
|
server_pins.append(thread)
|
||||||
server_pin_counter += 1
|
|
||||||
elif thread["thread_id"] in self.client_pinned_threads:
|
elif thread["thread_id"] in self.client_pinned_threads:
|
||||||
self.walker.insert(client_pin_counter, self.make_thread_body(thread, pinned="client"))
|
self.walker.insert(client_pin_counter, self.make_thread_body(thread, pinned="client"))
|
||||||
client_pin_counter += 1
|
client_pin_counter += 1
|
||||||
else:
|
else:
|
||||||
self.walker.append(self.make_thread_body(thread))
|
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)
|
self.set_bars(True)
|
||||||
|
|
||||||
if self.last_index_pos:
|
if self.last_index_pos:
|
||||||
|
@ -882,6 +887,14 @@ class App(object):
|
||||||
self.index()
|
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):
|
def search_index_callback(self, query):
|
||||||
simple_query = query.lower().strip()
|
simple_query = query.lower().strip()
|
||||||
threads, usermap = network.thread_index()
|
threads, usermap = network.thread_index()
|
||||||
|
@ -2233,6 +2246,9 @@ class ActionBox(urwid.ListBox):
|
||||||
elif key == "*":
|
elif key == "*":
|
||||||
app.toggle_client_pin()
|
app.toggle_client_pin()
|
||||||
|
|
||||||
|
elif key == "\\":
|
||||||
|
app.toggle_server_pin()
|
||||||
|
|
||||||
elif key == "~":
|
elif key == "~":
|
||||||
# sssssshhhhhhhh
|
# sssssshhhhhhhh
|
||||||
app.loop.stop()
|
app.loop.stop()
|
||||||
|
@ -2240,13 +2256,12 @@ class ActionBox(urwid.ListBox):
|
||||||
except: pass
|
except: pass
|
||||||
app.loop.start()
|
app.loop.start()
|
||||||
|
|
||||||
elif keyl == "f12":
|
elif keyl == "$":
|
||||||
app.loop.stop()
|
app.loop.stop()
|
||||||
call("clear", shell=True)
|
call("clear", shell=True)
|
||||||
motherfucking_rainbows(obnoxious_logo)
|
|
||||||
readline.set_completer(rlcompleter.Completer().complete)
|
readline.set_completer(rlcompleter.Completer().complete)
|
||||||
readline.parse_and_bind("tab: 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()
|
app.loop.start()
|
||||||
|
|
||||||
elif app.mode == "thread" and not app.window_split and not overlay:
|
elif app.mode == "thread" and not app.window_split and not overlay:
|
||||||
|
|
|
@ -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',)
|
|
|
@ -600,7 +600,7 @@ class API(object):
|
||||||
)
|
)
|
||||||
|
|
||||||
@api_method
|
@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`
|
Requires the arguments `thread_id` and `value`. `value`
|
||||||
must be a boolean of what the pinned status should be.
|
must be a boolean of what the pinned status should be.
|
||||||
|
@ -612,9 +612,9 @@ class API(object):
|
||||||
validate(args, ["thread_id", "value"])
|
validate(args, ["thread_id", "value"])
|
||||||
if not user["is_admin"]:
|
if not user["is_admin"]:
|
||||||
raise BBJUserError("Only admins can set thread pins")
|
raise BBJUserError("Only admins can set thread pins")
|
||||||
return db.set_thread_pin(database, args["thread_id"], args["value"])
|
return db.thread_set_pin(database, args["thread_id"], args["value"])
|
||||||
set_thread_pin.doctype = "Threads & Messages"
|
thread_set_pin.doctype = "Threads & Messages"
|
||||||
set_thread_pin.arglist = (
|
thread_set_pin.arglist = (
|
||||||
("thread_id", "string: the id of the thread to modify."),
|
("thread_id", "string: the id of the thread to modify."),
|
||||||
("value", "boolean: `true` to pin thread, `false` otherwise.")
|
("value", "boolean: `true` to pin thread, `false` otherwise.")
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue