Fix handling on public chat messages
This commit is contained in:
parent
b48522c59b
commit
bd1e6b0033
|
@ -26,6 +26,7 @@ const (
|
|||
)
|
||||
|
||||
var ErrMessageNotAllowed = errors.New("message from a non-contact")
|
||||
var ErrMessageForWrongChatType = errors.New("message for the wrong chat type")
|
||||
|
||||
// HandleMembershipUpdate updates a Chat instance according to the membership updates.
|
||||
// It retrieves chat, if exists, and merges membership updates from the message.
|
||||
|
@ -723,8 +724,10 @@ func (m *Messenger) HandleChatMessage(state *ReceivedMessageState) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if messages != nil {
|
||||
if len(messages) != 0 {
|
||||
chat.LastMessage = messages[0]
|
||||
} else {
|
||||
chat.LastMessage = nil
|
||||
}
|
||||
} else {
|
||||
err = chat.UpdateFromMessage(receivedMessage, m.getTimesource())
|
||||
|
@ -1008,6 +1011,9 @@ func (m *Messenger) matchChatEntity(chatEntity common.ChatEntity) (*Chat, error)
|
|||
if !ok {
|
||||
return nil, errors.New("received a public chatEntity from non-existing chat")
|
||||
}
|
||||
if !chat.Public() {
|
||||
return nil, ErrMessageForWrongChatType
|
||||
}
|
||||
return chat, nil
|
||||
case chatEntity.GetMessageType() == protobuf.MessageType_ONE_TO_ONE && common.IsPubKeyEqual(chatEntity.GetSigPubKey(), &m.identity.PublicKey):
|
||||
// It's a private message coming from us so we rely on Message.ChatID
|
||||
|
|
|
@ -28,6 +28,7 @@ import (
|
|||
"github.com/status-im/status-go/multiaccounts"
|
||||
"github.com/status-im/status-go/protocol/common"
|
||||
"github.com/status-im/status-go/protocol/protobuf"
|
||||
"github.com/status-im/status-go/protocol/requests"
|
||||
"github.com/status-im/status-go/protocol/tt"
|
||||
v1protocol "github.com/status-im/status-go/protocol/v1"
|
||||
"github.com/status-im/status-go/waku"
|
||||
|
@ -2505,3 +2506,61 @@ func (s *MessengerSuite) TestChatIdentity() {
|
|||
|
||||
spew.Dump(ci, len(ci.Images))
|
||||
}
|
||||
|
||||
func (s *MessengerSuite) TestPublicMessageOnCommunityChat() {
|
||||
alice := s.newMessenger(s.shh)
|
||||
bob := s.newMessenger(s.shh)
|
||||
|
||||
// Create a community
|
||||
description := &requests.CreateCommunity{
|
||||
Membership: protobuf.CommunityPermissions_NO_MEMBERSHIP,
|
||||
Name: "status",
|
||||
Color: "#ffffff",
|
||||
Description: "status community description",
|
||||
}
|
||||
|
||||
response, err := bob.CreateCommunity(description)
|
||||
s.Require().NoError(err)
|
||||
s.Require().NotNil(response)
|
||||
s.Require().Len(response.Communities(), 1)
|
||||
community := response.Communities()[0]
|
||||
|
||||
// Create a community chat
|
||||
response, err = bob.CreateCommunityChat(community.ID(), &protobuf.CommunityChat{
|
||||
Permissions: &protobuf.CommunityPermissions{
|
||||
Access: protobuf.CommunityPermissions_NO_MEMBERSHIP,
|
||||
},
|
||||
Identity: &protobuf.ChatIdentity{
|
||||
DisplayName: "community-name",
|
||||
},
|
||||
})
|
||||
s.Require().NoError(err)
|
||||
s.Require().NotNil(response)
|
||||
s.Require().Len(response.Chats(), 1)
|
||||
chat := response.Chats()[0]
|
||||
|
||||
inputMessage := buildTestMessage(*chat)
|
||||
inputMessage.ID = "1"
|
||||
inputMessage.Seen = false
|
||||
inputMessage.Text = "hey @" + common.PubkeyToHex(&s.m.identity.PublicKey)
|
||||
inputMessage.Mentioned = true
|
||||
inputMessage.MessageType = protobuf.MessageType_PUBLIC_GROUP
|
||||
|
||||
contact, err := BuildContactFromPublicKey(&alice.identity.PublicKey)
|
||||
s.Require().NoError(err)
|
||||
|
||||
// send a public chat message to a community on_request chat
|
||||
state := &ReceivedMessageState{
|
||||
Response: &MessengerResponse{},
|
||||
CurrentMessageState: &CurrentMessageState{
|
||||
Message: inputMessage.ChatMessage,
|
||||
MessageID: "0xabc",
|
||||
WhisperTimestamp: s.m.getTimesource().GetCurrentTime(),
|
||||
Contact: contact,
|
||||
PublicKey: &alice.identity.PublicKey,
|
||||
},
|
||||
}
|
||||
err = bob.HandleChatMessage(state)
|
||||
s.Require().Error(err)
|
||||
s.Require().Equal(ErrMessageForWrongChatType, err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue