Commit Diff
Diff:
a451df45d54ae2b9f154454aa17eb5e0887272c8
717ecca54bae3d8f05e7ec3851cb99ade2fe4818
Commit:
717ecca54bae3d8f05e7ec3851cb99ade2fe4818
Tree:
8efdd376d24762e6bcc634b164f5f88798566118
Author:
Omar Polo <op@omarpolo.com>
Date:
Sun Feb 28 20:28:34 2021 UTC
Message:
message as structs
commit - a451df45d54ae2b9f154454aa17eb5e0887272c8
commit + 717ecca54bae3d8f05e7ec3851cb99ade2fe4818
blob - a4f9d70a2966128f8d6f7a6941c2daecbc77391a
blob + df93cb882804c948aa5e4bbb4b6f623d6839c296
--- toxe-chat.el
+++ toxe-chat.el
@@ -44,11 +44,26 @@
(defvar-local toxe-chat-ewoc nil
"EWOC data for the current toxe chatbuf.")
-(defun toxe-chat--ewoc-pp (data)
- "Pretty print DATA (for EWOC)."
- (cl-destructuring-bind (from msg) data
- (insert from ":\t" msg)))
+(defmacro toxe-with-accessors (spec type struct &rest body)
+ "Like CL' with-accessors.
+Destructure a STRUCT of the given TYPE using SPEC. SPEC is in
+the form ((VAR-NAME ACCESSOR-NAME)). BODY is then executed with
+the bindings set."
+ (declare (indent 3))
+ (let ((o (gensym)))
+ `(let ((,o ,struct))
+ (cl-symbol-macrolet
+ ,(cl-loop for (var acc) in spec
+ collect `(,var (cl-struct-slot-value ,type ',acc ,o)))
+ ,@body))))
+(defun toxe-chat--ewoc-pp (msg)
+ "Pretty print MSG (for EWOC)."
+ (toxe-with-accessors ((from from)
+ (text tex))
+ 'toxe--message msg
+ (insert from ":\t" text)))
+
(defvar toxe-chat-mode-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "RET") #'toxe-chat-send)
@@ -68,9 +83,11 @@
(format "Chat with %s\n\n"
(toxe--friend-name toxe-chat-friend)))))
-(defun toxe-chat--insert (from msg)
- "Insert the message MSG from the user FROM."
- (let ((datum `(,from ,msg)))
+(defun toxe-chat--insert (from type msg)
+ "Insert the message MSG with TYPE from the user FROM."
+ (let ((datum (make-toxe--message :from from
+ :type type
+ :text msg)))
(setq toxe-chat-messages
(vconcat toxe-chat-messages datum))
(ewoc-enter-last toxe-chat-ewoc datum)
@@ -82,7 +99,7 @@
"Prompt for a message and send it."
(interactive)
(when-let (msg (read-string "Message: "))
- (toxe-chat--insert (or toxe-user-name "me") msg)
+ (toxe-chat--insert (or toxe-user-name "me") 'normal msg)
(toxe--cmd-friend-send-message (toxe--friend-number toxe-chat-friend)
'normal
msg)))
blob - 1b9d18b47dfe1d4a6558dd2ee889cf6a96ec052d
blob + 26e29a9c7a3d7c934610eebacbc718b58be12062
--- toxe.el
+++ toxe.el
@@ -106,6 +106,9 @@ status of the connection:
name status-message conn-status
buffer)
+(cl-defstruct toxe--message
+ from type text)
+
(defun toxe-connection-status ()
"Return the status of the connection."
toxe--connection-status)
@@ -196,7 +199,7 @@ ooooooooooooo
do (widget-insert "* ")
do (widget-create 'push-button
:notify (lambda (&rest _ignore)
- (message "deleting" key "from the list")
+ (message "deleting %s from the list" key)
(setq toxe--pending-friend-requests
(cl-delete-if (lambda (r)
(string= (car r) key))
@@ -312,7 +315,7 @@ matter. BODY is the implementation."
(toxe--defhandler friend-message (friend-number message-type message)
(when-let (f (toxe--friend-by-number friend-number))
(with-current-buffer (toxe--friend-getcreate-buffer f)
- (toxe-chat--insert (toxe--friend-name f) message)))
+ (toxe-chat--insert (toxe--friend-name f) message-type message)))
(run-hook-with-args toxe-friend-message-hook friend-number message-type message))
(toxe--defhandler connection-status (connection-status)
@@ -336,6 +339,9 @@ matter. BODY is the implementation."
(when-let (f (toxe--friend-by-number friend-number))
(setf (toxe--friend-conn-status f) connection-status)))
+(toxe--defhandler friend-read-receipt (friend-number message-id)
+ )
+
(defun toxe--send-request (req)
"Send REQ to the `toxe--process'."
(when (process-live-p toxe--process)
Omar Polo