2022-02-10 15:15:27 +00:00
|
|
|
package chat
|
2022-02-09 21:58:33 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"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")
|
2022-07-12 07:48:58 +00:00
|
|
|
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{
|
2024-10-28 20:54:17 +00:00
|
|
|
s: service,
|
2022-02-10 15:15:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type API struct {
|
2024-10-28 20:54:17 +00:00
|
|
|
s *Service
|
2022-02-10 15:15:27 +00:00
|
|
|
}
|
|
|
|
|
2024-05-13 19:06:21 +00:00
|
|
|
func (api *API) EditChat(ctx context.Context, communityID types.HexBytes, chatID string, name string, color string, image images.CroppedImage) (*protocol.MessengerResponse, error) {
|
2022-07-12 07:48:58 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2024-05-13 19:06:21 +00:00
|
|
|
return response, nil
|
2022-07-12 07:48:58 +00:00
|
|
|
}
|