-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix/get all reacted users #18
Changes from 8 commits
9f27c9e
e12b7c5
e6cd1c8
416501f
4784ab1
f0cbdbd
db34d6d
5f2bdb0
e8136cf
0ba9d0e
a5856d2
049520c
3887943
a63ad86
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,18 +68,35 @@ func (s *slackReactionUsersService) ListUsersEmailByReaction(ctx context.Context | |
if err != nil { | ||
return nil, err | ||
} | ||
inviteUserIDs := s.getReactionUserIDs(ctx, msg.Reactions, reactionName) | ||
inviteUserEmails, err := s.chunkedListUsersEmail(ctx, inviteUserIDs) | ||
if s.isReactionRefetchNeeded(msg.Reactions) { | ||
msg.Reactions, err = s.getFullReactions(ctx, channelID, ts) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
reactedUserIDs := s.getReactionUserIDs(ctx, msg.Reactions, reactionName) | ||
reactedUserEmails, err := s.chunkedListUsersEmail(ctx, reactedUserIDs) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return inviteUserEmails, nil | ||
return reactedUserEmails, nil | ||
} | ||
|
||
// isReactionRefetchNeeded returns true if more fetches is required | ||
func (s *slackReactionUsersService) isReactionRefetchNeeded(reactions []*model.SlackReaction) bool { | ||
for _, r := range reactions { | ||
if r.Count != len(r.UserIDs) { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
// getReactionUserIDs get reaction users by reactionName | ||
func (s *slackReactionUsersService) getReactionUserIDs(ctx context.Context, reactions []*model.SlackReaction, reactionName string) []string { | ||
var userIDs []string | ||
var targetReactions []*model.SlackReaction | ||
// filtered reactions by reactionName | ||
for _, reaction := range reactions { | ||
rn := slack.ExtractReactionName(reaction.Name) | ||
if slack.RemoveSkinToneFromReaction(rn) == reactionName { | ||
|
@@ -94,3 +111,7 @@ func (s *slackReactionUsersService) getReactionUserIDs(ctx context.Context, reac | |
} | ||
return slice.ToStringSet(userIDs) | ||
} | ||
|
||
func (s *slackReactionUsersService) getFullReactions(ctx context.Context, channelID, ts string) ([]*model.SlackReaction, error) { | ||
return s.slackRepository.GetReactions(ctx, channelID, ts, true) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. この処理 func に切り出すほどの処理だった? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ここでture直書きにしておきました |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,10 +41,12 @@ func Test_slackReactionUsersService_ListUsersEmailByReaction(t *testing.T) { | |
{ | ||
Name: "join", | ||
UserIDs: []string{"user01", "user02"}, | ||
Count: 2, | ||
}, | ||
{ | ||
Name: "reactionSample", | ||
UserIDs: []string{"user02", "user03"}, | ||
Count: 2, | ||
}, | ||
}, | ||
} | ||
|
@@ -76,6 +78,58 @@ func Test_slackReactionUsersService_ListUsersEmailByReaction(t *testing.T) { | |
{ID: "user03", Email: "[email protected]"}, | ||
}, | ||
}, | ||
{ | ||
name: "OK: There is difference between len(Reaction.UserIDs) and Reaction.Count", | ||
args: args{ | ||
channelID: "sampleCID", ts: "sampleTs", reactionName: "reactionSample", | ||
}, | ||
prepare: func(msr *mock_repository.MockSlackRepository) { | ||
gomock.InOrder( | ||
msr.EXPECT().GetParentMessage(gomock.Any(), "sampleCID", "sampleTs").Return( | ||
&model.SlackMessage{ | ||
ChannelID: "sampleCID", | ||
Reactions: []*model.SlackReaction{ | ||
{ | ||
Name: "join", | ||
UserIDs: []string{"user01", "user02"}, | ||
Count: 2, | ||
}, | ||
{ | ||
Name: "reactionSample", | ||
UserIDs: []string{"user02", "user03"}, | ||
Count: 4, // number of counts that need to be re-fetched | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. これって len(UserIDs) > Count のパターンってありえないんだっけ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ありえないと思う。APIドキュメントには明示されていなかったけど、実データとして確認しているのは There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fix implementation で |
||
}, | ||
}, | ||
}, nil), | ||
msr.EXPECT().GetReactions(gomock.Any(), "sampleCID", "sampleTs", true).Return( | ||
[]*model.SlackReaction{ | ||
{ | ||
Name: "join", | ||
UserIDs: []string{"user01", "user02"}, | ||
Count: 2, | ||
}, | ||
{ | ||
Name: "reactionSample", | ||
UserIDs: []string{"user02", "user03", "user04", "user05"}, // fully fetched | ||
Count: 4, | ||
}, | ||
}, nil), | ||
msr.EXPECT().ListUsersEmail(gomock.Any(), []string{"user02", "user03", "user04", "user05"}).Return( | ||
[]*model.SlackUserEmail{ | ||
{ID: "user02", Email: "[email protected]"}, | ||
{ID: "user03", Email: "[email protected]"}, | ||
{ID: "user04", Email: "[email protected]"}, | ||
{ID: "user05", Email: "[email protected]"}, | ||
}, nil), | ||
) | ||
}, | ||
want: []*model.SlackUserEmail{ | ||
{ID: "user02", Email: "[email protected]"}, | ||
{ID: "user03", Email: "[email protected]"}, | ||
{ID: "user04", Email: "[email protected]"}, | ||
{ID: "user05", Email: "[email protected]"}, | ||
}, | ||
}, | ||
{ | ||
name: "NG: error in GetParentMessage", | ||
args: args{ | ||
|
@@ -104,6 +158,35 @@ func Test_slackReactionUsersService_ListUsersEmailByReaction(t *testing.T) { | |
}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "NG: error in GetReactions", | ||
args: args{ | ||
channelID: "sampleCID", ts: "sampleTs", reactionName: "reactionSample", | ||
}, | ||
prepare: func(msr *mock_repository.MockSlackRepository) { | ||
gomock.InOrder( | ||
msr.EXPECT().GetParentMessage(gomock.Any(), "sampleCID", "sampleTs").Return( | ||
&model.SlackMessage{ | ||
ChannelID: "sampleCID", | ||
Reactions: []*model.SlackReaction{ | ||
{ | ||
Name: "join", | ||
UserIDs: []string{"user01", "user02"}, | ||
Count: 2, | ||
}, | ||
{ | ||
Name: "reactionSample", | ||
UserIDs: []string{"user02", "user03"}, | ||
Count: 4, // number of counts that need to be re-fetched | ||
}, | ||
}, | ||
}, nil), | ||
msr.EXPECT().GetReactions(gomock.Any(), "sampleCID", "sampleTs", true).Return( | ||
nil, errors.New("sample_error")), | ||
) | ||
}, | ||
wantErr: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ type SlackMessage struct { | |
|
||
type SlackReaction struct { | ||
Name string | ||
Count int | ||
UserIDs []string | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
どういう時に refetch が必要なのか、軽くコメント入れておいてくれると助かる。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ありがとう!入れておきました
add comment