2022-02-10 15:15:27 +00:00
|
|
|
package chat
|
2022-02-09 21:58:33 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
|
2023-10-23 19:08:28 +00:00
|
|
|
"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")
|
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{
|
2023-10-23 19:08:28 +00:00
|
|
|
s: service,
|
|
|
|
log: log.New("package", "status-go/services/chat.API"),
|
2022-02-10 15:15:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type API struct {
|
2023-10-23 19:08:28 +00:00
|
|
|
s *Service
|
|
|
|
log log.Logger
|
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
|
|
|
}
|