(slightly) less primitive message editing support

pull/4/head
Blake DeMarcy 2017-03-03 17:03:16 -06:00
parent e892d20e18
commit 53961bbece
3 changed files with 45 additions and 19 deletions

36
bbj.el
View File

@ -467,19 +467,31 @@ it worked on emacs 24."
(defun bbj-edit-post () (defun bbj-edit-post ()
(interactive) (interactive)
(let ((adminp (bbj-request "is_admin" 'target_user bbj-username)) (when (eq bbj-buffer-type 'index)
(callback `(lambda () (let ((buffer (current-buffer)))
(let* ((message (bbj-consume-window (current-buffer))) (bbj-enter)
(request (bbj-request "edit_post" (unless (eql buffer (current-buffer))
'post_id ,(alist-get 'post_id (bbj-post-prop 'data)) (bbj-edit-post))))
'body message 'thread_id ,thread-id))) (let* ((post (alist-get 'post_id (bbj-post-prop 'data)))
(if (numberp (bbj-descend request 'error 'code)) (adminp (bbj-request "is_admin" 'target_user bbj-username))
(message bbj-descend request 'error 'description) (message (alist-get 'body (bbj-post-prop 'data)))
(message "post edited") (query (bbj-request "edit_query" 'post_id post 'thread_id thread-id))
(bbj-enter-thread ,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 (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 () (defun bbj-browse-index ()

View File

@ -190,7 +190,12 @@ def user_namecheck(name):
return False, schema.error(4, return False, schema.error(4,
"Username cannot contain whitespace chars besides spaces.") "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, return False, schema.error(4,
"Username is too long (max 24 chars)") "Username is too long (max 24 chars)")
@ -199,7 +204,7 @@ def user_namecheck(name):
def user_authcheck(auth_hash): def user_authcheck(auth_hash):
if not auth_hash: if not auth_hash:
return schema.error(3, return False, schema.error(3,
"auth_hash may not be empty") "auth_hash may not be empty")
elif len(auth_hash) != 64: elif len(auth_hash) != 64:
@ -211,7 +216,7 @@ def user_authcheck(auth_hash):
def user_quipcheck(quip): def user_quipcheck(quip):
if not quip: if not quip:
return "" return True, True
elif contains_nonspaces(quip): elif contains_nonspaces(quip):
return False, schema.error(4, return False, schema.error(4,
@ -226,7 +231,7 @@ def user_quipcheck(quip):
def user_biocheck(bio): def user_biocheck(bio):
if not bio: if not bio:
return "" return True, True
elif len(bio) > 4096: elif len(bio) > 4096:
return False, schema.error(4, return False, schema.error(4,

View File

@ -13,6 +13,7 @@ endpoints = {
"thread_create": ["title", "body", "tags"], "thread_create": ["title", "body", "tags"],
"thread_reply": ["thread_id", "body"], "thread_reply": ["thread_id", "body"],
"edit_post": ["thread_id", "post_id", "body"], "edit_post": ["thread_id", "post_id", "body"],
"edit_query": ["thread_id", "post_id"],
"can_edit": ["thread_id", "post_id"], "can_edit": ["thread_id", "post_id"],
"user_register": ["user", "auth_hash", "quip", "bio"], "user_register": ["user", "auth_hash", "quip", "bio"],
"user_get": ["target_user"], "user_get": ["target_user"],
@ -100,13 +101,17 @@ def user_register(json):
return schema.response( return schema.response(
db.user_register( db.user_register(
json["user"],
json["auth_hash"], json["auth_hash"],
json["user"],
json["quip"], json["quip"],
json["bio"])) json["bio"]))
def user_get(json): 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"]) user = db.user_resolve(json["target_user"])
if not user: if not user:
return False return False
@ -146,6 +151,10 @@ def thread_reply(json):
return schema.response(reply) return schema.response(reply)
def edit_query(json):
return db.edit_handler(json)[1]
def can_edit(json): def can_edit(json):
return db.edit_handler(json)[0] return db.edit_handler(json)[0]
@ -154,9 +163,9 @@ def edit_post(json):
thread = db.thread_load(json["thread_id"]) thread = db.thread_load(json["thread_id"])
admin = db.user_is_admin(json["user"]) admin = db.user_is_admin(json["user"])
target_id = json["post_id"] 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["body"] = json["body"]
obj["lastmod"] = time() obj["lastmod"] = time()
obj["edited"] = True obj["edited"] = True