Skip to content

Commit

Permalink
Add: (ement-tag-room) command
Browse files Browse the repository at this point in the history
  • Loading branch information
alphapapa committed Apr 9, 2022
1 parent 41e9397 commit 05f658c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ If you want to install it manually, it's simple enough, but you should know what
- ~ement-join-room~ to join a room.
- ~ement-leave-room~ to leave a room.
- ~ement-forget-room~ to forget a room.
- ~ement-tag-room~ to add (or with interactive prefix, remove) a tag on a room (including favorite/low-priority status).
- ~ement-send-direct-message~ to send a direct message to a user (in an existing direct room, or creating a new one automatically).
- ~ement-room-edit-message~ to edit a message at point.
- ~ement-room-send-image~ to send an image message.
Expand Down
22 changes: 22 additions & 0 deletions ement.el
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,28 @@ new one automatically if necessary."
(ement-room-display-name room)
(ement-room-id room))))))

(defun ement-tag-room (tag room session &optional delete)
"Add TAG to ROOM on SESSION.
If DELETE (interactively, with prefix), delete it."
(interactive
(pcase-let* ((`(,room ,session) (ement-complete-room))
(prompt (if current-prefix-arg "Delete tag: " "Add tag: "))
(default-tags (ement-alist "Favourite" "m.favourite"
"Low-priority" "m.lowpriority"))
(input (completing-read prompt default-tags))
(tag (alist-get input default-tags (concat "u." input) nil #'string=)))
(list tag room session current-prefix-arg)))
(pcase-let* (((cl-struct ement-session user) session)
((cl-struct ement-user (id user-id)) user)
((cl-struct ement-room (id room-id)) room)
(endpoint (format "user/%s/rooms/%s/tags/%s"
(url-hexify-string user-id) (url-hexify-string room-id) (url-hexify-string tag)))
(method (if delete 'delete 'put)))
;; TODO: "order".
(ement-api session endpoint :version "v3" :method method :data (unless delete "{}")
:then (lambda (data)
(ement-debug "Changed tag on room" method tag data room)))))

;;;; Functions

(defalias 'ement--button-buttonize
Expand Down

0 comments on commit 05f658c

Please sign in to comment.