Skip to content

Commit

Permalink
More features, enhancements and fixes
Browse files Browse the repository at this point in the history
- [new] `telega-avatar-text-function' custom option, to control
avatar's text representation.  Fixes https://t.me/emacs_telega/44274
with customization like:
`(setq telega-avatar-text-function (lambda (&rest args) ""))`

- [enh] Insert avatar as line-prefix in the chatbuf, fixes formatting
for quotes if message content starts just after message header
line (i.e. no reply, no forwarding)

- [new] `telega-user-last-seen-date-format` Fixes #461

- [new] `telega-chat-auto-fill-mode` to auto fill chatbuf into
window's width

- [fix] `telega-chat-title` Use user title without badges, to avoid
inconsistent chat title in the `telega-chatbuf--name`

- [fix] Do not run any message hooks on internal messages Fixes #463

- [enh] Insert date breaks correctly when prepending messages into
chatbuf

- [new] `date-break-bar` format in the `telega-date-format-alist` for
the date break bars

Version -> 0.8.251
  • Loading branch information
zevlg committed Mar 8, 2024
1 parent 3477e9d commit cd639d2
Show file tree
Hide file tree
Showing 18 changed files with 891 additions and 563 deletions.
53 changes: 51 additions & 2 deletions contrib/telega-adblock.el
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
;; - {{{user-option(telega-adblock-chat-order-if-last-message-ignored, 2)}}}
;; - {{{user-option(telega-adblock-verbose, 2)}}}
;; - {{{user-option(telega-adblock-max-distance, 2)}}}
;; - {{{user-option(telega-adblock-same-link-count, 2)}}}
;; - {{{user-option(telega-adblock-block-msg-temex, 2)}}}
;; - {{{user-option(telega-adblock-allow-msg-temex, 2)}}}
;; - {{{user-option(telega-adblock-predicates, 2)}}}
Expand Down Expand Up @@ -75,6 +76,12 @@ Set it to less value if you see some advert messages not being blocked."
:type 'integer
:group 'telega-adblock)

(defcustom telega-adblock-same-link-count 3
"Number of links to the same resource.
Used by `telega-adblock-msg-multiple-same-links-p'."
:type 'integer
:group 'telega-adblock)

(defcustom telega-adblock-verbose nil
"Non-nil to show (in echo area) reason why message is ignored by adblock."
:type 'boolean
Expand All @@ -92,6 +99,8 @@ the rootbuf."
'(telega-adblock-msg-by-temex-p
telega-adblock-msg-forwarded-p
telega-adblock-msg-has-erid-p
telega-adblock-msg-multiple-same-links-p
telega-adblock-msg-has-reply-markup-p
telega-adblock-msg-has-advert-links-p)
"List of predicates to check message for advertisements.
Each predicate accepts single argument - message.
Expand All @@ -106,7 +115,7 @@ If any of predicates returns non-nil, then message contains advert."
:group 'telega-adblock)

(defcustom telega-adblock-allow-msg-temex
'(or is-reply-to-msg is-reply-to-story post-with-comments)
'(or is-reply-to-msg is-reply-to-story)
"Message's matching this temex will be allowed."
:type 'telega-msg-temex
:group 'telega-adblock)
Expand Down Expand Up @@ -259,7 +268,7 @@ an URL."
(seq-every-p (lambda (link-spec)
(telega-adblock-link-advert-p msg-chat link-spec))
(cdr url-group)))
(seq-group-by #'cdr (telega-adblock-msg-extract-links msg)))))
(seq-group-by #'cdr telega-adblock-msg-extracted-links))))

(defun telega-adblock-msg-has-erid-p (msg)
"Return non-nil if MSG text contains ERID label."
Expand All @@ -274,6 +283,46 @@ an URL."
""))))
telega-adblock-msg-extracted-links)))

