diff --git a/bbj.el b/bbj.el index 298fae8..a526ad2 100644 --- a/bbj.el +++ b/bbj.el @@ -467,19 +467,31 @@ it worked on emacs 24." (defun bbj-edit-post () (interactive) - (let ((adminp (bbj-request "is_admin" 'target_user bbj-username)) - (callback `(lambda () - (let* ((message (bbj-consume-window (current-buffer))) - (request (bbj-request "edit_post" - 'post_id ,(alist-get 'post_id (bbj-post-prop 'data)) - 'body message 'thread_id ,thread-id))) - (if (numberp (bbj-descend request 'error 'code)) - (message bbj-descend request 'error 'description) - (message "post edited") - (bbj-enter-thread ,thread-id)))))) + (when (eq bbj-buffer-type 'index) + (let ((buffer (current-buffer))) + (bbj-enter) + (unless (eql buffer (current-buffer)) + (bbj-edit-post)))) + (let* ((post (alist-get 'post_id (bbj-post-prop 'data))) + (adminp (bbj-request "is_admin" 'target_user bbj-username)) + (message (alist-get 'body (bbj-post-prop 'data))) + (query (bbj-request "edit_query" 'post_id post 'thread_id thread-id)) + (callback `(lambda () + (let* ((message (bbj-consume-window (current-buffer))) + (request (bbj-request "edit_post" + 'post_id ,post + 'body message 'thread_id ,thread-id))) + (if (numberp (bbj-descend request 'error 'code)) + (message bbj-descend request 'error 'description) + (message "post edited") + (bbj-enter-thread ,thread-id)))))) (cond - ((and (not (eq )))) - ))) + ((numberp (bbj-descend query 'error 'code)) + (message (bbj-descend query 'error 'description))) + (t + (bbj-compose-in-window "Editing post (including html) (C-c C-c to send)" callback) + (insert message) + (goto-char (point-min)))))) (defun bbj-browse-index () diff --git a/src/db.py b/src/db.py index 0eb38d7..0cbaf5a 100644 --- a/src/db.py +++ b/src/db.py @@ -190,7 +190,12 @@ def user_namecheck(name): return False, schema.error(4, "Username cannot contain whitespace chars besides spaces.") - elif len(username) > 24: + elif not name.strip(): + return False, schema.error(4, + "Username must contain at least one non-space character") + + + elif len(name) > 24: return False, schema.error(4, "Username is too long (max 24 chars)") @@ -199,7 +204,7 @@ def user_namecheck(name): def user_authcheck(auth_hash): if not auth_hash: - return schema.error(3, + return False, schema.error(3, "auth_hash may not be empty") elif len(auth_hash) != 64: @@ -211,7 +216,7 @@ def user_authcheck(auth_hash): def user_quipcheck(quip): if not quip: - return "" + return True, True elif contains_nonspaces(quip): return False, schema.error(4, @@ -226,7 +231,7 @@ def user_quipcheck(quip): def user_biocheck(bio): if not bio: - return "" + return True, True elif len(bio) > 4096: return False, schema.error(4, diff --git a/src/endpoints.py b/src/endpoints.py index 434f791..35a38dc 100644 --- a/src/endpoints.py +++ b/src/endpoints.py @@ -13,6 +13,7 @@ endpoints = { "thread_create": ["title", "body", "tags"], "thread_reply": ["thread_id", "body"], "edit_post": ["thread_id", "post_id", "body"], + "edit_query": ["thread_id", "post_id"], "can_edit": ["thread_id", "post_id"], "user_register": ["user", "auth_hash", "quip", "bio"], "user_get": ["target_user"], @@ -100,13 +101,17 @@ def user_register(json): return schema.response( db.user_register( - json["user"], json["auth_hash"], + json["user"], json["quip"], json["bio"])) def user_get(json): + """ + On success, returns an external user object for target_user (ID or name). + If the user isn't in the system, returns false. + """ user = db.user_resolve(json["target_user"]) if not user: return False @@ -146,6 +151,10 @@ def thread_reply(json): return schema.response(reply) +def edit_query(json): + return db.edit_handler(json)[1] + + def can_edit(json): return db.edit_handler(json)[0] @@ -154,9 +163,9 @@ def edit_post(json): thread = db.thread_load(json["thread_id"]) admin = db.user_is_admin(json["user"]) target_id = json["post_id"] - query, obj = db.edit_handler(json, thread) + ok, obj = db.edit_handler(json, thread) - if query: + if ok: obj["body"] = json["body"] obj["lastmod"] = time() obj["edited"] = True