Drop audio messages in public chats

This commit is contained in:
frank 2021-04-13 11:01:37 +08:00 committed by Andrea Maria Piana
parent 11c46edd8b
commit c799e5eb6b
3 changed files with 57 additions and 3 deletions

View File

@ -1 +1 @@
0.80.4
0.80.5

View File

@ -581,8 +581,13 @@ func (m *Messenger) HandleChatMessage(state *ReceivedMessageState) error {
// It looks like status-react created profile chats as public chats
// so for now we need to check for the presence of "@" in their chatID
if chat.Public() && receivedMessage.ContentType == protobuf.ChatMessage_IMAGE && !chat.ProfileUpdates() {
return errors.New("images are not allowed in public chats")
if chat.Public() && !chat.ProfileUpdates() {
switch receivedMessage.ContentType {
case protobuf.ChatMessage_IMAGE:
return errors.New("images are not allowed in public chats")
case protobuf.ChatMessage_AUDIO:
return errors.New("audio messages are not allowed in public chats")
}
}
// If profile updates check if author is the same as chat profile public key

View File

@ -308,6 +308,27 @@ func (s *MessengerSuite) TestInit() {
}
}
func buildAudioMessage(s *MessengerSuite, chat Chat) *common.Message {
clock, timestamp := chat.NextClockAndTimestamp(&testTimeSource{})
message := &common.Message{}
message.Text = "text-input-message"
message.ChatId = chat.ID
message.Clock = clock
message.Timestamp = timestamp
message.WhisperTimestamp = clock
message.LocalChatID = chat.ID
message.MessageType = protobuf.MessageType_PUBLIC_GROUP
message.ContentType = protobuf.ChatMessage_AUDIO
message.Payload = &protobuf.ChatMessage_Audio{
Audio: &protobuf.AudioMessage{
Type: 1,
Payload: []byte("some-payload"),
},
}
return message
}
func buildTestMessage(chat Chat) *common.Message {
clock, timestamp := chat.NextClockAndTimestamp(&testTimeSource{})
message := &common.Message{}
@ -614,6 +635,34 @@ func (s *MessengerSuite) TestRetrieveTheirPublic() {
s.Require().NoError(theirMessenger.Shutdown())
}
// Drop audio message in public group
func (s *MessengerSuite) TestDropAudioMessageInPublicGroup() {
theirMessenger := s.newMessenger(s.shh)
_, err := theirMessenger.Start()
s.Require().NoError(err)
theirChat := CreatePublicChat("status", s.m.transport)
err = theirMessenger.SaveChat(theirChat)
s.Require().NoError(err)
chat := CreatePublicChat("status", s.m.transport)
err = s.m.SaveChat(chat)
s.Require().NoError(err)
_, err = s.m.Join(chat)
s.Require().NoError(err)
inputMessage := buildAudioMessage(s, *chat)
_, err = theirMessenger.SendChatMessage(context.Background(), inputMessage)
s.NoError(err)
time.Sleep(100 * time.Millisecond)
response, err := s.m.RetrieveAll()
s.Require().NoError(err)
s.Require().Len(response.Messages(), 0)
s.Require().NoError(theirMessenger.Shutdown())
}
func (s *MessengerSuite) TestDeletedAtClockValue() {
theirMessenger := s.newMessenger(s.shh)
_, err := theirMessenger.Start()