Updated all MessageType references

This commit is contained in:
Samuel Hawksby-Robinson 2020-07-25 12:46:43 +01:00 committed by Andrea Maria Piana
parent c0a0238b0e
commit ceed618102
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
8 changed files with 57 additions and 51 deletions

View File

@ -44,7 +44,7 @@ func (s *MessageProcessorSuite) SetupTest() {
Text: "abc123",
ChatId: "testing-adamb",
ContentType: protobuf.ChatMessage_TEXT_PLAIN,
MessageType: protobuf.ChatMessage_PUBLIC_GROUP,
MessageType: protobuf.MessageType_PUBLIC_GROUP,
Clock: 154593077368201,
Timestamp: 1545930773682,
}

View File

@ -60,7 +60,7 @@ func eventToSystemMessage(e v1protocol.MembershipUpdateEvent, translations map[p
ChatMessage: protobuf.ChatMessage{
ChatId: e.ChatID,
Text: text,
MessageType: protobuf.ChatMessage_SYSTEM_MESSAGE_PRIVATE_GROUP,
MessageType: protobuf.MessageType_SYSTEM_MESSAGE_PRIVATE_GROUP,
ContentType: protobuf.ChatMessage_SYSTEM_MESSAGE_CONTENT_PRIVATE_GROUP,
Clock: e.ClockValue,
Timestamp: timestamp,

View File

@ -148,7 +148,7 @@ func (m *Message) MarshalJSON() ([]byte, error) {
CommandParameters *CommandParameters `json:"commandParameters"`
Timestamp uint64 `json:"timestamp"`
ContentType protobuf.ChatMessage_ContentType `json:"contentType"`
MessageType protobuf.ChatMessage_MessageType `json:"messageType"`
MessageType protobuf.MessageType `json:"messageType"`
}{
ID: m.ID,
WhisperTimestamp: m.WhisperTimestamp,

View File

@ -377,7 +377,7 @@ func (m *MessageHandler) HandleRequestAddressForTransaction(messageState *Receiv
Timestamp: messageState.CurrentMessageState.WhisperTimestamp,
Text: "Request address for transaction",
ChatId: contactIDFromPublicKey(&m.identity.PublicKey),
MessageType: protobuf.ChatMessage_ONE_TO_ONE,
MessageType: protobuf.MessageType_ONE_TO_ONE,
ContentType: protobuf.ChatMessage_TRANSACTION_COMMAND,
},
CommandParameters: &CommandParameters{
@ -401,7 +401,7 @@ func (m *MessageHandler) HandleRequestTransaction(messageState *ReceivedMessageS
Timestamp: messageState.CurrentMessageState.WhisperTimestamp,
Text: "Request transaction",
ChatId: contactIDFromPublicKey(&m.identity.PublicKey),
MessageType: protobuf.ChatMessage_ONE_TO_ONE,
MessageType: protobuf.MessageType_ONE_TO_ONE,
ContentType: protobuf.ChatMessage_TRANSACTION_COMMAND,
},
CommandParameters: &CommandParameters{
@ -574,7 +574,7 @@ func (m *MessageHandler) matchMessage(message *Message, chats map[string]*Chat,
}
switch {
case message.MessageType == protobuf.ChatMessage_PUBLIC_GROUP:
case message.MessageType == protobuf.MessageType_PUBLIC_GROUP:
// For public messages, all outgoing and incoming messages have the same chatID
// equal to a public chat name.
chatID := message.ChatId
@ -583,7 +583,7 @@ func (m *MessageHandler) matchMessage(message *Message, chats map[string]*Chat,
return nil, errors.New("received a public message from non-existing chat")
}
return chat, nil
case message.MessageType == protobuf.ChatMessage_ONE_TO_ONE && common.IsPubKeyEqual(message.SigPubKey, &m.identity.PublicKey):
case message.MessageType == protobuf.MessageType_ONE_TO_ONE && common.IsPubKeyEqual(message.SigPubKey, &m.identity.PublicKey):
// It's a private message coming from us so we rely on Message.ChatID
// If chat does not exist, it should be created to support multidevice synchronization.
chatID := message.ChatId
@ -606,7 +606,7 @@ func (m *MessageHandler) matchMessage(message *Message, chats map[string]*Chat,
chat = &newChat
}
return chat, nil
case message.MessageType == protobuf.ChatMessage_ONE_TO_ONE:
case message.MessageType == protobuf.MessageType_ONE_TO_ONE:
// It's an incoming private message. ChatID is calculated from the signature.
// If a chat does not exist, a new one is created and saved.
chatID := contactIDFromPublicKey(message.SigPubKey)
@ -617,7 +617,7 @@ func (m *MessageHandler) matchMessage(message *Message, chats map[string]*Chat,
chat = &newChat
}
return chat, nil
case message.MessageType == protobuf.ChatMessage_PRIVATE_GROUP:
case message.MessageType == protobuf.MessageType_PRIVATE_GROUP:
// In the case of a group message, ChatID is the same for all messages belonging to a group.
// It needs to be verified if the signature public key belongs to the chat.
chatID := message.ChatId
@ -691,4 +691,4 @@ func (m *MessageHandler) HandleEmojiReaction(state *ReceivedMessageState, messag
state.AllChats[chat.ID] = chat
return nil
}
}

View File

@ -167,7 +167,7 @@ func ValidateReceivedChatMessage(message *protobuf.ChatMessage, whisperTimestamp
return errors.New("chatId can't be empty")
}
if message.MessageType == protobuf.ChatMessage_UNKNOWN_MESSAGE_TYPE || message.MessageType == protobuf.ChatMessage_SYSTEM_MESSAGE_PRIVATE_GROUP {
if message.MessageType == protobuf.MessageType_UNKNOWN_MESSAGE_TYPE || message.MessageType == protobuf.MessageType_SYSTEM_MESSAGE_PRIVATE_GROUP {
return errors.New("unknown message type")
}

View File

@ -103,7 +103,7 @@ func (s *MessageValidatorSuite) TestValidatePlainTextMessage() {
Text: "some-text",
ResponseTo: "",
EnsName: "",
MessageType: protobuf.ChatMessage_ONE_TO_ONE,
MessageType: protobuf.MessageType_ONE_TO_ONE,
ContentType: protobuf.ChatMessage_TEXT_PLAIN,
},
},
@ -117,7 +117,7 @@ func (s *MessageValidatorSuite) TestValidatePlainTextMessage() {
Text: "some-text",
ResponseTo: "",
EnsName: "",
MessageType: protobuf.ChatMessage_ONE_TO_ONE,
MessageType: protobuf.MessageType_ONE_TO_ONE,
ContentType: protobuf.ChatMessage_TEXT_PLAIN,
},
},
@ -131,7 +131,7 @@ func (s *MessageValidatorSuite) TestValidatePlainTextMessage() {
Text: "some-text",
ResponseTo: "",
EnsName: "",
MessageType: protobuf.ChatMessage_ONE_TO_ONE,
MessageType: protobuf.MessageType_ONE_TO_ONE,
ContentType: protobuf.ChatMessage_TEXT_PLAIN,
},
},
@ -146,7 +146,7 @@ func (s *MessageValidatorSuite) TestValidatePlainTextMessage() {
Text: "some-text",
ResponseTo: "",
EnsName: "",
MessageType: protobuf.ChatMessage_ONE_TO_ONE,
MessageType: protobuf.MessageType_ONE_TO_ONE,
ContentType: protobuf.ChatMessage_TEXT_PLAIN,
},
},
@ -160,7 +160,7 @@ func (s *MessageValidatorSuite) TestValidatePlainTextMessage() {
Text: "some-text",
ResponseTo: "",
EnsName: "",
MessageType: protobuf.ChatMessage_ONE_TO_ONE,
MessageType: protobuf.MessageType_ONE_TO_ONE,
ContentType: protobuf.ChatMessage_TEXT_PLAIN,
},
},
@ -174,7 +174,7 @@ func (s *MessageValidatorSuite) TestValidatePlainTextMessage() {
Timestamp: 3,
ResponseTo: "",
EnsName: "",
MessageType: protobuf.ChatMessage_ONE_TO_ONE,
MessageType: protobuf.MessageType_ONE_TO_ONE,
ContentType: protobuf.ChatMessage_TEXT_PLAIN,
},
},
@ -189,7 +189,7 @@ func (s *MessageValidatorSuite) TestValidatePlainTextMessage() {
Timestamp: 3,
ResponseTo: "",
EnsName: "",
MessageType: protobuf.ChatMessage_ONE_TO_ONE,
MessageType: protobuf.MessageType_ONE_TO_ONE,
ContentType: protobuf.ChatMessage_TEXT_PLAIN,
},
},
@ -204,7 +204,7 @@ func (s *MessageValidatorSuite) TestValidatePlainTextMessage() {
Timestamp: 3,
ResponseTo: "",
EnsName: "",
MessageType: protobuf.ChatMessage_UNKNOWN_MESSAGE_TYPE,
MessageType: protobuf.MessageType_UNKNOWN_MESSAGE_TYPE,
ContentType: protobuf.ChatMessage_TEXT_PLAIN,
},
},
@ -219,7 +219,7 @@ func (s *MessageValidatorSuite) TestValidatePlainTextMessage() {
Timestamp: 3,
ResponseTo: "",
EnsName: "",
MessageType: protobuf.ChatMessage_ONE_TO_ONE,
MessageType: protobuf.MessageType_ONE_TO_ONE,
ContentType: protobuf.ChatMessage_UNKNOWN_CONTENT_TYPE,
},
},
@ -234,7 +234,7 @@ func (s *MessageValidatorSuite) TestValidatePlainTextMessage() {
Timestamp: 3,
ResponseTo: "",
EnsName: "",
MessageType: protobuf.ChatMessage_SYSTEM_MESSAGE_PRIVATE_GROUP,
MessageType: protobuf.MessageType_SYSTEM_MESSAGE_PRIVATE_GROUP,
ContentType: protobuf.ChatMessage_TEXT_PLAIN,
},
},
@ -249,7 +249,7 @@ func (s *MessageValidatorSuite) TestValidatePlainTextMessage() {
Timestamp: 3,
ResponseTo: "",
EnsName: "",
MessageType: protobuf.ChatMessage_ONE_TO_ONE,
MessageType: protobuf.MessageType_ONE_TO_ONE,
ContentType: protobuf.ChatMessage_TRANSACTION_COMMAND,
},
},
@ -264,7 +264,7 @@ func (s *MessageValidatorSuite) TestValidatePlainTextMessage() {
Timestamp: 3,
ResponseTo: "",
EnsName: "",
MessageType: protobuf.ChatMessage_ONE_TO_ONE,
MessageType: protobuf.MessageType_ONE_TO_ONE,
ContentType: protobuf.ChatMessage_EMOJI,
},
},
@ -301,7 +301,7 @@ func (s *MessageValidatorSuite) TestValidatePlainTextMessage() {
Hash: "some-hash",
},
},
MessageType: protobuf.ChatMessage_ONE_TO_ONE,
MessageType: protobuf.MessageType_ONE_TO_ONE,
ContentType: protobuf.ChatMessage_STICKER,
},
},
@ -321,7 +321,7 @@ func (s *MessageValidatorSuite) TestValidatePlainTextMessage() {
Pack: 1,
},
},
MessageType: protobuf.ChatMessage_ONE_TO_ONE,
MessageType: protobuf.MessageType_ONE_TO_ONE,
ContentType: protobuf.ChatMessage_STICKER,
},
},
@ -336,7 +336,7 @@ func (s *MessageValidatorSuite) TestValidatePlainTextMessage() {
Timestamp: 3,
ResponseTo: "",
EnsName: "",
MessageType: protobuf.ChatMessage_ONE_TO_ONE,
MessageType: protobuf.MessageType_ONE_TO_ONE,
ContentType: protobuf.ChatMessage_STICKER,
},
},
@ -357,7 +357,7 @@ func (s *MessageValidatorSuite) TestValidatePlainTextMessage() {
Payload: []byte("some-payload"),
},
},
MessageType: protobuf.ChatMessage_ONE_TO_ONE,
MessageType: protobuf.MessageType_ONE_TO_ONE,
ContentType: protobuf.ChatMessage_IMAGE,
},
},
@ -378,7 +378,7 @@ func (s *MessageValidatorSuite) TestValidatePlainTextMessage() {
Payload: []byte("some-payload"),
},
},
MessageType: protobuf.ChatMessage_ONE_TO_ONE,
MessageType: protobuf.MessageType_ONE_TO_ONE,
ContentType: protobuf.ChatMessage_STICKER,
},
},
@ -398,7 +398,7 @@ func (s *MessageValidatorSuite) TestValidatePlainTextMessage() {
Type: 1,
},
},
MessageType: protobuf.ChatMessage_ONE_TO_ONE,
MessageType: protobuf.MessageType_ONE_TO_ONE,
ContentType: protobuf.ChatMessage_IMAGE,
},
},

