Allow server to share configuration info with clients.

themes
desvox 2018-08-04 08:21:01 -05:00
parent 504ee3fc04
commit be24ae9dc2
3 changed files with 37 additions and 12 deletions

View File

@ -76,6 +76,7 @@ class BBJ(object):
self.send_auth = True
try:
self.user = self("get_me")["data"]
self.update_instance_info()
except URLError:
raise URLError("Cannot connect to %s (is the server down?)" % self.base[0:-2])
@ -178,6 +179,19 @@ class BBJ(object):
raise e
def update_instance_info(self):
"""
Stores configuration info for the connected BBJ server.
{
"instance_name": (string), // a title set by the server owner
"allow_anon": (bool) // whether anonymous participation is allowed
}
"""
response = self("instance_info")
self.instance_info = response["data"]
def validate(self, key, value, exception=AssertionError):
"""
Uses the server's db_validate method to verify the validty

View File

@ -218,7 +218,8 @@ default_prefs = {
"dramatic_exit": True,
"date": "%Y/%m/%d",
"time": "%H:%M",
"frame_title": "> > T I L D E T O W N < <",
"frame_title": "BBJ",
"use_custom_frame_title": False,
"max_text_width": 80,
"confirm_anon": True,
"edit_escapes": {
@ -278,31 +279,31 @@ pinpath = os.path.join(os.getenv("HOME"), ".bbjpins")
class App(object):
def __init__(self):
self.prefs = bbjrc("load")
self.mode = None
self.thread = None
self.usermap = {}
self.window_split = False
self.last_index_pos = None
self.last_alarm = None
self.client_pinned_threads = load_client_pins()
self.usermap = {}
self.match_data = {
"query": "",
"matches": [],
"position": 0,
}
# these can be changed and manipulated by other methods
self.mode = None
self.thread = None
self.window_split = False
self.last_index_pos = None
self.last_alarm = None
self.walker = urwid.SimpleFocusListWalker([])
self.box = ActionBox(self.walker)
self.body = urwid.AttrMap(
urwid.LineBox(
self.box,
title=self.prefs["frame_title"],
title=self.prefs["frame_title"]
if self.prefs["use_custom_frame_title"]
else network.instance_info["instance_name"],
**frame_theme()),
"default"
)
self.loop = urwid.MainLoop(
urwid.Frame(self.body),
palette=colormap,

View File

@ -26,7 +26,7 @@ try:
app_config.update(json.load(_conf))
except FileNotFoundError:
with open("config.json", "w") as _conf:
json.dump(app_config, _conf)
json.dump(app_config, _conf, indent=2)
def api_method(function):
@ -185,6 +185,16 @@ class API(object):
after each method definition are for use in the `mkendpoints.py` script.
"""
@api_method
def instance_info(self, args, database, user, **kwargs):
"""
Return configuration info for this running instance of the BBJ server.
"""
return {
"allow_anon": app_config["allow_anon"],
"instance_name": app_config["instance_name"]
}
@api_method
def user_register(self, args, database, user, **kwargs):
"""