From cf13abdab62b321a071f6ca396af3d8c0f3542e5 Mon Sep 17 00:00:00 2001 From: Alexey Shchepin Date: Mon, 24 Mar 2025 20:00:33 +0300 Subject: [PATCH] Preserve XMPP message IDs in Matrix rooms --- src/mod_matrix_gw_room.erl | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/mod_matrix_gw_room.erl b/src/mod_matrix_gw_room.erl index 380c67e06..2fd1f3be6 100644 --- a/src/mod_matrix_gw_room.erl +++ b/src/mod_matrix_gw_room.erl @@ -216,7 +216,8 @@ route(#presence{from = From, to = #jid{luser = <>} = To, end; route(#message{from = From, to = #jid{luser = <>} = To, type = groupchat, - body = Body}) + body = Body, + id = MsgID}) when C == $!; C == $# -> Host = ejabberd_config:get_myname(), @@ -232,7 +233,8 @@ route(#message{from = From, to = #jid{luser = <>} = To, JSON = #{<<"content">> => #{<<"body">> => Text, - <<"msgtype">> => <<"m.text">>}, + <<"msgtype">> => <<"m.text">>, + <<"net.process-one.xmpp-id">> => MsgID}, <<"sender">> => UserID, <<"type">> => ?ROOM_MESSAGE}, gen_statem:cast(Pid, {add_event, JSON}), @@ -2700,7 +2702,7 @@ notify_event_xmpp( notify_event_xmpp( #event{type = ?ROOM_MESSAGE, sender = Sender, json = #{<<"content">> := #{<<"msgtype">> := <<"m.text">>, - <<"body">> := Body}, + <<"body">> := Body} = Content, <<"origin_server_ts">> := OriginTS}}, #data{kind = #multi{users = Users}} = Data) -> case Sender of @@ -2714,7 +2716,15 @@ notify_event_xmpp( when JoinTS =< OriginTS -> From = jid:replace_resource(RoomJID, SenderUser), UserJID = jid:make(LUser, LServer, LResource), - Msg = #message{from = From, + MsgID = + case Content of + #{<<"net.process-one.xmpp-id">> := MID} -> + MID; + _ -> + <<"">> + end, + Msg = #message{id = MsgID, + from = From, to = UserJID, type = groupchat, body = [#text{data = Body}]