Skip to content

Commit

Permalink
resolved conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
jo-mut committed Feb 24, 2022
1 parent 381c5f6 commit 7d956be
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 1 deletion.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.94.7
0.94.8
6 changes: 6 additions & 0 deletions protocol/message_persistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -152,6 +154,7 @@ func (db sqlitePersistence) tableUserMessagesScanAllFields(row scanner, message
&message.ParsedText,
&sticker.Pack,
&sticker.Hash,
&image.Payload,
&audio.DurationMs,
&message.Base64Audio,
&communityID,
Expand Down Expand Up @@ -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
Expand Down
41 changes: 41 additions & 0 deletions protocol/messenger_chats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
27 changes: 27 additions & 0 deletions protocol/requests/share_image_message.go
Original file line number Diff line number Diff line change
@@ -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
}
5 changes: 5 additions & 0 deletions services/ext/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7d956be

Please sign in to comment.