Skip to content

Commit

Permalink
v1.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikunj committed Aug 6, 2020
2 parents a8db1ce + 2cd8517 commit 9fdd151
Show file tree
Hide file tree
Showing 18 changed files with 188 additions and 152 deletions.
19 changes: 3 additions & 16 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1302,22 +1302,6 @@
"message": "Typing Indicators",
"description": "Title of the typing indicators setting"
},
"multiDeviceDisabledTemporary": {
"message": "MultiDevice disabled temporarily",
"description": "Description of why multi device is disabled"
},
"multiDeviceDisabledTemporaryTitle": {
"message": "Changes to Multi-device",
"description": "Description of why multi device is disabled on app start"
},
"multiDeviceDisabledTemporaryDescriptionPrimary": {
"message": "You’re seeing this because you have a secondary device linked to your Session ID. To improve reliability and stability, we’ve decided to temporarily disable Session’s multi-device functionality. Device linking has been disabled, and existing secondary clients will be erased on <span style=\"color:#00f782\">August 6th</span>.</br></br>To read more about this change, visit the Session FAQ at <a href=\"https://getsession.org/faq\">getsession.org/faq</a>.",
"description": "Description of why multi device is disabled on app start for a primary device"
},
"multiDeviceDisabledTemporaryDescriptionSecondary": {
"message": "You’re seeing this because this is a secondary device in a multi-device setup. To improve reliability and stability, we’ve decided to temporarily disable Session’s multi-device functionality. Device linking has been disabled, and existing secondary clients will be erased on <span style=\"color:#00f782\">August 6th</span>.</br></br>To read more about this change, visit the Session FAQ at <a href=\"https://getsession.org/faq\">getsession.org/faq</a>.",
"description": "Description of why multi device is disabled on app start for a secondary device"
},
"messageTTL": {
"message": "Message TTL",
"description": "Title of the Message TTL setting"
Expand Down Expand Up @@ -1752,6 +1736,9 @@
"unlinked": {
"message": "Unlinked"
},
"successUnlinked": {
"message": "Your device was unlinked successfully"
},
"relink": {
"message": "Relink"
},
Expand Down
25 changes: 25 additions & 0 deletions app/sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,7 @@ const LOKI_SCHEMA_VERSIONS = [
updateToLokiSchemaVersion4,
updateToLokiSchemaVersion5,
updateToLokiSchemaVersion6,
updateToLokiSchemaVersion7,
];

async function updateToLokiSchemaVersion1(currentVersion, instance) {
Expand Down Expand Up @@ -1027,6 +1028,30 @@ async function updateToLokiSchemaVersion6(currentVersion, instance) {
console.log('updateToLokiSchemaVersion6: success!');
}

async function updateToLokiSchemaVersion7(currentVersion, instance) {
if (currentVersion >= 7) {
return;
}

console.log('updateToLokiSchemaVersion7: starting...');

await instance.run('BEGIN TRANSACTION;');

// Remove multi device data
await instance.run('DELETE FROM pairingAuthorisations;');

await instance.run(
`INSERT INTO loki_schema (
version
) values (
7
);`
);

await instance.run('COMMIT TRANSACTION;');
console.log('updateToLokiSchemaVersion7: success!');
}

async function updateLokiSchema(instance) {
const result = await instance.get(
"SELECT name FROM sqlite_master WHERE type = 'table' AND name='loki_schema';"
Expand Down
133 changes: 66 additions & 67 deletions js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,52 @@
// of preload.js processing
window.setImmediate = window.nodeSetImmediate;

window.toasts = new Map();
window.pushToast = options => {
// Setting toasts with the same ID can be used to prevent identical
// toasts from appearing at once (stacking).
// If toast already exists, it will be reloaded (updated)

const params = {
title: options.title,
id: options.id || window.generateID(),
description: options.description || '',
type: options.type || '',
icon: options.icon || '',
shouldFade: options.shouldFade,
};

// Give all toasts an ID. User may define.
let currentToast;
const toastID = params.id;
const toast = !!toastID && window.toasts.get(toastID);
if (toast) {
currentToast = window.toasts.get(toastID);
currentToast.update(params);
} else {
// Make new Toast
window.toasts.set(
toastID,
new Whisper.SessionToastView({
el: $('body'),
})
);

currentToast = window.toasts.get(toastID);
currentToast.render();
currentToast.update(params);
}

// Remove some toasts if too many exist
const maxToasts = 6;
while (window.toasts.size > maxToasts) {
const finalToastID = window.toasts.keys().next().value;
window.toasts.get(finalToastID).fadeToast();
}

return toastID;
};

const { IdleDetector, MessageDataMigrator } = Signal.Workflow;
const {
mandatoryMessageUpgrade,
Expand All @@ -151,6 +197,20 @@

window.log.info('background page reloaded');
window.log.info('environment:', window.getEnvironment());
const restartReason = localStorage.getItem('restart-reason');
window.log.info('restartReason:', restartReason);

if (restartReason === 'unlink') {
setTimeout(() => {
localStorage.removeItem('restart-reason');

window.pushToast({
title: window.i18n('successUnlinked'),
type: 'info',
id: '123',
});
}, 2000);
}

let idleDetector;
let initialLoadComplete = false;
Expand Down Expand Up @@ -300,6 +360,12 @@
storage.put('primaryDevicePubKey', textsecure.storage.user.getNumber());
}

// 4th August 2020 - Force wipe of secondary devices as multi device is being disabled.
if (storage.get('isSecondaryDevice')) {
await window.deleteAccount('unlink');
return;
}

// These make key operations available to IPC handlers created in preload.js
window.Events = {
getThemeSetting: () => 'dark', // storage.get('theme-setting', 'dark')
Expand Down Expand Up @@ -754,76 +820,9 @@
.toString(36)
.substring(3);

window.toasts = new Map();
window.pushToast = options => {
// Setting toasts with the same ID can be used to prevent identical
// toasts from appearing at once (stacking).
// If toast already exists, it will be reloaded (updated)

const params = {
title: options.title,
id: options.id || window.generateID(),
description: options.description || '',
type: options.type || '',
icon: options.icon || '',
shouldFade: options.shouldFade,
};

// Give all toasts an ID. User may define.
let currentToast;
const toastID = params.id;
const toast = !!toastID && window.toasts.get(toastID);
if (toast) {
currentToast = window.toasts.get(toastID);
currentToast.update(params);
} else {
// Make new Toast
window.toasts.set(
toastID,
new Whisper.SessionToastView({
el: $('body'),
})
);

currentToast = window.toasts.get(toastID);
currentToast.render();
currentToast.update(params);
}

// Remove some toasts if too many exist
const maxToasts = 6;
while (window.toasts.size > maxToasts) {
const finalToastID = window.toasts.keys().next().value;
window.toasts.get(finalToastID).fadeToast();
}

return toastID;
};

// Get memberlist. This function is not accurate >>
// window.getMemberList = window.lokiPublicChatAPI.getListOfMembers();

window.deleteAccount = async () => {
try {
window.log.info('Deleting everything!');

const { Logs } = window.Signal;
await Logs.deleteAll();

await window.Signal.Data.removeAll();
await window.Signal.Data.close();
await window.Signal.Data.removeDB();

await window.Signal.Data.removeOtherData();
} catch (error) {
window.log.error(
'Something went wrong deleting all data:',
error && error.stack ? error.stack : error
);
}
window.restart();
};

window.toggleTheme = () => {
const theme = window.Events.getThemeSetting();
const updatedTheme = theme === 'dark' ? 'light' : 'dark';
Expand Down
4 changes: 2 additions & 2 deletions js/logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,6 @@ window.onerror = (message, script, line, col, error) => {

window.addEventListener('unhandledrejection', rejectionEvent => {
const error = rejectionEvent.reason;
const errorInfo = error && error.stack ? error.stack : JSON.stringify(error);
window.log.error(`Top-level unhandled promise rejection: ${errorInfo}`);
const errorInfo = error && error.stack ? error.stack : error;
window.log.error('Top-level unhandled promise rejection:', errorInfo);
});
24 changes: 14 additions & 10 deletions js/models/conversations.js
Original file line number Diff line number Diff line change
Expand Up @@ -2210,16 +2210,20 @@
return;
}

const profileKeyBuffer = window.Signal.Crypto.base64ToArrayBuffer(
profileKey
);
const accessKeyBuffer = await window.Signal.Crypto.deriveAccessKey(
profileKeyBuffer
);
const accessKey = window.Signal.Crypto.arrayBufferToBase64(
accessKeyBuffer
);
this.set({ accessKey });
try {
const profileKeyBuffer = window.Signal.Crypto.base64ToArrayBuffer(
profileKey
);
const accessKeyBuffer = await window.Signal.Crypto.deriveAccessKey(
profileKeyBuffer
);
const accessKey = window.Signal.Crypto.arrayBufferToBase64(
accessKeyBuffer
);
this.set({ accessKey });
} catch (e) {
window.log.warn(`Failed to derive access key for ${this.id}`);
}
},

async upgradeMessages(messages) {
Expand Down
3 changes: 2 additions & 1 deletion js/modules/loki_app_dot_net_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1710,8 +1710,9 @@ class LokiPublicChannelAPI {
sigString += [...attachmentAnnotations, ...previewAnnotations]
.map(data => data.id || data.image.id)
.sort()
.join();
.join('');
sigString += sigVer;

return dcodeIO.ByteBuffer.wrap(sigString, 'utf8').toArrayBuffer();
}

Expand Down
4 changes: 4 additions & 0 deletions js/modules/loki_file_server_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ class LokiHomeServerInstance extends LokiFileServerInstance {
}

async updateOurDeviceMapping() {
if (!window.lokiFeatureFlags.useMultiDevice) {
return undefined;
}

const isPrimary = !storage.get('isSecondaryDevice');
const authorisations = await window.libsession.Protocols.MultiDeviceProtocol.getPairingAuthorisations(
this.ourKey
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "session-messenger-desktop",
"productName": "Session",
"description": "Private messaging from your desktop",
"version": "1.2.0",
"version": "1.2.1",
"license": "GPL-3.0",
"author": {
"name": "Loki Project",
Expand Down
25 changes: 25 additions & 0 deletions preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ window.lokiFeatureFlags = {
enableSenderKeys: false,
onionRequestHops: 3,
debugMessageLogs: process.env.ENABLE_MESSAGE_LOGS,
useMultiDevice: false,
};

// eslint-disable-next-line no-extend-native,func-names
Expand Down Expand Up @@ -492,6 +493,7 @@ if (config.environment.includes('test-integration')) {
useFileOnionRequests: false,
debugMessageLogs: true,
enableSenderKeys: true,
useMultiDevice: false,
};
}

Expand All @@ -502,3 +504,26 @@ const {
} = require('./ts/util/blockedNumberController');

window.BlockedNumberController = BlockedNumberController;

window.deleteAccount = async reason => {
try {
window.log.info('Deleting everything!');

const { Logs } = window.Signal;
await Logs.deleteAll();

await window.Signal.Data.removeAll();
await window.Signal.Data.close();
await window.Signal.Data.removeDB();

await window.Signal.Data.removeOtherData();
// 'unlink' => toast will be shown on app restart
window.localStorage.setItem('restart-reason', reason);
} catch (error) {
window.log.error(
'Something went wrong deleting all data:',
error && error.stack ? error.stack : error
);
}
window.restart();
};
42 changes: 0 additions & 42 deletions ts/components/session/ActionsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,48 +59,6 @@ export class ActionsPanel extends React.Component<Props, State> {
},
'refreshAvatarCallback'
);
setTimeout(async () => {
const disabledMultiDeviceCountDb = await getItemById(
'disabledMultiDeviceCount'
);
const disabledMultiDeviceCount =
Number(disabledMultiDeviceCountDb?.value) || 0;
const data = {
id: 'disabledMultiDeviceCount',
value: String(disabledMultiDeviceCount + 1),
};
await createOrUpdateItem(data);
if (disabledMultiDeviceCount % 5 !== 0) {
return;
}
const currentDevice = await UserUtil.getCurrentDevicePubKey();
if (!currentDevice) {
return;
}
const secondaryDevices = await MultiDeviceProtocol.getSecondaryDevices(
currentDevice
);
const isSecondary =
secondaryDevices.find(s => s.key === currentDevice) ||
!!window.textsecure.storage.get('isSecondaryDevice');

const hasMultipleDevices =
(await MultiDeviceProtocol.getOurDevices()).length > 1;
const primaryWithSecondary = !isSecondary && hasMultipleDevices;

if (!primaryWithSecondary && !isSecondary) {
return;
}

const opts = {
hideCancel: true,
title: window.i18n('multiDeviceDisabledTemporaryTitle'),
message: primaryWithSecondary
? window.i18n('multiDeviceDisabledTemporaryDescriptionPrimary')
: window.i18n('multiDeviceDisabledTemporaryDescriptionSecondary'),
};
window.Whisper.events.trigger('showConfirmationDialog', opts);
}, 1000);
}
);
}
Expand Down

0 comments on commit 9fdd151

Please sign in to comment.