Skip to content

Commit

Permalink
Merge pull request #174 from FleekHQ/hotfix/notifs/subs
Browse files Browse the repository at this point in the history
Hotfix/notifs: don't crash on unknown types and fix subscriptions
  • Loading branch information
jsonsivar authored Sep 11, 2020
2 parents 21d7363 + 938ac73 commit 44a8b9d
Show file tree
Hide file tree
Showing 7 changed files with 348 additions and 311 deletions.
3 changes: 2 additions & 1 deletion core/space/domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ type FileSharingInfo struct {
type NotificationTypes int

const (
INVITATION NotificationTypes = iota
UNKNOWN NotificationTypes = iota
INVITATION
USAGEALERT
INVITATION_REPLY
)
Expand Down
1 change: 1 addition & 0 deletions core/textile/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func NewClient(store db.Store, kc keychain.Keychain, hubAuth hub.HubAuth, uc Use
keypairDeleted: make(chan bool),
shuttingDown: make(chan bool),
onHealthy: make(chan bool),
mailEvents: make(chan mail.MailboxEvent),
isConnectedToHub: false,
hubAuth: hubAuth,
mbNotifier: nil,
Expand Down
43 changes: 33 additions & 10 deletions core/textile/mailbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,17 @@ func (tc *textileClient) parseMessage(ctx context.Context, msg client.Message) (
err = json.Unmarshal(p, b)

if err != nil {
return nil, err
log.Error("Error parsing message into MessageBody type", err)

// returning generic notification since body was not able to be parsed
n := &domain.Notification{
ID: msg.ID,
Body: string(p),
CreatedAt: msg.CreatedAt.Unix(),
ReadAt: msg.ReadAt.Unix(),
}

return n, nil
}

n := &domain.Notification{
Expand Down Expand Up @@ -153,7 +163,15 @@ func (tc *textileClient) listenForMessages(ctx context.Context) error {
// handle new message
log.Info("Received mail: " + e.MessageID.String())

p, err := tc.parseMessage(ctx, e.Message)
// need to fetch the message again because the event
// payload doesn't have the full deets, will remove
// once its fixed on txl end
msg, err := tc.mb.ListInboxMessages(ctx, client.WithSeek(e.MessageID.String()), client.WithLimit(1))
if err != nil {
return
}

p, err := tc.parseMessage(ctx, msg[0])
if err != nil {
log.Error("Unable to parse incoming message: ", err)
}
Expand All @@ -176,14 +194,19 @@ func (tc *textileClient) listenForMessages(ctx context.Context) error {
}()

// Start watching (the third param indicates we want to keep watching when offline)
_, err = tc.mb.WatchInbox(ctx, tc.mailEvents, true)
if err != nil {
return err
}
// TODO: handle connectivity state if needed
// for s := range state {
// // handle connectivity state
// }
go func() {
state, err := tc.mb.WatchInbox(ctx, tc.mailEvents, true)
if err != nil {
log.Error("Unable to watch mailbox, ", err)
return
}

// TODO: handle connectivity state if needed
for s := range state {
log.Info("received inbox watch state: " + s.State.String())
}
}()

return nil
}

Expand Down
598 changes: 303 additions & 295 deletions grpc/pb/space.pb.go

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions grpc/proto/space.proto
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,10 @@ message ListBucketsResponse {
}

enum NotificationType {
INVITATION = 0;
USAGEALERT = 1;
UNKNOWN = 0;
INVITATION = 1;
USAGEALERT = 2;
INVITATION_REPLY = 3;
}

enum InvitationStatus {
Expand Down
2 changes: 1 addition & 1 deletion swagger/bin_ui/statik.go

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions swagger/ui/space.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1917,10 +1917,12 @@
"spaceNotificationType": {
"type": "string",
"enum": [
"UNKNOWN",
"INVITATION",
"USAGEALERT"
"USAGEALERT",
"INVITATION_REPLY"
],
"default": "INVITATION"
"default": "UNKNOWN"
},
"spaceOpenFileRequest": {
"type": "object",
Expand Down

0 comments on commit 44a8b9d

Please sign in to comment.