feat: edit/delete/reply for emoji/sticker/audio (#2771)
* feat: edit/delete/reply for emoji/sticker/audio
This commit is contained in:
parent
dde0c71cfc
commit
938e7987ca
|
@ -31,6 +31,10 @@ type QuotedMessage struct {
|
||||||
ParsedText json.RawMessage `json:"parsedText,omitempty"`
|
ParsedText json.RawMessage `json:"parsedText,omitempty"`
|
||||||
// ImageLocalURL is the local url of the image
|
// ImageLocalURL is the local url of the image
|
||||||
ImageLocalURL string `json:"image,omitempty"`
|
ImageLocalURL string `json:"image,omitempty"`
|
||||||
|
// AudioLocalURL is the local url of the audio
|
||||||
|
AudioLocalURL string `json:"audio,omitempty"`
|
||||||
|
|
||||||
|
HasSticker bool `json:"sticker,omitempty"`
|
||||||
// CommunityID is the id of the community advertised
|
// CommunityID is the id of the community advertised
|
||||||
CommunityID string `json:"communityId,omitempty"`
|
CommunityID string `json:"communityId,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -4162,6 +4162,12 @@ func (m *Messenger) prepareMessage(msg *common.Message, s *server.MediaServer) {
|
||||||
if msg.QuotedMessage != nil && msg.QuotedMessage.ContentType == int64(protobuf.ChatMessage_IMAGE) {
|
if msg.QuotedMessage != nil && msg.QuotedMessage.ContentType == int64(protobuf.ChatMessage_IMAGE) {
|
||||||
msg.QuotedMessage.ImageLocalURL = s.MakeImageURL(msg.QuotedMessage.ID)
|
msg.QuotedMessage.ImageLocalURL = s.MakeImageURL(msg.QuotedMessage.ID)
|
||||||
}
|
}
|
||||||
|
if msg.QuotedMessage != nil && msg.QuotedMessage.ContentType == int64(protobuf.ChatMessage_AUDIO) {
|
||||||
|
msg.QuotedMessage.AudioLocalURL = s.MakeAudioURL(msg.QuotedMessage.ID)
|
||||||
|
}
|
||||||
|
if msg.QuotedMessage != nil && msg.QuotedMessage.ContentType == int64(protobuf.ChatMessage_STICKER) {
|
||||||
|
msg.QuotedMessage.HasSticker = true
|
||||||
|
}
|
||||||
if msg.ContentType == protobuf.ChatMessage_IMAGE {
|
if msg.ContentType == protobuf.ChatMessage_IMAGE {
|
||||||
msg.ImageLocalURL = s.MakeImageURL(msg.ID)
|
msg.ImageLocalURL = s.MakeImageURL(msg.ID)
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
|
|
||||||
var ErrInvalidEditOrDeleteAuthor = errors.New("sender is not the author of the message")
|
var ErrInvalidEditOrDeleteAuthor = errors.New("sender is not the author of the message")
|
||||||
var ErrInvalidDeleteTypeAuthor = errors.New("message type cannot be deleted")
|
var ErrInvalidDeleteTypeAuthor = errors.New("message type cannot be deleted")
|
||||||
var ErrInvalidEditContentType = errors.New("only text messages can be replaced")
|
var ErrInvalidEditContentType = errors.New("only text or emoji messages can be replaced")
|
||||||
|
|
||||||
func (m *Messenger) EditMessage(ctx context.Context, request *requests.EditMessage) (*MessengerResponse, error) {
|
func (m *Messenger) EditMessage(ctx context.Context, request *requests.EditMessage) (*MessengerResponse, error) {
|
||||||
err := request.Validate()
|
err := request.Validate()
|
||||||
|
@ -29,7 +29,7 @@ func (m *Messenger) EditMessage(ctx context.Context, request *requests.EditMessa
|
||||||
return nil, ErrInvalidEditOrDeleteAuthor
|
return nil, ErrInvalidEditOrDeleteAuthor
|
||||||
}
|
}
|
||||||
|
|
||||||
if message.ContentType != protobuf.ChatMessage_TEXT_PLAIN {
|
if message.ContentType != protobuf.ChatMessage_TEXT_PLAIN && message.ContentType != protobuf.ChatMessage_EMOJI {
|
||||||
return nil, ErrInvalidEditContentType
|
return nil, ErrInvalidEditContentType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,6 +44,7 @@ func (m *Messenger) EditMessage(ctx context.Context, request *requests.EditMessa
|
||||||
editMessage := &EditMessage{}
|
editMessage := &EditMessage{}
|
||||||
|
|
||||||
editMessage.Text = request.Text
|
editMessage.Text = request.Text
|
||||||
|
editMessage.ContentType = request.ContentType
|
||||||
editMessage.ChatId = message.ChatId
|
editMessage.ChatId = message.ChatId
|
||||||
editMessage.MessageId = request.ID.String()
|
editMessage.MessageId = request.ID.String()
|
||||||
editMessage.Clock = clock
|
editMessage.Clock = clock
|
||||||
|
@ -228,6 +229,7 @@ func (m *Messenger) applyEditMessage(editMessage *protobuf.EditMessage, message
|
||||||
}
|
}
|
||||||
message.Text = editMessage.Text
|
message.Text = editMessage.Text
|
||||||
message.EditedAt = editMessage.Clock
|
message.EditedAt = editMessage.Clock
|
||||||
|
message.ContentType = editMessage.ContentType
|
||||||
|
|
||||||
// Save original message as edit so we can retrieve history
|
// Save original message as edit so we can retrieve history
|
||||||
if message.EditedAt == 0 {
|
if message.EditedAt == 0 {
|
||||||
|
@ -236,6 +238,7 @@ func (m *Messenger) applyEditMessage(editMessage *protobuf.EditMessage, message
|
||||||
originalEdit.LocalChatID = message.LocalChatID
|
originalEdit.LocalChatID = message.LocalChatID
|
||||||
originalEdit.MessageId = message.ID
|
originalEdit.MessageId = message.ID
|
||||||
originalEdit.Text = message.Text
|
originalEdit.Text = message.Text
|
||||||
|
originalEdit.ContentType = message.ContentType
|
||||||
originalEdit.From = message.From
|
originalEdit.From = message.From
|
||||||
err := m.persistence.SaveEdit(originalEdit)
|
err := m.persistence.SaveEdit(originalEdit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -263,10 +263,12 @@ type EditMessage struct {
|
||||||
Text string `protobuf:"bytes,2,opt,name=text,proto3" json:"text,omitempty"`
|
Text string `protobuf:"bytes,2,opt,name=text,proto3" json:"text,omitempty"`
|
||||||
ChatId string `protobuf:"bytes,3,opt,name=chat_id,json=chatId,proto3" json:"chat_id,omitempty"`
|
ChatId string `protobuf:"bytes,3,opt,name=chat_id,json=chatId,proto3" json:"chat_id,omitempty"`
|
||||||
MessageId string `protobuf:"bytes,4,opt,name=message_id,json=messageId,proto3" json:"message_id,omitempty"`
|
MessageId string `protobuf:"bytes,4,opt,name=message_id,json=messageId,proto3" json:"message_id,omitempty"`
|
||||||
|
|
||||||
// Grant for community edit messages
|
// Grant for community edit messages
|
||||||
Grant []byte `protobuf:"bytes,5,opt,name=grant,proto3" json:"grant,omitempty"`
|
Grant []byte `protobuf:"bytes,5,opt,name=grant,proto3" json:"grant,omitempty"`
|
||||||
// The type of message (public/one-to-one/private-group-chat)
|
// The type of message (public/one-to-one/private-group-chat)
|
||||||
MessageType MessageType `protobuf:"varint,6,opt,name=message_type,json=messageType,proto3,enum=protobuf.MessageType" json:"message_type,omitempty"`
|
MessageType MessageType `protobuf:"varint,6,opt,name=message_type,json=messageType,proto3,enum=protobuf.MessageType" json:"message_type,omitempty"`
|
||||||
|
ContentType ChatMessage_ContentType `protobuf:"varint,7,opt,name=content_type,json=contentType,proto3,enum=protobuf.ChatMessage_ContentType" json:"content_type,omitempty"`
|
||||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||||
XXX_unrecognized []byte `json:"-"`
|
XXX_unrecognized []byte `json:"-"`
|
||||||
XXX_sizecache int32 `json:"-"`
|
XXX_sizecache int32 `json:"-"`
|
||||||
|
|
|
@ -39,6 +39,8 @@ message EditMessage {
|
||||||
|
|
||||||
// The type of message (public/one-to-one/private-group-chat)
|
// The type of message (public/one-to-one/private-group-chat)
|
||||||
MessageType message_type = 6;
|
MessageType message_type = 6;
|
||||||
|
|
||||||
|
ContentType content_type = 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
message DeleteMessage {
|
message DeleteMessage {
|
||||||
|
|
|
@ -4,14 +4,16 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/status-im/status-go/eth-node/types"
|
"github.com/status-im/status-go/eth-node/types"
|
||||||
|
"github.com/status-im/status-go/protocol/protobuf"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ErrEditMessageInvalidID = errors.New("edit-message: invalid id")
|
var ErrEditMessageInvalidID = errors.New("edit-message: invalid id")
|
||||||
var ErrEditMessageInvalidText = errors.New("edit-message: invalid text")
|
var ErrEditMessageInvalidText = errors.New("edit-message: invalid text")
|
||||||
|
|
||||||
type EditMessage struct {
|
type EditMessage struct {
|
||||||
ID types.HexBytes `json:"id"`
|
ID types.HexBytes `json:"id"`
|
||||||
Text string `json:"text"`
|
Text string `json:"text"`
|
||||||
|
ContentType protobuf.ChatMessage_ContentType `json:"content-type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *EditMessage) Validate() error {
|
func (e *EditMessage) Validate() error {
|
||||||
|
|
Loading…
Reference in New Issue