Skip to content

Commit

Permalink
Paid reactions and multiple sensor functions
Browse files Browse the repository at this point in the history
- [add] Initial support for paid reactions

- [enh] Makes sensor function for buttons inside other buttons to work

Version -> 0.8.392
  • Loading branch information
zevlg committed Nov 15, 2024
1 parent 0368bae commit 6ff8203
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 59 deletions.
2 changes: 2 additions & 0 deletions etc/langs/en.plist
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,8 @@ Example: 23 y.o. designer from San Francisco")
("lng_filters_remove_sure"
:value "This will remove the folder, chats won't be deleted.")
("lng_filters_all"
:value "All chats")
("lng_filters_type_groups"
:value "Groups")
("lng_filters_type_channels"
Expand Down
7 changes: 4 additions & 3 deletions telega-chat.el
Original file line number Diff line number Diff line change
Expand Up @@ -2680,12 +2680,13 @@ If NEW-FOCUS-STATE is specified, then focus state is forced."
(when msg-inserter
(telega-button--insert 'telega-msg msg
:inserter msg-inserter
;; TODO: Use `font-lock--add-text-property' to add
;; Use `telega--change-text-property' to add
;; `cursor-sensor-functions' to not override cursor sensor
;; function for buttons (such as [Instant View]) inside a
;; message
'cursor-sensor-functions (unless for-preview-p
'(telega-chatbuf-msg--sensor-func)))
:telega-add-sensor-func
(unless for-preview-p
#'telega-chatbuf-msg--sensor-func))

;; NOTE: we insert newline outside the button to provide
;; msg hover-in/hover-out hooks handled by sensor function.
Expand Down
27 changes: 15 additions & 12 deletions telega-core.el
Original file line number Diff line number Diff line change
Expand Up @@ -1471,18 +1471,21 @@ Return t if `:action' has been called."
Properties specified in PROPS are retained on
`telega-button--update-value' calls."
(declare (indent 2))
(let ((button (apply 'make-text-button
(prog1 (point)
(funcall (or (plist-get props :inserter)
(button-type-get button-type :inserter))
value))
(point)
:type button-type
:value value
:telega-retain-props
(telega-plist-map (lambda (prop _ignored) prop) props)
props)))
(button-at button)))
(let* ((beg (point))
(end (progn
(funcall (or (plist-get props :inserter)
(button-type-get button-type :inserter))
value)
(point)))
(pos
(apply #'make-text-button beg end
:type button-type
:value value
props)))
(when-let ((add-sensor (plist-get props :telega-add-sensor-func)))
(telega--change-text-property
beg end 'cursor-sensor-functions add-sensor 'append))
(button-at pos)))

(defmacro telega-button--change (button new-button)
"Change BUTTON to NEW-BUTTON."
Expand Down
4 changes: 2 additions & 2 deletions telega-info.el
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ If OFFLINE-P is non-nil, then do not send a request to telega-server."
(telega-button--insert 'telega photo
:inserter #'telega-ins--chat-photo
:action 'telega-photo--open
'cursor-sensor-functions
:telega-add-sensor-func
(when-let ((fake-anim (plist-get photo :telega-fake-animation)))
(list (telega-animation--gen-sensor-func fake-anim)))
(telega-animation--gen-sensor-func fake-anim))
'local-keymap
(when (telega-me-p user)
(let ((pp-del (lambda (profile-photo)
Expand Down
25 changes: 12 additions & 13 deletions telega-inline.el
Original file line number Diff line number Diff line change
Expand Up @@ -486,49 +486,48 @@
(telega-button--insert 'telega qr
:inserter 'telega-ins--inline-document
:action 'telega-inline-bot--action
'cursor-sensor-functions
'(telega-button-highlight--sensor-func))
:telega-add-sensor-func
#'telega-button-highlight--sensor-func)
(telega-ins--inline-delim))

(inlineQueryResultVideo
(telega-button--insert 'telega qr
:inserter 'telega-ins--inline-video
:action 'telega-inline-bot--action
'cursor-sensor-functions
'(telega-button-highlight--sensor-func))
:telega-add-sensor-func
#'telega-button-highlight--sensor-func)
(telega-ins--inline-delim))

(inlineQueryResultAudio
(telega-button--insert 'telega qr
:inserter 'telega-ins--inline-audio
:action 'telega-inline-bot--action
'cursor-sensor-functions
'(telega-button-highlight--sensor-func))
:telega-add-sensor-func
#'telega-button-highlight--sensor-func)
(telega-ins--inline-delim))

(inlineQueryResultVoiceNote
(telega-button--insert 'telega qr
:inserter 'telega-ins--inline-voice-note
:action 'telega-inline-bot--action
'cursor-sensor-functions
'(telega-button-highlight--sensor-func))
:telega-add-sensor-func
#'telega-button-highlight--sensor-func)
(telega-ins--inline-delim))

(inlineQueryResultArticle
(telega-button--insert 'telega qr
:inserter 'telega-ins--inline-article
:action 'telega-inline-bot--action
'cursor-sensor-functions
'(telega-button-highlight--sensor-func))
:telega-add-sensor-func
'telega-button-highlight--sensor-func)
(telega-ins--inline-delim))

(inlineQueryResultAnimation
(telega-button--insert 'telega qr
:inserter 'telega-ins--inline-animation
:action 'telega-inline-bot--action
'cursor-sensor-functions
(list (telega-animation--gen-sensor-func
(plist-get qr :animation)))
:telega-add-sensor-func
(telega-animation--gen-sensor-func (plist-get qr :animation))
'help-echo (when-let ((title (telega-tl-str qr :title)))
(format "GIF title: %s" title))))

Expand Down
2 changes: 1 addition & 1 deletion telega-ins.el
Original file line number Diff line number Diff line change
Expand Up @@ -4245,7 +4245,7 @@ argument of `ReactionType' type."
(telega-button--insert 'telega reaction-type
:inserter #'telega-ins--msg-reaction-type
:action custom-action
'cursor-sensor-functions
:telega-add-sensor-func
(when-let ((sticker
(when (eq (telega--tl-type reaction-type)
'reactionTypeCustomEmoji)
Expand Down
3 changes: 1 addition & 2 deletions telega-modes.el
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,7 @@ Return filename of the generated icon."
:type 'telega-msg-temex
:options '((and (not outgoing)
(or (type Animation Sticker AnimatedEmoji Gift)
(link-preview Animation)
(link-preview Sticker))))
(link-preview Animation Sticker))))
:group 'telega-modes)

(defcustom telega-autoplay-custom-emojis 10
Expand Down
11 changes: 3 additions & 8 deletions telega-sticker.el
Original file line number Diff line number Diff line change
Expand Up @@ -476,11 +476,10 @@ called when some sticker is selected."
(concat "Emoji: " emoji " " (telega-emoji-name emoji)))
'action #'telega-sticker--chosen-action
:action custom-action
'cursor-sensor-functions
:telega-add-sensor-func
(when (and (not (telega-sticker-static-p sticker))
telega-sticker-animated-play)
(list (telega-sticker--gen-sensor-func sticker)))
)
(telega-sticker--gen-sensor-func sticker)))
(when telega-sticker-set-show-emoji
(telega-ins (telega-sticker-emoji sticker) " "))

Expand Down Expand Up @@ -1022,11 +1021,7 @@ If SLICES-P is non-nil, then insert ANIMATION using slices."
(telega-ins-prefix (unless (bolp) "\n")
(telega-button--insert 'telega-animation anim
'action #'telega-animation--choosen-action
;; NOTE: use different sensor functions, so all animations
;; can be places next to each other and still sensor
;; detection will work properly
'cursor-sensor-functions
(list (telega-animation--gen-sensor-func anim)))
:telega-add-sensor-func (telega-animation--gen-sensor-func anim))
(> (current-column) (current-fill-column))))
)))

