Skip to content

Commit

Permalink
Fixes and enhancements
Browse files Browse the repository at this point in the history
[fix] regress.  Keep formatting when sending text already having
      entity types

[fix] Formattnig for inline reply for forwarded messages

[enh] Terminal friendly marking messages

[enh] Terminal friendly formatting for messages with unread mention

Version -> 0.8.213
  • Loading branch information
zevlg committed Nov 15, 2023
1 parent 140c044 commit 7068403
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 38 deletions.
2 changes: 1 addition & 1 deletion telega-chat.el
Original file line number Diff line number Diff line change
Expand Up @@ -2407,7 +2407,7 @@ Global chat bindings:
;; Enable filling by default to resemble old style telega formatting
;; We give a little bit extra space for filling column ot accomodate
;; inaccuracies in message header width calculation
(setq visual-fill-column-extra-text-width '(0 . 2))
(setq visual-fill-column-extra-text-width '(0 . 1))
(visual-fill-column-mode 1)

(cursor-sensor-mode 1)
Expand Down
17 changes: 10 additions & 7 deletions telega-core.el
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@
("RUB" . ""))
"Alist of currency symbols.")

(defvar telega--column-offset 0
"Additional offset for the `telega-currency-column'.")

(defconst telega-symbol-nbsp "\u00a0"
"Non-breakable space.")

Expand Down Expand Up @@ -1734,7 +1737,6 @@ Return what BODY returns."

