Skip to content

Commit

Permalink
update received share event
Browse files Browse the repository at this point in the history
Signed-off-by: jkoberg <[email protected]>
  • Loading branch information
kobergj committed Mar 10, 2022
1 parent 0a09110 commit e395e77
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
14 changes: 14 additions & 0 deletions internal/grpc/interceptors/eventsmiddleware/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,20 @@ func ShareUpdated(r *collaboration.UpdateShareResponse, req *collaboration.Updat
}
}

// ReceivedShareUpdated converts the response to an event
func ReceivedShareUpdated(r *collaboration.UpdateReceivedShareResponse) events.ReceivedShareUpdated {
return events.ReceivedShareUpdated{
ShareID: r.Share.Share.Id,
ItemID: r.Share.Share.ResourceId,
Permissions: r.Share.Share.Permissions,
GranteeUserID: r.Share.Share.GetGrantee().GetUserId(),
GranteeGroupID: r.Share.Share.GetGrantee().GetGroupId(),
Sharer: r.Share.Share.Creator,
MTime: r.Share.Share.Mtime,
State: collaboration.ShareState_name[int32(r.Share.State)],
}
}

// LinkCreated converts the response to an event
func LinkCreated(r *link.CreatePublicShareResponse) events.LinkCreated {
return events.LinkCreated{
Expand Down
4 changes: 4 additions & 0 deletions internal/grpc/interceptors/eventsmiddleware/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ func NewUnary(m map[string]interface{}) (grpc.UnaryServerInterceptor, int, error
if isSuccess(v) {
ev = ShareUpdated(v, req.(*collaboration.UpdateShareRequest))
}
case *collaboration.UpdateReceivedShareResponse:
if isSuccess(v) {
ev = ReceivedShareUpdated(v)
}
case *link.CreatePublicShareResponse:
if isSuccess(v) {
ev = LinkCreated(v)
Expand Down
1 change: 1 addition & 0 deletions pkg/events/example/consumer/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func Example(c events.Consumer) {
events.ShareCreated{},
events.ShareUpdated{},
events.ShareRemoved{},
events.ReceivedShareUpdated{},
events.LinkCreated{},
events.LinkUpdated{},
events.LinkRemoved{},
Expand Down
20 changes: 20 additions & 0 deletions pkg/events/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,26 @@ func (ShareUpdated) Unmarshal(v []byte) (interface{}, error) {
return e, err
}

// ReceivedShareUpdated is emitted when a received share is accepted or declined
type ReceivedShareUpdated struct {
ShareID *collaboration.ShareId
ItemID *provider.ResourceId
Permissions *collaboration.SharePermissions
GranteeUserID *user.UserId
GranteeGroupID *group.GroupId
Sharer *user.UserId
MTime *types.Timestamp

State string
}

// Unmarshal to fulfill umarshaller interface
func (ReceivedShareUpdated) Unmarshal(v []byte) (interface{}, error) {
e := ReceivedShareUpdated{}
err := json.Unmarshal(v, &e)
return e, err
}

// LinkCreated is emitted when a public link is created
type LinkCreated struct {
ShareID *link.PublicShareId
Expand Down

0 comments on commit e395e77

Please sign in to comment.