fix issues
ober
e8c16701bd730970055116d8dfdf0fbeec89e017
--- a/signal/tui/main.ss +++ b/signal/tui/main.ss @@ -724,9 +724,16 @@ [outcome (list-ref ev 6)] [retry-hint (list-ref ev 7)] [success-status (list-ref ev 8)] - [conv (find-conversation - (tui-state-conversations state) - (canonical-conversation-id state conv-id))]) + [conv (or (find-conversation (tui-state-conversations state) conv-id) + (let* ([parsed (parse-conversation-id conv-id)] + [kind (and parsed (car parsed))] + [target (and parsed (cdr parsed))] + [new-conv (make-conversation conv-id conv-id kind target '() 0 #f)]) + (tui-state-conversations-set! state + (append (tui-state-conversations state) (list new-conv))) + (append-system-message! state + (string-append "Recreated missing conversation for send: " conv-id)) + new-conv))]) (if (eq? (car outcome) 'sent) (handle-send-success! state kind conv conv-id display-text started (cdr outcome) success-status) @@ -742,8 +749,12 @@ (make-chat-message 'out "You" display-text ts 'data 'sent)) (clear-conversation-rate-limit! state conv) (conversation-unread-set! conv 0)) + (tui-state-thread-scroll-set! state 0) (when (and (tui-state-live-capture? state) (tui-state-logdb state)) + (guard (_ [(condition? _) (void)]) + (capture-outbound! (tui-state-logdb state) (tui-state-account state) + conv-id display-text ts)) (enqueue-capture-event! state (list 'outbound conv-id display-text ts))) @@ -791,13 +802,30 @@ conv (make-chat-message 'system "system" line #f 'system #f)))) - (def (append-message-to-conversation! conv msg) + (def (outbound-message-duplicate? existing new) + (and (eq? (chat-message-direction existing) 'out) + (eq? (chat-message-direction new) 'out) + (string=? (chat-message-sender existing) (chat-message-sender new)) + (string=? (chat-message-text existing) (chat-message-text new)) + (not (chat-message-timestamp existing)))) + +(def (merge-outbound-timestamps! existing new) + (when (and (not (chat-message-timestamp existing)) + (chat-message-timestamp new)) + (chat-message-timestamp-set! existing (chat-message-timestamp new)))) +(def (append-message-to-conversation! conv msg) (let* ([messages (conversation-messages conv)] [len (length messages)] [base (if (>= len 200) (drop-oldest messages (- len 199)) messages)]) - (conversation-messages-set! conv (append base (list msg))))) + (if (and (pair? base) + (outbound-message-duplicate? (last base) msg)) + (begin + (merge-outbound-timestamps! (last base) msg) + (when (not (eq? base messages)) + (conversation-messages-set! conv base))) + (conversation-messages-set! conv (append base (list msg)))))) (def (apply-chat-event! state chat-event) (cond @@ -2600,8 +2628,7 @@ (add! 'status)) (when (changed? 'selected-index (tui-state-selected-index state)) (add! 'conversations) - (add! 'thread) - (add! 'details)) + (add! 'thread)) (when (changed? 'thread-scroll (tui-state-thread-scroll state)) (add! 'thread)) (when (changed? 'conv-scroll (tui-state-conv-scroll state)) @@ -2611,8 +2638,7 @@ (add! 'conversations)) (when (changed? 'selected-conversation-id (and conv (conversation-id conv))) (add! 'conversations) - (add! 'thread) - (add! 'details)) + (add! 'thread)) (when (changed? 'selected-conversation-title (and conv (conversation-title conv))) (add! 'conversations) (add! 'thread)) @@ -2621,14 +2647,14 @@ (add! 'conversations)) (when (changed? 'selected-typing (and conv (conversation-typing conv))) (add! 'thread))) - (when (changed? 'event-count (tui-state-event-count state)) - (add! 'details)) (when (changed? 'mention-active? (tui-state-mention-active? state)) (add! 'mention)) (when (changed? 'mention-index (tui-state-mention-index state)) (add! 'mention)) (when (changed? 'mention-candidates-count (length (tui-state-mention-candidates state))) (add! 'mention)) + (when (changed? 'event-count (tui-state-event-count state)) + (add! 'conversations)) dirty)) (def (update-last-drawn! state) @@ -2657,10 +2683,8 @@ [h (max 12 (tui-state-height state))] [status-y (- h 1)] [left-w (if (< w 80) 18 24)] - [details-w (if (>= w 100) 26 0)] [thread-x (+ left-w 1)] - [thread-w (max 10 (- w left-w details-w 2))] - [details-x (- w details-w)] + [thread-w (max 10 (- w left-w 2))] [body-h (max 4 (- h 4))] [composer-y (- h 3)] [dirty (compute-dirty-regions state)]) @@ -2682,13 +2706,9 @@ [else (draw-panel! 0 0 left-w body-h "Conversations") (draw-panel! thread-x 0 thread-w body-h "Messages") - (when (> details-w 0) - (draw-panel! details-x 0 details-w body-h "Details")) (draw-conversations! state 1 2 (- left-w 2) (- body-h 3)) (draw-thread! state (+ thread-x 1) 2 (- thread-w 2) (- body-h 3)) - (when (> details-w 0) - (draw-details! state (+ details-x 1) 2 (- details-w 2) (- body-h 3))) (draw-composer! state 0 composer-y w) (draw-mention-popup! state 0 composer-y w) @@ -2707,9 +2727,6 @@ (when (memq 'thread dirty) (draw-panel! thread-x 0 thread-w body-h "Messages") (draw-thread! state (+ thread-x 1) 2 (- thread-w 2) (- body-h 3))) - (when (and (> details-w 0) (memq 'details dirty)) - (draw-panel! details-x 0 details-w body-h "Details") - (draw-details! state (+ details-x 1) 2 (- details-w 2) (- body-h 3))) ;; Mentions float over the thread panel; redraw them when either ;; the mention state or the underlying thread changed. (when (or (memq 'mention dirty) @@ -3025,7 +3042,7 @@ (let ([conv (selected-conversation state)]) (when conv (let* ([w (max 10 (- (tui-state-width state) - (if (< (tui-state-width state) 80) 20 26) + (if (< (tui-state-width state) 80) 22 28) 2))] [height (let* ([body-h (max 4 (- (tui-state-height state) 4))] [typing (active-typing-sender conv)] @@ -3160,23 +3177,6 @@ (reverse acc) (loop (cdr lines) (cons (cons msg (car lines)) acc))))) - (def (draw-details! state x y width height) - (draw-text! x y width (fg-strong) (panel-bg) "Account") - (draw-text! x (+ y 2) width (fg) (panel-bg) (tui-state-account state)) - (draw-text! x (+ y 4) width (fg-strong) (panel-bg) "signal-cli") - (draw-text! x (+ y 6) width (fg) (panel-bg) (tui-state-version state)) - (draw-text! x (+ y 8) width (fg-strong) (panel-bg) "Receive") - (draw-text! x (+ y 10) width (fg) (panel-bg) (tui-state-receive-mode state)) - (draw-text! x (+ y 12) width (fg-strong) (panel-bg) "Events") - (draw-text! x (+ y 14) width (fg) (panel-bg) - (number->string (tui-state-event-count state))) - (let ([conv (selected-conversation state)]) - (when conv - (draw-text! x (+ y 16) width (fg-strong) (panel-bg) "Conversation") - (draw-text! x (+ y 18) width (fg) (panel-bg) (conversation-title conv)) - (draw-text! x (+ y 20) width (fg-dim) (panel-bg) - (conversation-subtitle conv))))) - (def (draw-composer! state x y width) (fill-rect! x y width 2 (fg) (input-bg)) (draw-hline! x y width (fg-dim) (input-bg))