From 1ea33f7a319acb5b9001b3dacd420a17001c9349 Mon Sep 17 00:00:00 2001 From: WaDadidou <50441633+WaDadidou@users.noreply.github.com> Date: Thu, 21 Nov 2024 02:30:33 -0500 Subject: [PATCH] fix(feed): Properly get reactions from Posts endpoint (#1396) * fix(feed): Properly get reactions from Posts endpoint * fix(feed): Unmarshal instead of Scan in handleExecuteReactPost in indexer --- go/internal/indexerhandler/feed.go | 5 ++++- go/pkg/feed/service.go | 9 +++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/go/internal/indexerhandler/feed.go b/go/internal/indexerhandler/feed.go index 631c906a7f..7c3a70ecc3 100644 --- a/go/internal/indexerhandler/feed.go +++ b/go/internal/indexerhandler/feed.go @@ -103,7 +103,10 @@ func (h *Handler) handleExecuteReactPost(_ *Message, execMsg *wasmtypes.MsgExecu } userReactions := make(map[string]interface{}) - post.UserReactions.Scan(&userReactions) + if err := json.Unmarshal(post.UserReactions, &userReactions); err != nil { + h.logger.Error("failed to unmarshal UserReactions", zap.String("data", string(post.UserReactions)), zap.Error(err)) + } + var users []networks.UserID reactedUsers, found := userReactions[reactPost.Icon] if found { diff --git a/go/pkg/feed/service.go b/go/pkg/feed/service.go index 6b944bae2e..ce723daef3 100644 --- a/go/pkg/feed/service.go +++ b/go/pkg/feed/service.go @@ -171,8 +171,13 @@ func (s *FeedService) Posts(ctx context.Context, req *feedpb.PostsRequest) (*fee posts := make([]*feedpb.Post, len(dbPostWithExtras)) for idx, dbPost := range dbPostWithExtras { var reactions []*feedpb.Reaction - reactionsMap := map[string]interface{}{} - dbPost.UserReactions.Scan(&reactionsMap) + + reactionsMap := make(map[string]interface{}) + if err := json.Unmarshal(dbPost.UserReactions, &reactionsMap); err != nil { + s.conf.Logger.Error("failed to unmarshal UserReactions", zap.String("data", string(dbPost.UserReactions)), zap.Error(err)) + continue + } + for icon, users := range reactionsMap { ownState := false if queryUserID != "" {