From de6e4e4920a88bbdade12c32923c4ca3d037dd5f Mon Sep 17 00:00:00 2001 From: sachaaaaa Date: Thu, 26 Sep 2019 16:27:53 +1000 Subject: [PATCH] Add updateOurDeviceMapping that wraps setOurDeviceMapping --- js/modules/loki_file_server_api.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/js/modules/loki_file_server_api.js b/js/modules/loki_file_server_api.js index 5b110e199..e59a80a64 100644 --- a/js/modules/loki_file_server_api.js +++ b/js/modules/loki_file_server_api.js @@ -1,3 +1,7 @@ +/* global storage: false */ +/* global libloki: false */ +/* global Signal: false */ + const LokiAppDotNetAPI = require('./loki_app_dot_net_api'); const DEVICE_MAPPING_ANNOTATION_KEY = 'network.loki.messenger.devicemapping'; @@ -21,7 +25,22 @@ class LokiFileServerAPI { ); } - setOurDeviceMapping(authorisations, isPrimary) { + async updateOurDeviceMapping() { + const isPrimary = !storage.get('isSecondaryDevice'); + let authorisations; + if (isPrimary) { + authorisations = await Signal.Data.getGrantAuthorisationsForPrimaryPubKey( + this.ourKey + ); + } else { + authorisations = [ + await libloki.storage.getGrantAuthorisationForSecondaryPubKey(this.ourKey), + ]; + } + return this._setOurDeviceMapping(authorisations, isPrimary); + } + + _setOurDeviceMapping(authorisations, isPrimary) { const content = { isPrimary: isPrimary ? '1' : '0', authorisations,