2020-01-10 18:59:01 +00:00
|
|
|
package protocol
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/ecdsa"
|
|
|
|
|
|
|
|
"github.com/status-im/status-go/eth-node/crypto"
|
|
|
|
"github.com/status-im/status-go/eth-node/types"
|
2020-09-01 13:27:01 +00:00
|
|
|
"github.com/status-im/status-go/protocol/common"
|
2020-01-10 18:59:01 +00:00
|
|
|
"github.com/status-im/status-go/protocol/identity/alias"
|
|
|
|
"github.com/status-im/status-go/protocol/identity/identicon"
|
|
|
|
)
|
|
|
|
|
2020-09-01 13:27:01 +00:00
|
|
|
func extendMessageFromChat(message *common.Message, chat *Chat, key *ecdsa.PublicKey, timesource TimeSource) error {
|
2020-01-20 16:44:32 +00:00
|
|
|
clock, timestamp := chat.NextClockAndTimestamp(timesource)
|
2020-01-10 18:59:01 +00:00
|
|
|
|
|
|
|
message.LocalChatID = chat.ID
|
|
|
|
message.Clock = clock
|
|
|
|
message.Timestamp = timestamp
|
|
|
|
message.From = types.EncodeHex(crypto.FromECDSAPub(key))
|
|
|
|
message.SigPubKey = key
|
|
|
|
message.WhisperTimestamp = timestamp
|
|
|
|
message.Seen = true
|
2020-09-01 13:27:01 +00:00
|
|
|
message.OutgoingStatus = common.OutgoingStatusSending
|
2020-01-10 18:59:01 +00:00
|
|
|
|
|
|
|
identicon, err := identicon.GenerateBase64(message.From)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
message.Identicon = identicon
|
|
|
|
|
|
|
|
alias, err := alias.GenerateFromPublicKeyString(message.From)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
message.Alias = alias
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|