diff --git a/VERSION b/VERSION index b5ac4b949..6ebb6dd91 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.94.7 +0.94.8 \ No newline at end of file diff --git a/protocol/message_persistence.go b/protocol/message_persistence.go index a22a0515d..84817723f 100644 --- a/protocol/message_persistence.go +++ b/protocol/message_persistence.go @@ -74,6 +74,7 @@ func (db sqlitePersistence) tableUserMessagesAllFieldsJoin() string { m1.parsed_text, m1.sticker_pack, m1.sticker_hash, + m1.image_payload, COALESCE(m1.audio_duration_ms,0), m1.audio_base64, m1.community_id, @@ -134,6 +135,7 @@ func (db sqlitePersistence) tableUserMessagesScanAllFields(row scanner, message sticker := &protobuf.StickerMessage{} command := &common.CommandParameters{} audio := &protobuf.AudioMessage{} + image := &protobuf.ImageMessage{} args := []interface{}{ &message.ID, @@ -152,6 +154,7 @@ func (db sqlitePersistence) tableUserMessagesScanAllFields(row scanner, message &message.ParsedText, &sticker.Pack, &sticker.Hash, + &image.Payload, &audio.DurationMs, &message.Base64Audio, &communityID, @@ -242,6 +245,9 @@ func (db sqlitePersistence) tableUserMessagesScanAllFields(row scanner, message case protobuf.ChatMessage_TRANSACTION_COMMAND: message.CommandParameters = command + + case protobuf.ChatMessage_IMAGE: + message.Payload = &protobuf.ChatMessage_Image{Image: image} } return nil diff --git a/protocol/messenger_chats.go b/protocol/messenger_chats.go index 821d23e1f..c04f395e5 100644 --- a/protocol/messenger_chats.go +++ b/protocol/messenger_chats.go @@ -575,3 +575,44 @@ func (m *Messenger) clearHistory(id string) (*MessengerResponse, error) { response.AddChat(chat) return response, nil } + +func (m *Messenger) ShareImageMessage(request *requests.ShareImageMessage) (*MessengerResponse, error) { + if err := request.Validate(); err != nil { + return nil, err + } + response := &MessengerResponse{} + + msg, err := m.persistence.MessageByID(request.MessageID) + if err != nil { + return nil, err + } + + var messages []*common.Message + for _, pk := range request.Users { + message := &common.Message{} + message.ChatId = pk.String() + message.Payload = msg.Payload + message.ContentType = protobuf.ChatMessage_IMAGE + messages = append(messages, message) + + r, err := m.CreateOneToOneChat(&requests.CreateOneToOneChat{ID: pk}) + if err != nil { + return nil, err + } + + if err := response.Merge(r); err != nil { + return nil, err + } + } + + sendMessagesResponse, err := m.SendChatMessages(context.Background(), messages) + if err != nil { + return nil, err + } + + if err := response.Merge(sendMessagesResponse); err != nil { + return nil, err + } + + return response, nil +} diff --git a/protocol/requests/share_image_message.go b/protocol/requests/share_image_message.go new file mode 100644 index 000000000..c9c0cedd7 --- /dev/null +++ b/protocol/requests/share_image_message.go @@ -0,0 +1,27 @@ +package requests + +import ( + "errors" + + "github.com/status-im/status-go/eth-node/types" +) + +var ErrShareMessageInvalidID = errors.New("share image message: invalid id") +var ErrShareMessageEmptyUsers = errors.New("share image message: empty users") + +type ShareImageMessage struct { + MessageID string `json:"id"` + Users []types.HexBytes `json:"users"` +} + +func (s *ShareImageMessage) Validate() error { + if len(s.MessageID) == 0 { + return ErrShareMessageInvalidID + } + + if len(s.Users) == 0 { + return ErrShareMessageEmptyUsers + } + + return nil +} diff --git a/services/ext/api.go b/services/ext/api.go index 61dafdbc1..4369b7b7c 100644 --- a/services/ext/api.go +++ b/services/ext/api.go @@ -411,6 +411,11 @@ func (api *PublicAPI) ShareCommunity(request *requests.ShareCommunity) (*protoco return api.service.messenger.ShareCommunity(request) } +// ShareImageMessage share the selected chat image with a set of users +func (api *PublicAPI) ShareImageMessage(request *requests.ShareImageMessage) (*protocol.MessengerResponse, error) { + return api.service.messenger.ShareImageMessage(request) +} + // RemoveUserFromCommunity removes the user with pk from the community with ID func (api *PublicAPI) RemoveUserFromCommunity(communityID types.HexBytes, userPublicKey string) (*protocol.MessengerResponse, error) { return api.service.messenger.RemoveUserFromCommunity(communityID, userPublicKey)