diff --git a/app/bot.go b/app/bot.go index 04491b6245..5be79588f3 100644 --- a/app/bot.go +++ b/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 diff --git a/model/bot.go b/model/bot.go index c17f82fb8e..15ef6a70ca 100644 --- a/model/bot.go +++ b/model/bot.go @@ -22,14 +22,15 @@ const ( // Note that the primary key of a bot is the UserId, and matches the primary key of the // corresponding user. type Bot struct { - UserId string `json:"user_id"` - Username string `json:"username"` - DisplayName string `json:"display_name,omitempty"` - Description string `json:"description,omitempty"` - OwnerId string `json:"owner_id"` - CreateAt int64 `json:"create_at"` - UpdateAt int64 `json:"update_at"` - DeleteAt int64 `json:"delete_at"` + UserId string `json:"user_id"` + Username string `json:"username"` + DisplayName string `json:"display_name,omitempty"` + Description string `json:"description,omitempty"` + OwnerId string `json:"owner_id"` + LastIconUpdate int64 `json:"last_icon_update,omitempty"` + CreateAt int64 `json:"create_at"` + UpdateAt int64 `json:"update_at"` + DeleteAt int64 `json:"delete_at"` } // BotPatch is a description of what fields to update on an existing bot. diff --git a/model/bot_test.go b/model/bot_test.go index cd0d073011..50dd1e1a32 100644 --- a/model/bot_test.go +++ b/model/bot_test.go @@ -14,14 +14,15 @@ import ( func TestBotTrace(t *testing.T) { bot := &Bot{ - UserId: NewId(), - Username: "username", - DisplayName: "display name", - Description: "description", - OwnerId: NewId(), - CreateAt: 1, - UpdateAt: 2, - DeleteAt: 3, + UserId: NewId(), + Username: "username", + DisplayName: "display name", + Description: "description", + OwnerId: NewId(), + LastIconUpdate: 1, + CreateAt: 2, + UpdateAt: 3, + DeleteAt: 4, } require.Equal(t, map[string]interface{}{"user_id": bot.UserId}, bot.Trace()) @@ -29,14 +30,15 @@ func TestBotTrace(t *testing.T) { func TestBotClone(t *testing.T) { bot := &Bot{ - UserId: NewId(), - Username: "username", - DisplayName: "display name", - Description: "description", - OwnerId: NewId(), - CreateAt: 1, - UpdateAt: 2, - DeleteAt: 3, + UserId: NewId(), + Username: "username", + DisplayName: "display name", + Description: "description", + OwnerId: NewId(), + LastIconUpdate: 1, + CreateAt: 2, + UpdateAt: 3, + DeleteAt: 4, } clone := bot.Clone() @@ -59,154 +61,165 @@ func TestBotIsValid(t *testing.T) { { "bot with missing user id", &Bot{ - UserId: "", - Username: "username", - DisplayName: "display name", - Description: "description", - OwnerId: NewId(), - CreateAt: 1, - UpdateAt: 2, - DeleteAt: 3, + UserId: "", + Username: "username", + DisplayName: "display name", + Description: "description", + OwnerId: NewId(), + LastIconUpdate: 1, + CreateAt: 2, + UpdateAt: 3, + DeleteAt: 4, }, false, }, { "bot with invalid user id", &Bot{ - UserId: "invalid", - Username: "username", - DisplayName: "display name", - Description: "description", - OwnerId: NewId(), - CreateAt: 1, - UpdateAt: 2, - DeleteAt: 3, + UserId: "invalid", + Username: "username", + DisplayName: "display name", + Description: "description", + OwnerId: NewId(), + LastIconUpdate: 1, + CreateAt: 2, + UpdateAt: 3, + DeleteAt: 4, }, false, }, { "bot with missing username", &Bot{ - UserId: NewId(), - Username: "", - DisplayName: "display name", - Description: "description", - OwnerId: NewId(), - CreateAt: 1, - UpdateAt: 2, - DeleteAt: 3, + UserId: NewId(), + Username: "", + DisplayName: "display name", + Description: "description", + OwnerId: NewId(), + LastIconUpdate: 1, + CreateAt: 2, + UpdateAt: 3, + DeleteAt: 4, }, false, }, { "bot with invalid username", &Bot{ - UserId: NewId(), - Username: "a@", - DisplayName: "display name", - Description: "description", - OwnerId: NewId(), - CreateAt: 1, - UpdateAt: 2, - DeleteAt: 3, + UserId: NewId(), + Username: "a@", + DisplayName: "display name", + Description: "description", + OwnerId: NewId(), + LastIconUpdate: 1, + CreateAt: 2, + UpdateAt: 3, + DeleteAt: 4, }, false, }, { "bot with long description", &Bot{ - UserId: "", - Username: "username", - DisplayName: "display name", - Description: strings.Repeat("x", 1025), - OwnerId: NewId(), - CreateAt: 1, - UpdateAt: 2, - DeleteAt: 3, + UserId: "", + Username: "username", + DisplayName: "display name", + Description: strings.Repeat("x", 1025), + OwnerId: NewId(), + LastIconUpdate: 1, + CreateAt: 2, + UpdateAt: 3, + DeleteAt: 4, }, false, }, { "bot with missing creator id", &Bot{ - UserId: NewId(), - Username: "username", - DisplayName: "display name", - Description: "description", - OwnerId: "", - CreateAt: 1, - UpdateAt: 2, - DeleteAt: 3, + UserId: NewId(), + Username: "username", + DisplayName: "display name", + Description: "description", + OwnerId: "", + LastIconUpdate: 1, + CreateAt: 2, + UpdateAt: 3, + DeleteAt: 4, }, false, }, { "bot without create at timestamp", &Bot{ - UserId: NewId(), - Username: "username", - DisplayName: "display name", - Description: "description", - OwnerId: NewId(), - CreateAt: 0, - UpdateAt: 2, - DeleteAt: 3, + UserId: NewId(), + Username: "username", + DisplayName: "display name", + Description: "description", + OwnerId: NewId(), + LastIconUpdate: 1, + CreateAt: 0, + UpdateAt: 3, + DeleteAt: 4, }, false, }, { "bot without update at timestamp", &Bot{ - UserId: NewId(), - Username: "username", - DisplayName: "display name", - Description: "description", - OwnerId: NewId(), - CreateAt: 1, - UpdateAt: 0, - DeleteAt: 3, + UserId: NewId(), + Username: "username", + DisplayName: "display name", + Description: "description", + OwnerId: NewId(), + LastIconUpdate: 1, + CreateAt: 2, + UpdateAt: 0, + DeleteAt: 4, }, false, }, { "bot", &Bot{ - UserId: NewId(), - Username: "username", - DisplayName: "display name", - Description: "description", - OwnerId: NewId(), - CreateAt: 1, - UpdateAt: 2, - DeleteAt: 0, + UserId: NewId(), + Username: "username", + DisplayName: "display name", + Description: "description", + OwnerId: NewId(), + LastIconUpdate: 1, + CreateAt: 2, + UpdateAt: 3, + DeleteAt: 0, }, true, }, { "bot without description", &Bot{ - UserId: NewId(), - Username: "username", - DisplayName: "display name", - Description: "", - OwnerId: NewId(), - CreateAt: 1, - UpdateAt: 2, - DeleteAt: 0, + UserId: NewId(), + Username: "username", + DisplayName: "display name", + Description: "", + OwnerId: NewId(), + LastIconUpdate: 1, + CreateAt: 2, + UpdateAt: 3, + DeleteAt: 0, }, true, }, { "deleted bot", &Bot{ - UserId: NewId(), - Username: "username", - DisplayName: "display name", - Description: "a description", - OwnerId: NewId(), - CreateAt: 1, - UpdateAt: 2, - DeleteAt: 3, + UserId: NewId(), + Username: "username", + DisplayName: "display name", + Description: "a description", + OwnerId: NewId(), + LastIconUpdate: 1, + CreateAt: 2, + UpdateAt: 3, + DeleteAt: 4, }, true, }, @@ -225,12 +238,13 @@ func TestBotIsValid(t *testing.T) { func TestBotPreSave(t *testing.T) { bot := &Bot{ - UserId: NewId(), - Username: "username", - DisplayName: "display name", - Description: "description", - OwnerId: NewId(), - DeleteAt: 0, + UserId: NewId(), + Username: "username", + DisplayName: "display name", + Description: "description", + OwnerId: NewId(), + LastIconUpdate: 0, + DeleteAt: 0, } originalBot := &*bot @@ -246,13 +260,14 @@ func TestBotPreSave(t *testing.T) { func TestBotPreUpdate(t *testing.T) { bot := &Bot{ - UserId: NewId(), - Username: "username", - DisplayName: "display name", - Description: "description", - OwnerId: NewId(), - CreateAt: 1, - DeleteAt: 0, + UserId: NewId(), + Username: "username", + DisplayName: "display name", + Description: "description", + OwnerId: NewId(), + LastIconUpdate: 1, + CreateAt: 2, + DeleteAt: 0, } originalBot := &*bot @@ -267,14 +282,15 @@ func TestBotPreUpdate(t *testing.T) { func TestBotEtag(t *testing.T) { t.Run("same etags", func(t *testing.T) { bot1 := &Bot{ - UserId: NewId(), - Username: "username", - DisplayName: "display name", - Description: "description", - OwnerId: NewId(), - CreateAt: 1, - UpdateAt: 2, - DeleteAt: 3, + UserId: NewId(), + Username: "username", + DisplayName: "display name", + Description: "description", + OwnerId: NewId(), + LastIconUpdate: 1, + CreateAt: 2, + UpdateAt: 3, + DeleteAt: 4, } bot2 := bot1 @@ -283,48 +299,52 @@ func TestBotEtag(t *testing.T) { t.Run("different etags", func(t *testing.T) { t.Run("different user id", func(t *testing.T) { bot1 := &Bot{ - UserId: NewId(), - Username: "username", - DisplayName: "display name", - Description: "description", - OwnerId: NewId(), - CreateAt: 1, - UpdateAt: 2, - DeleteAt: 3, + UserId: NewId(), + Username: "username", + DisplayName: "display name", + Description: "description", + OwnerId: NewId(), + LastIconUpdate: 1, + CreateAt: 2, + UpdateAt: 3, + DeleteAt: 4, } bot2 := &Bot{ - UserId: NewId(), - Username: "username", - DisplayName: "display name", - Description: "description", - OwnerId: bot1.OwnerId, - CreateAt: 1, - UpdateAt: 2, - DeleteAt: 3, + UserId: NewId(), + Username: "username", + DisplayName: "display name", + Description: "description", + OwnerId: bot1.OwnerId, + LastIconUpdate: 1, + CreateAt: 2, + UpdateAt: 3, + DeleteAt: 4, } assert.NotEqual(t, bot1.Etag(), bot2.Etag()) }) t.Run("different update at", func(t *testing.T) { bot1 := &Bot{ - UserId: NewId(), - Username: "username", - DisplayName: "display name", - Description: "description", - OwnerId: NewId(), - CreateAt: 1, - UpdateAt: 2, - DeleteAt: 3, + UserId: NewId(), + Username: "username", + DisplayName: "display name", + Description: "description", + OwnerId: NewId(), + LastIconUpdate: 1, + CreateAt: 2, + UpdateAt: 3, + DeleteAt: 4, } bot2 := &Bot{ - UserId: bot1.UserId, - Username: "username", - DisplayName: "display name", - Description: "description", - OwnerId: bot1.OwnerId, - CreateAt: 1, - UpdateAt: 10, - DeleteAt: 3, + UserId: bot1.UserId, + Username: "username", + DisplayName: "display name", + Description: "description", + OwnerId: bot1.OwnerId, + LastIconUpdate: 1, + CreateAt: 2, + UpdateAt: 10, + DeleteAt: 4, } assert.NotEqual(t, bot1.Etag(), bot2.Etag()) @@ -334,25 +354,27 @@ func TestBotEtag(t *testing.T) { func TestBotToAndFromJson(t *testing.T) { bot1 := &Bot{ - UserId: NewId(), - Username: "username", - DisplayName: "display name", - Description: "description", - OwnerId: NewId(), - CreateAt: 1, - UpdateAt: 2, - DeleteAt: 3, + UserId: NewId(), + Username: "username", + DisplayName: "display name", + Description: "description", + OwnerId: NewId(), + LastIconUpdate: 1, + CreateAt: 2, + UpdateAt: 3, + DeleteAt: 4, } bot2 := &Bot{ - UserId: NewId(), - Username: "username", - DisplayName: "display name", - Description: "description 2", - OwnerId: NewId(), - CreateAt: 4, - UpdateAt: 5, - DeleteAt: 6, + UserId: NewId(), + Username: "username", + DisplayName: "display name", + Description: "description 2", + OwnerId: NewId(), + LastIconUpdate: 5, + CreateAt: 6, + UpdateAt: 7, + DeleteAt: 8, } assert.Equal(t, bot1, BotFromJson(bytes.NewReader(bot1.ToJson()))) @@ -376,38 +398,41 @@ func TestBotPatch(t *testing.T) { { "no update", &Bot{ - UserId: userId1, - Username: "username", - DisplayName: "display name", - Description: "description", - OwnerId: creatorId1, - CreateAt: 1, - UpdateAt: 2, - DeleteAt: 3, + UserId: userId1, + Username: "username", + DisplayName: "display name", + Description: "description", + OwnerId: creatorId1, + LastIconUpdate: 1, + CreateAt: 2, + UpdateAt: 3, + DeleteAt: 4, }, &BotPatch{}, &Bot{ - UserId: userId1, - Username: "username", - DisplayName: "display name", - Description: "description", - OwnerId: creatorId1, - CreateAt: 1, - UpdateAt: 2, - DeleteAt: 3, + UserId: userId1, + Username: "username", + DisplayName: "display name", + Description: "description", + OwnerId: creatorId1, + LastIconUpdate: 1, + CreateAt: 2, + UpdateAt: 3, + DeleteAt: 4, }, }, { "partial update", &Bot{ - UserId: userId1, - Username: "username", - DisplayName: "display name", - Description: "description", - OwnerId: creatorId1, - CreateAt: 1, - UpdateAt: 2, - DeleteAt: 3, + UserId: userId1, + Username: "username", + DisplayName: "display name", + Description: "description", + OwnerId: creatorId1, + LastIconUpdate: 1, + CreateAt: 2, + UpdateAt: 3, + DeleteAt: 4, }, &BotPatch{ Username: sToP("new_username"), @@ -415,27 +440,29 @@ func TestBotPatch(t *testing.T) { Description: sToP("new description"), }, &Bot{ - UserId: userId1, - Username: "new_username", - DisplayName: "display name", - Description: "new description", - OwnerId: creatorId1, - CreateAt: 1, - UpdateAt: 2, - DeleteAt: 3, + UserId: userId1, + Username: "new_username", + DisplayName: "display name", + Description: "new description", + OwnerId: creatorId1, + LastIconUpdate: 1, + CreateAt: 2, + UpdateAt: 3, + DeleteAt: 4, }, }, { "full update", &Bot{ - UserId: userId1, - Username: "username", - DisplayName: "display name", - Description: "description", - OwnerId: creatorId1, - CreateAt: 1, - UpdateAt: 2, - DeleteAt: 3, + UserId: userId1, + Username: "username", + DisplayName: "display name", + Description: "description", + OwnerId: creatorId1, + LastIconUpdate: 1, + CreateAt: 2, + UpdateAt: 3, + DeleteAt: 4, }, &BotPatch{ Username: sToP("new_username"), @@ -443,14 +470,15 @@ func TestBotPatch(t *testing.T) { Description: sToP("new description"), }, &Bot{ - UserId: userId1, - Username: "new_username", - DisplayName: "new display name", - Description: "new description", - OwnerId: creatorId1, - CreateAt: 1, - UpdateAt: 2, - DeleteAt: 3, + UserId: userId1, + Username: "new_username", + DisplayName: "new display name", + Description: "new description", + OwnerId: creatorId1, + LastIconUpdate: 1, + CreateAt: 2, + UpdateAt: 3, + DeleteAt: 4, }, }, } @@ -482,25 +510,27 @@ func TestBotPatchToAndFromJson(t *testing.T) { func TestUserFromBot(t *testing.T) { bot1 := &Bot{ - UserId: NewId(), - Username: "username", - DisplayName: "display name", - Description: "description", - OwnerId: NewId(), - CreateAt: 1, - UpdateAt: 2, - DeleteAt: 3, + UserId: NewId(), + Username: "username", + DisplayName: "display name", + Description: "description", + OwnerId: NewId(), + LastIconUpdate: 1, + CreateAt: 2, + UpdateAt: 3, + DeleteAt: 4, } bot2 := &Bot{ - UserId: NewId(), - Username: "username2", - DisplayName: "display name 2", - Description: "description 2", - OwnerId: NewId(), - CreateAt: 4, - UpdateAt: 5, - DeleteAt: 6, + UserId: NewId(), + Username: "username2", + DisplayName: "display name 2", + Description: "description 2", + OwnerId: NewId(), + LastIconUpdate: 5, + CreateAt: 6, + UpdateAt: 7, + DeleteAt: 8, } assert.Equal(t, &User{ @@ -549,14 +579,15 @@ func TestBotListToAndFromJson(t *testing.T) { "single item", BotList{ &Bot{ - UserId: NewId(), - Username: "username", - DisplayName: "display name", - Description: "description", - OwnerId: NewId(), - CreateAt: 1, - UpdateAt: 2, - DeleteAt: 3, + UserId: NewId(), + Username: "username", + DisplayName: "display name", + Description: "description", + OwnerId: NewId(), + LastIconUpdate: 1, + CreateAt: 2, + UpdateAt: 3, + DeleteAt: 4, }, }, }, @@ -564,25 +595,27 @@ func TestBotListToAndFromJson(t *testing.T) { "multiple items", BotList{ &Bot{ - UserId: NewId(), - Username: "username", - DisplayName: "display name", - Description: "description", - OwnerId: NewId(), - CreateAt: 1, - UpdateAt: 2, - DeleteAt: 3, + UserId: NewId(), + Username: "username", + DisplayName: "display name", + Description: "description", + OwnerId: NewId(), + LastIconUpdate: 1, + CreateAt: 2, + UpdateAt: 3, + DeleteAt: 4, }, &Bot{ - UserId: NewId(), - Username: "username", - DisplayName: "display name", - Description: "description 2", - OwnerId: NewId(), - CreateAt: 4, - UpdateAt: 5, - DeleteAt: 6, + UserId: NewId(), + Username: "username", + DisplayName: "display name", + Description: "description 2", + OwnerId: NewId(), + LastIconUpdate: 5, + CreateAt: 6, + UpdateAt: 7, + DeleteAt: 8, }, }, }, @@ -597,36 +630,39 @@ func TestBotListToAndFromJson(t *testing.T) { func TestBotListEtag(t *testing.T) { bot1 := &Bot{ - UserId: NewId(), - Username: "username", - DisplayName: "display name", - Description: "description", - OwnerId: NewId(), - CreateAt: 1, - UpdateAt: 2, - DeleteAt: 3, + UserId: NewId(), + Username: "username", + DisplayName: "display name", + Description: "description", + OwnerId: NewId(), + LastIconUpdate: 1, + CreateAt: 2, + UpdateAt: 3, + DeleteAt: 4, } bot1Updated := &Bot{ - UserId: NewId(), - Username: "username", - DisplayName: "display name", - Description: "description", - OwnerId: NewId(), - CreateAt: 1, - UpdateAt: 10, - DeleteAt: 3, + UserId: NewId(), + Username: "username", + DisplayName: "display name", + Description: "description", + OwnerId: NewId(), + LastIconUpdate: 1, + CreateAt: 2, + UpdateAt: 10, + DeleteAt: 4, } bot2 := &Bot{ - UserId: NewId(), - Username: "username", - DisplayName: "display name", - Description: "description", - OwnerId: NewId(), - CreateAt: 4, - UpdateAt: 5, - DeleteAt: 6, + UserId: NewId(), + Username: "username", + DisplayName: "display name", + Description: "description", + OwnerId: NewId(), + LastIconUpdate: 5, + CreateAt: 6, + UpdateAt: 7, + DeleteAt: 8, } testCases := []struct { diff --git a/model/user.go b/model/user.go index 20d5243427..9474f761d4 100644 --- a/model/user.go +++ b/model/user.go @@ -87,6 +87,7 @@ type User struct { LastActivityAt int64 `db:"-" json:"last_activity_at,omitempty"` IsBot bool `db:"-" json:"is_bot,omitempty"` BotDescription string `db:"-" json:"bot_description,omitempty"` + BotLastIconUpdate int64 `db:"-" json:"bot_last_icon_update,omitempty"` TermsOfServiceId string `db:"-" json:"terms_of_service_id,omitempty"` TermsOfServiceCreateAt int64 `db:"-" json:"terms_of_service_create_at,omitempty"` } @@ -487,7 +488,7 @@ func (u *UserAuth) ToJson() string { // Generate a valid strong etag so the browser can cache the results func (u *User) Etag(showFullName, showEmail bool) string { - return Etag(u.Id, u.UpdateAt, u.TermsOfServiceId, u.TermsOfServiceCreateAt, showFullName, showEmail) + return Etag(u.Id, u.UpdateAt, u.TermsOfServiceId, u.TermsOfServiceCreateAt, showFullName, showEmail, u.BotLastIconUpdate) } // Remove any private data from the user object diff --git a/store/sqlstore/bot_store.go b/store/sqlstore/bot_store.go index e10d4e5602..b51fb2e017 100644 --- a/store/sqlstore/bot_store.go +++ b/store/sqlstore/bot_store.go @@ -15,22 +15,24 @@ import ( // bot is a subset of the model.Bot type, omitting the model.User fields. type bot struct { - UserId string `json:"user_id"` - Description string `json:"description"` - OwnerId string `json:"owner_id"` - CreateAt int64 `json:"create_at"` - UpdateAt int64 `json:"update_at"` - DeleteAt int64 `json:"delete_at"` + UserId string `json:"user_id"` + Description string `json:"description"` + OwnerId string `json:"owner_id"` + LastIconUpdate int64 `json:"last_icon_update"` + CreateAt int64 `json:"create_at"` + UpdateAt int64 `json:"update_at"` + DeleteAt int64 `json:"delete_at"` } func botFromModel(b *model.Bot) *bot { return &bot{ - UserId: b.UserId, - Description: b.Description, - OwnerId: b.OwnerId, - CreateAt: b.CreateAt, - UpdateAt: b.UpdateAt, - DeleteAt: b.DeleteAt, + UserId: b.UserId, + Description: b.Description, + OwnerId: b.OwnerId, + LastIconUpdate: b.LastIconUpdate, + CreateAt: b.CreateAt, + UpdateAt: b.UpdateAt, + DeleteAt: b.DeleteAt, } } @@ -89,6 +91,7 @@ func (us SqlBotStore) Get(botUserId string, includeDeleted bool) (*model.Bot, *m u.FirstName AS DisplayName, b.Description, b.OwnerId, + b.LastIconUpdate, b.CreateAt, b.UpdateAt, b.DeleteAt @@ -145,6 +148,7 @@ func (us SqlBotStore) GetAll(options *model.BotGetOptions) ([]*model.Bot, *model u.FirstName AS DisplayName, b.Description, b.OwnerId, + b.LastIconUpdate, b.CreateAt, b.UpdateAt, b.DeleteAt @@ -205,6 +209,7 @@ func (us SqlBotStore) Update(bot *model.Bot) (*model.Bot, *model.AppError) { oldBot.Description = bot.Description oldBot.OwnerId = bot.OwnerId + oldBot.LastIconUpdate = bot.LastIconUpdate oldBot.UpdateAt = bot.UpdateAt oldBot.DeleteAt = bot.DeleteAt bot = oldBot diff --git a/store/sqlstore/user_store.go b/store/sqlstore/user_store.go index 9a60223f87..a00ab06831 100644 --- a/store/sqlstore/user_store.go +++ b/store/sqlstore/user_store.go @@ -60,7 +60,7 @@ func NewSqlUserStore(sqlStore SqlStore, metrics einterfaces.MetricsInterface) st } us.usersQuery = us.getQueryBuilder(). - Select("u.*", "b.UserId IS NOT NULL AS IsBot", "COALESCE(b.Description, '') AS BotDescription"). + Select("u.*", "b.UserId IS NOT NULL AS IsBot", "COALESCE(b.Description, '') AS BotDescription", "COALESCE(b.LastIconUpdate, 0) AS BotLastIconUpdate"). From("Users u"). LeftJoin("Bots b ON ( b.UserId = u.Id )")