From 4f4a765e7d0bbfdfecc0c52ae4be35f8d3b737ca Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Tue, 23 Jan 2018 11:04:44 -0500 Subject: ABC-90 Add POST /emoji/search and GET /emoji/autocomplete API endpoints (#8125) * Add POST /emoji/search and GET /emoji/autocomplete API endpoints * Add constant to be clearer --- app/emoji.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'app/emoji.go') diff --git a/app/emoji.go b/app/emoji.go index 2786af9c9..2271d650d 100644 --- a/app/emoji.go +++ b/app/emoji.go @@ -134,11 +134,11 @@ func (a *App) DeleteEmoji(emoji *model.Emoji) *model.AppError { func (a *App) GetEmoji(emojiId string) (*model.Emoji, *model.AppError) { if !*a.Config().ServiceSettings.EnableCustomEmoji { - return nil, model.NewAppError("deleteEmoji", "api.emoji.disabled.app_error", nil, "", http.StatusNotImplemented) + return nil, model.NewAppError("GetEmoji", "api.emoji.disabled.app_error", nil, "", http.StatusNotImplemented) } if len(*a.Config().FileSettings.DriverName) == 0 { - return nil, model.NewAppError("deleteImage", "api.emoji.storage.app_error", nil, "", http.StatusNotImplemented) + return nil, model.NewAppError("GetEmoji", "api.emoji.storage.app_error", nil, "", http.StatusNotImplemented) } if result := <-a.Srv.Store.Emoji().Get(emojiId, false); result.Err != nil { @@ -169,6 +169,18 @@ func (a *App) GetEmojiImage(emojiId string) (imageByte []byte, imageType string, } } +func (a *App) SearchEmoji(name string, prefixOnly bool, limit int) ([]*model.Emoji, *model.AppError) { + if !*a.Config().ServiceSettings.EnableCustomEmoji { + return nil, model.NewAppError("SearchEmoji", "api.emoji.disabled.app_error", nil, "", http.StatusNotImplemented) + } + + if result := <-a.Srv.Store.Emoji().Search(name, prefixOnly, limit); result.Err != nil { + return nil, result.Err + } else { + return result.Data.([]*model.Emoji), nil + } +} + func resizeEmojiGif(gifImg *gif.GIF) *gif.GIF { // Create a new RGBA image to hold the incremental frames. firstFrame := gifImg.Image[0].Bounds() -- cgit v1.2.3-1-g7c22