View File

@ -1428,20 +1428,20 @@ func (m *Messenger) SendChatMessage(ctx context.Context, message *Message) (*Mes
switch chat.ChatType {
case ChatTypeOneToOne:
logger.Debug("sending private message")
message.MessageType = protobuf.ChatMessage_ONE_TO_ONE
message.MessageType = protobuf.MessageType_ONE_TO_ONE
encodedMessage, err = proto.Marshal(message)
if err != nil {
return nil, err
}
case ChatTypePublic:
logger.Debug("sending public message", zap.String("chatName", chat.Name))
message.MessageType = protobuf.ChatMessage_PUBLIC_GROUP
message.MessageType = protobuf.MessageType_PUBLIC_GROUP
encodedMessage, err = proto.Marshal(message)
if err != nil {
return nil, err
}
case ChatTypePrivateGroupChat:
message.MessageType = protobuf.ChatMessage_PRIVATE_GROUP
message.MessageType = protobuf.MessageType_PRIVATE_GROUP
logger.Debug("sending group message", zap.String("chatName", chat.Name))
group, err := newProtocolGroupFromChat(chat)
@ -1899,6 +1899,7 @@ func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filte
logger.Warn("failed to handle ChatMessage", zap.Error(err))
continue
}
case protobuf.PairInstallation:
if !common.IsPubKeyEqual(messageState.CurrentMessageState.PublicKey, &m.identity.PublicKey) {
logger.Warn("not coming from us, ignoring")
@ -1925,6 +1926,7 @@ func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filte
logger.Warn("failed to handle SyncInstallationContact", zap.Error(err))
continue
}
case protobuf.SyncInstallationPublicChat:
if !common.IsPubKeyEqual(messageState.CurrentMessageState.PublicKey, &m.identity.PublicKey) {
logger.Warn("not coming from us, ignoring")
@ -1938,6 +1940,7 @@ func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filte
logger.Warn("failed to handle SyncInstallationPublicChat", zap.Error(err))
continue
}
case protobuf.RequestAddressForTransaction:
command := msg.ParsedMessage.(protobuf.RequestAddressForTransaction)
logger.Debug("Handling RequestAddressForTransaction", zap.Any("message", command))
@ -1946,6 +1949,7 @@ func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filte
logger.Warn("failed to handle RequestAddressForTransaction", zap.Error(err))
continue
}
case protobuf.SendTransaction:
command := msg.ParsedMessage.(protobuf.SendTransaction)
logger.Debug("Handling SendTransaction", zap.Any("message", command))
@ -1954,6 +1958,7 @@ func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filte
logger.Warn("failed to handle SendTransaction", zap.Error(err))
continue
}
case protobuf.AcceptRequestAddressForTransaction:
command := msg.ParsedMessage.(protobuf.AcceptRequestAddressForTransaction)
logger.Debug("Handling AcceptRequestAddressForTransaction")
@ -1989,11 +1994,10 @@ func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filte
logger.Warn("failed to handle RequestTransaction", zap.Error(err))
continue
}
case protobuf.ContactUpdate:
logger.Debug("Handling ContactUpdate")
contactUpdate := msg.ParsedMessage.(protobuf.ContactUpdate)
err = m.handler.HandleContactUpdate(messageState, contactUpdate)
if err != nil {
logger.Warn("failed to handle ContactUpdate", zap.Error(err))
@ -2057,6 +2061,7 @@ func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filte
// We continue in any case, no changes to messenger
continue
case protobuf.EmojiReaction:
logger.Debug("Handling EmojiReaction")
err = m.handler.HandleEmojiReaction(messageState, msg.ParsedMessage.(protobuf.EmojiReaction))
if err != nil {
logger.Warn("failed to handle EmojiReaction", zap.Error(err))
@ -2064,6 +2069,7 @@ func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filte
}
case protobuf.EmojiReactionRetraction:
logger.Debug("Handling EmojiReactionRetraction")
err = m.handler.HandleEmojiReactionRetraction(messageState, msg.ParsedMessage.(protobuf.EmojiReactionRetraction))
if err != nil {
logger.Warn("failed to handle EmojiReactionRetraction", zap.Error(err))
@ -2394,7 +2400,7 @@ func (m *Messenger) RequestTransaction(ctx context.Context, chatID, value, contr
return nil, err
}
message.MessageType = protobuf.ChatMessage_ONE_TO_ONE
message.MessageType = protobuf.MessageType_ONE_TO_ONE
message.ContentType = protobuf.ChatMessage_TRANSACTION_COMMAND
message.Text = "Request transaction"
@ -2471,7 +2477,7 @@ func (m *Messenger) RequestAddressForTransaction(ctx context.Context, chatID, fr
return nil, err
}
message.MessageType = protobuf.ChatMessage_ONE_TO_ONE
message.MessageType = protobuf.MessageType_ONE_TO_ONE
message.ContentType = protobuf.ChatMessage_TRANSACTION_COMMAND
message.Text = "Request address for transaction"
@ -2905,7 +2911,7 @@ func (m *Messenger) SendTransaction(ctx context.Context, chatID, value, contract
return nil, err
}
message.MessageType = protobuf.ChatMessage_ONE_TO_ONE
message.MessageType = protobuf.MessageType_ONE_TO_ONE
message.ContentType = protobuf.ChatMessage_TRANSACTION_COMMAND
message.LocalChatID = chatID
@ -3006,7 +3012,7 @@ func (m *Messenger) ValidateTransactions(ctx context.Context, addresses []types.
}
}
message.MessageType = protobuf.ChatMessage_ONE_TO_ONE
message.MessageType = protobuf.MessageType_ONE_TO_ONE
message.ContentType = protobuf.ChatMessage_TRANSACTION_COMMAND
message.LocalChatID = chatID
message.OutgoingStatus = ""

View File

@ -295,11 +295,11 @@ func buildTestMessage(chat Chat) *Message {
message.ContentType = protobuf.ChatMessage_TEXT_PLAIN
switch chat.ChatType {
case ChatTypePublic:
message.MessageType = protobuf.ChatMessage_PUBLIC_GROUP
message.MessageType = protobuf.MessageType_PUBLIC_GROUP
case ChatTypeOneToOne:
message.MessageType = protobuf.ChatMessage_ONE_TO_ONE
message.MessageType = protobuf.MessageType_ONE_TO_ONE
case ChatTypePrivateGroupChat:
message.MessageType = protobuf.ChatMessage_PRIVATE_GROUP
message.MessageType = protobuf.MessageType_PRIVATE_GROUP
}
return message
@ -371,7 +371,7 @@ func (s *MessengerSuite) TestSendPublic() {
s.Require().True(outputMessage.Seen, "it marks the message as seen")
s.Require().Equal(outputMessage.OutgoingStatus, OutgoingStatusSending, "it marks the message as sending")
s.Require().NotEmpty(outputMessage.ID, "it sets the ID field")
s.Require().Equal(protobuf.ChatMessage_PUBLIC_GROUP, outputMessage.MessageType)
s.Require().Equal(protobuf.MessageType_PUBLIC_GROUP, outputMessage.MessageType)
savedMessages, _, err := s.m.MessageByChatID(chat.ID, "", 10)
s.Require().NoError(err)
@ -402,7 +402,7 @@ func (s *MessengerSuite) TestSendPrivateOneToOne() {
s.Require().True(outputMessage.Seen, "it marks the message as seen")
s.Require().Equal(outputMessage.OutgoingStatus, OutgoingStatusSending, "it marks the message as sending")
s.Require().NotEmpty(outputMessage.ID, "it sets the ID field")
s.Require().Equal(protobuf.ChatMessage_ONE_TO_ONE, outputMessage.MessageType)
s.Require().Equal(protobuf.MessageType_ONE_TO_ONE, outputMessage.MessageType)
}
func (s *MessengerSuite) TestSendPrivateGroup() {
@ -435,7 +435,7 @@ func (s *MessengerSuite) TestSendPrivateGroup() {
s.Require().True(outputMessage.Seen, "it marks the message as seen")
s.Require().Equal(outputMessage.OutgoingStatus, OutgoingStatusSending, "it marks the message as sending")
s.Require().NotEmpty(outputMessage.ID, "it sets the ID field")
s.Require().Equal(protobuf.ChatMessage_PRIVATE_GROUP, outputMessage.MessageType)
s.Require().Equal(protobuf.MessageType_PRIVATE_GROUP, outputMessage.MessageType)
}
func (s *MessengerSuite) TestSendPrivateEmptyGroup() {
@ -463,7 +463,7 @@ func (s *MessengerSuite) TestSendPrivateEmptyGroup() {
s.Require().True(outputMessage.Seen, "it marks the message as seen")
s.Require().Equal(outputMessage.OutgoingStatus, OutgoingStatusSending, "it marks the message as sending")
s.Require().NotEmpty(outputMessage.ID, "it sets the ID field")
s.Require().Equal(protobuf.ChatMessage_PRIVATE_GROUP, outputMessage.MessageType)
s.Require().Equal(protobuf.MessageType_PRIVATE_GROUP, outputMessage.MessageType)
}
// Make sure public messages sent by us are not
@ -2168,7 +2168,7 @@ func (s *MessageHandlerSuite) TestRun() {
Message: Message{
ChatMessage: protobuf.ChatMessage{
ChatId: "test-chat",
MessageType: protobuf.ChatMessage_PUBLIC_GROUP,
MessageType: protobuf.MessageType_PUBLIC_GROUP,
Text: "test-text"},
},
SigPubKey: &key1.PublicKey,
@ -2180,7 +2180,7 @@ func (s *MessageHandlerSuite) TestRun() {
Message: Message{
ChatMessage: protobuf.ChatMessage{
ChatId: "test-chat",
MessageType: protobuf.ChatMessage_ONE_TO_ONE,
MessageType: protobuf.MessageType_ONE_TO_ONE,
Text: "test-text"},
},
SigPubKey: &key1.PublicKey,
@ -2192,7 +2192,7 @@ func (s *MessageHandlerSuite) TestRun() {
Message: Message{
ChatMessage: protobuf.ChatMessage{
ChatId: "test-chat",
MessageType: protobuf.ChatMessage_ONE_TO_ONE,
MessageType: protobuf.MessageType_ONE_TO_ONE,
Text: "test-text"},
},
@ -2204,7 +2204,7 @@ func (s *MessageHandlerSuite) TestRun() {
Message: Message{
ChatMessage: protobuf.ChatMessage{
ChatId: "test-chat",
MessageType: protobuf.ChatMessage_ONE_TO_ONE,
MessageType: protobuf.MessageType_ONE_TO_ONE,
Text: "test-text"},
},
@ -2216,7 +2216,7 @@ func (s *MessageHandlerSuite) TestRun() {
Message: Message{
ChatMessage: protobuf.ChatMessage{
ChatId: "test-chat",
MessageType: protobuf.ChatMessage_ONE_TO_ONE,
MessageType: protobuf.MessageType_ONE_TO_ONE,
Text: "test-text"},
},
@ -2233,7 +2233,7 @@ func (s *MessageHandlerSuite) TestRun() {
Message: Message{
ChatMessage: protobuf.ChatMessage{
ChatId: "non-existing-chat",
MessageType: protobuf.ChatMessage_PRIVATE_GROUP,
MessageType: protobuf.MessageType_PRIVATE_GROUP,
Text: "test-text"},
},
Error: true,