Include "federated" in "join" events for fed. sessions.

This commit is contained in:
Joachim Bauch 2024-07-25 08:24:20 +02:00
commit 86721347f9
No known key found for this signature in database
GPG key ID: 77C1D22D53E15F02
5 changed files with 22 additions and 0 deletions

View file

@ -1053,6 +1053,7 @@ type EventServerMessageSessionEntry struct {
UserId string `json:"userid"`
User json.RawMessage `json:"user,omitempty"`
RoomSessionId string `json:"roomsessionid,omitempty"`
Federated bool `json:"federated,omitempty"`
}
func (e *EventServerMessageSessionEntry) Clone() *EventServerMessageSessionEntry {
@ -1061,6 +1062,7 @@ func (e *EventServerMessageSessionEntry) Clone() *EventServerMessageSessionEntry
UserId: e.UserId,
User: e.User,
RoomSessionId: e.RoomSessionId,
Federated: e.Federated,
}
}

View file

@ -3951,6 +3951,8 @@ func easyjson29f189fbDecodeGithubComStrukturagNextcloudSpreedSignaling35(in *jle
}
case "roomsessionid":
out.RoomSessionId = string(in.String())
case "federated":
out.Federated = bool(in.Bool())
default:
in.SkipRecursive()
}
@ -3985,6 +3987,11 @@ func easyjson29f189fbEncodeGithubComStrukturagNextcloudSpreedSignaling35(out *jw
out.RawString(prefix)
out.String(string(in.RoomSessionId))
}
if in.Federated {
const prefix string = ",\"federated\":"
out.RawString(prefix)
out.Bool(bool(in.Federated))
}
out.RawByte('}')
}

View file

@ -650,6 +650,10 @@ Room event session object:
}
}
If a session is federated, an additional entry `"federated": true` will be
available.
Message format (Server -> Client, user(s) left):
{

View file

@ -137,6 +137,7 @@ func Test_Federation(t *testing.T) {
remoteSessionId = evt.SessionId
assert.NotEqual(hello2.Hello.SessionId, remoteSessionId)
assert.Equal(testDefaultUserId+"2", evt.UserId)
assert.True(evt.Federated)
}
// The client2 will see its own session id, not the one from the remote server.
@ -183,6 +184,7 @@ func Test_Federation(t *testing.T) {
remoteSessionId = evt.SessionId
assert.NotEqual(hello2.Hello.SessionId, remoteSessionId)
assert.Equal(testDefaultUserId+"2", evt.UserId)
assert.True(evt.Federated)
}
assert.NoError(client2.RunUntilJoined(ctx, hello1.Hello, hello2.Hello))
@ -347,6 +349,7 @@ func Test_Federation(t *testing.T) {
remoteSessionId4 = evt.SessionId
assert.NotEqual(hello4.Hello.SessionId, remoteSessionId)
assert.Equal(testDefaultUserId+"4", evt.UserId)
assert.True(evt.Federated)
}
assert.NoError(client2.RunUntilJoined(ctx, &HelloServerMessage{
@ -449,6 +452,7 @@ func Test_FederationMedia(t *testing.T) {
remoteSessionId = evt.SessionId
assert.NotEqual(hello2.Hello.SessionId, remoteSessionId)
assert.Equal(testDefaultUserId+"2", evt.UserId)
assert.True(evt.Federated)
}
// The client2 will see its own session id, not the one from the remote server.
@ -540,6 +544,7 @@ func Test_FederationResume(t *testing.T) {
remoteSessionId = evt.SessionId
assert.NotEqual(hello2.Hello.SessionId, remoteSessionId)
assert.Equal(testDefaultUserId+"2", evt.UserId)
assert.True(evt.Federated)
}
// The client2 will see its own session id, not the one from the remote server.
@ -667,6 +672,7 @@ func Test_FederationResumeNewSession(t *testing.T) {
remoteSessionId = evt.SessionId
assert.NotEqual(hello2.Hello.SessionId, remoteSessionId)
assert.Equal(hello2.Hello.UserId, evt.UserId)
assert.True(evt.Federated)
}
// The client2 will see its own session id, not the one from the remote server.
@ -708,6 +714,7 @@ func Test_FederationResumeNewSession(t *testing.T) {
remoteSessionId = evt.SessionId
assert.NotEqual(hello2.Hello.SessionId, remoteSessionId)
assert.Equal(hello2.Hello.UserId, evt.UserId)
assert.True(evt.Federated)
}
// client2 will join the room again after the reconnect with the new

View file

@ -367,6 +367,7 @@ func (r *Room) notifySessionJoined(sessionId string) {
}
if s, ok := s.(*ClientSession); ok {
entry.RoomSessionId = s.RoomSessionId()
entry.Federated = s.ClientType() == HelloClientTypeFederation
}
events = append(events, entry)
}
@ -535,6 +536,7 @@ func (r *Room) PublishSessionJoined(session Session, sessionData *RoomSessionDat
}
if session, ok := session.(*ClientSession); ok {
message.Event.Join[0].RoomSessionId = session.RoomSessionId()
message.Event.Join[0].Federated = session.ClientType() == HelloClientTypeFederation
}
if err := r.publish(message); err != nil {
log.Printf("Could not publish session joined message in room %s: %s", r.Id(), err)