Skip to content

Commit

Permalink
Bas' comment.
Browse files Browse the repository at this point in the history
  • Loading branch information
clemire committed Feb 8, 2025
1 parent 0f64e32 commit 32b0fad
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 30 deletions.
11 changes: 3 additions & 8 deletions core/node/events/tracked_stream_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,19 @@ func (ts *TrackedStreamViewImpl) Init(
streamID shared.StreamId,
cfg crypto.OnChainConfiguration,
stream *StreamAndCookie,
onViewLoaded func(view *StreamView) error,
onNewEvent func(ctx context.Context, view *StreamView, event *ParsedEvent) error,
) error {
) (*StreamView, error) {
view, err := MakeRemoteStreamView(ctx, stream)
if err != nil {
return err
return nil, err
}

ts.streamID = streamID
ts.onNewEvent = onNewEvent
ts.view = view
ts.cfg = cfg

if err := onViewLoaded(view); err != nil {
return err
}

return nil
return view, nil
}

func (ts *TrackedStreamViewImpl) ApplyBlock(
Expand Down
42 changes: 20 additions & 22 deletions core/node/notifications/sync/tracked_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,6 @@ type notificationsTrackedStreamView struct {
userPreferences UserPreferencesStore
}

func (n *notificationsTrackedStreamView) onViewLoaded(view *StreamView) error {
// Load the list of users that someone has blocked from their personal user settings stream into the user
// preference cache which is queried when determining if a notification must be sent.
streamId := view.StreamId()
if streamId.Type() == shared.STREAM_USER_SETTINGS_BIN {
user := common.BytesToAddress(streamId[1:21])
if blockedUsers, err := view.BlockedUsers(); err == nil {
blockedUsers.Each(func(address common.Address) bool {
n.userPreferences.BlockUser(user, address)
return false
})
}
}
return nil
}

func (n *notificationsTrackedStreamView) onNewEvent(ctx context.Context, view *StreamView, event *ParsedEvent) error {
// in case the event was a block/unblock event update the users blocked list.
streamID := view.StreamId()
Expand Down Expand Up @@ -106,20 +90,34 @@ func NewTrackedStreamForNotifications(
listener StreamEventListener,
userPreferences UserPreferencesStore,
) (TrackedStreamView, error) {
view := &notificationsTrackedStreamView{
trackedView := &notificationsTrackedStreamView{
listener: listener,
userPreferences: userPreferences,
}

if err := view.TrackedStreamViewImpl.Init(
internalView, err := trackedView.TrackedStreamViewImpl.Init(
ctx,
streamID,
cfg,
stream,
view.onViewLoaded,
view.onNewEvent,
); err != nil {
trackedView.onNewEvent,
)
if err != nil {
return nil, err
}
return view, nil

// Load the list of users that someone has blocked from their personal user settings stream into the user
// preference cache which is queried when determining if a notification must be sent.
streamId := internalView.StreamId()
if streamId.Type() == shared.STREAM_USER_SETTINGS_BIN {
user := common.BytesToAddress(streamId[1:21])
if blockedUsers, err := internalView.BlockedUsers(); err == nil {
blockedUsers.Each(func(address common.Address) bool {
trackedView.userPreferences.BlockUser(user, address)
return false
})
}
}

return trackedView, nil
}

0 comments on commit 32b0fad

Please sign in to comment.