2021-10-11 15:39:52 +00:00
|
|
|
package protocol
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/golang/protobuf/proto"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
|
2023-05-16 10:48:00 +00:00
|
|
|
"github.com/status-im/status-go/multiaccounts/accounts"
|
2022-11-30 09:41:35 +00:00
|
|
|
"github.com/status-im/status-go/multiaccounts/settings"
|
2021-10-11 15:39:52 +00:00
|
|
|
"github.com/status-im/status-go/protocol/common"
|
|
|
|
"github.com/status-im/status-go/protocol/protobuf"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
BackupContactsPerBatch = 20
|
|
|
|
)
|
|
|
|
|
|
|
|
// backupTickerInterval is how often we should check for backups
|
|
|
|
var backupTickerInterval = 120 * time.Second
|
|
|
|
|
|
|
|
// backupIntervalSeconds is the amount of seconds we should allow between
|
|
|
|
// backups
|
|
|
|
var backupIntervalSeconds uint64 = 28800
|
|
|
|
|
|
|
|
func (m *Messenger) backupEnabled() (bool, error) {
|
|
|
|
return m.settings.BackupEnabled()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Messenger) lastBackup() (uint64, error) {
|
|
|
|
return m.settings.LastBackup()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Messenger) startBackupLoop() {
|
|
|
|
ticker := time.NewTicker(backupTickerInterval)
|
|
|
|
go func() {
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-ticker.C:
|
2023-12-05 10:08:26 +00:00
|
|
|
if !m.Online() {
|
2021-10-11 15:39:52 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
enabled, err := m.backupEnabled()
|
|
|
|
if err != nil {
|
|
|
|
m.logger.Error("failed to fetch backup enabled")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if !enabled {
|
|
|
|
m.logger.Debug("backup not enabled, skipping")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
lastBackup, err := m.lastBackup()
|
|
|
|
if err != nil {
|
|
|
|
m.logger.Error("failed to fetch last backup time")
|
2021-10-27 10:59:43 +00:00
|
|
|
continue
|
2021-10-11 15:39:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
now := time.Now().Unix()
|
|
|
|
if uint64(now) <= backupIntervalSeconds+lastBackup {
|
|
|
|
m.logger.Debug("not backing up")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
m.logger.Debug("backing up data")
|
|
|
|
|
2021-10-27 10:59:43 +00:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
|
|
|
|
defer cancel()
|
|
|
|
_, err = m.BackupData(ctx)
|
2021-10-11 15:39:52 +00:00
|
|
|
if err != nil {
|
|
|
|
m.logger.Error("failed to backup data", zap.Error(err))
|
|
|
|
}
|
|
|
|
case <-m.quit:
|
2021-10-22 14:20:42 +00:00
|
|
|
ticker.Stop()
|
2021-10-11 15:39:52 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Messenger) BackupData(ctx context.Context) (uint64, error) {
|
2022-11-30 09:41:35 +00:00
|
|
|
clock, chat := m.getLastClockWithRelatedChat()
|
|
|
|
contactsToBackup := m.backupContacts(ctx)
|
|
|
|
communitiesToBackup, err := m.backupCommunities(ctx, clock)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
2023-10-12 21:15:05 +00:00
|
|
|
chatsToBackup := m.backupChats(ctx, clock)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
2022-11-30 09:41:35 +00:00
|
|
|
profileToBackup, err := m.backupProfile(ctx, clock)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
2023-03-30 10:18:13 +00:00
|
|
|
_, settings, errors := m.prepareSyncSettingsMessages(clock, true)
|
2022-11-30 09:41:35 +00:00
|
|
|
if len(errors) != 0 {
|
|
|
|
// return just the first error, the others have been logged
|
|
|
|
return 0, errors[0]
|
|
|
|
}
|
|
|
|
|
2023-06-28 19:45:36 +00:00
|
|
|
keypairsToBackup, err := m.backupKeypairs()
|
2023-04-19 14:44:57 +00:00
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
2023-05-16 10:48:00 +00:00
|
|
|
woAccountsToBackup, err := m.backupWatchOnlyAccounts()
|
2023-02-27 10:19:18 +00:00
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
2022-11-30 09:41:35 +00:00
|
|
|
backupDetailsOnly := func() *protobuf.Backup {
|
|
|
|
return &protobuf.Backup{
|
|
|
|
Clock: clock,
|
2023-10-12 21:15:05 +00:00
|
|
|
ChatsDetails: &protobuf.FetchingBackedUpDataDetails{
|
|
|
|
DataNumber: uint32(0),
|
|
|
|
TotalNumber: uint32(len(chatsToBackup)),
|
|
|
|
},
|
2022-11-30 09:41:35 +00:00
|
|
|
ContactsDetails: &protobuf.FetchingBackedUpDataDetails{
|
|
|
|
DataNumber: uint32(0),
|
|
|
|
TotalNumber: uint32(len(contactsToBackup)),
|
|
|
|
},
|
|
|
|
CommunitiesDetails: &protobuf.FetchingBackedUpDataDetails{
|
|
|
|
DataNumber: uint32(0),
|
|
|
|
TotalNumber: uint32(len(communitiesToBackup)),
|
|
|
|
},
|
|
|
|
ProfileDetails: &protobuf.FetchingBackedUpDataDetails{
|
|
|
|
DataNumber: uint32(0),
|
|
|
|
TotalNumber: uint32(len(profileToBackup)),
|
|
|
|
},
|
|
|
|
SettingsDetails: &protobuf.FetchingBackedUpDataDetails{
|
|
|
|
DataNumber: uint32(0),
|
|
|
|
TotalNumber: uint32(len(settings)),
|
|
|
|
},
|
2023-06-28 19:45:36 +00:00
|
|
|
KeypairDetails: &protobuf.FetchingBackedUpDataDetails{
|
2023-04-19 14:44:57 +00:00
|
|
|
DataNumber: uint32(0),
|
2023-06-28 19:45:36 +00:00
|
|
|
TotalNumber: uint32(len(keypairsToBackup)),
|
2023-04-19 14:44:57 +00:00
|
|
|
},
|
2023-05-16 10:48:00 +00:00
|
|
|
WatchOnlyAccountDetails: &protobuf.FetchingBackedUpDataDetails{
|
2023-02-27 10:19:18 +00:00
|
|
|
DataNumber: uint32(0),
|
2023-05-16 10:48:00 +00:00
|
|
|
TotalNumber: uint32(len(woAccountsToBackup)),
|
2023-02-27 10:19:18 +00:00
|
|
|
},
|
2022-11-30 09:41:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update contacts messages encode and dispatch
|
|
|
|
for i, d := range contactsToBackup {
|
|
|
|
pb := backupDetailsOnly()
|
|
|
|
pb.ContactsDetails.DataNumber = uint32(i + 1)
|
|
|
|
pb.Contacts = d.Contacts
|
|
|
|
err = m.encodeAndDispatchBackupMessage(ctx, pb, chat.ID)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update communities messages encode and dispatch
|
|
|
|
for i, d := range communitiesToBackup {
|
|
|
|
pb := backupDetailsOnly()
|
|
|
|
pb.CommunitiesDetails.DataNumber = uint32(i + 1)
|
|
|
|
pb.Communities = d.Communities
|
|
|
|
err = m.encodeAndDispatchBackupMessage(ctx, pb, chat.ID)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update profile messages encode and dispatch
|
|
|
|
for i, d := range profileToBackup {
|
|
|
|
pb := backupDetailsOnly()
|
|
|
|
pb.ProfileDetails.DataNumber = uint32(i + 1)
|
|
|
|
pb.Profile = d.Profile
|
|
|
|
err = m.encodeAndDispatchBackupMessage(ctx, pb, chat.ID)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-12 21:15:05 +00:00
|
|
|
// Update chats encode and dispatch
|
|
|
|
for i, d := range chatsToBackup {
|
|
|
|
pb := backupDetailsOnly()
|
|
|
|
pb.ChatsDetails.DataNumber = uint32(i + 1)
|
|
|
|
pb.Chats = d.Chats
|
|
|
|
err = m.encodeAndDispatchBackupMessage(ctx, pb, chat.ID)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-30 09:41:35 +00:00
|
|
|
// Update settings messages encode and dispatch
|
|
|
|
for i, d := range settings {
|
|
|
|
pb := backupDetailsOnly()
|
|
|
|
pb.SettingsDetails.DataNumber = uint32(i + 1)
|
|
|
|
pb.Setting = d
|
|
|
|
err = m.encodeAndDispatchBackupMessage(ctx, pb, chat.ID)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-16 10:48:00 +00:00
|
|
|
// Update keypairs messages encode and dispatch
|
2023-06-28 19:45:36 +00:00
|
|
|
for i, d := range keypairsToBackup {
|
2023-04-19 14:44:57 +00:00
|
|
|
pb := backupDetailsOnly()
|
2023-06-28 19:45:36 +00:00
|
|
|
pb.KeypairDetails.DataNumber = uint32(i + 1)
|
|
|
|
pb.Keypair = d.Keypair
|
2023-04-19 14:44:57 +00:00
|
|
|
err = m.encodeAndDispatchBackupMessage(ctx, pb, chat.ID)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-16 10:48:00 +00:00
|
|
|
// Update watch only messages encode and dispatch
|
|
|
|
for i, d := range woAccountsToBackup {
|
|
|
|
pb := backupDetailsOnly()
|
|
|
|
pb.WatchOnlyAccountDetails.DataNumber = uint32(i + 1)
|
|
|
|
pb.WatchOnlyAccount = d.WatchOnlyAccount
|
|
|
|
err = m.encodeAndDispatchBackupMessage(ctx, pb, chat.ID)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
2023-02-27 10:19:18 +00:00
|
|
|
}
|
|
|
|
|
2022-11-30 09:41:35 +00:00
|
|
|
chat.LastClockValue = clock
|
|
|
|
err = m.saveChat(chat)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
clockInSeconds := clock / 1000
|
|
|
|
err = m.settings.SetLastBackup(clockInSeconds)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
if m.config.messengerSignalsHandler != nil {
|
|
|
|
m.config.messengerSignalsHandler.BackupPerformed(clockInSeconds)
|
|
|
|
}
|
|
|
|
|
|
|
|
return clockInSeconds, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Messenger) encodeAndDispatchBackupMessage(ctx context.Context, message *protobuf.Backup, chatID string) error {
|
|
|
|
encodedMessage, err := proto.Marshal(message)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = m.dispatchMessage(ctx, common.RawMessage{
|
|
|
|
LocalChatID: chatID,
|
|
|
|
Payload: encodedMessage,
|
2023-11-08 18:05:33 +00:00
|
|
|
SkipEncryptionLayer: true,
|
2022-11-30 09:41:35 +00:00
|
|
|
SendOnPersonalTopic: true,
|
|
|
|
MessageType: protobuf.ApplicationMetadataMessage_BACKUP,
|
|
|
|
})
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Messenger) backupContacts(ctx context.Context) []*protobuf.Backup {
|
2021-10-11 15:39:52 +00:00
|
|
|
var contacts []*protobuf.SyncInstallationContactV2
|
|
|
|
m.allContacts.Range(func(contactID string, contact *Contact) (shouldContinue bool) {
|
2023-01-20 14:28:30 +00:00
|
|
|
syncContact := m.buildSyncContactMessage(contact)
|
2021-10-11 15:39:52 +00:00
|
|
|
if syncContact != nil {
|
|
|
|
contacts = append(contacts, syncContact)
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
|
2022-11-30 09:41:35 +00:00
|
|
|
var backupMessages []*protobuf.Backup
|
2021-10-11 15:39:52 +00:00
|
|
|
for i := 0; i < len(contacts); i += BackupContactsPerBatch {
|
|
|
|
j := i + BackupContactsPerBatch
|
|
|
|
if j > len(contacts) {
|
|
|
|
j = len(contacts)
|
|
|
|
}
|
|
|
|
|
|
|
|
contactsToAdd := contacts[i:j]
|
|
|
|
|
|
|
|
backupMessage := &protobuf.Backup{
|
|
|
|
Contacts: contactsToAdd,
|
|
|
|
}
|
2022-11-30 09:41:35 +00:00
|
|
|
backupMessages = append(backupMessages, backupMessage)
|
2021-10-11 15:39:52 +00:00
|
|
|
}
|
2022-01-06 16:35:08 +00:00
|
|
|
|
2022-11-30 09:41:35 +00:00
|
|
|
return backupMessages
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Messenger) backupCommunities(ctx context.Context, clock uint64) ([]*protobuf.Backup, error) {
|
2022-04-11 16:14:08 +00:00
|
|
|
joinedCs, err := m.communitiesManager.JoinedAndPendingCommunitiesWithRequests()
|
2022-01-06 16:35:08 +00:00
|
|
|
if err != nil {
|
2022-11-30 09:41:35 +00:00
|
|
|
return nil, err
|
2022-01-06 16:35:08 +00:00
|
|
|
}
|
2022-04-11 16:14:08 +00:00
|
|
|
|
|
|
|
deletedCs, err := m.communitiesManager.DeletedCommunities()
|
|
|
|
if err != nil {
|
2022-11-30 09:41:35 +00:00
|
|
|
return nil, err
|
2022-04-11 16:14:08 +00:00
|
|
|
}
|
|
|
|
|
2022-11-30 09:41:35 +00:00
|
|
|
var backupMessages []*protobuf.Backup
|
2022-04-11 16:14:08 +00:00
|
|
|
cs := append(joinedCs, deletedCs...)
|
2022-01-06 16:35:08 +00:00
|
|
|
for _, c := range cs {
|
2022-09-29 11:50:23 +00:00
|
|
|
_, beingImported := m.importingCommunities[c.IDString()]
|
|
|
|
if !beingImported {
|
|
|
|
settings, err := m.communitiesManager.GetCommunitySettingsByID(c.ID())
|
|
|
|
if err != nil {
|
2022-11-30 09:41:35 +00:00
|
|
|
return nil, err
|
2022-09-29 11:50:23 +00:00
|
|
|
}
|
2022-01-06 16:35:08 +00:00
|
|
|
|
2023-09-21 11:16:05 +00:00
|
|
|
syncControlNode, err := m.communitiesManager.GetSyncControlNode(c.ID())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
syncMessage, err := c.ToSyncInstallationCommunityProtobuf(clock, settings, syncControlNode)
|
2022-09-29 11:50:23 +00:00
|
|
|
if err != nil {
|
2022-11-30 09:41:35 +00:00
|
|
|
return nil, err
|
2022-09-29 11:50:23 +00:00
|
|
|
}
|
2022-01-06 16:35:08 +00:00
|
|
|
|
2024-02-21 10:54:33 +00:00
|
|
|
err = m.propagateSyncInstallationCommunityWithHRKeys(syncMessage, c)
|
2022-11-07 17:30:00 +00:00
|
|
|
if err != nil {
|
2022-11-30 09:41:35 +00:00
|
|
|
return nil, err
|
2022-11-07 17:30:00 +00:00
|
|
|
}
|
|
|
|
|
2022-09-29 11:50:23 +00:00
|
|
|
backupMessage := &protobuf.Backup{
|
2023-08-18 11:39:59 +00:00
|
|
|
Communities: []*protobuf.SyncInstallationCommunity{syncMessage},
|
2022-09-29 11:50:23 +00:00
|
|
|
}
|
2022-01-06 16:35:08 +00:00
|
|
|
|
2022-11-30 09:41:35 +00:00
|
|
|
backupMessages = append(backupMessages, backupMessage)
|
2022-01-06 16:35:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-30 09:41:35 +00:00
|
|
|
return backupMessages, nil
|
2021-10-11 15:39:52 +00:00
|
|
|
}
|
|
|
|
|
2023-10-12 21:15:05 +00:00
|
|
|
func (m *Messenger) backupChats(ctx context.Context, clock uint64) []*protobuf.Backup {
|
|
|
|
var oneToOneAndGroupChats []*protobuf.SyncChat
|
|
|
|
m.allChats.Range(func(chatID string, chat *Chat) bool {
|
|
|
|
if !chat.OneToOne() && !chat.PrivateGroupChat() {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
syncChat := protobuf.SyncChat{
|
2023-10-17 13:24:15 +00:00
|
|
|
Clock: clock,
|
2023-10-12 21:15:05 +00:00
|
|
|
Id: chatID,
|
|
|
|
ChatType: uint32(chat.ChatType),
|
|
|
|
Active: chat.Active,
|
|
|
|
}
|
|
|
|
chatMuteTill, _ := time.Parse(time.RFC3339, chat.MuteTill.Format(time.RFC3339))
|
|
|
|
if chat.Muted && chatMuteTill.Equal(time.Time{}) {
|
|
|
|
// Only set Muted if it is "permanently" muted
|
|
|
|
syncChat.Muted = true
|
|
|
|
}
|
|
|
|
if chat.PrivateGroupChat() {
|
|
|
|
syncChat.Name = chat.Name // The Name is only useful in the case of a group chat
|
|
|
|
|
|
|
|
syncChat.MembershipUpdateEvents = make([]*protobuf.MembershipUpdateEvents, len(chat.MembershipUpdates))
|
|
|
|
for i, membershipUpdate := range chat.MembershipUpdates {
|
|
|
|
syncChat.MembershipUpdateEvents[i] = &protobuf.MembershipUpdateEvents{
|
|
|
|
Clock: membershipUpdate.ClockValue,
|
|
|
|
Type: uint32(membershipUpdate.Type),
|
|
|
|
Members: membershipUpdate.Members,
|
|
|
|
Name: membershipUpdate.Name,
|
|
|
|
Signature: membershipUpdate.Signature,
|
|
|
|
ChatId: membershipUpdate.ChatID,
|
|
|
|
From: membershipUpdate.From,
|
|
|
|
RawPayload: membershipUpdate.RawPayload,
|
|
|
|
Color: membershipUpdate.Color,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
oneToOneAndGroupChats = append(oneToOneAndGroupChats, &syncChat)
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
|
|
|
|
var backupMessages []*protobuf.Backup
|
|
|
|
backupMessage := &protobuf.Backup{
|
|
|
|
Chats: oneToOneAndGroupChats,
|
|
|
|
}
|
|
|
|
backupMessages = append(backupMessages, backupMessage)
|
|
|
|
return backupMessages
|
|
|
|
}
|
|
|
|
|
2023-01-20 14:28:30 +00:00
|
|
|
func (m *Messenger) buildSyncContactMessage(contact *Contact) *protobuf.SyncInstallationContactV2 {
|
2021-10-11 15:39:52 +00:00
|
|
|
var ensName string
|
|
|
|
if contact.ENSVerified {
|
2022-02-17 15:13:10 +00:00
|
|
|
ensName = contact.EnsName
|
2021-10-11 15:39:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
oneToOneChat, ok := m.allChats.Load(contact.ID)
|
|
|
|
muted := false
|
|
|
|
if ok {
|
|
|
|
muted = oneToOneChat.Muted
|
|
|
|
}
|
|
|
|
|
|
|
|
return &protobuf.SyncInstallationContactV2{
|
2023-01-20 14:28:30 +00:00
|
|
|
LastUpdatedLocally: contact.LastUpdatedLocally,
|
|
|
|
LastUpdated: contact.LastUpdated,
|
|
|
|
Id: contact.ID,
|
2023-02-14 17:44:00 +00:00
|
|
|
DisplayName: contact.DisplayName,
|
2023-01-20 14:28:30 +00:00
|
|
|
EnsName: ensName,
|
|
|
|
LocalNickname: contact.LocalNickname,
|
|
|
|
Added: contact.added(),
|
|
|
|
Blocked: contact.Blocked,
|
|
|
|
Muted: muted,
|
|
|
|
HasAddedUs: contact.hasAddedUs(),
|
|
|
|
Removed: contact.Removed,
|
|
|
|
ContactRequestLocalState: int64(contact.ContactRequestLocalState),
|
|
|
|
ContactRequestRemoteState: int64(contact.ContactRequestRemoteState),
|
|
|
|
ContactRequestRemoteClock: int64(contact.ContactRequestRemoteClock),
|
|
|
|
ContactRequestLocalClock: int64(contact.ContactRequestLocalClock),
|
|
|
|
VerificationStatus: int64(contact.VerificationStatus),
|
|
|
|
TrustStatus: int64(contact.TrustStatus),
|
2021-10-11 15:39:52 +00:00
|
|
|
}
|
|
|
|
}
|
2022-11-30 09:41:35 +00:00
|
|
|
|
|
|
|
func (m *Messenger) backupProfile(ctx context.Context, clock uint64) ([]*protobuf.Backup, error) {
|
|
|
|
displayName, err := m.settings.DisplayName()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
displayNameClock, err := m.settings.GetSettingLastSynced(settings.DisplayName)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
keyUID := m.account.KeyUID
|
|
|
|
images, err := m.multiAccounts.GetIdentityImages(keyUID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-04-26 15:37:18 +00:00
|
|
|
pictureProtos := make([]*protobuf.SyncProfilePicture, len(images))
|
2022-11-30 09:41:35 +00:00
|
|
|
for i, image := range images {
|
|
|
|
p := &protobuf.SyncProfilePicture{}
|
|
|
|
p.Name = image.Name
|
|
|
|
p.Payload = image.Payload
|
|
|
|
p.Width = uint32(image.Width)
|
|
|
|
p.Height = uint32(image.Height)
|
|
|
|
p.FileSize = uint32(image.FileSize)
|
|
|
|
p.ResizeTarget = uint32(image.ResizeTarget)
|
|
|
|
if image.Clock == 0 {
|
|
|
|
p.Clock = clock
|
|
|
|
} else {
|
|
|
|
p.Clock = image.Clock
|
|
|
|
}
|
2023-04-26 15:37:18 +00:00
|
|
|
pictureProtos[i] = p
|
2022-11-30 09:41:35 +00:00
|
|
|
}
|
|
|
|
|
2023-04-19 22:59:09 +00:00
|
|
|
socialLinks, err := m.settings.GetSocialLinks()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2023-06-05 11:10:26 +00:00
|
|
|
|
|
|
|
socialLinksClock, err := m.settings.GetSocialLinksClock()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
syncSocialLinks := &protobuf.SyncSocialLinks{
|
|
|
|
SocialLinks: socialLinks.ToProtobuf(),
|
|
|
|
Clock: socialLinksClock,
|
2023-04-19 22:59:09 +00:00
|
|
|
}
|
|
|
|
|
2023-04-26 15:37:18 +00:00
|
|
|
ensUsernameDetails, err := m.getEnsUsernameDetails()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
ensUsernameDetailProtos := make([]*protobuf.SyncEnsUsernameDetail, len(ensUsernameDetails))
|
|
|
|
for i, ensUsernameDetail := range ensUsernameDetails {
|
|
|
|
ensUsernameDetailProtos[i] = &protobuf.SyncEnsUsernameDetail{
|
|
|
|
Username: ensUsernameDetail.Username,
|
|
|
|
Clock: ensUsernameDetail.Clock,
|
|
|
|
Removed: ensUsernameDetail.Removed,
|
|
|
|
ChainId: ensUsernameDetail.ChainID,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-17 18:07:20 +00:00
|
|
|
profileShowcasePreferences, err := m.GetProfileShowcasePreferences()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-11-30 09:41:35 +00:00
|
|
|
backupMessage := &protobuf.Backup{
|
|
|
|
Profile: &protobuf.BackedUpProfile{
|
2024-02-17 18:07:20 +00:00
|
|
|
KeyUid: keyUID,
|
|
|
|
DisplayName: displayName,
|
|
|
|
Pictures: pictureProtos,
|
|
|
|
DisplayNameClock: displayNameClock,
|
|
|
|
SocialLinks: syncSocialLinks,
|
|
|
|
EnsUsernameDetails: ensUsernameDetailProtos,
|
|
|
|
ProfileShowcasePreferences: ToProfileShowcasePreferencesProto(profileShowcasePreferences),
|
2022-11-30 09:41:35 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
backupMessages := []*protobuf.Backup{backupMessage}
|
|
|
|
|
|
|
|
return backupMessages, nil
|
|
|
|
}
|
2023-04-19 14:44:57 +00:00
|
|
|
|
2023-05-16 10:48:00 +00:00
|
|
|
func (m *Messenger) backupKeypairs() ([]*protobuf.Backup, error) {
|
2023-07-25 15:17:17 +00:00
|
|
|
keypairs, err := m.settings.GetActiveKeypairs()
|
2023-05-16 10:48:00 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var backupMessages []*protobuf.Backup
|
|
|
|
for _, kp := range keypairs {
|
|
|
|
|
|
|
|
kp.SyncedFrom = accounts.SyncedFromBackup
|
2023-06-28 19:45:36 +00:00
|
|
|
keypair, err := m.prepareSyncKeypairMessage(kp)
|
2023-05-16 10:48:00 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
backupMessage := &protobuf.Backup{
|
2023-06-28 19:45:36 +00:00
|
|
|
Keypair: keypair,
|
2023-05-16 10:48:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
backupMessages = append(backupMessages, backupMessage)
|
|
|
|
}
|
|
|
|
|
|
|
|
return backupMessages, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Messenger) backupWatchOnlyAccounts() ([]*protobuf.Backup, error) {
|
2023-07-26 05:52:45 +00:00
|
|
|
accounts, err := m.settings.GetAllWatchOnlyAccounts()
|
2023-04-19 14:44:57 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-05-16 10:48:00 +00:00
|
|
|
var backupMessages []*protobuf.Backup
|
|
|
|
for _, acc := range accounts {
|
|
|
|
|
|
|
|
backupMessage := &protobuf.Backup{}
|
|
|
|
backupMessage.WatchOnlyAccount = m.prepareSyncAccountMessage(acc)
|
|
|
|
|
|
|
|
backupMessages = append(backupMessages, backupMessage)
|
|
|
|
}
|
|
|
|
|
|
|
|
return backupMessages, nil
|
2023-04-19 14:44:57 +00:00
|
|
|
}
|