github.com/status-im/status-go@v1.1.0/services/chat/api.go (about) 1 package chat 2 3 import ( 4 "context" 5 "errors" 6 7 "github.com/ethereum/go-ethereum/log" 8 9 "github.com/status-im/status-go/eth-node/types" 10 "github.com/status-im/status-go/images" 11 "github.com/status-im/status-go/protocol" 12 ) 13 14 var ( 15 ErrChatNotFound = errors.New("can't find chat") 16 ErrCommunitiesNotSupported = errors.New("communities are not supported") 17 ErrChatTypeNotSupported = errors.New("chat type not supported") 18 ) 19 20 func NewAPI(service *Service) *API { 21 return &API{ 22 s: service, 23 log: log.New("package", "status-go/services/chat.API"), 24 } 25 } 26 27 type API struct { 28 s *Service 29 log log.Logger 30 } 31 32 func (api *API) EditChat(ctx context.Context, communityID types.HexBytes, chatID string, name string, color string, image images.CroppedImage) (*protocol.MessengerResponse, error) { 33 if len(communityID) != 0 { 34 return nil, ErrCommunitiesNotSupported 35 } 36 37 chatToEdit := api.s.messenger.Chat(chatID) 38 if chatToEdit == nil { 39 return nil, ErrChatNotFound 40 } 41 42 if chatToEdit.ChatType != protocol.ChatTypePrivateGroupChat { 43 return nil, ErrChatTypeNotSupported 44 } 45 46 response, err := api.s.messenger.EditGroupChat(ctx, chatID, name, color, image) 47 if err != nil { 48 return nil, err 49 } 50 51 return response, nil 52 }