2019-11-21 16:19:22 +00:00
|
|
|
package protocol
|
2019-08-06 21:50:13 +00:00
|
|
|
|
|
|
|
import (
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
"crypto/ecdsa"
|
|
|
|
"encoding/json"
|
|
|
|
"strings"
|
|
|
|
"unicode"
|
|
|
|
"unicode/utf8"
|
2019-08-06 21:50:13 +00:00
|
|
|
|
2020-02-10 16:52:43 +00:00
|
|
|
"github.com/status-im/markdown"
|
2020-01-02 09:10:19 +00:00
|
|
|
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
"github.com/status-im/status-go/protocol/protobuf"
|
2019-08-06 21:50:13 +00:00
|
|
|
)
|
|
|
|
|
2019-08-20 11:20:25 +00:00
|
|
|
// QuotedMessage contains the original text of the message replied to
|
|
|
|
type QuotedMessage struct {
|
|
|
|
// From is a public key of the author of the message.
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
From string `json:"from"`
|
|
|
|
Text string `json:"text"`
|
2019-08-20 11:20:25 +00:00
|
|
|
}
|
|
|
|
|
2020-01-10 18:59:01 +00:00
|
|
|
type CommandState int
|
|
|
|
|
|
|
|
const (
|
|
|
|
CommandStateRequestAddressForTransaction CommandState = iota + 1
|
|
|
|
CommandStateRequestAddressForTransactionDeclined
|
|
|
|
CommandStateRequestAddressForTransactionAccepted
|
|
|
|
CommandStateRequestTransaction
|
|
|
|
CommandStateRequestTransactionDeclined
|
|
|
|
CommandStateTransactionPending
|
|
|
|
CommandStateTransactionSent
|
|
|
|
)
|
|
|
|
|
|
|
|
type CommandParameters struct {
|
|
|
|
// ID is the ID of the initial message
|
|
|
|
ID string `json:"id"`
|
|
|
|
// From is the address we are sending the command from
|
|
|
|
From string `json:"from"`
|
|
|
|
// Address is the address sent with the command
|
|
|
|
Address string `json:"address"`
|
|
|
|
// Contract is the contract address for ERC20 tokens
|
|
|
|
Contract string `json:"contract"`
|
|
|
|
// Value is the value as a string sent
|
|
|
|
Value string `json:"value"`
|
|
|
|
// TransactionHash is the hash of the transaction
|
|
|
|
TransactionHash string `json:"transactionHash"`
|
|
|
|
// CommandState is the state of the command
|
|
|
|
CommandState CommandState `json:"commandState"`
|
|
|
|
// The Signature of the pk-bytes+transaction-hash from the wallet
|
|
|
|
// address originating
|
|
|
|
Signature []byte `json:"signature"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *CommandParameters) IsTokenTransfer() bool {
|
|
|
|
return len(c.Contract) != 0
|
|
|
|
}
|
|
|
|
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
const (
|
|
|
|
OutgoingStatusSending = "sending"
|
|
|
|
OutgoingStatusSent = "sent"
|
|
|
|
)
|
|
|
|
|
2019-08-06 21:50:13 +00:00
|
|
|
// Message represents a message record in the database,
|
2020-01-10 18:59:01 +00:00
|
|
|
// more specifically in user_messages table.
|
2019-08-06 21:50:13 +00:00
|
|
|
type Message struct {
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
protobuf.ChatMessage
|
|
|
|
|
2019-08-06 21:50:13 +00:00
|
|
|
// ID calculated as keccak256(compressedAuthorPubKey, data) where data is unencrypted payload.
|
|
|
|
ID string `json:"id"`
|
|
|
|
// WhisperTimestamp is a timestamp of a Whisper envelope.
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
WhisperTimestamp uint64 `json:"whisperTimestamp"`
|
2019-08-06 21:50:13 +00:00
|
|
|
// From is a public key of the author of the message.
|
2019-08-20 11:20:25 +00:00
|
|
|
From string `json:"from"`
|
2019-09-26 07:01:17 +00:00
|
|
|
// Random 3 words name
|
|
|
|
Alias string `json:"alias"`
|
|
|
|
// Identicon of the author
|
|
|
|
Identicon string `json:"identicon"`
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
// The chat id to be stored locally
|
|
|
|
LocalChatID string `json:"localChatId"`
|
|
|
|
|
2019-08-06 21:50:13 +00:00
|
|
|
Seen bool `json:"seen"`
|
|
|
|
OutgoingStatus string `json:"outgoingStatus,omitempty"`
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
|
2019-08-20 11:20:25 +00:00
|
|
|
QuotedMessage *QuotedMessage `json:"quotedMessage"`
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
|
2020-01-10 18:59:01 +00:00
|
|
|
// CommandParameters is the parameters sent with the message
|
|
|
|
CommandParameters *CommandParameters `json:"commandParameters"`
|
|
|
|
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
// Computed fields
|
Add replies to messages
Currently replies to messages are handled in status-react.
This causes some issues with the fact that sometimes replies might come
out of order, they might be offloaded to the database etc.
This commit changes the behavior so that status-go always returns the
replies, and in case a reply comes out of order (first the reply, later
the message being replied to), it will include in the messages the
updated message.
It also adds some fields (RTL,Replace,LineCount) to the database which
were not previously saved, resulting in some potential bugs.
The method that we use to pull replies is currently a bit naive, we just
pull all the message again from the database, but has the advantage of
being simple. It will go through performance testing to make sure
performnace are acceptable, if so I think it's reasonable to avoid some
complexity.
2020-04-08 13:42:02 +00:00
|
|
|
// RTL is whether this is a right-to-left message (arabic/hebrew script etc)
|
|
|
|
RTL bool `json:"rtl"`
|
|
|
|
// ParsedText is the parsed markdown for displaying
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
ParsedText []byte `json:"parsedText"`
|
Add replies to messages
Currently replies to messages are handled in status-react.
This causes some issues with the fact that sometimes replies might come
out of order, they might be offloaded to the database etc.
This commit changes the behavior so that status-go always returns the
replies, and in case a reply comes out of order (first the reply, later
the message being replied to), it will include in the messages the
updated message.
It also adds some fields (RTL,Replace,LineCount) to the database which
were not previously saved, resulting in some potential bugs.
The method that we use to pull replies is currently a bit naive, we just
pull all the message again from the database, but has the advantage of
being simple. It will go through performance testing to make sure
performnace are acceptable, if so I think it's reasonable to avoid some
complexity.
2020-04-08 13:42:02 +00:00
|
|
|
// LineCount is the count of newlines in the message
|
|
|
|
LineCount int `json:"lineCount"`
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
|
2020-01-10 18:59:01 +00:00
|
|
|
// Replace indicates that this is a replacement of a message
|
|
|
|
// that has been updated
|
2020-02-10 11:22:37 +00:00
|
|
|
Replace string `json:"replace,omitempty"`
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
SigPubKey *ecdsa.PublicKey `json:"-"`
|
2020-01-10 18:59:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// RawMessage represent a sent or received message, kept for being able
|
|
|
|
// to re-send/propagate
|
|
|
|
type RawMessage struct {
|
|
|
|
ID string
|
|
|
|
LocalChatID string
|
|
|
|
LastSent uint64
|
|
|
|
SendCount int
|
|
|
|
Sent bool
|
|
|
|
ResendAutomatically bool
|
|
|
|
MessageType protobuf.ApplicationMetadataMessage_Type
|
|
|
|
Payload []byte
|
|
|
|
Recipients []*ecdsa.PublicKey
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Message) MarshalJSON() ([]byte, error) {
|
2020-01-15 07:25:09 +00:00
|
|
|
type StickerAlias struct {
|
|
|
|
Hash string `json:"hash"`
|
|
|
|
Pack int32 `json:"pack"`
|
|
|
|
}
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
item := struct {
|
2020-01-10 18:59:01 +00:00
|
|
|
ID string `json:"id"`
|
|
|
|
WhisperTimestamp uint64 `json:"whisperTimestamp"`
|
|
|
|
From string `json:"from"`
|
|
|
|
Alias string `json:"alias"`
|
|
|
|
Identicon string `json:"identicon"`
|
|
|
|
Seen bool `json:"seen"`
|
|
|
|
OutgoingStatus string `json:"outgoingStatus,omitempty"`
|
|
|
|
QuotedMessage *QuotedMessage `json:"quotedMessage"`
|
|
|
|
RTL bool `json:"rtl"`
|
|
|
|
ParsedText json.RawMessage `json:"parsedText"`
|
|
|
|
LineCount int `json:"lineCount"`
|
|
|
|
Text string `json:"text"`
|
2020-02-10 11:22:37 +00:00
|
|
|
ChatID string `json:"chatId"`
|
2020-01-10 18:59:01 +00:00
|
|
|
LocalChatID string `json:"localChatId"`
|
|
|
|
Clock uint64 `json:"clock"`
|
2020-02-10 11:22:37 +00:00
|
|
|
Replace string `json:"replace"`
|
2020-01-10 18:59:01 +00:00
|
|
|
ResponseTo string `json:"responseTo"`
|
|
|
|
EnsName string `json:"ensName"`
|
2020-01-15 07:25:09 +00:00
|
|
|
Sticker *StickerAlias `json:"sticker"`
|
2020-01-10 18:59:01 +00:00
|
|
|
CommandParameters *CommandParameters `json:"commandParameters"`
|
|
|
|
Timestamp uint64 `json:"timestamp"`
|
|
|
|
ContentType protobuf.ChatMessage_ContentType `json:"contentType"`
|
|
|
|
MessageType protobuf.ChatMessage_MessageType `json:"messageType"`
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
}{
|
2020-01-10 18:59:01 +00:00
|
|
|
ID: m.ID,
|
|
|
|
WhisperTimestamp: m.WhisperTimestamp,
|
|
|
|
From: m.From,
|
|
|
|
Alias: m.Alias,
|
|
|
|
Identicon: m.Identicon,
|
|
|
|
Seen: m.Seen,
|
|
|
|
OutgoingStatus: m.OutgoingStatus,
|
|
|
|
QuotedMessage: m.QuotedMessage,
|
|
|
|
RTL: m.RTL,
|
|
|
|
ParsedText: m.ParsedText,
|
|
|
|
LineCount: m.LineCount,
|
|
|
|
Text: m.Text,
|
|
|
|
Replace: m.Replace,
|
2020-02-10 11:22:37 +00:00
|
|
|
ChatID: m.ChatId,
|
2020-01-10 18:59:01 +00:00
|
|
|
LocalChatID: m.LocalChatID,
|
|
|
|
Clock: m.Clock,
|
|
|
|
ResponseTo: m.ResponseTo,
|
|
|
|
EnsName: m.EnsName,
|
|
|
|
Timestamp: m.Timestamp,
|
|
|
|
ContentType: m.ContentType,
|
|
|
|
MessageType: m.MessageType,
|
|
|
|
CommandParameters: m.CommandParameters,
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
}
|
|
|
|
|
2020-01-15 07:25:09 +00:00
|
|
|
if sticker := m.GetSticker(); sticker != nil {
|
|
|
|
item.Sticker = &StickerAlias{
|
|
|
|
Pack: sticker.Pack,
|
|
|
|
Hash: sticker.Hash,
|
|
|
|
}
|
|
|
|
}
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
return json.Marshal(item)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Message) UnmarshalJSON(data []byte) error {
|
|
|
|
type Alias Message
|
|
|
|
aux := struct {
|
|
|
|
*Alias
|
|
|
|
ResponseTo string `json:"responseTo"`
|
|
|
|
EnsName string `json:"ensName"`
|
|
|
|
ChatID string `json:"chatId"`
|
|
|
|
Sticker *protobuf.StickerMessage `json:"sticker"`
|
|
|
|
ContentType protobuf.ChatMessage_ContentType `json:"contentType"`
|
|
|
|
}{
|
|
|
|
Alias: (*Alias)(m),
|
|
|
|
}
|
|
|
|
if err := json.Unmarshal(data, &aux); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if aux.ContentType == protobuf.ChatMessage_STICKER {
|
|
|
|
m.Payload = &protobuf.ChatMessage_Sticker{Sticker: aux.Sticker}
|
|
|
|
}
|
|
|
|
m.ResponseTo = aux.ResponseTo
|
|
|
|
m.EnsName = aux.EnsName
|
|
|
|
m.ChatId = aux.ChatID
|
|
|
|
m.ContentType = aux.ContentType
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the first character is Hebrew or Arabic or the RTL character
|
|
|
|
func isRTL(s string) bool {
|
|
|
|
first, _ := utf8.DecodeRuneInString(s)
|
|
|
|
return unicode.Is(unicode.Hebrew, first) ||
|
|
|
|
unicode.Is(unicode.Arabic, first) ||
|
|
|
|
// RTL character
|
|
|
|
first == '\u200f'
|
|
|
|
}
|
|
|
|
|
|
|
|
// PrepareContent return the parsed content of the message, the line-count and whether
|
|
|
|
// is a right-to-left message
|
|
|
|
func (m *Message) PrepareContent() error {
|
|
|
|
parsedText := markdown.Parse([]byte(m.Text), nil)
|
|
|
|
jsonParsedText, err := json.Marshal(parsedText)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
m.ParsedText = jsonParsedText
|
|
|
|
m.LineCount = strings.Count(m.Text, "\n")
|
|
|
|
m.RTL = isRTL(m.Text)
|
|
|
|
return nil
|
2019-08-06 21:50:13 +00:00
|
|
|
}
|