Rewrite chat room mentions for federation.

This commit is contained in:
Joachim Bauch 2025-09-29 14:36:23 +02:00
commit 962f0254b1
No known key found for this signature in database
GPG key ID: 77C1D22D53E15F02
2 changed files with 31 additions and 13 deletions

View file

@ -363,6 +363,10 @@ func TestFeatureChatRelayFederation(t *testing.T) {
"mention-id": "federated_user/" + hello2.Hello.UserId + "@" + getCloudUrl(server2.URL),
"server": server2.URL,
},
"mention-call": {
"type": "call",
"id": roomId,
},
},
}
federatedChatComment := map[string]any{
@ -390,6 +394,10 @@ func TestFeatureChatRelayFederation(t *testing.T) {
"name": "User 2",
"mention-id": "federated_user/" + hello2.Hello.UserId + "@" + getCloudUrl(server2.URL),
},
"mention-call": {
"type": "call",
"id": federatedRoomId,
},
},
}
message := api.StringMap{

View file

@ -648,20 +648,30 @@ func (c *FederationClient) updateComment(comment api.StringMap, localCloudUrl st
continue
}
if ptype, found := api.GetStringMapString[string](param, "type"); found && ptype == "user" {
if server, found := api.GetStringMapString[string](param, "server"); found && server == localUrl {
delete(param, "server")
params[key] = param
changed = true
continue
}
if ptype, found := api.GetStringMapString[string](param, "type"); found {
switch ptype {
case "user":
if server, found := api.GetStringMapString[string](param, "server"); found && server == localUrl {
delete(param, "server")
params[key] = param
changed = true
continue
}
if _, found := api.GetStringMapString[string](param, "mention-id"); !found {
param["mention-id"] = param["id"]
param["server"] = remoteUrl
params[key] = param
changed = true
continue
if _, found := api.GetStringMapString[string](param, "mention-id"); !found {
param["mention-id"] = param["id"]
param["server"] = remoteUrl
params[key] = param
changed = true
continue
}
case "call":
roomId := c.RoomId()
remoteRoomId := c.RemoteRoomId()
// TODO: Should we also rewrite the room avatar url in "icon-url"?
if c.changeRoomId.Load() && param["id"] == remoteRoomId {
param["id"] = roomId
}
}
}
}