From 6ed5f505c38f6f017cf59b76cc60c3b3c4f16ee0 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Mon, 1 Feb 2021 15:07:59 +1100 Subject: [PATCH 1/3] be able to remove a closed group once we left it already --- .../session/menu/ConversationHeaderMenu.tsx | 1 + .../menu/ConversationListItemContextMenu.tsx | 1 + ts/components/session/menu/Menu.tsx | 16 +++++++++++++--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/ts/components/session/menu/ConversationHeaderMenu.tsx b/ts/components/session/menu/ConversationHeaderMenu.tsx index caa274622..f0a0454a9 100644 --- a/ts/components/session/menu/ConversationHeaderMenu.tsx +++ b/ts/components/session/menu/ConversationHeaderMenu.tsx @@ -125,6 +125,7 @@ export const ConversationHeaderMenu = (props: PropsConversationHeaderMenu) => { isMe, isGroup, isPublic, + left, onDeleteContact, window.i18n )} diff --git a/ts/components/session/menu/ConversationListItemContextMenu.tsx b/ts/components/session/menu/ConversationListItemContextMenu.tsx index f18bb260d..5d0ea6ff2 100644 --- a/ts/components/session/menu/ConversationListItemContextMenu.tsx +++ b/ts/components/session/menu/ConversationListItemContextMenu.tsx @@ -92,6 +92,7 @@ export const ConversationListItemContextMenu = ( isMe, type === 'group', isPublic, + left, onDeleteContact, window.i18n )} diff --git a/ts/components/session/menu/Menu.tsx b/ts/components/session/menu/Menu.tsx index 87072aad1..bb0be3d15 100644 --- a/ts/components/session/menu/Menu.tsx +++ b/ts/components/session/menu/Menu.tsx @@ -39,9 +39,11 @@ function showCopyId(isPublic: boolean, isGroup: boolean): boolean { function showDeleteContact( isMe: boolean, isGroup: boolean, - isPublic: boolean + isPublic: boolean, + isGroupLeft: boolean ): boolean { - return !isMe && Boolean(!isGroup || isPublic); + // you need to have left a closed group first to be able to delete it completely. + return (!isMe && !isGroup) || (isGroup && isGroupLeft); } function showAddModerators( @@ -97,10 +99,18 @@ export function getDeleteContactMenuItem( isMe: boolean | undefined, isGroup: boolean | undefined, isPublic: boolean | undefined, + isLeft: boolean | undefined, action: any, i18n: LocalizerType ): JSX.Element | null { - if (showDeleteContact(Boolean(isMe), Boolean(isGroup), Boolean(isPublic))) { + if ( + showDeleteContact( + Boolean(isMe), + Boolean(isGroup), + Boolean(isPublic), + Boolean(isLeft) + ) + ) { if (isPublic) { return {i18n('leaveGroup')}; } From f179694439df283070fed777d73a3d98d0f65a33 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Mon, 1 Feb 2021 15:43:05 +1100 Subject: [PATCH 2/3] remove unused worker --- js/background.js | 2 - libtextsecure/libsignal-protocol.js | 71 ----------------------------- libtextsecure/protocol_wrapper.js | 5 +- ts/util/lint/linter.ts | 1 - 4 files changed, 1 insertion(+), 78 deletions(-) diff --git a/js/background.js b/js/background.js index 283365e64..73a18ae64 100644 --- a/js/background.js +++ b/js/background.js @@ -106,8 +106,6 @@ window.document.title = window.getTitle(); - // start a background worker for ecc - textsecure.startWorker('js/libsignal-protocol-worker.js'); let messageReceiver; Whisper.events = _.clone(Backbone.Events); Whisper.events.isListenedTo = eventName => diff --git a/libtextsecure/libsignal-protocol.js b/libtextsecure/libsignal-protocol.js index f34a981a1..dfda09ecc 100644 --- a/libtextsecure/libsignal-protocol.js +++ b/libtextsecure/libsignal-protocol.js @@ -25316,77 +25316,6 @@ })(); - ; (function () { - - 'use strict'; - - // I am the...workee? - var origCurve25519 = Internal.curve25519_async; - - Internal.startWorker = function (url) { - Internal.stopWorker(); // there can be only one - - Internal.curve25519_async = new Curve25519Worker(url); - Internal.Curve.async = Internal.wrapCurve25519(Internal.curve25519_async); - libsignal.Curve.async = Internal.wrapCurve(Internal.Curve.async); - }; - - Internal.stopWorker = function () { - if (Internal.curve25519_async instanceof Curve25519Worker) { - var worker = Internal.curve25519_async.worker; - - Internal.curve25519_async = origCurve25519; - Internal.Curve.async = Internal.wrapCurve25519(Internal.curve25519_async); - libsignal.Curve.async = Internal.wrapCurve(Internal.Curve.async); - - worker.terminate(); - } - }; - - libsignal.worker = { - startWorker: Internal.startWorker, - stopWorker: Internal.stopWorker, - }; - - function Curve25519Worker(url) { - this.jobs = {}; - this.jobId = 0; - this.worker = new Worker(url); - this.worker.onmessage = function (e) { - var job = this.jobs[e.data.id]; - if (e.data.error && typeof job.onerror === 'function') { - job.onerror(new Error(e.data.error)); - } else if (typeof job.onsuccess === 'function') { - job.onsuccess(e.data.result); - } - delete this.jobs[e.data.id]; - }.bind(this); - } - - Curve25519Worker.prototype = { - constructor: Curve25519Worker, - postMessage: function (methodName, args, onsuccess, onerror) { - return new Promise(function (resolve, reject) { - this.jobs[this.jobId] = { onsuccess: resolve, onerror: reject }; - this.worker.postMessage({ id: this.jobId, methodName: methodName, args: args }); - this.jobId++; - }.bind(this)); - }, - keyPair: function (privKey) { - return this.postMessage('keyPair', [privKey]); - }, - sharedSecret: function (pubKey, privKey) { - return this.postMessage('sharedSecret', [pubKey, privKey]); - }, - sign: function (privKey, message) { - return this.postMessage('sign', [privKey, message]); - }, - verify: function (pubKey, message, sig) { - return this.postMessage('verify', [pubKey, message, sig]); - } - }; - - })(); /* Copyright 2013 Daniel Wirtz diff --git a/libtextsecure/protocol_wrapper.js b/libtextsecure/protocol_wrapper.js index 1846f26b9..73391ae4e 100644 --- a/libtextsecure/protocol_wrapper.js +++ b/libtextsecure/protocol_wrapper.js @@ -1,11 +1,8 @@ -/* global window, textsecure, SignalProtocolStore, libsignal */ +/* global window, textsecure, SignalProtocolStore */ // eslint-disable-next-line func-names (function() { window.textsecure = window.textsecure || {}; window.textsecure.storage = window.textsecure.storage || {}; textsecure.storage.protocol = new SignalProtocolStore(); - - textsecure.startWorker = libsignal.worker.startWorker; - textsecure.stopWorker = libsignal.worker.stopWorker; })(); diff --git a/ts/util/lint/linter.ts b/ts/util/lint/linter.ts index 48f5e31b7..e8b939cb7 100644 --- a/ts/util/lint/linter.ts +++ b/ts/util/lint/linter.ts @@ -64,7 +64,6 @@ const excludedFiles = [ '^test/test.js', // From libsignal-protocol-javascript project - '^js/libsignal-protocol-worker.js', '^libtextsecure/libsignal-protocol.js', // Test files From 446a1ecefbe8361e9ea3ffc98b851689c4a001b5 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Mon, 1 Feb 2021 17:07:44 +1100 Subject: [PATCH 3/3] show Delete conversation menu when we got removed from the group too --- js/models/conversations.js | 6 +++++- ts/components/session/menu/ConversationHeaderMenu.tsx | 1 + .../session/menu/ConversationListItemContextMenu.tsx | 1 + ts/components/session/menu/Menu.tsx | 9 ++++++--- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/js/models/conversations.js b/js/models/conversations.js index a16f2fe50..80de7e568 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -1360,7 +1360,11 @@ let title = i18n('delete'); let message = i18n('deleteContactConfirmation'); - if (this.isGroup()) { + if ( + this.isGroup() && + !this.get('left') && + !this.get('isKickedFromGroup') + ) { title = i18n('leaveGroup'); message = i18n('leaveGroupConfirmation'); } diff --git a/ts/components/session/menu/ConversationHeaderMenu.tsx b/ts/components/session/menu/ConversationHeaderMenu.tsx index f0a0454a9..9dcd0a37e 100644 --- a/ts/components/session/menu/ConversationHeaderMenu.tsx +++ b/ts/components/session/menu/ConversationHeaderMenu.tsx @@ -126,6 +126,7 @@ export const ConversationHeaderMenu = (props: PropsConversationHeaderMenu) => { isGroup, isPublic, left, + isKickedFromGroup, onDeleteContact, window.i18n )} diff --git a/ts/components/session/menu/ConversationListItemContextMenu.tsx b/ts/components/session/menu/ConversationListItemContextMenu.tsx index 5d0ea6ff2..7c3eadfb5 100644 --- a/ts/components/session/menu/ConversationListItemContextMenu.tsx +++ b/ts/components/session/menu/ConversationListItemContextMenu.tsx @@ -93,6 +93,7 @@ export const ConversationListItemContextMenu = ( type === 'group', isPublic, left, + isKickedFromGroup, onDeleteContact, window.i18n )} diff --git a/ts/components/session/menu/Menu.tsx b/ts/components/session/menu/Menu.tsx index bb0be3d15..25b83ae7d 100644 --- a/ts/components/session/menu/Menu.tsx +++ b/ts/components/session/menu/Menu.tsx @@ -40,10 +40,11 @@ function showDeleteContact( isMe: boolean, isGroup: boolean, isPublic: boolean, - isGroupLeft: boolean + isGroupLeft: boolean, + isKickedFromGroup: boolean ): boolean { // you need to have left a closed group first to be able to delete it completely. - return (!isMe && !isGroup) || (isGroup && isGroupLeft); + return (!isMe && !isGroup) || (isGroup && (isGroupLeft || isKickedFromGroup)); } function showAddModerators( @@ -100,6 +101,7 @@ export function getDeleteContactMenuItem( isGroup: boolean | undefined, isPublic: boolean | undefined, isLeft: boolean | undefined, + isKickedFromGroup: boolean | undefined, action: any, i18n: LocalizerType ): JSX.Element | null { @@ -108,7 +110,8 @@ export function getDeleteContactMenuItem( Boolean(isMe), Boolean(isGroup), Boolean(isPublic), - Boolean(isLeft) + Boolean(isLeft), + Boolean(isKickedFromGroup) ) ) { if (isPublic) {