diff --git a/design/presence.md b/design/presence.md index b82b5baaf..639891951 100644 --- a/design/presence.md +++ b/design/presence.md @@ -55,7 +55,7 @@ doc.getMyPresence(); // { color: 'blue', cursor: { x: 1, y: 1 } } doc.getPresence(clientID); // Get all users currently participating in the document -const users = doc.getPresences(); +const users = doc.getUsers(); for (const { clientID, presence } of users) { // Do something... } diff --git a/pkg/document/document.go b/pkg/document/document.go index d9ca6b2dd..1963988de 100644 --- a/pkg/document/document.go +++ b/pkg/document/document.go @@ -303,16 +303,15 @@ func (d *Document) PresenceForTest(clientID string) innerpresence.Presence { return d.doc.PresenceForTest(clientID) } -// Presences returns the presence map of online clients. -func (d *Document) Presences() map[string]innerpresence.Presence { +// Users returns online users who are watching the document. +func (d *Document) Users() map[string]innerpresence.Presence { // TODO(hackerwins): We need to use client key instead of actor ID for exposing presence. - return d.doc.Presences() + return d.doc.Users() } -// AllPresences returns the presence map of all clients -// regardless of whether the client is online or not. -func (d *Document) AllPresences() map[string]innerpresence.Presence { - return d.doc.AllPresences() +// AllUsers returns the all users regardless of whether the user is online or not. +func (d *Document) AllUsers() map[string]innerpresence.Presence { + return d.doc.AllUsers() } // SetOnlineClients sets the online clients. diff --git a/pkg/document/internal_document.go b/pkg/document/internal_document.go index 4f1cdd1ad..bb6fd746b 100644 --- a/pkg/document/internal_document.go +++ b/pkg/document/internal_document.go @@ -326,8 +326,8 @@ func (d *InternalDocument) PresenceForTest(clientID string) innerpresence.Presen return d.presences.Load(clientID).DeepCopy() } -// Presences returns the presence map of online clients. -func (d *InternalDocument) Presences() map[string]innerpresence.Presence { +// Users returns online users who are watching the document. +func (d *InternalDocument) Users() map[string]innerpresence.Presence { presences := make(map[string]innerpresence.Presence) d.onlineClients.Range(func(key, value interface{}) bool { p := d.presences.Load(key.(string)) @@ -340,9 +340,8 @@ func (d *InternalDocument) Presences() map[string]innerpresence.Presence { return presences } -// AllPresences returns the presence map of all clients -// regardless of whether the client is online or not. -func (d *InternalDocument) AllPresences() map[string]innerpresence.Presence { +// AllUsers returns the all users regardless of whether the user is online or not. +func (d *InternalDocument) AllUsers() map[string]innerpresence.Presence { presences := make(map[string]innerpresence.Presence) d.presences.Range(func(key string, value innerpresence.Presence) bool { presences[key] = value.DeepCopy() diff --git a/server/backend/database/memory/database.go b/server/backend/database/memory/database.go index aa46dcfef..116d91ab7 100644 --- a/server/backend/database/memory/database.go +++ b/server/backend/database/memory/database.go @@ -967,7 +967,7 @@ func (d *DB) CreateSnapshotInfo( docID types.ID, doc *document.InternalDocument, ) error { - snapshot, err := converter.SnapshotToBytes(doc.RootObject(), doc.AllPresences()) + snapshot, err := converter.SnapshotToBytes(doc.RootObject(), doc.AllUsers()) if err != nil { return err } diff --git a/server/backend/database/mongo/client.go b/server/backend/database/mongo/client.go index 65c319ef8..1b7123527 100644 --- a/server/backend/database/mongo/client.go +++ b/server/backend/database/mongo/client.go @@ -1050,7 +1050,7 @@ func (c *Client) CreateSnapshotInfo( if err != nil { return err } - snapshot, err := converter.SnapshotToBytes(doc.RootObject(), doc.AllPresences()) + snapshot, err := converter.SnapshotToBytes(doc.RootObject(), doc.AllUsers()) if err != nil { return err } diff --git a/server/packs/pushpull.go b/server/packs/pushpull.go index e3c5151e2..3944ce404 100644 --- a/server/packs/pushpull.go +++ b/server/packs/pushpull.go @@ -157,7 +157,7 @@ func pullSnapshot( } cpAfterPull := cpAfterPush.NextServerSeq(docInfo.ServerSeq) - snapshot, err := converter.SnapshotToBytes(doc.RootObject(), doc.AllPresences()) + snapshot, err := converter.SnapshotToBytes(doc.RootObject(), doc.AllUsers()) if err != nil { return nil, err } diff --git a/server/rpc/admin_server.go b/server/rpc/admin_server.go index 2e754ff25..b1dedb2dc 100644 --- a/server/rpc/admin_server.go +++ b/server/rpc/admin_server.go @@ -254,7 +254,7 @@ func (s *adminServer) GetSnapshotMeta( return nil, err } - snapshot, err := converter.SnapshotToBytes(doc.RootObject(), doc.AllPresences()) + snapshot, err := converter.SnapshotToBytes(doc.RootObject(), doc.AllUsers()) if err != nil { return nil, err } diff --git a/test/integration/presence_test.go b/test/integration/presence_test.go index e2b37aa69..a5c3b1f9d 100644 --- a/test/integration/presence_test.go +++ b/test/integration/presence_test.go @@ -58,14 +58,14 @@ func TestPresence(t *testing.T) { p.Set("updated", "true") return nil })) - encoded, err := gojson.Marshal(d1.AllPresences()) + encoded, err := gojson.Marshal(d1.AllUsers()) assert.NoError(t, err) assert.Equal(t, fmt.Sprintf(`{"%s":{"updated":"true"}}`, c1.ID()), string(encoded)) // 03 Sync documents and check that the presence is updated on the other client assert.NoError(t, c1.Sync(ctx)) assert.NoError(t, c2.Sync(ctx)) - encoded, err = gojson.Marshal(d2.AllPresences()) + encoded, err = gojson.Marshal(d2.AllUsers()) assert.NoError(t, err) assert.Equal(t, fmt.Sprintf(`{"%s":{"updated":"true"},"%s":{}}`, c1.ID(), c2.ID()), string(encoded)) }) @@ -88,14 +88,14 @@ func TestPresence(t *testing.T) { return nil })) } - encoded, err := gojson.Marshal(d1.AllPresences()) + encoded, err := gojson.Marshal(d1.AllUsers()) assert.NoError(t, err) assert.Equal(t, fmt.Sprintf(`{"%s":{"updated":"9"}}`, c1.ID()), string(encoded)) // 03 Sync documents and check that the presence is updated on the other client assert.NoError(t, c1.Sync(ctx)) assert.NoError(t, c2.Sync(ctx)) - encoded, err = gojson.Marshal(d2.AllPresences()) + encoded, err = gojson.Marshal(d2.AllUsers()) assert.NoError(t, err) assert.Equal(t, fmt.Sprintf(`{"%s":{"updated":"9"},"%s":{}}`, c1.ID(), c2.ID()), string(encoded)) })