Skip to content
Snippets Groups Projects
Select Git revision
  • e63b12aed5fda0e94531f8be0f4d524969e0ed3f
  • release default protected
  • 11-22-implement-kv-interface-defined-in-collectiveversionedkvgo
  • hotfix/TestHostPool_UpdateNdf_AddFilter
  • XX-4719/announcementChannels
  • xx-4717/logLevel
  • jonah/noob-channel
  • master protected
  • XX-4707/tagDiskJson
  • xx-4698/notification-retry
  • hotfix/notifylockup
  • syncNodes
  • hotfix/localCB
  • XX-4677/NewChanManagerMobile
  • XX-4689/DmSync
  • duplicatePrefix
  • XX-4601/HavenInvites
  • finalizedUICallbacks
  • XX-4673/AdminKeySync
  • debugNotifID
  • anne/test
  • v4.7.5
  • v4.7.4
  • v4.7.3
  • v4.7.2
  • v4.7.1
  • v4.6.3
  • v4.6.1
  • v4.5.0
  • v4.4.4
  • v4.3.11
  • v4.3.8
  • v4.3.7
  • v4.3.6
  • v4.3.5
  • v4.2.0
  • v4.3.0
  • v4.3.4
  • v4.3.3
  • v4.3.2
  • v4.3.1
41 results

restoreContacts.go

Blame
  • restoreContacts.go 3.13 KiB
    ///////////////////////////////////////////////////////////////////////////////
    // Copyright © 2020 xx network SEZC                                          //
    //                                                                           //
    // Use of this source code is governed by a license that can be found in the //
    // LICENSE file                                                              //
    ///////////////////////////////////////////////////////////////////////////////
    
    package bindings
    
    import (
    	"gitlab.com/elixxir/client/xxmutils"
    	"gitlab.com/xx_network/primitives/id"
    )
    
    // RestoreContactsUpdater interface provides a callback function
    // for receiving update information from RestoreContactsFromBackup.
    type RestoreContactsUpdater interface {
    	// RestoreContactsCallback is called to report the current # of contacts
    	// that have been found and how many have been restored
    	// against the total number that need to be
    	// processed. If an error occurs it it set on the err variable as a
    	// plain string.
    	RestoreContactsCallback(numFound, numRestored, total int, err string)
    }
    
    // RestoreContactsReport is a gomobile friendly report structure
    // for determining which IDs restored, which failed, and why.
    type RestoreContactsReport struct {
    	restored []*id.ID
    	failed   []*id.ID
    	errs     []error
    	restErr  error
    }
    
    // LenRestored returns the length of ID's restored.
    func (r *RestoreContactsReport) LenRestored() int {
    	return len(r.restored)
    }
    
    // LenFailed returns the length of the ID's failed.
    func (r *RestoreContactsReport) LenFailed() int {
    	return len(r.failed)
    }
    
    // GetRestoredAt returns the restored ID at index
    func (r *RestoreContactsReport) GetRestoredAt(index int) []byte {
    	return r.restored[index].Bytes()
    }
    
    // GetFailedAt returns the failed ID at index
    func (r *RestoreContactsReport) GetFailedAt(index int) []byte {
    	return r.failed[index].Bytes()
    }
    
    // GetErrorAt returns the error string at index
    func (r *RestoreContactsReport) GetErrorAt(index int) string {
    	return r.errs[index].Error()
    }
    
    // GetRestoreContactsError returns an error string. Empty if no error.
    func (r *RestoreContactsReport) GetRestoreContactsError() string {
    	if r.restErr == nil {
    		return ""
    	}
    	return r.restErr.Error()
    }
    
    // RestoreContactsFromBackup takes as input the jason output of the
    // `NewClientFromBackup` function, unmarshals it into IDs, looks up
    // each ID in user discovery, and initiates a session reset request.
    // This function will not return until every id in the list has been sent a
    // request. It should be called again and again until it completes.
    // xxDK users should not use this function. This function is used by
    // the mobile phone apps and are not intended to be part of the xxDK. It
    // should be treated as internal functions specific to the phone apps.
    func RestoreContactsFromBackup(backupPartnerIDs []byte, client *Client,
    	udManager *UserDiscovery,
    	updatesCb RestoreContactsUpdater) *RestoreContactsReport {
    
    	restored, failed, errs, err := xxmutils.RestoreContactsFromBackup(
    		backupPartnerIDs, &client.api, udManager.ud, updatesCb)
    
    	return &RestoreContactsReport{
    		restored: restored,
    		failed:   failed,
    		errs:     errs,
    		restErr:  err,
    	}
    
    }