alphapapa / alphapapa/ement.el

Provide a way to influence highlighting decisions in rooms

Open
#281 22 comments 0 reactions 1 assignee Claimed by @alphapapa View on GitHub
bug enhancement help wanted
Dominant language
Emacs Lisp
Stars
604
Forks
54
PR merge metrics
No merged PRs in 30d

Description

### 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, and `sergiodj` 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:

```
NICKNAME: This is an example message mentioning a user whose nick is NICKNAME.
```

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:

- Generate a desktop notification (fixed; see below).
- End up in the `*Ement Mentions*` buffer (fixed; see below).
- Cause the message to be highlighted in the room (this is what this bug is about).

I fixed the first problem by adding the following function to `ement-notify-ignore-predicates`:

```elisp
(defun sdj/ement-notify--event-from-other-heisenbridge-user (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))
(pcase-let* (((cl-struct ement-event content) event)
((map body formatted_body) content)
(body (or formatted_body body)))
(when body
(save-match-data
(let ((idx 0)
(found-me nil))
(while (string-match
(rx ""))) ">"
(group (minimal-match (1+ (not "<"))))
"
")
body idx)
(setq found-me (or found-me
(string= (match-string 1 body) "sergiodj")))
(setq idx (match-end 1)))
(not found-me))))))))
```

The second problem was fixed by removing `ement-notify--event-mentions-session-user-p` from `ement-notify-mention-predicates` and adding the following function instead:

```elisp
(defun sdj/ement-notify--event-doesnt-mention-heisenbridge (event room session)
(pcase-let* (((cl-struct ement-session user) session)
((cl-struct ement-event sender) event))
(and (not (equal (ement-user-id user) (ement-user-id sender)))
(ement-room--event-mentions-user-p event user room)
(not (sdj/ement-notify--event-from-other-heisenbridge-user event room session)))))
```

### 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_

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.