Skip to content

Commit

Permalink
Change 'Documents' from plural to singular in DocEvent (#613)
Browse files Browse the repository at this point in the history
* Change 'Documents' from plural to singular in DocEvent

* Add some comments
  • Loading branch information
chacha912 authored Aug 18, 2023
1 parent 932a9c7 commit 54c926f
Show file tree
Hide file tree
Showing 11 changed files with 210 additions and 202 deletions.
12 changes: 6 additions & 6 deletions api/converter/from_pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,12 @@ func FromDocumentID(pbID string) (types.ID, error) {
// FromEventType converts the given Protobuf formats to model format.
func FromEventType(pbDocEventType api.DocEventType) (types.DocEventType, error) {
switch pbDocEventType {
case api.DocEventType_DOC_EVENT_TYPE_DOCUMENTS_CHANGED:
return types.DocumentsChangedEvent, nil
case api.DocEventType_DOC_EVENT_TYPE_DOCUMENTS_WATCHED:
return types.DocumentsWatchedEvent, nil
case api.DocEventType_DOC_EVENT_TYPE_DOCUMENTS_UNWATCHED:
return types.DocumentsUnwatchedEvent, nil
case api.DocEventType_DOC_EVENT_TYPE_DOCUMENT_CHANGED:
return types.DocumentChangedEvent, nil
case api.DocEventType_DOC_EVENT_TYPE_DOCUMENT_WATCHED:
return types.DocumentWatchedEvent, nil
case api.DocEventType_DOC_EVENT_TYPE_DOCUMENT_UNWATCHED:
return types.DocumentUnwatchedEvent, nil
}
return "", fmt.Errorf("%v: %w", pbDocEventType, ErrUnsupportedEventType)
}
Expand Down
12 changes: 6 additions & 6 deletions api/converter/to_pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,12 @@ func ToChangeID(id change.ID) *api.ChangeID {
// ToDocEventType converts the given model format to Protobuf format.
func ToDocEventType(eventType types.DocEventType) (api.DocEventType, error) {
switch eventType {
case types.DocumentsChangedEvent:
return api.DocEventType_DOC_EVENT_TYPE_DOCUMENTS_CHANGED, nil
case types.DocumentsWatchedEvent:
return api.DocEventType_DOC_EVENT_TYPE_DOCUMENTS_WATCHED, nil
case types.DocumentsUnwatchedEvent:
return api.DocEventType_DOC_EVENT_TYPE_DOCUMENTS_UNWATCHED, nil
case types.DocumentChangedEvent:
return api.DocEventType_DOC_EVENT_TYPE_DOCUMENT_CHANGED, nil
case types.DocumentWatchedEvent:
return api.DocEventType_DOC_EVENT_TYPE_DOCUMENT_WATCHED, nil
case types.DocumentUnwatchedEvent:
return api.DocEventType_DOC_EVENT_TYPE_DOCUMENT_UNWATCHED, nil
default:
return 0, fmt.Errorf("%s: %w", eventType, ErrUnsupportedEventType)
}
Expand Down
12 changes: 6 additions & 6 deletions api/types/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ package types
type DocEventType string

const (
// DocumentsChangedEvent is an event indicating that documents are being
// DocumentChangedEvent is an event indicating that document is being
// modified by a change.
DocumentsChangedEvent DocEventType = "documents-changed"
DocumentChangedEvent DocEventType = "document-changed"

// DocumentsWatchedEvent is an event that occurs when documents are watched
// DocumentWatchedEvent is an event that occurs when document is watched
// by other clients.
DocumentsWatchedEvent DocEventType = "documents-watched"
DocumentWatchedEvent DocEventType = "document-watched"

// DocumentsUnwatchedEvent is an event that occurs when documents are
// DocumentUnwatchedEvent is an event that occurs when document is
// unwatched by other clients.
DocumentsUnwatchedEvent DocEventType = "documents-unwatched"
DocumentUnwatchedEvent DocEventType = "document-unwatched"
)
346 changes: 173 additions & 173 deletions api/yorkie/v1/resources.pb.go

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions api/yorkie/v1/resources.proto
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,9 @@ enum ValueType {
}

enum DocEventType {
DOC_EVENT_TYPE_DOCUMENTS_CHANGED = 0;
DOC_EVENT_TYPE_DOCUMENTS_WATCHED = 1;
DOC_EVENT_TYPE_DOCUMENTS_UNWATCHED = 2;
DOC_EVENT_TYPE_DOCUMENT_CHANGED = 0;
DOC_EVENT_TYPE_DOCUMENT_WATCHED = 1;
DOC_EVENT_TYPE_DOCUMENT_UNWATCHED = 2;
}

message DocEvent {
Expand Down
6 changes: 3 additions & 3 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,9 @@ func (c *Client) Watch(
}

switch eventType {
case types.DocumentsChangedEvent:
case types.DocumentChangedEvent:
return &WatchResponse{Type: DocumentChanged}, nil
case types.DocumentsWatchedEvent:
case types.DocumentWatchedEvent:
doc.AddOnlineClient(cli.String())
if doc.Presence(cli.String()) == nil {
return nil, nil
Expand All @@ -460,7 +460,7 @@ func (c *Client) Watch(
cli.String(): doc.Presence(cli.String()),
},
}, nil
case types.DocumentsUnwatchedEvent:
case types.DocumentUnwatchedEvent:
p := doc.Presence(cli.String())
doc.RemoveOnlineClient(cli.String())
if p == nil {
Expand Down
8 changes: 8 additions & 0 deletions pkg/document/internal_document.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ func (d *InternalDocument) ApplyChanges(changes ...*change.Change) ([]DocEvent,
if _, ok := d.onlineClients.Load(clientID); ok {
switch c.PresenceChange().ChangeType {
case innerpresence.Put:
// NOTE(chacha912): When the user exists in onlineClients, but
// their presence was initially absent, we can consider that we have
// received their initial presence, so trigger the 'watched' event.
eventType := PresenceChangedEvent
if !d.presences.Has(clientID) {
eventType = WatchedEvent
Expand All @@ -271,6 +274,11 @@ func (d *InternalDocument) ApplyChanges(changes ...*change.Change) ([]DocEvent,
}
events = append(events, event)
case innerpresence.Clear:
// NOTE(chacha912): When the user exists in onlineClients, but
// PresenceChange(clear) is received, we can consider it as detachment
// occurring before unwatching.
// Detached user is no longer participating in the document, we remove
// them from the online clients and trigger the 'unwatched' event.
event := DocEvent{
Type: UnwatchedEvent,
Presences: map[string]innerpresence.Presence{
Expand Down
2 changes: 1 addition & 1 deletion server/backend/sync/memory/pubsub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestPubSub(t *testing.T) {
pubSub := memory.NewPubSub()
id := types.ID(t.Name() + "id")
docEvent := sync.DocEvent{
Type: types.DocumentsWatchedEvent,
Type: types.DocumentWatchedEvent,
Publisher: idB,
DocumentID: id,
}
Expand Down
2 changes: 1 addition & 1 deletion server/packs/packs.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func PushPull(
ctx,
publisherID,
sync.DocEvent{
Type: types.DocumentsChangedEvent,
Type: types.DocumentChangedEvent,
Publisher: publisherID,
DocumentID: docInfo.ID,
},
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 @@ -375,7 +375,7 @@ func (s *adminServer) RemoveDocumentByAdmin(
ctx,
publisherID,
sync.DocEvent{
Type: types.DocumentsChangedEvent,
Type: types.DocumentChangedEvent,
Publisher: publisherID,
DocumentID: docInfo.ID,
},
Expand Down
4 changes: 2 additions & 2 deletions server/rpc/yorkie_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ func (s *yorkieServer) watchDoc(
ctx,
subscription.Subscriber(),
sync.DocEvent{
Type: types.DocumentsWatchedEvent,
Type: types.DocumentWatchedEvent,
Publisher: subscription.Subscriber(),
DocumentID: documentID,
},
Expand All @@ -549,7 +549,7 @@ func (s *yorkieServer) unwatchDoc(
ctx,
subscription.Subscriber(),
sync.DocEvent{
Type: types.DocumentsUnwatchedEvent,
Type: types.DocumentUnwatchedEvent,
Publisher: subscription.Subscriber(),
DocumentID: documentID,
},
Expand Down

0 comments on commit 54c926f

Please sign in to comment.