(defun telega-adblock-msg-multiple-same-links-p (msg)
"Return non-nil if MSG has multiple links to the same resource."
(>= (- (length telega-adblock-msg-extracted-links)
(length (seq-uniq (mapcar #'cdr telega-adblock-msg-extracted-links))))
3))

(defun telega-adblock-msg-has-reply-markup-p (msg)
"Messages with reply markup buttons are usually an advert.
Because regular user can't send messages with reply markup buttons."
(plist-get msg :reply_markup))

;; TODO
(defun telega-adblock-msg-multiple-messages-with-same-media-p (msg)
"Return non-nil if MSG is sent to multiple channels at once.
To be marked as ignored it need to have at least one external link."
;; NOTE: (from TDLib dev) remote files are the same if `:unique_id'
;; is the same even if `:id' differs
(when telega-adblock-msg-extracted-links
;; NOTE: `telega-adblock-msg-extracted-links' is non-nil if there
;; is at least one link
;; Forwarded messages does not count
(let* ((chat (telega-msg-chat msg))
(last-p (>= (plist-get msg :id)
(or (telega--tl-get chat :last_message :id) 0)))
(media-file (telega-msg--content-file msg))
(chats-list telega--ordered-chats)
(other-messages nil))
(when (and last-p media-file (not (plist-get msg :forward_info)))
(while (and chats-list
(not (eq chat (car chats-list)))
(< (length other-messages)
3 ;Trigger number
))
(when-let* ((ochat (car chats-list))
(olast-msg (plist-get ochat :last_message))
(ofile (telega-msg--content-file olast-msg)))
(setq other-messages (cons olast-msg other-messages)))))

(>= (length other-messages) 3))))

(defun telega-adblock-msg-ignore-p (msg)
"Return non-nil if message MSG is advert message."
(and (telega-chat-match-p (telega-msg-chat msg) telega-adblock-for)
Expand Down
119 changes: 65 additions & 54 deletions docs/index.html

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions docs/telega-ellit.org
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ Use ~telega-story-match-p~ to match a story.

#+ELLIT-INCLUDE: ../telega-match.el :label story-temex

** Customizable options making use of Telega Match Expressions
** Some customizable options making use of Telega Match Expressions

- {{{user-option(telega-filter-default, 2)}}}
- {{{user-option(telega-filters-custom, 2)}}}
Expand All @@ -567,7 +567,6 @@ Use ~telega-story-match-p~ to match a story.
- {{{user-option(telega-chat-prompt-format, 2)}}}
- {{{user-option(telega-chat-group-messages-for, 2)}}}
- {{{user-option(telega-chat-show-deleted-messages-for, 2)}}}
- {{{user-option(telega-chat-use-date-breaks-for, 2)}}}
- {{{user-option(telega-root-view-grouping-alist, 2)}}}

* Chat Folders
Expand Down Expand Up @@ -1178,10 +1177,12 @@ To view recent notifications use

See also [[#telega-alertel--notifications-using-alertel][Notifications using alert.el]]

#+ELLIT-INCLUDE: ../telega-modes.el :label minor-modes

#+ELLIT-INCLUDE: ../telega-root.el :label minor-modes

#+ELLIT-INCLUDE: ../telega-chat.el :label minor-modes

#+ELLIT-INCLUDE: ../telega-modes.el :label minor-modes

#+ELLIT-INCLUDE: ../telega-voip.el :label minor-modes

* Contributed packages
Expand Down
71 changes: 39 additions & 32 deletions docs/telega-manual.org
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#+options: timestamp:nil \n:t num:nil ellit-cid:t
#+title: Telega Manual (v0.8.250)
#+title: Telega Manual (v0.8.251)
#+author: Zajcev Evgeny
#+startup: showall

Expand Down Expand Up @@ -53,7 +53,7 @@ Do not edit manually. Modify =telega-ellit.org= or comments in
- [[#list-of-message-sender-temexes][List of Message Sender Temexes]]
- [[#list-of-forum-topic-temexes][List of Forum Topic Temexes]]
- [[#list-of-story-temexes][List of Story Temexes]]
- [[#customizable-options-making-use-of-telega-match-expressions][Customizable options making use of Telega Match Expressions]]
- [[#some-customizable-options-making-use-of-telega-match-expressions][Some customizable options making use of Telega Match Expressions]]
- [[#chat-folders][Chat Folders]]
- [[#filtering-chats][Filtering chats]]
- [[#sorting-chats][Sorting chats]]
Expand Down Expand Up @@ -88,6 +88,8 @@ Do not edit manually. Modify =telega-ellit.org= or comments in
- [[#multiple-accounts][Multiple accounts]]
- [[#minor-modes][Minor Modes]]
- [[#notifications-for-incoming-messages][Notifications for incoming messages]]
- [[#telega-root-auto-fill-mode][telega-root-auto-fill-mode]]
- [[#telega-chat-auto-fill-mode][telega-chat-auto-fill-mode]]
- [[#telega-mode-line-mode][telega-mode-line-mode]]
- [[#telega-appindicator-mode][telega-appindicator-mode]]
- [[#telega-autoplay-mode][telega-autoplay-mode]]
Expand All @@ -103,7 +105,6 @@ Do not edit manually. Modify =telega-ellit.org= or comments in
- [[#telega-auto-translate-mode][telega-auto-translate-mode]]
- [[#telega-auto-download-mode-wip][telega-auto-download-mode (WIP)]]
- [[#telega-play-media-sequence-mode][telega-play-media-sequence-mode]]
- [[#telega-root-auto-fill-mode][telega-root-auto-fill-mode]]
- [[#telega-voip-sounds-mode][telega-voip-sounds-mode]]
- [[#contributed-packages][Contributed packages]]
- [[#ol-telegael--org-mode-links-to-telegram-chats-and-messages][/ol-telega.el/ -- Org mode links to telegram chats and messages]]
Expand Down Expand Up @@ -1527,9 +1528,9 @@ Use ~telega-story-match-p~ to match a story.
- is-photo ::
Matches if story has photo content.

** Customizable options making use of Telega Match Expressions
** Some customizable options making use of Telega Match Expressions
:PROPERTIES:
:CUSTOM_ID: customizable-options-making-use-of-telega-match-expressions
:CUSTOM_ID: some-customizable-options-making-use-of-telega-match-expressions
:END:

- User Option: ~telega-filter-default~
Expand Down Expand Up @@ -1597,18 +1598,6 @@ Use ~telega-story-match-p~ to match a story.
Chat Filter for chats where to show deleted messages in chatbuf.

Default value: ~nil~
- User Option: ~telega-chat-use-date-breaks-for~

Chat Filter for chats where to insert date breaks.
Date break is a special mark separating two messages received on
different days. Such as:
#+begin_example
MSG1 <--- msg sent on 27dec
-------(28 December 2020)------ <--- date break
MSG2 <--- msg sent on 28dec
#+end_example

Default value: ~all~
- User Option: ~telega-root-view-grouping-alist~

Alist of chat temexes for "grouping" root view.
Expand Down Expand Up @@ -1883,9 +1872,9 @@ Important customizable options:
Column to fill chat messages to.

Default value: ~70~
- User Option: ~telega-chat-use-date-breaks-for~
- User Option: ~telega-chat-use-date-breaks~

Chat Filter for chats where to insert date breaks.
Non-nil to insert date break bar in chat buffers.
Date break is a special mark separating two messages received on
different days. Such as:
#+begin_example
Expand All @@ -1894,7 +1883,7 @@ Important customizable options:
MSG2 <--- msg sent on 28dec
#+end_example

Default value: ~all~
Default value: ~t~

** Chatbuf fast navigation
:PROPERTIES:
Expand Down Expand Up @@ -2135,7 +2124,7 @@ Attachment types to attach with
Use this attachment to disable/enable notification on the receiver side.
- enable-notification :: Toggle disable-notification chat option for the subsequent chatbuf input.
Use this attachment to disable/enable notification on the receiver side.
- disable-webpage-preview :: Disable webpage preview for the following text message.
- link-preview-options :: Change ~telega-chat-send-link-preview-options~ for the following messages.
- send-by :: Set sender for the following message.
- custom-emoji :: Interactively attach a custom emoji.
- delimiter :: Attach explicit messages delimiter.
Expand Down Expand Up @@ -2927,6 +2916,26 @@ To view recent notifications use

See also [[#telega-alertel--notifications-using-alertel][Notifications using alert.el]]

** telega-root-auto-fill-mode
:PROPERTIES:
:CUSTOM_ID: telega-root-auto-fill-mode
:END:

Global minor mode to automatically adjust ~telega-root-fill-column~
to the width of the window displaying rootbuf.

~telega-root-auto-fill-mode~ is enabled by default.

** telega-chat-auto-fill-mode
:PROPERTIES:
:CUSTOM_ID: telega-chat-auto-fill-mode
:END:

Minor mode to automatically adjust ~telega-chat-fill-column~
to the width of the window displaying chatbuf.

~telega-chat-auto-fill-mode~ is enabled by default.

** telega-mode-line-mode
:PROPERTIES:
:CUSTOM_ID: telega-mode-line-mode
Expand Down Expand Up @@ -3310,16 +3319,6 @@ Customizable options:

Play media content in subsequent manner.

** telega-root-auto-fill-mode
:PROPERTIES:
:CUSTOM_ID: telega-root-auto-fill-mode
:END:

Global minor mode to automatically adjust ~telega-root-fill-column~
to the width of the window displaying rootbuf.

~telega-root-auto-fill-mode~ is enabled by default.

** telega-voip-sounds-mode
:PROPERTIES:
:CUSTOM_ID: telega-voip-sounds-mode
Expand Down Expand Up @@ -3721,6 +3720,12 @@ Customizable options:
Set it to less value if you see some advert messages not being blocked.

Default value: ~4~
- User Option: ~telega-adblock-same-link-count~

Number of links to the same resource.
Used by ~telega-adblock-msg-multiple-same-links-p~.

Default value: ~3~
- User Option: ~telega-adblock-block-msg-temex~

Message temex for ~telega-adblock-msg-by-temex-p~ predicate.
Expand All @@ -3730,7 +3735,7 @@ Customizable options:

Message's matching this temex will be allowed.

Default value: ~(or is-reply-to-msg is-reply-to-story post-with-comments)~
Default value: ~(or is-reply-to-msg is-reply-to-story)~
- User Option: ~telega-adblock-predicates~

List of predicates to check message for advertisements.
Expand All @@ -3741,6 +3746,8 @@ Customizable options:
#+begin_src emacs-lisp
(telega-adblock-msg-by-temex-p telega-adblock-msg-forwarded-p
telega-adblock-msg-has-erid-p
telega-adblock-msg-multiple-same-links-p
telega-adblock-msg-has-reply-markup-p
telega-adblock-msg-has-advert-links-p)
#+end_src

Expand Down
27 changes: 23 additions & 4 deletions etc/langs/en.plist
Original file line number Diff line number Diff line change
Expand Up @@ -568,17 +568,15 @@ Example: 23 y.o. designer from San Francisco")
:value "This message will pop notification on receiver side")
("telega_forward_new_caption_help"
:value "New caption for the forwarded message")
("telega_disable_webpage_preview_help"
:value "This message won't have webpage preview")
("telega_link_preview_options_help"
:value "This message will have custom link preview options")
("telega_reset_notifications_help"
:value "Undo all custom notification settings for all chats")
("telega_enable_notification"
:value "Enable Receiver Notification")
("telega_disable_notification"
:value "Disable Receiver Notification")
("telega_disable_webpage_preview"
:value "Disable WebPage Preview")
("telega_reset_notifications"
:value "Reset All Notifications")
Expand Down Expand Up @@ -1085,6 +1083,8 @@ Online ads should no longer be synonymous with abuse of user privacy. Let us red
Unlike other apps, Telegram doesn't track whether you tapped on a sponsored message and doesn't profile you based on your activity. We also prevent external links in sponsored messages to ensure that third parties can’t spy on our users. We believe that everyone has the right to privacy, and technological platforms should respect that.
Telegram offers a free and unlimited service to hundreds of millions of users, which involves significant server and traffic costs. In order to remain independent and stay true to its values, Telegram developed a paid tool to promote messages with user privacy in mind. We welcome responsible advertisers at:")
("lng_sponsored_hide_ads"
:value "Hide")
;; Errors
("lng_error_nocopy_group"
Expand Down Expand Up @@ -1430,11 +1430,30 @@ You can send them an invite link as message instead.")
:value "This giveaway is sponsored by {admins}.")
("lng_prizes_how_when_finish"
:value "On {date}, Telegram will automatically select {winners}.")
("lng_prizes_winners_all_of_one"
:one_value "{count} random subscriber of {channel}"
:other_value "{count} random subscribers of {channel}")
("lng_prizes_winners_all_of_many"
:one_value "{count} random subscriber of {channel} and other listed groups and channels"
:other_value "{count} random subscribers of {channel} and other listed groups and channels")
("lng_prizes_winners_new_of_one"
:one_value "{count} random user that joined {channel} after {start_date}"
:other_value "{count} random users that joined {channel} after {start_date}")
("lng_prizes_winners_new_of_many"
:one_value "{count} random user that joined {channel} and other listed groups and channels after {start_date}"
:other_value "{count} random users that joined {channel} and other listed groups and channels after {start_date}")
("lng_prizes_how_yes_joined_one"
:value "You are participating in this giveaway because you joined the channel {channel}.")
("lng_prizes_how_yes_joined_many"
:value "You are participating in this giveaway because you joined the channel {channel} (and other listed groups and channels).")
("lng_prizes_how_no_admin"
:value "You are not eligible to participate in this giveaway because you are an admin of a participating channel ({channel}).")
("lng_prizes_how_no_country"
:value "You are not eligible to participate in this giveaway because your country is not included in the terms of the giveaway.")
("lng_prizes_how_no_joined"
:value "You are not eligible to participate in this giveaway because you joined this channel on {date}, which is before the giveaway started.")
("lng_prizes_how_no_joined_group"
:value "You are not eligible to participate in this giveaway, because you joined this group on {date}, which is before the contest started.")
("lng_prizes_admins"
:one_value "the admins of {channel}, who acquired **{count} Telegram Premium** subscription {duration} for its followers"
:other_value "the admins of {channel}, who acquired **{count} Telegram Premium** subscriptions {duration} for its followers")
Expand Down
Loading

0 comments on commit cd639d2

Please sign in to comment.