(defmacro telega-ins--line-wrap-prefix (prefix &rest body)
"Execute BODY adding `line-prefix' and `wrap-prefix' properties.
PREFIX evaluates *after* BODY.
`line-prefix' and `wrap-prefix' are contatenated on subsequent calls to
`telega-ins--line-wrap-prefix'."
(declare (indent 1))
Expand All @@ -1743,14 +1745,15 @@ PREFIX evaluates *after* BODY.
(start-sym (gensym "start"))
(region-sym (gensym "region")))
`(let* ((,start-sym (point))
,lwprefix-sym ,lwprefix-props-sym ,region-sym)
(,lwprefix-sym ,prefix)
(,lwprefix-props-sym (list :telega-lwprefix ,lwprefix-sym
'line-prefix ,lwprefix-sym
'wrap-prefix ,lwprefix-sym))
(telega--column-offset (+ telega--column-offset
(string-width ,lwprefix-sym)))
,region-sym)
(prog1
(progn ,@body)
(setq ,lwprefix-sym ,prefix
,lwprefix-props-sym (list :telega-lwprefix ,lwprefix-sym
'line-prefix ,lwprefix-sym
'wrap-prefix ,lwprefix-sym))

(while (setq ,region-sym (telega--region-by-text-prop
,start-sym 'line-prefix (point)))
(add-text-properties ,start-sym (car ,region-sym)
Expand Down
12 changes: 4 additions & 8 deletions telega-customize.el
Original file line number Diff line number Diff line change
Expand Up @@ -2222,10 +2222,9 @@ If nil, then user's online status is not displayed."
(vector #b11111111) nil nil '(top periodic)))

(defcustom telega-symbol-mark
(if (fboundp 'define-fringe-bitmap)
(propertize "*" 'display '(left-fringe telega-mark error))
(propertize "*" 'face 'error))
(propertize " " 'face 'custom-invalid)
"*Symbol used to denote marked messages/chats."
:package-version '(telega . "0.8.213")
:type 'string
:group 'telega-symbol)

Expand Down Expand Up @@ -2261,12 +2260,9 @@ If nil, then user's online status is not displayed."
)))

(defcustom telega-symbol-mention-mark
(if (fboundp 'define-fringe-bitmap)
(propertize "\u200B" 'display
'(left-fringe telega-mention telega-mention-count))
(propertize "\u200B" 'face 'telega-mention-count))
(propertize "@" 'face 'telega-mention-count)
"*Symbol used to denote massages which contains unread mention."
:package-version '(telega . "0.6.30")
:package-version '(telega . "0.8.213")
:type 'string
:group 'telega-symbol)

Expand Down
40 changes: 26 additions & 14 deletions telega-ins.el
Original file line number Diff line number Diff line change
Expand Up @@ -2661,7 +2661,7 @@ ADDON-HEADER-INSERTER is passed directly to `telega-ins--message-header'."
;; inside `telega--entity-to-properties'
(telega-msg-contains-unread-mention
(plist-get msg :contains_unread_mention))
ccol)
content-prefix)
(if (and no-header
(zerop (plist-get msg :edit_date))
(zerop (plist-get msg :via_bot_user_id)))
Expand All @@ -2681,16 +2681,29 @@ ADDON-HEADER-INSERTER is passed directly to `telega-ins--message-header'."
(telega-ins--image avatar 1
:no-display-if (not telega-chat-show-avatars))))

(setq ccol (telega-current-column))
;; NOTE: we use `current-column' because line/wrap prefix could
;; be already in use by marked message for example
(setq content-prefix (make-string (current-column) ?\s))
(telega-ins--fwd-info-inline fwd-info)
;; NOTE: Three lines avatars in "Replies" chat
(when msg-for-replies-p
(telega-ins--image avatar 2
:no-display-if (not telega-chat-show-avatars)))

(telega-ins--line-wrap-prefix (make-string ccol ?\s)
(telega-ins--msg-reply-inline msg)

;; NOTE: `line-prefix' applies only if inserting at the
;; beginning of the line, inline reply can be inserted in two
;; different ways:
;; 1. Following the avatar (no fwd info)
;; 2. At the beginning of the line
;;
;; We need `telega-current-column' to return correct values in
;; both cases
(if (bolp)
(telega-ins--line-wrap-prefix content-prefix
(telega-ins--msg-reply-inline msg))
(telega-ins--msg-reply-inline msg))

(telega-ins--line-wrap-prefix content-prefix
(telega-ins--content msg)

(telega-ins-prefix "\n"
Expand Down Expand Up @@ -2735,15 +2748,14 @@ ADDON-HEADER-INSERTER is passed directly to `telega-ins--message-header'."
"Inserter for the message MSG.
Pass all ARGS directly to `telega-ins--message0'."
(declare (indent 1))
(if (telega-msg-marked-p msg)
(telega-ins--line-wrap-prefix telega-symbol-mark
(apply #'telega-ins--message0 msg args))

(when (plist-get msg :contains_unread_mention)
(telega-ins telega-symbol-mention-mark))
(when (telega-msg-match-p msg 'unread-reactions)
(telega-ins telega-symbol-reaction-mark))
(apply #'telega-ins--message0 msg args)))
(telega-ins--line-wrap-prefix
(concat (when (telega-msg-marked-p msg)
telega-symbol-mark)
(when (plist-get msg :contains_unread_mention)
telega-symbol-mention-mark))
(when (telega-msg-match-p msg 'unread-reactions)
(telega-ins telega-symbol-reaction-mark))
(apply #'telega-ins--message0 msg args)))

(defun telega-ins--message-no-header (msg)
"Insert message MSG without header."
Expand Down
15 changes: 9 additions & 6 deletions telega-util.el
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ Also take into account `:align-to' display property, used by
(string-width (buffer-substring dpoint spoint)))))))

(+ (or ccolumn (current-column))
telega--column-offset
(or (when-let ((lwprefix (or (get-text-property bol-point 'line-prefix)
(get-text-property bol-point 'wrap-prefix))))
(string-width lwprefix))
Expand Down Expand Up @@ -1173,16 +1174,18 @@ Return nil if STR does not specify an org mode link."
"Split TEXT by `:tl-entity-type'.
Return list of list where first element is markup function, second is
substring and rest are additional arguments to markup function."
;; NOTE: if markup is applied, then ignore all tl entity types
;; except for custom emojis and mentions, so you can cut&paste text
;; already having entity-type and apply new markup to it
(let ((result nil)
(tomarkup-ss nil))
(seq-doseq (ss (telega--split-by-text-prop text :tl-entity-type))
(let ((ent-type (get-text-property 0 :tl-entity-type ss)))
(if (and ent-type
(memq (telega--tl-type ent-type)
'(textEntityTypeCustomEmoji textEntityTypeMentionName)))
;; NOTE: if markup is applied, then ignore all tl entity types
;; except for custom emojis and mentions, so you can cut&paste
;; text already having entity-type and apply new markup to it
(if (or (eq default-markup-func #'telega-markup-as-is-fmt)
(and ent-type
(memq (telega--tl-type ent-type)
'(textEntityTypeCustomEmoji
textEntityTypeMentionName))))
(progn
(when tomarkup-ss
(push (list default-markup-func tomarkup-ss) result)
Expand Down
4 changes: 2 additions & 2 deletions telega.el
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
;; Keywords: comm
;; Package-Requires: ((emacs "27.1") (visual-fill-column "1.9") (rainbow-identifiers "0.2.2"))
;; URL: https://github.com/zevlg/telega.el
;; Version: 0.8.212
(defconst telega-version "0.8.212")
;; Version: 0.8.213
(defconst telega-version "0.8.213")
(defconst telega-server-min-version "0.7.7")
(defconst telega-tdlib-min-version "1.8.21")
(defconst telega-tdlib-max-version nil)
Expand Down

0 comments on commit 7068403

Please sign in to comment.