Skip to content

Commit

Permalink
Add a FileTouched event for TouchFile calls
Browse files Browse the repository at this point in the history
  • Loading branch information
aduffeck committed Jun 22, 2022
1 parent 1092d07 commit b9cc0b8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions internal/grpc/interceptors/eventsmiddleware/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ func LinkRemoved(r *link.RemovePublicShareResponse, req *link.RemovePublicShareR
}
}

// FileTouched converts the response to an event
func FileTouched(r *provider.TouchFileResponse, req *provider.TouchFileRequest, executant *user.UserId) events.FileTouched {
return events.FileTouched{
Executant: executant,
Ref: req.Ref,
}
}

// FileUploaded converts the response to an event
func FileUploaded(r *provider.InitiateFileUploadResponse, req *provider.InitiateFileUploadRequest, executant *user.UserId) events.FileUploaded {
return events.FileUploaded{
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 @@ -156,6 +156,10 @@ func NewUnary(m map[string]interface{}) (grpc.UnaryServerInterceptor, int, error
ev = SpaceDisabled(v, r, executantID)
}
}
case *provider.TouchFileResponse:
if isSuccess(v) {
ev = FileTouched(v, req.(*provider.TouchFileRequest), executantID)
}
}

if ev != nil {
Expand Down
13 changes: 13 additions & 0 deletions pkg/events/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ func (FileUploaded) Unmarshal(v []byte) (interface{}, error) {
return e, err
}

// FileTouched is emitted when a file is uploaded
type FileTouched struct {
Executant *user.UserId
Ref *provider.Reference
}

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

// FileDownloaded is emitted when a file is downloaded
type FileDownloaded struct {
Executant *user.UserId
Expand Down

0 comments on commit b9cc0b8

Please sign in to comment.