Send room updates, invite and disinvite only to connected sessions.

Removes the requirement for Talk to include the ids of all users invited to
the room.
This commit is contained in:
Joachim Bauch 2026-01-15 09:57:10 +01:00
commit 3e14038fbc
No known key found for this signature in database
GPG key ID: 77C1D22D53E15F02
4 changed files with 16 additions and 46 deletions

View file

@ -400,7 +400,7 @@ func (b *BackendServer) sendRoomDisinvite(roomid string, backend *talk.Backend,
wg.Wait()
}
func (b *BackendServer) sendRoomUpdate(roomid string, backend *talk.Backend, notified_userids []string, all_userids []string, properties json.RawMessage) {
func (b *BackendServer) sendRoomUpdate(roomid string, backend *talk.Backend, properties json.RawMessage) {
msg := &events.AsyncMessage{
Type: "message",
Message: &api.ServerMessage{
@ -415,19 +415,8 @@ func (b *BackendServer) sendRoomUpdate(roomid string, backend *talk.Backend, not
},
},
}
notified := make(map[string]bool)
for _, userid := range notified_userids {
notified[userid] = true
}
// Only send to users not notified otherwise.
for _, userid := range all_userids {
if notified[userid] {
continue
}
if err := b.events.PublishUserMessage(userid, backend, msg); err != nil {
b.logger.Printf("Could not publish room update for user %s in backend %s: %s", userid, backend.Id(), err)
}
if err := b.events.PublishRoomMessage(roomid, backend, msg); err != nil {
b.logger.Printf("Could not publish room update for %s in backend %s: %s", roomid, backend.Id(), err)
}
}
@ -902,17 +891,17 @@ func (b *BackendServer) roomHandler(ctx context.Context, w http.ResponseWriter,
switch request.Type {
case "invite":
b.sendRoomInvite(roomid, backend, request.Invite.UserIds, request.Invite.Properties)
b.sendRoomUpdate(roomid, backend, request.Invite.UserIds, request.Invite.AllUserIds, request.Invite.Properties)
b.sendRoomUpdate(roomid, backend, request.Invite.Properties)
case "disinvite":
b.sendRoomUpdate(roomid, backend, request.Disinvite.Properties)
b.sendRoomDisinvite(roomid, backend, api.DisinviteReasonDisinvited, request.Disinvite.UserIds, request.Disinvite.SessionIds)
b.sendRoomUpdate(roomid, backend, request.Disinvite.UserIds, request.Disinvite.AllUserIds, request.Disinvite.Properties)
case "update":
message := &events.AsyncMessage{
Type: "room",
Room: &request,
}
err = b.events.PublishBackendRoomMessage(roomid, backend, message)
b.sendRoomUpdate(roomid, backend, nil, request.Update.UserIds, request.Update.Properties)
b.sendRoomUpdate(roomid, backend, request.Update.Properties)
case "delete":
message := &events.AsyncMessage{
Type: "room",

View file

@ -336,9 +336,6 @@ func TestBackendServer_OldCompatAuth(t *testing.T) {
UserIds: []string{
userid,
},
AllUserIds: []string{
userid,
},
Properties: roomProperties,
},
}
@ -447,9 +444,6 @@ func RunTestBackendServer_RoomInvite(ctx context.Context, t *testing.T) {
UserIds: []string{
userid,
},
AllUserIds: []string{
userid,
},
Properties: roomProperties,
},
}
@ -527,7 +521,6 @@ func RunTestBackendServer_RoomDisinvite(ctx context.Context, t *testing.T) {
SessionIds: []api.RoomSessionId{
api.RoomSessionId(fmt.Sprintf("%s-%s"+roomId, hello.Hello.SessionId)),
},
AllUserIds: []string{},
Properties: roomProperties,
},
}
@ -547,6 +540,9 @@ func RunTestBackendServer_RoomDisinvite(ctx context.Context, t *testing.T) {
assert.Empty(string(event.Disinvite.Properties))
}
if message, ok := client.RunUntilRoomlistUpdate(ctx); ok {
assert.Equal(roomId, message.RoomId)
}
if message, ok := client.RunUntilRoomlistDisinvite(ctx); ok {
assert.Equal(roomId, message.RoomId)
}
@ -587,7 +583,6 @@ func TestBackendServer_RoomDisinviteDifferentRooms(t *testing.T) {
SessionIds: []api.RoomSessionId{
api.RoomSessionId(fmt.Sprintf("%s-%s"+roomId1, hello1.Hello.SessionId)),
},
AllUserIds: []string{},
},
}
@ -600,6 +595,9 @@ func TestBackendServer_RoomDisinviteDifferentRooms(t *testing.T) {
assert.NoError(err)
assert.Equal(http.StatusOK, res.StatusCode, "Expected successful request, got %s", string(body))
if message, ok := client1.RunUntilRoomlistUpdate(ctx); ok {
assert.Equal(roomId1, message.RoomId)
}
if message, ok := client1.RunUntilRoomlistDisinvite(ctx); ok {
assert.Equal(roomId1, message.RoomId)
}
@ -613,9 +611,6 @@ func TestBackendServer_RoomDisinviteDifferentRooms(t *testing.T) {
msg = &talk.BackendServerRoomRequest{
Type: "update",
Update: &talk.BackendRoomUpdateRequest{
UserIds: []string{
testDefaultUserId,
},
Properties: testRoomProperties,
},
}
@ -662,24 +657,20 @@ func RunTestBackendServer_RoomUpdate(ctx context.Context, t *testing.T) {
require.NoError(err, "Could not create room")
defer room.Close()
userid := "test-userid"
roomProperties := json.RawMessage("{\"foo\":\"bar\"}")
eventsChan := make(events.AsyncChannel, 1)
listener := &channelEventListener{
ch: eventsChan,
}
require.NoError(asyncEvents.RegisterUserListener(userid, backend, listener))
require.NoError(asyncEvents.RegisterRoomListener(roomId, backend, listener))
defer func() {
assert.NoError(asyncEvents.UnregisterUserListener(userid, backend, listener))
assert.NoError(asyncEvents.UnregisterRoomListener(roomId, backend, listener))
}()
msg := &talk.BackendServerRoomRequest{
Type: "update",
Update: &talk.BackendRoomUpdateRequest{
UserIds: []string{
userid,
},
Properties: roomProperties,
},
}

View file

@ -111,9 +111,6 @@ func TestRoom_Update(t *testing.T) {
msg := &talk.BackendServerRoomRequest{
Type: "update",
Update: &talk.BackendRoomUpdateRequest{
UserIds: []string{
testDefaultUserId,
},
Properties: roomProperties,
},
}

View file

@ -110,24 +110,17 @@ type BackendServerRoomRequest struct {
}
type BackendRoomInviteRequest struct {
UserIds []string `json:"userids,omitempty"`
// TODO(jojo): We should get rid of "AllUserIds" and find a better way to
// notify existing users the room has changed and they need to update it.
AllUserIds []string `json:"alluserids,omitempty"`
UserIds []string `json:"userids,omitempty"`
Properties json.RawMessage `json:"properties,omitempty"`
}
type BackendRoomDisinviteRequest struct {
UserIds []string `json:"userids,omitempty"`
SessionIds []api.RoomSessionId `json:"sessionids,omitempty"`
// TODO(jojo): We should get rid of "AllUserIds" and find a better way to
// notify existing users the room has changed and they need to update it.
AllUserIds []string `json:"alluserids,omitempty"`
Properties json.RawMessage `json:"properties,omitempty"`
Properties json.RawMessage `json:"properties,omitempty"`
}
type BackendRoomUpdateRequest struct {
UserIds []string `json:"userids,omitempty"`
Properties json.RawMessage `json:"properties,omitempty"`
}