Skip to content

Instantly share code, notes, and snippets.

@tychoish
Last active November 5, 2023 20:51
Show Gist options
  • Save tychoish/1c493e79839e80efe3fa97237aff804c to your computer and use it in GitHub Desktop.
Save tychoish/1c493e79839e80efe3fa97237aff804c to your computer and use it in GitHub Desktop.
(defun telega--chat-observable-p (msg)
(let ((chat (telega-msg-chat msg)))
(with-telega-chatbuf chat
(and (telega-chatbuf--msg-observable-p msg)
(not (telega-chatbuf--history-state-get :newer-freezed))))))
(defun telega-notifications-msg-notify-p (msg)
"tychoish's custom override for notificationable"
(let* ((chat (telega-msg-chat msg))
(title (plist-get chat :title)))
(cond
;; chat window is open and viable: skip notify
((telega--chat-observable-p msg)
(progn (telega-debug "NOTIFY-CHECK: observed chat [%s], skip notify" title) nil))
;; if it's muted: skip notify
((telega-chat-muted-p chat)
(progn (telega-debug "NOTIFY-CHECK: muted chat [%s], skip notify" title) nil))
;; overly clear, but for groupchats where I am not a member: skip notify
;; after: https://github.com/zevlg/ytelega.el/issues/224
((telega-chat-match-p chat '(and (type basicgroup supergroup channel) (not me-is-member)))
(progn (telega-debug "NOTIFY-CHECK: group chat where I am not a member [%s], skip notify" title) nil))
;; message I sent (from another device): skip notify
((telega-msg-match-p msg '(sender me))
(progn (telega-debug "NOTIFY-CHECK: message I sent [%s], skip notify" title) nil))
;; message that is a mention but notification of mentions are
;; disabled: skip notify
((and
(plist-get msg :contains_unread_mention)
(telega-chat-notification-setting chat :disable_mention_notifications))
(progn (telega-debug "NOTIFY-CHECK: contains a mention [%s], notify" title) nil))
;; notify for messages in chats that are directly sent to me, including bots
((telega-chat-match-p chat '(or (type private secret bot)))
(progn (telega-debug "NOTIFY-CHECK: is DM or BOT [%s], can notify" title) t))
;; for things that are a group, and I am a member, notify
((telega-chat-match-p chat 'is-member)
(progn (telega-debug "NOTIFY-CHECK: member of a group [%s], can notify" title) t))
;; nothing has matched, this is probably "cases we haven't
;; explicitly called out above, probably a skip, but should be
;; explict:" notify for now
(t
(progn (message (format "TELEGA-NOTIFY: unexpected message [%s], notifying anyway" title)) t)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment