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"`
|
||||
// ImageLocalURL is the local url of the image
|
||||
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 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) {
|
||||
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 {
|
||||
msg.ImageLocalURL = s.MakeImageURL(msg.ID)
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
|
||||
var ErrInvalidEditOrDeleteAuthor = errors.New("sender is not the author of the message")
|
||||
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) {
|
||||
err := request.Validate()
|
||||
|
@ -29,7 +29,7 @@ func (m *Messenger) EditMessage(ctx context.Context, request *requests.EditMessa
|
|||
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
|
||||
}
|
||||
|
||||
|
@ -44,6 +44,7 @@ func (m *Messenger) EditMessage(ctx context.Context, request *requests.EditMessa
|
|||
editMessage := &EditMessage{}
|
||||
|
||||
editMessage.Text = request.Text
|
||||
editMessage.ContentType = request.ContentType
|
||||
editMessage.ChatId = message.ChatId
|
||||
editMessage.MessageId = request.ID.String()
|
||||
editMessage.Clock = clock
|
||||
|
@ -228,6 +229,7 @@ func (m *Messenger) applyEditMessage(editMessage *protobuf.EditMessage, message
|
|||
}
|
||||
message.Text = editMessage.Text
|
||||
message.EditedAt = editMessage.Clock
|
||||
message.ContentType = editMessage.ContentType
|
||||
|
||||
// Save original message as edit so we can retrieve history
|
||||
if message.EditedAt == 0 {
|
||||
|
@ -236,6 +238,7 @@ func (m *Messenger) applyEditMessage(editMessage *protobuf.EditMessage, message
|
|||
originalEdit.LocalChatID = message.LocalChatID
|
||||
originalEdit.MessageId = message.ID
|
||||
originalEdit.Text = message.Text
|
||||
originalEdit.ContentType = message.ContentType
|
||||
originalEdit.From = message.From
|
||||
err := m.persistence.SaveEdit(originalEdit)
|
||||
if err != nil {
|
||||
|
|
|
@ -263,10 +263,12 @@ type EditMessage struct {
|
|||
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"`
|
||||
MessageId string `protobuf:"bytes,4,opt,name=message_id,json=messageId,proto3" json:"message_id,omitempty"`
|
||||
|
||||
// Grant for community edit messages
|
||||
Grant []byte `protobuf:"bytes,5,opt,name=grant,proto3" json:"grant,omitempty"`
|
||||
// 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"`
|
||||
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_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
|
|
|
@ -39,6 +39,8 @@ message EditMessage {
|
|||
|
||||
// The type of message (public/one-to-one/private-group-chat)
|
||||
MessageType message_type = 6;
|
||||
|
||||
ContentType content_type = 7;
|
||||
}
|
||||
|
||||
message DeleteMessage {
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"errors"
|
||||
|
||||
"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")
|
||||
|
@ -12,6 +13,7 @@ var ErrEditMessageInvalidText = errors.New("edit-message: invalid text")
|
|||
type EditMessage struct {
|
||||
ID types.HexBytes `json:"id"`
|
||||
Text string `json:"text"`
|
||||
ContentType protobuf.ChatMessage_ContentType `json:"content-type"`
|
||||
}
|
||||
|
||||
func (e *EditMessage) Validate() error {
|
||||
|
|
Loading…
Reference in New Issue