[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.
Этот коммит содержится в:
Renil Joseph
2019-12-29 07:30:18 -07:00
коммит произвёл Ben Schumacher
родитель f8d31def8e
Коммит 803a58f991
6 изменённых файлов: 366 добавлений и 314 удалений

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

@@ -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