* fixed: `identifier` is unused lint error

* make saveMultipleMembersT method saveMultipleMembers

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Mahmudul Haque
2021-02-04 11:38:05 +06:00
коммит произвёл GitHub
родитель 78ccf8a775
Коммит a63dea6c55
62 изменённых файлов: 257 добавлений и 245 удалений

Просмотреть файл

@@ -459,7 +459,7 @@ func (a *App) WaitForChannelMembership(channelId string, userId string) {
}
func (a *App) CreateGroupChannel(userIds []string, creatorId string) (*model.Channel, *model.AppError) {
channel, err := a.createGroupChannel(userIds, creatorId)
channel, err := a.createGroupChannel(userIds)
if err != nil {
if err.Id == store.ChannelExistsError {
return channel, nil
@@ -482,7 +482,7 @@ func (a *App) CreateGroupChannel(userIds []string, creatorId string) (*model.Cha
return channel, nil
}
func (a *App) createGroupChannel(userIds []string, creatorId string) (*model.Channel, *model.AppError) {
func (a *App) createGroupChannel(userIds []string) (*model.Channel, *model.AppError) {
if len(userIds) > model.CHANNEL_GROUP_MAX_USERS || len(userIds) < model.CHANNEL_GROUP_MIN_USERS {
return nil, model.NewAppError("CreateGroupChannel", "api.channel.create_group.bad_size.app_error", nil, "", http.StatusBadRequest)
}
@@ -1285,7 +1285,7 @@ func (a *App) DeleteChannel(channel *model.Channel, userId string) *model.AppErr
return nil
}
func (a *App) addUserToChannel(user *model.User, channel *model.Channel, teamMember *model.TeamMember) (*model.ChannelMember, *model.AppError) {
func (a *App) addUserToChannel(user *model.User, channel *model.Channel) (*model.ChannelMember, *model.AppError) {
if channel.Type != model.CHANNEL_OPEN && channel.Type != model.CHANNEL_PRIVATE {
return nil, model.NewAppError("AddUserToChannel", "api.channel.add_user_to_channel.type.app_error", nil, "", http.StatusBadRequest)
}
@@ -1359,7 +1359,7 @@ func (a *App) AddUserToChannel(user *model.User, channel *model.Channel) (*model
return nil, model.NewAppError("AddUserToChannel", "api.channel.add_user.to.channel.failed.deleted.app_error", nil, "", http.StatusBadRequest)
}
newMember, err := a.addUserToChannel(user, channel, teamMember)
newMember, err := a.addUserToChannel(user, channel)
if err != nil {
return nil, err
}

Просмотреть файл

@@ -75,7 +75,7 @@ func (es *EmailService) setupInviteEmailRateLimiting() error {
return nil
}
func (es *EmailService) sendChangeUsernameEmail(oldUsername, newUsername, email, locale, siteURL string) *model.AppError {
func (es *EmailService) sendChangeUsernameEmail(newUsername, email, locale, siteURL string) *model.AppError {
T := utils.GetUserTranslations(locale)
subject := T("api.templates.username_change_subject",

Просмотреть файл

@@ -808,7 +808,7 @@ func (a *App) importUserTeams(user *model.User, data *[]UserTeamImportData) *mod
}
}
channelsToImport := channels[team.Id]
if err := a.importUserChannels(user, team, teamMemberByTeamID[team.Id], &channelsToImport); err != nil {
if err := a.importUserChannels(user, team, &channelsToImport); err != nil {
return err
}
}
@@ -816,7 +816,7 @@ func (a *App) importUserTeams(user *model.User, data *[]UserTeamImportData) *mod
return nil
}
func (a *App) importUserChannels(user *model.User, team *model.Team, teamMember *model.TeamMember, data *[]UserChannelImportData) *model.AppError {
func (a *App) importUserChannels(user *model.User, team *model.Team, data *[]UserChannelImportData) *model.AppError {
if data == nil {
return nil
}
@@ -986,7 +986,7 @@ func (a *App) importUserChannels(user *model.User, team *model.Team, teamMember
return nil
}
func (a *App) importReaction(data *ReactionImportData, post *model.Post, dryRun bool) *model.AppError {
func (a *App) importReaction(data *ReactionImportData, post *model.Post) *model.AppError {
if err := validateReactionImportData(data, post.CreateAt); err != nil {
return err
}
@@ -1016,7 +1016,7 @@ func (a *App) importReaction(data *ReactionImportData, post *model.Post, dryRun
return nil
}
func (a *App) importReplies(data []ReplyImportData, post *model.Post, teamId string, dryRun bool) *model.AppError {
func (a *App) importReplies(data []ReplyImportData, post *model.Post, teamId string) *model.AppError {
var err *model.AppError
usernames := []string{}
for _, replyData := range data {
@@ -1064,7 +1064,7 @@ func (a *App) importReplies(data []ReplyImportData, post *model.Post, teamId str
reply.Message = *replyData.Message
reply.CreateAt = *replyData.CreateAt
fileIds, err := a.uploadAttachments(replyData.Attachments, reply, teamId, dryRun)
fileIds, err := a.uploadAttachments(replyData.Attachments, reply, teamId)
if err != nil {
return err
}
@@ -1112,7 +1112,7 @@ func (a *App) importReplies(data []ReplyImportData, post *model.Post, teamId str
return nil
}
func (a *App) importAttachment(data *AttachmentImportData, post *model.Post, teamId string, dryRun bool) (*model.FileInfo, *model.AppError) {
func (a *App) importAttachment(data *AttachmentImportData, post *model.Post, teamId string) (*model.FileInfo, *model.AppError) {
file, err := os.Open(*data.Path)
if file == nil || err != nil {
return nil, model.NewAppError("BulkImport", "app.import.attachment.bad_file.error", map[string]interface{}{"FilePath": *data.Path}, "", http.StatusBadRequest)
@@ -1319,7 +1319,7 @@ func (a *App) importMultiplePostLines(lines []LineImportWorkerData, dryRun bool)
post.Props = *line.Post.Props
}
fileIds, appErr := a.uploadAttachments(line.Post.Attachments, post, team.Id, dryRun)
fileIds, appErr := a.uploadAttachments(line.Post.Attachments, post, team.Id)
if appErr != nil {
return line.LineNumber, appErr
}
@@ -1403,14 +1403,14 @@ func (a *App) importMultiplePostLines(lines []LineImportWorkerData, dryRun bool)
if postWithData.postData.Reactions != nil {
for _, reaction := range *postWithData.postData.Reactions {
reaction := reaction
if err := a.importReaction(&reaction, postWithData.post, dryRun); err != nil {
if err := a.importReaction(&reaction, postWithData.post); err != nil {
return postWithData.lineNumber, err
}
}
}
if postWithData.postData.Replies != nil && len(*postWithData.postData.Replies) > 0 {
err := a.importReplies(*postWithData.postData.Replies, postWithData.post, postWithData.team.Id, dryRun)
err := a.importReplies(*postWithData.postData.Replies, postWithData.post, postWithData.team.Id)
if err != nil {
return postWithData.lineNumber, err
}
@@ -1421,14 +1421,14 @@ func (a *App) importMultiplePostLines(lines []LineImportWorkerData, dryRun bool)
}
// uploadAttachments imports new attachments and returns current attachments of the post as a map
func (a *App) uploadAttachments(attachments *[]AttachmentImportData, post *model.Post, teamId string, dryRun bool) (map[string]bool, *model.AppError) {
func (a *App) uploadAttachments(attachments *[]AttachmentImportData, post *model.Post, teamId string) (map[string]bool, *model.AppError) {
if attachments == nil {
return nil, nil
}
fileIds := make(map[string]bool)
for _, attachment := range *attachments {
attachment := attachment
fileInfo, err := a.importAttachment(&attachment, post, teamId, dryRun)
fileInfo, err := a.importAttachment(&attachment, post, teamId)
if err != nil {
return nil, err
}
@@ -1473,7 +1473,7 @@ func (a *App) importDirectChannel(data *DirectChannelImportData, dryRun bool) *m
}
channel = ch
} else {
ch, err := a.createGroupChannel(userIds, userIds[0])
ch, err := a.createGroupChannel(userIds)
if err != nil && err.Id != store.ChannelExistsError {
return model.NewAppError("BulkImport", "app.import.import_direct_channel.create_group_channel.error", nil, err.Error(), http.StatusBadRequest)
}
@@ -1578,7 +1578,7 @@ func (a *App) importMultipleDirectPostLines(lines []LineImportWorkerData, dryRun
}
channel = ch
} else {
ch, err = a.createGroupChannel(userIds, userIds[0])
ch, err = a.createGroupChannel(userIds)
if err != nil && err.Id != store.ChannelExistsError {
return line.LineNumber, model.NewAppError("BulkImport", "app.import.import_direct_post.create_group_channel.error", nil, err.Error(), http.StatusBadRequest)
}
@@ -1615,7 +1615,7 @@ func (a *App) importMultipleDirectPostLines(lines []LineImportWorkerData, dryRun
post.Props = *line.DirectPost.Props
}
fileIds, err := a.uploadAttachments(line.DirectPost.Attachments, post, "noteam", dryRun)
fileIds, err := a.uploadAttachments(line.DirectPost.Attachments, post, "noteam")
if err != nil {
return line.LineNumber, err
}
@@ -1697,14 +1697,14 @@ func (a *App) importMultipleDirectPostLines(lines []LineImportWorkerData, dryRun
if postWithData.directPostData.Reactions != nil {
for _, reaction := range *postWithData.directPostData.Reactions {
reaction := reaction
if err := a.importReaction(&reaction, postWithData.post, dryRun); err != nil {
if err := a.importReaction(&reaction, postWithData.post); err != nil {
return postWithData.lineNumber, err
}
}
}
if postWithData.directPostData.Replies != nil {
if err := a.importReplies(*postWithData.directPostData.Replies, postWithData.post, "noteam", dryRun); err != nil {
if err := a.importReplies(*postWithData.directPostData.Replies, postWithData.post, "noteam"); err != nil {
return postWithData.lineNumber, err
}
}

Просмотреть файл

@@ -1856,16 +1856,14 @@ func TestImportUserChannels(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
user := th.CreateUser()
th.App.joinUserToTeam(th.BasicTeam, user)
teamMember, err := th.App.GetTeamMember(th.BasicTeam.Id, user.Id)
require.Nil(t, err)
// Two times import must end with the same results
for x := 0; x < 2; x++ {
err = th.App.importUserChannels(user, th.BasicTeam, teamMember, tc.data)
appErr := th.App.importUserChannels(user, th.BasicTeam, tc.data)
if tc.expectedError {
require.NotNil(t, err)
require.NotNil(t, appErr)
} else {
require.Nil(t, err)
require.Nil(t, appErr)
}
channelMembers, err := th.App.Srv().Store.Channel().GetMembersForUser(th.BasicTeam.Id, user.Id)
require.Nil(t, err)
@@ -3101,7 +3099,7 @@ func TestImportImportDirectChannel(t *testing.T) {
th.BasicUser2.Id,
user3.Id,
}
channel, appErr := th.App.createGroupChannel(userIds, th.BasicUser.Id)
channel, appErr := th.App.createGroupChannel(userIds)
require.Equal(t, appErr.Id, store.ChannelExistsError)
require.Equal(t, channel.Header, *data.Header)
@@ -3402,7 +3400,7 @@ func TestImportImportDirectPost(t *testing.T) {
th.BasicUser2.Id,
user3.Id,
}
channel, appErr = th.App.createGroupChannel(userIds, th.BasicUser.Id)
channel, appErr = th.App.createGroupChannel(userIds)
require.Equal(t, appErr.Id, store.ChannelExistsError)
groupChannel = channel
@@ -3893,14 +3891,14 @@ func TestImportAttachment(t *testing.T) {
userId := model.NewId()
data := AttachmentImportData{Path: &testImage}
_, err := th.App.importAttachment(&data, &model.Post{UserId: userId, ChannelId: "some-channel"}, "some-team", true)
_, err := th.App.importAttachment(&data, &model.Post{UserId: userId, ChannelId: "some-channel"}, "some-team")
assert.Nil(t, err, "sample run without errors")
attachments := GetAttachments(userId, th, t)
assert.Len(t, attachments, 1)
data = AttachmentImportData{Path: &invalidPath}
_, err = th.App.importAttachment(&data, &model.Post{UserId: model.NewId(), ChannelId: "some-channel"}, "some-team", true)
_, err = th.App.importAttachment(&data, &model.Post{UserId: model.NewId(), ChannelId: "some-channel"}, "some-team")
assert.NotNil(t, err, "should have failed when opening the file")
assert.Equal(t, err.Id, "app.import.attachment.bad_file.error")
}

Просмотреть файл

@@ -160,8 +160,8 @@ func (a *App) sendPushNotification(notification *PostNotification, user *model.U
}
}
func (a *App) getPushNotificationMessage(contentsConfig, postMessage string, explicitMention, channelWideMention, hasFiles bool,
senderName, channelName, channelType, replyToThreadType string, userLocale i18n.TranslateFunc) string {
func (a *App) getPushNotificationMessage(contentsConfig, postMessage string, explicitMention, channelWideMention,
hasFiles bool, senderName, channelType, replyToThreadType string, userLocale i18n.TranslateFunc) string {
// If the post only has images then push an appropriate message
if postMessage == "" && hasFiles {
@@ -591,7 +591,17 @@ func (a *App) buildFullPushNotificationMessage(contentsConfig string, post *mode
userLocale := utils.GetUserTranslations(user.Locale)
hasFiles := post.FileIds != nil && len(post.FileIds) > 0
msg.Message = a.getPushNotificationMessage(contentsConfig, post.Message, explicitMention, channelWideMention, hasFiles, msg.SenderName, channelName, channel.Type, replyToThreadType, userLocale)
msg.Message = a.getPushNotificationMessage(
contentsConfig,
post.Message,
explicitMention,
channelWideMention,
hasFiles,
msg.SenderName,
channel.Type,
replyToThreadType,
userLocale,
)
return msg
}

Просмотреть файл

@@ -912,7 +912,6 @@ func TestGetPushNotificationMessage(t *testing.T) {
tc.channelWideMention,
tc.HasFiles,
"user",
"channel",
tc.ChannelType,
tc.replyToThreadType,
utils.GetUserTranslations(locale),

Просмотреть файл

@@ -175,7 +175,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
return token
}
makeRequest := func(t *testing.T, cookie string) *http.Request {
makeRequest := func(cookie string) *http.Request {
request, _ := http.NewRequest(http.MethodGet, "https://mattermost.example.com", nil)
if cookie != "" {
@@ -264,7 +264,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
defer th.TearDown()
cookie := model.NewId()
request := makeRequest(t, "")
request := makeRequest("")
state := makeState(makeToken(th, cookie))
_, _, _, _, err := th.App.AuthorizeOAuthUser(nil, request, model.SERVICE_GITLAB, "", state, "")
@@ -281,7 +281,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
token, err := th.App.CreateOAuthStateToken(model.NewId())
require.Nil(t, err)
request := makeRequest(t, cookie)
request := makeRequest(cookie)
state := makeState(token)
_, _, _, _, err = th.App.AuthorizeOAuthUser(nil, request, model.SERVICE_GITLAB, "", state, "")
@@ -294,7 +294,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
defer th.TearDown()
cookie := model.NewId()
request := makeRequest(t, cookie)
request := makeRequest(cookie)
state := makeState(makeToken(th, cookie))
_, _, _, _, err := th.App.AuthorizeOAuthUser(&httptest.ResponseRecorder{}, request, model.SERVICE_GITLAB, "", state, "")
@@ -312,7 +312,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
defer th.TearDown()
cookie := model.NewId()
request := makeRequest(t, cookie)
request := makeRequest(cookie)
state := makeState(makeToken(th, cookie))
_, _, _, _, err := th.App.AuthorizeOAuthUser(&httptest.ResponseRecorder{}, request, model.SERVICE_GITLAB, "", state, "")
@@ -331,7 +331,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
defer th.TearDown()
cookie := model.NewId()
request := makeRequest(t, cookie)
request := makeRequest(cookie)
state := makeState(makeToken(th, cookie))
_, _, _, _, err := th.App.AuthorizeOAuthUser(&httptest.ResponseRecorder{}, request, model.SERVICE_GITLAB, "", state, "")
@@ -353,7 +353,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
defer th.TearDown()
cookie := model.NewId()
request := makeRequest(t, cookie)
request := makeRequest(cookie)
state := makeState(makeToken(th, cookie))
_, _, _, _, err := th.App.AuthorizeOAuthUser(&httptest.ResponseRecorder{}, request, model.SERVICE_GITLAB, "", state, "")
@@ -374,7 +374,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
defer th.TearDown()
cookie := model.NewId()
request := makeRequest(t, cookie)
request := makeRequest(cookie)
state := makeState(makeToken(th, cookie))
_, _, _, _, err := th.App.AuthorizeOAuthUser(&httptest.ResponseRecorder{}, request, model.SERVICE_GITLAB, "", state, "")
@@ -395,7 +395,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
defer th.TearDown()
cookie := model.NewId()
request := makeRequest(t, cookie)
request := makeRequest(cookie)
state := makeState(makeToken(th, cookie))
_, _, _, _, err := th.App.AuthorizeOAuthUser(&httptest.ResponseRecorder{}, request, model.SERVICE_GITLAB, "", state, "")
@@ -423,7 +423,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
defer th.TearDown()
cookie := model.NewId()
request := makeRequest(t, cookie)
request := makeRequest(cookie)
state := makeState(makeToken(th, cookie))
_, _, _, _, err := th.App.AuthorizeOAuthUser(&httptest.ResponseRecorder{}, request, model.SERVICE_GITLAB, "", state, "")
@@ -452,7 +452,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
defer th.TearDown()
cookie := model.NewId()
request := makeRequest(t, cookie)
request := makeRequest(cookie)
state := makeState(makeToken(th, cookie))
_, _, _, _, err := th.App.AuthorizeOAuthUser(&httptest.ResponseRecorder{}, request, model.SERVICE_GITLAB, "", state, "")
@@ -496,7 +496,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
})
cookie := model.NewId()
request := makeRequest(t, cookie)
request := makeRequest(cookie)
stateProps := map[string]string{
"team_id": model.NewId(),

Просмотреть файл

@@ -69,10 +69,10 @@ func TestExportPermissions(t *testing.T) {
}
expectations := map[string]func(str string) string{
scheme.DisplayName: func(str string) string { return row["display_name"].(string) },
scheme.Name: func(str string) string { return row["name"].(string) },
scheme.Description: func(str string) string { return row["description"].(string) },
scheme.Scope: func(str string) string { return row["scope"].(string) },
scheme.DisplayName: func(_ string) string { return row["display_name"].(string) },
scheme.Name: func(_ string) string { return row["name"].(string) },
scheme.Description: func(_ string) string { return row["description"].(string) },
scheme.Scope: func(_ string) string { return row["scope"].(string) },
scheme.DefaultTeamAdminRole: func(str string) string { return getRoleByName(str) },
scheme.DefaultTeamUserRole: func(str string) string { return getRoleByName(str) },
scheme.DefaultTeamGuestRole: func(str string) string { return getRoleByName(str) },

Просмотреть файл

@@ -13,7 +13,7 @@ type Plugin struct {
plugin.MattermostPlugin
}
func (p *Plugin) ServeHTTP(c *plugin.Context, w http.ResponseWriter, r *http.Request) {
func (p *Plugin) ServeHTTP(_ *plugin.Context, w http.ResponseWriter, _ *http.Request) {
hj, ok := w.(http.Hijacker)
if !ok {
w.WriteHeader(http.StatusInternalServerError)

Просмотреть файл

@@ -17,7 +17,7 @@ type Plugin struct {
plugin.MattermostPlugin
}
func (p *Plugin) ServeHTTP(c *plugin.Context, w http.ResponseWriter, r *http.Request) {
func (p *Plugin) ServeHTTP(_ *plugin.Context, w http.ResponseWriter, r *http.Request) {
upgrader := websocket.Upgrader{}
ws, err := upgrader.Upgrade(w, r, nil)

Просмотреть файл

@@ -30,7 +30,7 @@ func (p *MyPlugin) OnConfigurationChange() error {
return nil
}
func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
if p.configuration.MyStringSetting != "override" {
return nil, "MyStringSetting has invalid value"
}

Просмотреть файл

@@ -33,7 +33,7 @@ func (p *MyPlugin) OnConfigurationChange() error {
return nil
}
func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
if p.configuration.MyStringSetting != "str" {
return nil, "MyStringSetting has invalid value"
}

Просмотреть файл

@@ -21,7 +21,7 @@ func (p *MyPlugin) OnConfigurationChange() error {
return nil
}
func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
createdBot, err := p.API.CreateBot(&model.Bot{
Username: "bot",
Description: "a plugin bot",

Просмотреть файл

@@ -22,7 +22,7 @@ func main() {
plugin.ClientMain(&PluginUsingLogAPI{})
}
func (p *PluginUsingLogAPI) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
func (p *PluginUsingLogAPI) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
p.API.LogDebug("LogDebug", "one", 1, "two", "two", "foo", Foo{bar: 3.1416})
p.API.LogInfo("LogInfo", "one", 1, "two", "two", "foo", Foo{bar: 3.1416})
p.API.LogWarn("LogWarn", "one", 1, "two", "two", "foo", Foo{bar: 3.1416})

Просмотреть файл

@@ -24,7 +24,7 @@ func (p *MyPlugin) OnConfigurationChange() error {
return nil
}
func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
bundlePath, err := p.API.GetBundlePath()
if err != nil {
return nil, err.Error() + "failed get bundle path"

Просмотреть файл

@@ -21,7 +21,7 @@ func (p *MyPlugin) OnConfigurationChange() error {
return nil
}
func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
channels, err := p.API.GetChannelsForTeamForUser(p.configuration.BasicTeamId, p.configuration.BasicUserId, false)
if err != nil {

Просмотреть файл

@@ -21,7 +21,7 @@ func (p *MyPlugin) OnConfigurationChange() error {
return nil
}
func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
dm1, err := p.API.GetDirectChannel(p.configuration.BasicUserId, p.configuration.BasicUser2Id)
if err != nil {
return nil, err.Error()

Просмотреть файл

@@ -21,7 +21,7 @@ func (p *MyPlugin) OnConfigurationChange() error {
return nil
}
func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
status, err := p.API.GetPluginStatus("test_get_plugin_status_plugin")
if err != nil {
return nil, err.Error()

Просмотреть файл

@@ -21,7 +21,7 @@ func (p *MyPlugin) OnConfigurationChange() error {
return nil
}
func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
// check existing user first
data, err := p.API.GetProfileImage(p.configuration.BasicUserId)

Просмотреть файл

@@ -21,7 +21,7 @@ func (p *MyPlugin) OnConfigurationChange() error {
return nil
}
func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
channelMembers, err := p.API.GetChannelMembersForUser(p.configuration.BasicTeamId, p.configuration.BasicUserId, 0, 10)
if err != nil {

Просмотреть файл

@@ -21,7 +21,7 @@ func (p *MyPlugin) OnConfigurationChange() error {
return nil
}
func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
teamMembers, err := p.API.GetTeamMembersForUser(p.configuration.BasicUserId, 0, 10)
if err != nil {
return nil, err.Error() + "failed to get team members"

Просмотреть файл

@@ -21,7 +21,7 @@ func (p *MyPlugin) OnConfigurationChange() error {
return nil
}
func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
channels, err := p.API.SearchChannels(p.configuration.BasicTeamId, p.configuration.BasicChannelName)
if err != nil {

Просмотреть файл

@@ -23,7 +23,7 @@ func (p *MyPlugin) OnConfigurationChange() error {
return nil
}
func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
testCases := []struct {
description string
teamID string

Просмотреть файл

@@ -23,7 +23,7 @@ func (p *MyPlugin) OnConfigurationChange() error {
return nil
}
func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
teams, err := p.API.SearchTeams(p.configuration.BasicTeamName)
if err != nil {
return nil, "search failed: " + err.Message

Просмотреть файл

@@ -25,7 +25,7 @@ func (p *MyPlugin) OnConfigurationChange() error {
return nil
}
func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
to := p.configuration.BasicUserEmail
subject := "testing plugin api sending email"
body := "this is a test."

Просмотреть файл

@@ -27,7 +27,7 @@ func (p *MyPlugin) OnConfigurationChange() error {
return nil
}
func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
// Create an 128 x 128 image
img := image.NewRGBA(image.Rect(0, 0, 128, 128))

Просмотреть файл

@@ -21,7 +21,7 @@ func (p *MyPlugin) OnConfigurationChange() error {
return nil
}
func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
uid := p.configuration.BasicUserId
if err := p.API.UpdateUserActive(uid, true); err != nil {
return nil, err.Error()

Просмотреть файл

@@ -23,7 +23,7 @@ func (p *MyPlugin) OnConfigurationChange() error {
return nil
}
func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
func (p *MyPlugin) MessageWillBePosted(_ *plugin.Context, _ *model.Post) (*model.Post, string) {
uid := p.configuration.BasicUserId
statuses := []string{model.STATUS_ONLINE, model.STATUS_AWAY, model.STATUS_DND, model.STATUS_OFFLINE}

Просмотреть файл

@@ -50,7 +50,9 @@ func cleanupVersion(originalVersion string) string {
return strings.Join(versionPartsOut, ".")
}
func noticeMatchesConditions(config *model.Config, preferences store.PreferenceStore, userId string, client model.NoticeClientType, clientVersion, locale string, postCount, userCount int64, isSystemAdmin, isTeamAdmin bool, isCloud bool, sku string, notice *model.ProductNotice) (bool, error) {
func noticeMatchesConditions(config *model.Config, preferences store.PreferenceStore, userId string,
client model.NoticeClientType, clientVersion string, postCount int64, userCount int64, isSystemAdmin bool,
isTeamAdmin bool, isCloud bool, sku string, notice *model.ProductNotice) (bool, error) {
cnd := notice.Conditions
// check client type
@@ -248,11 +250,12 @@ func (a *App) GetProductNotices(userId, teamId string, client model.NoticeClient
continue
}
}
result, err := noticeMatchesConditions(a.Config(), a.Srv().Store.Preference(),
result, err := noticeMatchesConditions(
a.Config(),
a.Srv().Store.Preference(),
userId,
client,
clientVersion,
locale,
cachedPostCount,
cachedUserCount,
isSystemAdmin,

Просмотреть файл

@@ -53,7 +53,6 @@ func TestNoticeValidation(t *testing.T) {
type args struct {
client model.NoticeClientType
clientVersion string
locale string
sku string
postCount, userCount int64
cloud bool
@@ -550,7 +549,20 @@ func TestNoticeValidation(t *testing.T) {
if model.BuildNumber == "" {
model.BuildNumber = "5.26.1"
}
if ok, err := noticeMatchesConditions(th.App.Config(), th.App.Srv().Store.Preference(), "test", tt.args.client, clientVersion, tt.args.locale, tt.args.postCount, tt.args.userCount, tt.args.systemAdmin, tt.args.teamAdmin, tt.args.cloud, tt.args.sku, tt.args.notice); (err != nil) != tt.wantErr {
if ok, err := noticeMatchesConditions(
th.App.Config(),
th.App.Srv().Store.Preference(),
"test",
tt.args.client,
clientVersion,
tt.args.postCount,
tt.args.userCount,
tt.args.systemAdmin,
tt.args.teamAdmin,
tt.args.cloud,
tt.args.sku,
tt.args.notice,
); (err != nil) != tt.wantErr {
t.Errorf("noticeMatchesConditions() error = %v, wantErr %v", err, tt.wantErr)
} else if ok != tt.wantOk {
t.Errorf("noticeMatchesConditions() result = %v, wantOk %v", ok, tt.wantOk)

Просмотреть файл

@@ -63,7 +63,7 @@ func (a *App) SaveReactionForPost(reaction *model.Reaction) (*model.Reaction, *m
}
a.Srv().Go(func() {
a.sendReactionEvent(model.WEBSOCKET_EVENT_REACTION_ADDED, reaction, post, true)
a.sendReactionEvent(model.WEBSOCKET_EVENT_REACTION_ADDED, reaction, post)
})
return reaction, nil
@@ -131,11 +131,6 @@ func (a *App) DeleteReactionForPost(reaction *model.Reaction) *model.AppError {
}
}
hasReactions := true
if reactions, _ := a.GetReactionsForPost(post.Id); len(reactions) <= 1 {
hasReactions = false
}
if _, err := a.Srv().Store.Reaction().Delete(reaction); err != nil {
return model.NewAppError("DeleteReactionForPost", "app.reaction.delete_all_with_emoji_name.get_reactions.app_error", nil, err.Error(), http.StatusInternalServerError)
}
@@ -154,13 +149,13 @@ func (a *App) DeleteReactionForPost(reaction *model.Reaction) *model.AppError {
}
a.Srv().Go(func() {
a.sendReactionEvent(model.WEBSOCKET_EVENT_REACTION_REMOVED, reaction, post, hasReactions)
a.sendReactionEvent(model.WEBSOCKET_EVENT_REACTION_REMOVED, reaction, post)
})
return nil
}
func (a *App) sendReactionEvent(event string, reaction *model.Reaction, post *model.Post, hasReactions bool) {
func (a *App) sendReactionEvent(event string, reaction *model.Reaction, post *model.Post) {
// send out that a reaction has been added/removed
message := model.NewWebSocketEvent(event, "", post.ChannelId, "", nil)
message.Add("reaction", reaction.ToJson())

Просмотреть файл

@@ -1302,7 +1302,7 @@ func (a *App) UpdateUser(user *model.User, sendNotifications bool) (*model.User,
if userUpdate.New.Username != userUpdate.Old.Username {
a.Srv().Go(func() {
if err := a.Srv().EmailService.sendChangeUsernameEmail(userUpdate.Old.Username, userUpdate.New.Username, userUpdate.New.Email, userUpdate.New.Locale, a.GetSiteURL()); err != nil {
if err := a.Srv().EmailService.sendChangeUsernameEmail(userUpdate.New.Username, userUpdate.New.Email, userUpdate.New.Locale, a.GetSiteURL()); err != nil {
mlog.Error("Failed to send change username email", mlog.Err(err))
}
})

Просмотреть файл

@@ -588,7 +588,7 @@ func TestTriggerOutGoingWebhookWithUsernameAndIconURL(t *testing.T) {
}
}
waitUntilWebhookResposeIsCreatedAsPost := func(channel *model.Channel, th *TestHelper, t *testing.T, createdPost chan *model.Post) {
waitUntilWebhookResposeIsCreatedAsPost := func(channel *model.Channel, th *TestHelper, createdPost chan *model.Post) {
go func() {
for i := 0; i < 5; i++ {
time.Sleep(time.Second)
@@ -686,7 +686,7 @@ func TestTriggerOutGoingWebhookWithUsernameAndIconURL(t *testing.T) {
th.App.TriggerWebhook(payload, hook, th.BasicPost, channel)
waitUntilWebhookResposeIsCreatedAsPost(channel, th, t, createdPost)
waitUntilWebhookResposeIsCreatedAsPost(channel, th, createdPost)
select {
case webhookPost := <-createdPost: