~williewillus/public-inbox

r16: Add typing indicator for trick evaluations v1 SUPERSEDED

: 3
 Add typing indicator for trick evaluations
 Remove a debug print lmao
 Wrap http call in a catch

 3 files changed, 32 insertions(+), 11 deletions(-)
#442934 linux_buildtest.yml failed
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~williewillus/public-inbox/patches/20669/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH r16] Add typing indicator for trick evaluations Export this patch

From: Alwinfy <20421383+Alwinfy@users.noreply.github.com>

---
 r16.rkt | 40 +++++++++++++++++++++++++++++++---------
 1 file changed, 31 insertions(+), 9 deletions(-)

diff --git a/r16.rkt b/r16.rkt
index 5cd74a5..1c982c9 100755
--- a/r16.rkt
+++ b/r16.rkt
@@ -85,6 +85,25 @@
                (http:delete-message client (rc:message-channel-id message) (rc:message-id message)))
              (loop))))))

(define typing-thread
  (thread
   (thunk
    (let loop ([data #hash()])
      (match-let ([(list val client channel) (thread-receive)])
        (let* ([key (cons (rc:user-id (rc:client-user client)) channel)]
               [newval (+ val (hash-ref data key 0))])
          (displayln (~a newval " " key))
          (unless (zero? newval)
            (http:trigger-typing-indicator client channel))
          (loop (hash-set data key newval))))))))

(define (with-typing-indicator client message thunk)
  (let ([payload (list client (rc:message-channel-id message))])
    (thread-send typing-thread (cons 1 payload))
    (let ([result (call-with-values thunk list)])
      (thread-send typing-thread (cons -1 payload))
      (apply values result))))


(define (make-trick body message parent)
  (trick (if parent (trick-author parent) (message-author-id message))
@@ -95,7 +114,8 @@
(define (run-snippet client db message code)
  (let ([code (strip-backticks code)]
        [text (rc:message-content message)])
    (ev:run code (evaluation-ctx client message (db:get-trick-context db message) "" #f))))
    (with-typing-indicator client message
      (thunk (ev:run code (evaluation-ctx client message (db:get-trick-context db message) "" #f))))))

(define (register-trick client db message text)
  (check-trick-prereqs
@@ -115,14 +135,15 @@
      (if trick
        (begin
          (db:update-trick! context name (lambda (t) (set-trick-invocations! t (add1 (trick-invocations t))) t) (const #t))
          (ev:run
            (trick-body trick)
            (evaluation-ctx
              client
              message
              context
              (or body "")
              #f)))
          (with-typing-indicator client message
            (thunk (ev:run
              (trick-body trick)
              (evaluation-ctx
                client
                message
                context
                (or body "")
                #f)))))
        (~a "Trick " name " doesn't exist!")))))

(define (update-trick client db message text)
@@ -283,6 +304,7 @@
    (placeholder-set! placeholder (make-hash ctx))
    (make-reader-graph ctx)))


(define command-table
  `(("eval"     . ,run-snippet)
    ("register" . ,register-trick)
-- 
2.25.1
A couple comments. Also, please specify what patches your patch should
be applied on top of/depends on, or base them off of current master if possible.

wenming.yi@gmail.com writes:
builds.sr.ht
r16/patches/linux_buildtest.yml: FAILED in 48s

[Add typing indicator for trick evaluations][0] from [][1]

[0]: https://lists.sr.ht/~williewillus/public-inbox/patches/20669
[1]: mailto:wenming.yi@gmail.com

✗ #442934 FAILED r16/patches/linux_buildtest.yml https://builds.sr.ht/~williewillus/job/442934

[PATCH r16] Remove a debug print lmao Export this patch

From: Alwinfy <20421383+Alwinfy@users.noreply.github.com>


---
 r16.rkt | 1 -
 1 file changed, 1 deletion(-)

diff --git a/r16.rkt b/r16.rkt
index 1c982c9..2608816 100755
--- a/r16.rkt
+++ b/r16.rkt
@@ -92,7 +92,6 @@
      (match-let ([(list val client channel) (thread-receive)])
        (let* ([key (cons (rc:user-id (rc:client-user client)) channel)]
               [newval (+ val (hash-ref data key 0))])
          (displayln (~a newval " " key))
          (unless (zero? newval)
            (http:trigger-typing-indicator client channel))
          (loop (hash-set data key newval))))))))
-- 
2.25.1

[PATCH] Wrap http call in a catch Export this patch

From: Alwinfy <20421383+Alwinfy@users.noreply.github.com>



---

> please specify what patches your patch should be applied on top
> of/depends on, or base them off of current master if possible.  
Sorry, I've just been piling them on top of my other patches, so I guess
just merge in order?

> How long does this indicator last? Do you have to send a signal to
> turn it off?
Typing indicators last about ten seconds or until the next message is
sent, hence why we send it twice.

> What happens if the thunk throws?
I'm pretty sure there's a with-handlers block in an earlier patch of
mine, upstream in ev:run

> Also, this needs error handling lest a throw from the http
> method crash the entire thread.
See below:

 r16.rkt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/r16.rkt b/r16.rkt
index 2608816..7cbe603 100755
--- a/r16.rkt
+++ b/r16.rkt
@@ -93,7 +93,7 @@
        (let* ([key (cons (rc:user-id (rc:client-user client)) channel)]
               [newval (+ val (hash-ref data key 0))])
          (unless (zero? newval)
            (http:trigger-typing-indicator client channel))
            (with-handlers ([exn:fail? (const #f)]) (http:trigger-typing-indicator client channel)))
          (loop (hash-set data key newval))))))))

(define (with-typing-indicator client message thunk)
-- 
2.25.1