2019-11-21 16:19:22 +00:00
|
|
|
package protocol
|
2019-08-06 21:50:13 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql/driver"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
2019-11-21 16:19:22 +00:00
|
|
|
protocol "github.com/status-im/status-go/protocol/types"
|
2019-08-06 21:50:13 +00:00
|
|
|
)
|
|
|
|
|
2019-11-21 16:19:22 +00:00
|
|
|
type hexutilSQL protocol.HexBytes
|
2019-08-06 21:50:13 +00:00
|
|
|
|
|
|
|
func (h hexutilSQL) Value() (driver.Value, error) {
|
|
|
|
return []byte(h), nil
|
|
|
|
}
|
|
|
|
|
2019-08-20 11:20:25 +00:00
|
|
|
func (h hexutilSQL) String() string {
|
2019-11-21 16:19:22 +00:00
|
|
|
return protocol.EncodeHex(h)
|
2019-08-20 11:20:25 +00:00
|
|
|
}
|
|
|
|
|
2019-08-06 21:50:13 +00:00
|
|
|
func (h *hexutilSQL) Scan(value interface{}) error {
|
|
|
|
if value == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if b, ok := value.([]byte); ok {
|
|
|
|
*h = hexutilSQL(b)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return errors.New("failed to scan hexutilSQL")
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
From string `json:"from"`
|
|
|
|
Content string `json:"content"`
|
|
|
|
}
|
|
|
|
|
2019-08-06 21:50:13 +00:00
|
|
|
// Message represents a message record in the database,
|
|
|
|
// more specifically in user_messages_legacy table.
|
|
|
|
// Encoding and decoding of byte blobs should be performed
|
|
|
|
// using hexutil package.
|
|
|
|
type Message struct {
|
|
|
|
// ID calculated as keccak256(compressedAuthorPubKey, data) where data is unencrypted payload.
|
|
|
|
ID string `json:"id"`
|
|
|
|
// WhisperTimestamp is a timestamp of a Whisper envelope.
|
|
|
|
WhisperTimestamp int64 `json:"whisperTimestamp"`
|
|
|
|
// 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"`
|
2019-08-06 21:50:13 +00:00
|
|
|
// To is a public key of the recipient unless it's a public message then it's empty.
|
|
|
|
To hexutilSQL `json:"to,omitempty"`
|
|
|
|
// BEGIN: fields from protocol.Message.
|
|
|
|
Content string `json:"content"`
|
|
|
|
ContentType string `json:"contentType"`
|
|
|
|
Timestamp int64 `json:"timestamp"`
|
|
|
|
ChatID string `json:"chatId"`
|
|
|
|
MessageType string `json:"messageType,omitempty"`
|
|
|
|
MessageStatus string `json:"messageStatus,omitempty"`
|
|
|
|
ClockValue int64 `json:"clockValue"`
|
|
|
|
// END
|
|
|
|
Username string `json:"username,omitempty"`
|
|
|
|
RetryCount int `json:"retryCount"`
|
|
|
|
Show bool `json:"show"` // default true
|
|
|
|
Seen bool `json:"seen"`
|
|
|
|
OutgoingStatus string `json:"outgoingStatus,omitempty"`
|
2019-08-20 11:20:25 +00:00
|
|
|
// MessageID of the replied message
|
|
|
|
ReplyTo string `json:"replyTo"`
|
|
|
|
QuotedMessage *QuotedMessage `json:"quotedMessage"`
|
2019-08-06 21:50:13 +00:00
|
|
|
}
|