Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Presences to Users #616

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion design/presence.md
Original file line number Diff line number Diff line change
Expand Up @@ -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...
}
Expand Down
13 changes: 6 additions & 7 deletions pkg/document/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 4 additions & 5 deletions pkg/document/internal_document.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion server/backend/database/memory/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion server/backend/database/mongo/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion server/packs/pushpull.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion server/rpc/admin_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions test/integration/presence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
Expand All @@ -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))
})
Expand Down
Loading