Expand Down
22 changes: 7 additions & 15 deletions telega-util.el
Original file line number Diff line number Diff line change
Expand Up @@ -1624,18 +1624,6 @@ ENTITY-TO-MARKUP-FUN is function to convert TDLib entities to string."
"Return formatted text FMT-TEXT as string with org mode syntax."
(telega--fmt-text-markup fmt-text #'telega--entity-to-org))

(defun telega--fmt-text-entities-compare (entity1 entity2)
"Compare format text entities to sort them."
(let ((ent-type1 (telega--tl-type (plist-get entity1 :type)))
(ent-type2 (telega--tl-type (plist-get entity2 :type))))
(cond ((memq ent-type2 '(textEntityTypeBlockQuote
textEntityTypeExpandableBlockQuote))
(not (memq ent-type1 '(textEntityTypeBlockQuote
textEntityTypeExpandableBlockQuote))))
((eq ent-type2 'textEntityTypeSpoiler)
(not (eq ent-type1 'textEntityTypeSpoiler)))
)))

;; NOTE: FOR-MSG might be used by advices, see contrib/telega-mnz.el
(defun telega--fmt-text-faces (fmt-text &optional _for-msg)
"Apply faces to formatted text FMT-TEXT.
Expand Down Expand Up @@ -3131,13 +3119,17 @@ COLUMN is the column to aligned to."
(propertize emoji-name
'display (get-text-property 0 'display emoji))))))
(reactionTypeCustomEmoji
(let* ((custom-emoji (telega-custom-emoji-get
(plist-get reaction-type :custom_emoji_id)))
(let* ((custom-emoji-id (plist-get reaction-type :custom_emoji_id))
(custom-emoji (or (telega-custom-emoji-get custom-emoji-id)
(seq-first (telega--getCustomEmojiStickers
(list custom-emoji-id)))))
(emoji (telega-tl-str custom-emoji :emoji)))
(telega-ins--as-string
(telega-ins--image
(telega-sticker--image custom-emoji) nil
:telega-text (concat emoji (telega-emoji-name emoji))))))))
:telega-text (concat emoji (telega-emoji-name emoji))))))
(reactionTypePaid
(telega-symbol 'telegram-star))))

(defun telega-completing-read-msg-reaction (msg prompt &optional
msg-available-reactions
Expand Down
2 changes: 1 addition & 1 deletion telega-webpage.el
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ Keymap:
:inserter #'telega-webpage--animation-inserter
:action #'telega-webpage--animation-action
:telega-animation animation
'cursor-sensor-functions '(telega-webpage--animation-sensor-func)
:telega-add-sensor-func #'telega-webpage--animation-sensor-func
'help-echo "RET to play animation"))

(defun telega-webpage--ins-pb (pb)
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") (transient "0.3.0"))
;; URL: https://github.com/zevlg/telega.el
;; Version: 0.8.391
(defconst telega-version "0.8.391")
;; Version: 0.8.392
(defconst telega-version "0.8.392")
(defconst telega-server-min-version "0.7.7")
(defconst telega-tdlib-min-version "1.8.39")
(defconst telega-tdlib-max-version nil)
Expand Down

0 comments on commit 6ff8203

Please sign in to comment.