@@ -2,8 +2,6 @@ package protocol
2
2
3
3
import (
4
4
"context"
5
- "os"
6
- "path/filepath"
7
5
"time"
8
6
9
7
"github.com/golang/protobuf/proto"
@@ -15,9 +13,7 @@ import (
15
13
"github.com/status-im/status-go/multiaccounts/settings"
16
14
"github.com/status-im/status-go/protocol/common"
17
15
"github.com/status-im/status-go/protocol/communities"
18
- "github.com/status-im/status-go/protocol/encryption"
19
16
"github.com/status-im/status-go/protocol/protobuf"
20
- v1protocol "github.com/status-im/status-go/protocol/v1"
21
17
)
22
18
23
19
const (
@@ -157,14 +153,11 @@ func (m *Messenger) BackupData(ctx context.Context) (uint64, error) {
157
153
}
158
154
}
159
155
160
- fullBackup := & protobuf.Backup {}
161
-
162
156
// Update contacts messages encode and dispatch
163
157
for i , d := range contactsToBackup {
164
158
pb := backupDetailsOnly ()
165
159
pb .ContactsDetails .DataNumber = uint32 (i + 1 )
166
160
pb .Contacts = d .Contacts
167
- fullBackup .Contacts = append (fullBackup .Contacts , d .Contacts ... )
168
161
err = m .encodeAndDispatchBackupMessage (ctx , pb , chat .ID )
169
162
if err != nil {
170
163
return 0 , err
@@ -176,7 +169,6 @@ func (m *Messenger) BackupData(ctx context.Context) (uint64, error) {
176
169
pb := backupDetailsOnly ()
177
170
pb .CommunitiesDetails .DataNumber = uint32 (i + 1 )
178
171
pb .Communities = d .Communities
179
- fullBackup .Communities = append (fullBackup .Communities , d .Communities ... )
180
172
err = m .encodeAndDispatchBackupMessage (ctx , pb , chat .ID )
181
173
if err != nil {
182
174
return 0 , err
@@ -187,7 +179,6 @@ func (m *Messenger) BackupData(ctx context.Context) (uint64, error) {
187
179
pb := backupDetailsOnly ()
188
180
pb .ProfileDetails .DataNumber = uint32 (1 )
189
181
pb .Profile = profileToBackup .Profile
190
- fullBackup .Profile = profileToBackup .Profile
191
182
err = m .encodeAndDispatchBackupMessage (ctx , pb , chat .ID )
192
183
if err != nil {
193
184
return 0 , err
@@ -198,7 +189,6 @@ func (m *Messenger) BackupData(ctx context.Context) (uint64, error) {
198
189
pb := backupDetailsOnly ()
199
190
pb .ChatsDetails .DataNumber = uint32 (i + 1 )
200
191
pb .Chats = d .Chats
201
- fullBackup .Chats = append (fullBackup .Chats , d .Chats ... )
202
192
err = m .encodeAndDispatchBackupMessage (ctx , pb , chat .ID )
203
193
if err != nil {
204
194
return 0 , err
@@ -210,8 +200,6 @@ func (m *Messenger) BackupData(ctx context.Context) (uint64, error) {
210
200
pb := backupDetailsOnly ()
211
201
pb .SettingsDetails .DataNumber = uint32 (i + 1 )
212
202
pb .Setting = d
213
- // TODO find a way to get all settings
214
- // fullBackup.Setting = append(fullBackup.Setting, d)
215
203
err = m .encodeAndDispatchBackupMessage (ctx , pb , chat .ID )
216
204
if err != nil {
217
205
return 0 , err
@@ -223,8 +211,6 @@ func (m *Messenger) BackupData(ctx context.Context) (uint64, error) {
223
211
pb := backupDetailsOnly ()
224
212
pb .KeypairDetails .DataNumber = uint32 (i + 1 )
225
213
pb .Keypair = d .Keypair
226
- // TODO find a way to get all settings
227
- // fullBackup.Keypair = append(fullBackup.Keypair, d.Keypair)
228
214
err = m .encodeAndDispatchBackupMessage (ctx , pb , chat .ID )
229
215
if err != nil {
230
216
return 0 , err
@@ -236,49 +222,12 @@ func (m *Messenger) BackupData(ctx context.Context) (uint64, error) {
236
222
pb := backupDetailsOnly ()
237
223
pb .WatchOnlyAccountDetails .DataNumber = uint32 (i + 1 )
238
224
pb .WatchOnlyAccount = d .WatchOnlyAccount
239
- // TODO find a way to get all settings
240
- // fullBackup.WatchOnlyAccount = append(fullBackup.WatchOnlyAccount, d.Keypair)
241
225
err = m .encodeAndDispatchBackupMessage (ctx , pb , chat .ID )
242
226
if err != nil {
243
227
return 0 , err
244
228
}
245
229
}
246
230
247
- if m .config .featureFlags .EnableLocalBackup {
248
- // TODO put file in a constant
249
- path := filepath .Join (m .config .backupConfig .DataDir , "user_data.bkp" )
250
-
251
- if err := os .MkdirAll (m .config .backupConfig .DataDir , 0700 ); err != nil {
252
- return 0 , err
253
- }
254
-
255
- file , err := os .Create (path )
256
- if err != nil {
257
- return 0 , err
258
- }
259
- defer file .Close ()
260
-
261
- mashalledMessage , err := proto .Marshal (fullBackup )
262
- if err != nil {
263
- return 0 , err
264
- }
265
-
266
- messageSpec , err := m .encryptor .BuildDHMessage (m .identity , & m .identity .PublicKey , mashalledMessage )
267
- if err != nil {
268
- return 0 , err
269
- }
270
-
271
- encryptedMessage , err := proto .Marshal (messageSpec .Message )
272
- if err != nil {
273
- return 0 , err
274
- }
275
- err = os .WriteFile (path , encryptedMessage , 0600 )
276
- if err != nil {
277
- m .logger .Error ("failed to write backup message to file" , zap .Error (err ), zap .String ("path" , path ))
278
- return 0 , err
279
- }
280
- }
281
-
282
231
chat .LastClockValue = clock
283
232
err = m .saveChat (chat )
284
233
if err != nil {
@@ -297,62 +246,6 @@ func (m *Messenger) BackupData(ctx context.Context) (uint64, error) {
297
246
return clockInSeconds , nil
298
247
}
299
248
300
- func (m * Messenger ) importLocalBackupFile (filePath string ) (* MessengerResponse , error ) {
301
- if ! m .config .featureFlags .EnableLocalBackup {
302
- return nil , nil
303
- }
304
-
305
- // Make sure the backup file exists
306
- content , err := os .ReadFile (filePath )
307
- if err != nil {
308
- return nil , err
309
- }
310
-
311
- // Decrypt the backup file
312
- // Unmarshal the content to get the message spec
313
- var messageSpec encryption.ProtocolMessage
314
- err = proto .Unmarshal (content , & messageSpec )
315
- if err != nil {
316
- return nil , err
317
- }
318
-
319
- // Decrypt the payload
320
- var defaultMessageID = []byte ("default" )
321
- decryptedPayload1 , err := m .encryptor .HandleMessage (m .identity , & m .identity .PublicKey , & messageSpec , defaultMessageID )
322
- if err != nil {
323
- return nil , err
324
- }
325
-
326
- // Unmarshal the decrypted payload to get the backup message
327
- var backupMessage protobuf.Backup
328
- err = proto .Unmarshal (decryptedPayload1 .DecryptedMessage , & backupMessage )
329
- if err != nil {
330
- return nil , err
331
- }
332
-
333
- // Handle the backup
334
- state := ReceivedMessageState {
335
- Response : & MessengerResponse {},
336
- AllChats : & chatMap {},
337
- AllContacts : & contactMap {
338
- me : m .selfContact ,
339
- },
340
- Timesource : m .getTimesource (),
341
- ModifiedContacts : & stringBoolMap {},
342
- ModifiedInstallations : & stringBoolMap {},
343
- }
344
- err = m .HandleBackup (
345
- & state ,
346
- & backupMessage ,
347
- & v1protocol.StatusMessage {},
348
- )
349
- if err != nil {
350
- return nil , err
351
- }
352
-
353
- return m .saveDataAndPrepareResponse (& state )
354
- }
355
-
356
249
func (m * Messenger ) encodeAndDispatchBackupMessage (ctx context.Context , message * protobuf.Backup , chatID string ) error {
357
250
encodedMessage , err := proto .Marshal (message )
358
251
if err != nil {
0 commit comments