-
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
Merged
Merged
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
9f27c9e
fix variable names and add comment
sho0126hiro e12b7c5
add slackClient.GetReaction method'
sho0126hiro e6cd1c8
fix slackReactionUsersService.ListUsersEmailByReaction
sho0126hiro 416501f
delete unused field
sho0126hiro 4784ab1
delete unused field
sho0126hiro f0cbdbd
change method name
sho0126hiro db34d6d
mock generate
sho0126hiro 5f2bdb0
add testing
sho0126hiro e8136cf
fix condition
sho0126hiro 0ba9d0e
add comment
sho0126hiro a5856d2
fix implementation
sho0126hiro 049520c
delete testing
sho0126hiro 3887943
move reactions(var)
sho0126hiro a63ad86
fix pkg name
sho0126hiro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -18,7 +18,8 @@ package repository | |||||||||||
|
||||||||||||
import ( | ||||||||||||
"context" | ||||||||||||
"fmt" | ||||||||||||
|
||||||||||||
slack2 "github.com/slack-go/slack" | ||||||||||||
|
||||||||||||
"github.com/moneyforward/auriga/app/pkg/slack" | ||||||||||||
|
||||||||||||
|
@@ -55,23 +56,40 @@ func (r *slackRepository) GetParentMessage(ctx context.Context, channelID, ts st | |||||||||||
return nil, err | ||||||||||||
} | ||||||||||||
} | ||||||||||||
if len(msgs) <= 0 { | ||||||||||||
return nil, errors.New("number of messages is zero") | ||||||||||||
} | ||||||||||||
parentMessage := msgs[0] | ||||||||||||
var reactions []*model.SlackReaction | ||||||||||||
if r.isIncompleteReaction(parentMessage.Reactions) { | ||||||||||||
// get full reactions | ||||||||||||
parentMessage.Reactions, err = r.client.GetReaction(ctx, channelID, ts, true) | ||||||||||||
if err != nil { | ||||||||||||
return nil, err | ||||||||||||
} | ||||||||||||
} | ||||||||||||
for _, reaction := range parentMessage.Reactions { | ||||||||||||
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. 変数宣言と使用箇所が無駄に離れてる
Suggested change
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. 対応しておきました move reactions(var) |
||||||||||||
reactions = append(reactions, &model.SlackReaction{ | ||||||||||||
Name: reaction.Name, | ||||||||||||
UserIDs: reaction.Users, | ||||||||||||
Count: reaction.Count, | ||||||||||||
}) | ||||||||||||
} | ||||||||||||
return &model.SlackMessage{ | ||||||||||||
ChannelID: parentMessage.Channel, | ||||||||||||
Reactions: reactions, | ||||||||||||
}, nil | ||||||||||||
} | ||||||||||||
|
||||||||||||
if len(msgs) > 0 { | ||||||||||||
fmt.Printf("%#v \n", msgs[0]) | ||||||||||||
parentMessage := msgs[0] | ||||||||||||
var reactions []*model.SlackReaction | ||||||||||||
for _, reaction := range parentMessage.Reactions { | ||||||||||||
reactions = append(reactions, &model.SlackReaction{ | ||||||||||||
Name: reaction.Name, | ||||||||||||
UserIDs: reaction.Users, | ||||||||||||
}) | ||||||||||||
// isIncompleteReaction returns true if more fetches is required | ||||||||||||
// reactions[*].Count may be greater than len(reactions[*].Users), at which point a fetch is required. | ||||||||||||
func (r *slackRepository) isIncompleteReaction(reactions []slack2.ItemReaction) bool { | ||||||||||||
for _, reaction := range reactions { | ||||||||||||
if reaction.Count > len(reaction.Users) { | ||||||||||||
return true | ||||||||||||
} | ||||||||||||
return &model.SlackMessage{ | ||||||||||||
ChannelID: parentMessage.Channel, | ||||||||||||
Reactions: reactions, | ||||||||||||
}, nil | ||||||||||||
} | ||||||||||||
return nil, errors.New("number of messages is zero") | ||||||||||||
return false | ||||||||||||
} | ||||||||||||
|
||||||||||||
func (r *slackRepository) ListUsersEmail(ctx context.Context, userID []string) ([]*model.SlackUserEmail, error) { | ||||||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
こっち pkgslack とかにしとく?
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.
👍 fix pkg name