aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordesvox <ofunknowndescent@gmail.com>2018-08-05 22:25:02 -0500
committerdesvox <ofunknowndescent@gmail.com>2018-08-05 22:25:02 -0500
commit1c296cc500e507008b9a7a0ffb06b0dc26202a1a (patch)
tree6b2bdd636b40df089130cdbccffeff153e9285a5
parentcba92412a82f0737cf2517412fabb825ed133ccb (diff)
downloadbbj-1c296cc500e507008b9a7a0ffb06b0dc26202a1a.tar.gz
Allow admins to set server pins from client.
-rw-r--r--clients/network_client.py5
-rw-r--r--clients/urwid/main.py27
-rw-r--r--logs/exceptions/996fef24266a11e78aa402e6a9e126c87
-rw-r--r--server.py8
4 files changed, 27 insertions, 20 deletions
diff --git a/clients/network_client.py b/clients/network_client.py
index 3a2ca3d..6cd4883 100644
--- a/clients/network_client.py
+++ b/clients/network_client.py
@@ -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"]
diff --git a/clients/urwid/main.py b/clients/urwid/main.py
index 06bae27..d95b505 100644
--- a/clients/urwid/main.py
+++ b/clients/urwid/main.py
@@ -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:
diff --git a/logs/exceptions/996fef24266a11e78aa402e6a9e126c8 b/logs/exceptions/996fef24266a11e78aa402e6a9e126c8
deleted file mode 100644
index 2bc229e..0000000
--- a/logs/exceptions/996fef24266a11e78aa402e6a9e126c8
+++ /dev/null
@@ -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',) \ No newline at end of file
diff --git a/server.py b/server.py
index f650ecc..a923e18 100644
--- a/server.py
+++ b/server.py
@@ -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.")
)
Un proyecto texto-plano.xyz