status-go/services/chat/api.go

53 lines
1.2 KiB
Go
Raw Permalink Normal View History

2022-02-10 15:15:27 +00:00
package chat
2022-02-09 21:58:33 +00:00
import (
"context"
"errors"
"github.com/ethereum/go-ethereum/log"
2022-02-09 21:58:33 +00:00
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/images"
"github.com/status-im/status-go/protocol"
)
var (
2022-02-11 16:29:57 +00:00
ErrChatNotFound = errors.New("can't find chat")
ErrCommunitiesNotSupported = errors.New("communities are not supported")
ErrChatTypeNotSupported = errors.New("chat type not supported")
2022-02-09 21:58:33 +00:00
)
2022-02-10 15:15:27 +00:00
func NewAPI(service *Service) *API {
return &API{
s: service,
log: log.New("package", "status-go/services/chat.API"),
2022-02-10 15:15:27 +00:00
}
}
type API struct {
s *Service
log log.Logger
2022-02-10 15:15:27 +00:00
}
func (api *API) EditChat(ctx context.Context, communityID types.HexBytes, chatID string, name string, color string, image images.CroppedImage) (*protocol.MessengerResponse, error) {
if len(communityID) != 0 {
return nil, ErrCommunitiesNotSupported
}
chatToEdit := api.s.messenger.Chat(chatID)
if chatToEdit == nil {
return nil, ErrChatNotFound
}
if chatToEdit.ChatType != protocol.ChatTypePrivateGroupChat {
return nil, ErrChatTypeNotSupported
}
response, err := api.s.messenger.EditGroupChat(ctx, chatID, name, color, image)
if err != nil {
return nil, err
}
return response, nil
}