-
Notifications
You must be signed in to change notification settings - Fork 44
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
Provide a way to influence highlighting decisions in rooms #281
Comments
Hi Sergio, Thanks for the well-written report. FWIW I think you could solve two of these problems by applying advice to the function In the meantime, the idea to have more control over what highlights a message is not a bad one, so it will go on the to-do list. Thanks. |
Thanks for the quick reply!
Indeed, I thought about using advices, too. I like being able to cleanly modify a function's behaviour using hooks or other mechanisms, so that's why I chose the "hard" way of reimplementing things and using hooks instead, but I will revisit the code and see if I can make it simpler :-).
Thanks for considering the idea. Do you think it's also possible to use an advice to solve this problem, BTW? |
I don't see why not. Advice allows you to replace a function with your own code, which can do anything. |
Wouldn't the simple solution be just ignoring the sender field in ement-room--event-mentions-user-p and/or ement-notify--event-mentions-session-user-p? It doesn't seem like matching on that would be correct in any situation. |
That's used to negate matches, i.e. if the user types his own name or MXID, we don't want to act as if he mentioned himself. |
ement-notify--event-mentions-session-user-p has a separate check for that, (unless (equal (ement-user-id user) (ement-user-id sender)). The problem is indeed that ement-room--event-mentions-user-p doesn't check for that, and acts as if the user mentioned themselves. |
The lines in question are here: The problem is how to distinguish |
The best idea I have is to allow the user to specify an "anti-mention" regexp, which would nullify any apparent mention. In this case, the user could set it to something like |
Excluding the sender field from the matching wouldn't have any of the mentioned issues. |
I think we must be miscommunicating. If the message body has one of these bridged MXIDs in it, that is causing this false mention. Unless I'm just totally misunderstanding what's going on here... |
You are entirely correct. I went through this in my head a few more times last night and finally it clicked. The match isn't on sender, but on body contents. The way I've been avoiding this in practice is by using |
Sorry about the delay in replying, and I see now that my question was (cl-defun sdj/ement-room--event-doesnt-mention-other-heisenbridge-user-p (event user &optional _ignore)
"Verify whether USER is a Heisenbridge user. If it is, and if it isn't me, return nil. Otherwise, return t."
(pcase-let* (((cl-struct ement-event content) event)
((map body formatted_body) content)
(body (or formatted_body body)))
(when body
(cond
((string-match-p (regexp-quote "@hbirc_") body)
;; This comes from Heisenbridge.
(let ((idx 0)
(found-me nil))
(save-match-data
(while (and (not found-me)
(string-match
(rx "<a href=\"https://matrix.to/#/@hbirc_"
(minimal-match (1+ (not ">"))) ">"
(group (minimal-match (1+ (not "<"))))
"</a>")
body idx))
(setq found-me (string= (match-string 1 body) "sergiodj"))
(setq idx (match-end 1))))
found-me))
((string-match-p (regexp-quote "sergiodj") body)
;; This is likely a "regular" Matrix message with my nick in it.
t)
(t nil)))))
(defun sdj/ement-notify--event-from-other-heisenbridge-user-p (event room session)
"Return non-nil if EVENT in ROOM comes from another heisenbridge user."
(pcase-let* (((cl-struct ement-session user) session)
((cl-struct ement-event sender) event))
(unless (equal (ement-user-id user) (ement-user-id sender))
(not (sdj/ement-room--event-doesnt-mention-other-heisenbridge-user-p event user)))))
(advice-add #'ement-room--event-mentions-user-p
:before-while #'sdj/ement-room--event-doesnt-mention-other-heisenbridge-user-p)
(add-to-list 'ement-notify-ignore-predicates
#'sdj/ement-notify--event-from-other-heisenbridge-user-p
t) |
I think it's obvious by looking at the code I posted, but the way I'm IOW, I like the idea of having an "anti-mention" regexp; I think it's |
Yeah, I keep meaning to fix that. It annoys me too. |
Well, it's not quite obvious to me; whether it's due to the docstring or the formatting, I'm not sure. ;) Also, it's a bit unusual to write a "doesn't" predicate function; it would probably be easier to understand if you wrote it in positive terms and then negate the result where you use it. Anyway, what you describe now is what the existing code already does: looks for your displayname in the message body. So I'm not sure how your advice function is solving the problem. FWIW, I've never seen |
Ah, the docstring got messed up when I pasted the code, sorry about In a way, the function already works in "positive terms" as you put
My advice function extends the existing check by supporting matching
Hah, it's probably the latter. But it made sense to use it because I |
It's probably just me, but I still find the first function confusing. I'd suggest 1) writing the docstring in terms of, "Return non-nil if..." (this is standard Emacs convention; and there's no need to say that it returns nil otherwise); 2) narrow its scope: as is, it seems less like a predicate function, because it seems to test two different things. It might be best split into two functions. OTOH if this is just for your config and it works for you, then that's all that matters. |
Ah, good data point. I've rewritten the docstring now.
Would you care expanding on this point? I see how I could split this
Yeah, this is just for my personal config, but I'm also interested in |
@sergiodj It seems that I was looking at #281 (comment) while you were updating the code in #281 (comment). |
@alphapapa, nope, I was updating the code on comment #281 (comment). That's pretty much the last version of the code I have here. |
@sergiodj I'm not sure what you mean; #281 (comment) has no code in it. |
@alphapapa sorry, I should have said #281 (comment) |
OS/platform
GNU/Linux
Emacs version and provenance
30.0.50, compiled manually.
Emacs command
emacs server + client
Emacs frame type
A mix of both (mainly GUI, though)
Ement package version and provenance
0.15.1, from ELPA
Actions taken
I use Heisenbridge to connect to my ZNC bouncer, which gives me a nice way to be natively on IRC while at the same time having access to everything via Matrix too.
Heisenbridge works by creating Matrix users for each IRC user it sees. These Matrix user IDs have the form of
@hbirc_libera.znc_NICK:sergiodj.net
.Observed results
I run my own Matrix server, and my domain name is the same as my Matrix user (
sergiodj.net
for the domain, andsergiodj
for the user). Because the Heisenbridge user IDs contain my domain name in them, and because IRC messages look like the below excerpt on Matrix:Ement mistakenly thinks that I'm being mentioned whenever someone mentions anyone else on IRC.
This causes many problems. Namely, all IRC messages which mention some user:
*Ement Mentions*
buffer (fixed; see below).I fixed the first problem by adding the following function to
ement-notify-ignore-predicates
:The second problem was fixed by removing
ement-notify--event-mentions-session-user-p
fromement-notify-mention-predicates
and adding the following function instead:Expected results
It would be great to have a way to control the events which make highlighting happen in the room. Currently I can't hook into the function that decides to do that.
Backtrace
No response
Etc.
No response
The text was updated successfully, but these errors were encountered: