alphapapa / alphapapa/ement.el

Internal links won't necessarily be "matrix.to" URLs

Ouverte
#188 3 commentaires 0 réactions 1 personne assignée Réclamée par @alphapapa Voir sur GitHub
enhancement help wanted
Langage dominant
Emacs Lisp
Étoiles
604
Forks
54
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

This follows on from these three comments in https://github.com/alphapapa/ement.el/pull/92:

* https://github.com/alphapapa/ement.el/pull/92#issuecomment-1252109379
* https://github.com/alphapapa/ement.el/pull/92#issuecomment-1252113491
* https://github.com/alphapapa/ement.el/pull/92#issuecomment-1262596198

On the server I'm using, our room/event and user link URLs are respectively:

* `https:///#/room/...`
* `https:///#/user/@...`

I.e. a custom domain, and the addition of `/room` or `/user` after the `/#` component, compared to the `matrix.to` URLs.

At present I mostly have questions and no answers, but I wanted to jot down these initial notes.

I think this issue will need to confirm:

* how many different types of links there are
* whether each type might need its own URL template/generator
* how much potential variation there might be between types (are `/#/room` and `/#/user` the single standard variation on `/#` or could they potentially be anything? If the former, can we *already* use those variants with the `matrix.to` domain? If so, that might reduce the issue to *just* the domain.)
* whether any of this is auto-detectable when connecting
* what the sensible way of configuring these URLs will be

Aside from the uses in `tests/ement-tests.el`, I see the following cases in the code. The first is the variable mentioned in that earlier PR, which can be overridden with relative ease, but the others case are more hard-coded at present:

```el
(defvar ement-room-matrix.to-url-regexp
(rx "http" (optional "s") "://"
"matrix.to" "/#/"
(group (or "!" "#") (1+ (not (any "/"))))
(optional "/" (group "$" (1+ (not (any "?" "/")))))
(optional "?" (group (1+ anything))))
"Regexp matching \"matrix.to\" URLs.")
```
----
```el
(defun ement-room-send-org-filter (content room)
"Return event CONTENT for ROOM having processed its Org content.
The CONTENT's body is exported with
`org-html-export-as-html' (with some adjustments for
compatibility), and the result is added to the CONTENT as
\"formatted_body\"."
(require 'ox-html)
;; The CONTENT alist has string keys before being sent.
(pcase-let* ((body (alist-get "body" content nil nil #'equal))
(formatted-body
(save-window-excursion
(with-temp-buffer
(insert (ement--format-body-mentions body room
:template "[[https://matrix.to/#/%s][%s]]"))
```
----
```el
(cl-defun ement--format-body-mentions
(body room &key (template "%s"))
"Return string for BODY with mentions in ROOM linkified with TEMPLATE.
TEMPLATE is a format string in which the first \"%s\" is replaced
with the user's MXID and the second with the displayname. A
mention is qualified by an \"@\"-prefixed displayname or
MXID (optionally suffixed with a colon), or a colon-suffixed
displayname, followed by a blank, question mark, comma, or
period, anywhere in the body."
```
----
```el
(defun ement--add-reply (data replying-to-event room)
"Return DATA adding reply data for REPLYING-TO-EVENT in ROOM.
DATA is an unsent message event's data alist."
;; SPEC: "13.2.2.6.1 Rich replies"
;; FIXME: Rename DATA.
(pcase-let* (((cl-struct ement-event (id replying-to-event-id)
content (sender replying-to-sender))
replying-to-event)
((cl-struct ement-user (id replying-to-sender-id)) replying-to-sender)
((map ('body replying-to-body) ('formatted_body replying-to-formatted-body)) content)
(replying-to-sender-name (ement--user-displayname-in ement-room replying-to-sender))
(quote-string (format "> <%s> %s\n\n" replying-to-sender-name replying-to-body))
(reply-body (alist-get "body" data nil nil #'string=))
(reply-formatted-body (alist-get "formatted_body" data nil nil #'string=))
(reply-body-with-quote (concat quote-string reply-body))
(reply-formatted-body-with-quote
(format "


In reply to
%s


%s

%s"
```
----

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.