Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlight quote when jumping to message #450

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 45 additions & 2 deletions telega-chat.el
Original file line number Diff line number Diff line change
Expand Up @@ -5766,12 +5766,55 @@ Return non-nil on success."
(cl-assert (eq (button-type msg-button) 'telega-msg))
(with-no-warnings
(pulse-momentary-highlight-region
(button-start msg-button) (button-end msg-button))))

(button-start msg-button) (button-end msg-button))
(when (and (listp highlight)
(equal (plist-get highlight :@type) "textQuote"))
(sit-for 0.5)
(telega-chatbuf--highlight-quote
highlight
(button-get msg-button :value)))))
(when callback
(funcall callback msg-button)))
t))

(defun telega-chatbuf--remove-highlight-quote (&rest _)
"Remove highlighted quote."
(remove-overlays nil nil 'telega-chatbuf--highlight-quote t)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work

(remove-hook
'telega-msg-hover-out-hook
#'telega-chatbuf--remove-highlight-quote
:local))

(defun telega-chatbuf--highlight-quote (text-quote msg)
"Highlight the TEXT-QUOTE in the MSG."
(let* ((msg-content-fmt (telega--tl-get msg :content :text))
(quote-fmt (telega--tl-get text-quote :text))
(quote-position (telega--tl-get text-quote :position))
(found-position (telega-server--call
(list :@type "searchQuote"
:text msg-content-fmt
:quote quote-fmt
:quote_position quote-position))))
(if (equal 404 (telega--tl-get found-position :code))
(message "The exact quote is not found")
(let* ((chat (telega-msg-chat msg))
(gaps-workaround-p
(telega-chat-match-p chat telega-avatar-workaround-gaps-for))
;; FIXME: get the msg content starting point more reliable
(msg-start-point (+ (if gaps-workaround-p 0 4) (save-excursion (forward-line 1) (point))))
(start-point (+ msg-start-point
(telega--tl-get found-position :position)))
(end-point (+ start-point
(length (telega--tl-get quote-fmt :text))))
(overlay (make-overlay start-point end-point)))
(overlay-put overlay 'telega-chatbuf--highlight-quote t)
(overlay-put overlay 'face 'telega-highlight-text-face)
(add-hook
'telega-msg-hover-out-hook
#'telega-chatbuf--remove-highlight-quote
nil
:local)))))

(defun telega-chatbuf--goto-msg (msg-id &optional highlight callback)
"In CHAT goto message denoted by MSG-ID.
If HIGHLIGHT is non-nil then highlight with fading background color.
Expand Down
5 changes: 3 additions & 2 deletions telega-msg.el
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,10 @@ Return nil for deleted messages."
"Goto message denoted by `:reply_to' field of the message MSG."
(let* ((reply-to (plist-get msg :reply_to))
(chat-id (plist-get reply-to :chat_id))
(msg-id (plist-get reply-to :message_id)))
(msg-id (plist-get reply-to :message_id))
(text-quote (plist-get reply-to :quote)))
(unless (or (telega-zerop chat-id) (telega-zerop msg-id))
(telega-chat--goto-msg (telega-chat-get chat-id) msg-id 'highlight))))
(telega-chat--goto-msg (telega-chat-get chat-id) msg-id text-quote))))

(defun telega-msg-open-sticker (msg &optional sticker)
"Open content for sticker message MSG."
Expand Down
Loading