[MM-17422] Added code to update, delete last bot_icon time in model.bot. (#12229)
Display LHS bot Icon in web app. As part of mentioned task, Added LastIconUpdate variable in model.bot to store last update time of icon. Also added code to update/delete value of the mentioned variable when setting/deleting bot icon.
Этот коммит содержится в:
коммит произвёл
Ben Schumacher
родитель
f8d31def8e
Коммит
803a58f991
23
app/bot.go
23
app/bot.go
@@ -328,7 +328,8 @@ func (a *App) SetBotIconImageFromMultiPartFile(botUserId string, imageData *mult
|
||||
|
||||
// SetBotIconImage sets LHS icon for a bot.
|
||||
func (a *App) SetBotIconImage(botUserId string, file io.ReadSeeker) *model.AppError {
|
||||
if _, err := a.GetBot(botUserId, true); err != nil {
|
||||
bot, err := a.GetBot(botUserId, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -338,12 +339,13 @@ func (a *App) SetBotIconImage(botUserId string, file io.ReadSeeker) *model.AppEr
|
||||
|
||||
// Set icon
|
||||
file.Seek(0, 0)
|
||||
if _, err := a.WriteFile(file, getBotIconPath(botUserId)); err != nil {
|
||||
if _, err = a.WriteFile(file, getBotIconPath(botUserId)); err != nil {
|
||||
return model.NewAppError("SetBotIconImage", "api.bot.set_bot_icon_image.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
if err := a.Srv.Store.User().UpdateLastPictureUpdate(botUserId); err != nil {
|
||||
mlog.Error(err.Error())
|
||||
bot.LastIconUpdate = model.GetMillis()
|
||||
if _, err = a.Srv.Store.Bot().Update(bot); err != nil {
|
||||
return err
|
||||
}
|
||||
a.invalidateUserCacheAndPublish(botUserId)
|
||||
|
||||
@@ -352,18 +354,25 @@ func (a *App) SetBotIconImage(botUserId string, file io.ReadSeeker) *model.AppEr
|
||||
|
||||
// DeleteBotIconImage deletes LHS icon for a bot.
|
||||
func (a *App) DeleteBotIconImage(botUserId string) *model.AppError {
|
||||
if _, err := a.GetBot(botUserId, true); err != nil {
|
||||
bot, err := a.GetBot(botUserId, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Delete icon
|
||||
if err := a.RemoveFile(getBotIconPath(botUserId)); err != nil {
|
||||
if err = a.RemoveFile(getBotIconPath(botUserId)); err != nil {
|
||||
return model.NewAppError("DeleteBotIconImage", "api.bot.delete_bot_icon_image.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
if err := a.Srv.Store.User().UpdateLastPictureUpdate(botUserId); err != nil {
|
||||
if err = a.Srv.Store.User().UpdateLastPictureUpdate(botUserId); err != nil {
|
||||
mlog.Error(err.Error())
|
||||
}
|
||||
|
||||
bot.LastIconUpdate = int64(0)
|
||||
if _, err = a.Srv.Store.Bot().Update(bot); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
a.invalidateUserCacheAndPublish(botUserId)
|
||||
|
||||
return nil
|
||||
|
||||
Ссылка в новой задаче
Block a user