summaryrefslogtreecommitdiffhomepage
path: root/net
diff options
context:
space:
mode:
Diffstat (limited to 'net')
-rw-r--r--net/signel.org30
1 files changed, 20 insertions, 10 deletions
diff --git a/net/signel.org b/net/signel.org
index 89ba415..d8b54c2 100644
--- a/net/signel.org
+++ b/net/signel.org
@@ -168,16 +168,21 @@ but its ~isReceipt~ flag is set to ~false~. At other times, we get
#+end_src
It is very easy to parse JSON in emacs and extract signal-cli's
-envelopes:
+envelopes (and it's become faster in emacs 27, but the interface is a
+bit different):
#+begin_src emacs-lisp
+(defun signel--parse-json (str)
+ (if (> emacs-major-version 26)
+ (json-parse-string str
+ :null-object nil
+ :false-object nil
+ :object-type 'alist
+ :array-type 'list)
+ (json-read-from-string str)))
+
(defun signel--msg-contents (str)
- (alist-get 'envelope
- (ignore-errors (json-parse-string str
- :null-object nil
- :false-object nil
- :object-type 'alist
- :array-type 'list))))
+ (alist-get 'envelope (ignore-errors (signel--parse-json str))))
#+end_src
Here i am being old-school and opting to receive JSON dicitionaries as
@@ -200,11 +205,15 @@ boring) to get into its components:
(format-time-string "%H:%M" (/ msecs 1000))
""))
+;; emacs 26 compat
+(defun signel--not-false (x)
+ (and (not (eq :json-false x)) x))
+
(defun signel--msg-receipt (msg)
(alist-get 'receiptMessage msg))
(defun signel--msg-is-receipt (msg)
- (alist-get 'isReceipt msg))
+ (signel--not-false (alist-get 'isReceipt msg)))
(defun signel--msg-receipt-timestamp (msg)
(when-let (msecs (alist-get 'when (signel--msg-receipt msg)))
@@ -212,11 +221,11 @@ boring) to get into its components:
(defun signel--msg-is-delivery (msg)
(when-let ((receipt (signel--msg-receipt msg)))
- (alist-get 'isDelivery msg)))
+ (signel--not-false (alist-get 'isDelivery msg))))
(defun signel--msg-is-read (msg)
(when-let ((receipt (signel--msg-receipt msg)))
- (alist-get 'isRead msg)))
+ (signel--not-false (alist-get 'isRead msg))))
#+end_src
* A process output filter
@@ -239,6 +248,7 @@ Or, in elisp:
(defun signel--filter (proc str)
(signel--ordinary-insertion-filter proc str)
(let ((str (concat signel--line-buffer str)))
+ (message "signel: processing: '%s'" str)
(if-let ((msg (signel--msg-contents str)))
(let ((source (signel--msg-source msg))
(stamp (signel--msg-timestamp msg))