diff --git a/ts/components/conversation/MessageRequestButtons.tsx b/ts/components/conversation/MessageRequestButtons.tsx index 0f22d88b9..454769607 100644 --- a/ts/components/conversation/MessageRequestButtons.tsx +++ b/ts/components/conversation/MessageRequestButtons.tsx @@ -98,6 +98,25 @@ export const ConversationMessageRequestButtons = () => { return ( + + { + void handleAcceptConversationRequest({ convoId: selectedConvoId }); + }} + text={window.i18n('accept')} + dataTestId="accept-message-request" + /> + { + handleDeclineConversationRequest(selectedConvoId, selectedConvoId, convoOrigin); + }} + dataTestId="decline-message-request" + /> + + + {isOutgoingRequest ? ( ) : ( @@ -116,24 +135,6 @@ export const ConversationMessageRequestButtons = () => { {window.i18n('block')} ) : null} - - - { - void handleAcceptConversationRequest({ convoId: selectedConvoId }); - }} - text={window.i18n('accept')} - dataTestId="accept-message-request" - /> - { - handleDeclineConversationRequest(selectedConvoId, selectedConvoId, convoOrigin); - }} - dataTestId="decline-message-request" - /> - )} diff --git a/ts/components/conversation/SessionMessagesListContainer.tsx b/ts/components/conversation/SessionMessagesListContainer.tsx index 5c48f47ce..c8deb3f19 100644 --- a/ts/components/conversation/SessionMessagesListContainer.tsx +++ b/ts/components/conversation/SessionMessagesListContainer.tsx @@ -27,7 +27,6 @@ import { import { getSelectedConversationKey } from '../../state/selectors/selectedConversation'; import { SessionMessagesList } from './SessionMessagesList'; import { TypingBubble } from './TypingBubble'; -import { ConversationMessageRequestButtons } from './MessageRequestButtons'; export type SessionMessageListProps = { messageContainerRef: RefObject; @@ -126,7 +125,6 @@ class SessionMessagesListContainerInner extends Component { key="typing-bubble" /> - { const showMsgRequestUI = selectedConversation && isIncomingMessageRequest; const hasOutgoingMessages = useSelector(hasSelectedConversationOutgoingMessages); + const isGroupV2 = useSelectedIsGroupV2() + + if (isGroupV2) { + return + } + if (!showMsgRequestUI || hasOutgoingMessages) { return null; } diff --git a/ts/node/logging.ts b/ts/node/logging.ts index 80bd5f7d8..e22901442 100644 --- a/ts/node/logging.ts +++ b/ts/node/logging.ts @@ -197,6 +197,7 @@ async function fetchLogFile(logFile: string) { } function logAtLevel(level: string, ...args: any) { + if (logger) { // To avoid [Object object] in our log since console.log handles non-strings smoothly const str = args.map((item: any) => { diff --git a/ts/session/apis/snode_api/snodePool.ts b/ts/session/apis/snode_api/snodePool.ts index 3aafab6a0..ab9b94bd4 100644 --- a/ts/session/apis/snode_api/snodePool.ts +++ b/ts/session/apis/snode_api/snodePool.ts @@ -49,7 +49,6 @@ async function dropSnodeFromSnodePool(snodeEd25519: string) { async function getRandomSnode(excludingEd25519Snode?: Array): Promise { // make sure we have a few snodes in the pool excluding the one passed as args const requiredCount = SnodePoolConstants.minSnodePoolCount + (excludingEd25519Snode?.length || 0); - debugger; if (randomSnodePool.length < requiredCount) { await SnodePool.getSnodePoolFromDBOrFetchFromSeed(excludingEd25519Snode?.length); @@ -67,7 +66,6 @@ async function getRandomSnode(excludingEd25519Snode?: Array): Promise { TestUtils.stubCreateObjectUrl(); }); - it('url starts with attachment path but is not already decrypted', () => { - expect( - DecryptedAttachmentsManager.getAlreadyDecryptedMediaUrl('/local/attachment/attachment1') - ).to.be.eq(null); - }); - it('url starts with attachment path but is not already decrypted', async () => { expect( DecryptedAttachmentsManager.getAlreadyDecryptedMediaUrl('/local/attachment/attachment1') ).to.be.eq(null); + expect(readFileContent.callCount).to.be.eq(0); expect(decryptAttachmentBufferNode.callCount).to.be.eq(0); expect(getItemById.callCount).to.be.eq(0); diff --git a/ts/test/session/unit/libsession_wrapper/libsession_wrapper_metagroup_test.ts b/ts/test/session/unit/libsession_wrapper/libsession_wrapper_metagroup_test.ts index 6e756ee9c..3da57731e 100644 --- a/ts/test/session/unit/libsession_wrapper/libsession_wrapper_metagroup_test.ts +++ b/ts/test/session/unit/libsession_wrapper/libsession_wrapper_metagroup_test.ts @@ -169,6 +169,7 @@ describe('libsession_metagroup', () => { }); it('can add member by setting its promoted state, both ok and nok', () => { + metaGroupWrapper.memberConstructAndSet(member); metaGroupWrapper.memberSetPromotionSent(member); expect(metaGroupWrapper.memberGetAll().length).to.be.deep.eq(1); expect(metaGroupWrapper.memberGetAll()[0]).to.be.deep.eq({ diff --git a/ts/test/session/unit/swarm_polling/SwarmPolling_test.ts b/ts/test/session/unit/swarm_polling/SwarmPolling_test.ts index be6114d2e..98c028a8a 100644 --- a/ts/test/session/unit/swarm_polling/SwarmPolling_test.ts +++ b/ts/test/session/unit/swarm_polling/SwarmPolling_test.ts @@ -15,7 +15,7 @@ import { UserSync } from '../../../../session/utils/job_runners/jobs/UserSyncJob import { sleepFor } from '../../../../session/utils/Promise'; import { UserGroupsWrapperActions } from '../../../../webworker/workers/browser/libsession_worker_interface'; import { TestUtils } from '../../../test-utils'; -import { generateFakeSnodes, stubData } from '../../../test-utils/utils'; +import { generateFakeSnodes, stubData, stubLibSessionWorker } from '../../../test-utils/utils'; import { ConversationTypeEnum } from '../../../../models/types'; import { ConvoHub } from '../../../../session/conversations'; import { SnodePool } from '../../../../session/apis/snode_api/snodePool'; @@ -135,7 +135,7 @@ describe('SwarmPolling', () => { }); }); - describe('groupv3', () => { + describe('groupv2', () => { it('returns ACTIVE for convo with less than two days old activeAt', () => { const convo = ConvoHub.use().getOrCreate( TestUtils.generateFakeClosedGroupV2PkStr(), @@ -189,36 +189,47 @@ describe('SwarmPolling', () => { describe('pollForAllKeys', () => { beforeEach(() => { + stubData('createOrUpdateItem').resolves(); }); afterEach(() => { Sinon.restore(); }); it('does run for our pubkey even if activeAt is really old ', async () => { + stubLibSessionWorker([]); + const convo = ConvoHub.use().getOrCreate(ourNumber, ConversationTypeEnum.PRIVATE); convo.set('active_at', Date.now() - 1000 * 3600 * 25); await swarmPolling.start(true); expect(pollOnceForKeySpy.callCount).to.eq(1); - expect(pollOnceForKeySpy.firstCall.args).to.deep.eq([ourPubkey, false, [0, 2, 3, 5, 4]]); + expect(pollOnceForKeySpy.firstCall.args[0]).to.deep.eq([ourPubkey.key, 'private']); }); it('does run for our pubkey even if activeAt is recent ', async () => { + stubLibSessionWorker([]); + const convo = ConvoHub.use().getOrCreate(ourNumber, ConversationTypeEnum.PRIVATE); convo.set('active_at', Date.now()); await swarmPolling.start(true); expect(pollOnceForKeySpy.callCount).to.eq(1); - expect(pollOnceForKeySpy.firstCall.args).to.deep.eq([ourPubkey, false, [0, 2, 3, 5, 4]]); + expect(pollOnceForKeySpy.firstCall.args[0]).to.deep.eq([ourPubkey.key, 'private']); }); describe('legacy group', () => { it('does run for group pubkey on start no matter the recent timestamp', async () => { + const convo = ConvoHub.use().getOrCreate( TestUtils.generateFakePubKeyStr(), ConversationTypeEnum.GROUP ); - TestUtils.stubLibSessionWorker(undefined); + TestUtils.stubLibSessionWorker([]); + stubData('removeAllMessagesInConversation').resolves() + stubData('getLatestClosedGroupEncryptionKeyPair').resolves() + stubData('removeAllClosedGroupEncryptionKeyPairs').resolves() + stubData('removeConversation').resolves() + stubData('fetchConvoMemoryDetails').resolves() convo.set('active_at', Date.now()); const groupConvoPubkey = PubKey.cast(convo.id as string); swarmPolling.addGroupId(groupConvoPubkey); @@ -226,8 +237,8 @@ describe('SwarmPolling', () => { // our pubkey will be polled for, hence the 2 expect(pollOnceForKeySpy.callCount).to.eq(2); - expect(pollOnceForKeySpy.firstCall.args).to.deep.eq([ourPubkey, false, [0, 2, 3, 5, 4]]); - expect(pollOnceForKeySpy.secondCall.args).to.deep.eq([groupConvoPubkey, true, [-10]]); + expect(pollOnceForKeySpy.firstCall.args[0]).to.deep.eq([ourPubkey.key, 'private']); + expect(pollOnceForKeySpy.secondCall.args[0]).to.deep.eq([groupConvoPubkey.key, 'private']); }); it('does only poll from -10 for closed groups if HF >= 19.1 ', async () => { diff --git a/ts/test/session/unit/utils/OpenGroupUtils_test.ts b/ts/test/session/unit/utils/OpenGroupUtils_test.ts index a86cd4b74..0dc372ffd 100644 --- a/ts/test/session/unit/utils/OpenGroupUtils_test.ts +++ b/ts/test/session/unit/utils/OpenGroupUtils_test.ts @@ -96,7 +96,7 @@ describe('OpenGroupUtils', () => { serverPublicKey: '', serverUrl: 'https://example.org', }) - ).to.throw('getCompleteUrlFromRoom needs serverPublicKey, roomid and serverUrl to be set'); + ).to.throw('getCompleteUrlFromRoom needs serverPublicKey, roomId and serverUrl to be set'); }); it('throws if serverUrl is empty', () => { @@ -106,7 +106,7 @@ describe('OpenGroupUtils', () => { serverPublicKey: '05123456789', serverUrl: '', }) - ).to.throw('getCompleteUrlFromRoom needs serverPublicKey, roomid and serverUrl to be set'); + ).to.throw('getCompleteUrlFromRoom needs serverPublicKey, roomId and serverUrl to be set'); }); it('throws if roomId is empty', () => { @@ -116,7 +116,7 @@ describe('OpenGroupUtils', () => { serverPublicKey: '05123456789', serverUrl: 'https://example.org', }) - ).to.throw('getCompleteUrlFromRoom needs serverPublicKey, roomid and serverUrl to be set'); + ).to.throw('getCompleteUrlFromRoom needs serverPublicKey, roomId and serverUrl to be set'); }); it('throws if pubkey is null', () => { expect(() => @@ -125,7 +125,7 @@ describe('OpenGroupUtils', () => { serverPublicKey: null as any, serverUrl: 'https://example.org', }) - ).to.throw('getCompleteUrlFromRoom needs serverPublicKey, roomid and serverUrl to be set'); + ).to.throw('getCompleteUrlFromRoom needs serverPublicKey, roomId and serverUrl to be set'); }); it('throws if serverUrl is null', () => { @@ -135,7 +135,7 @@ describe('OpenGroupUtils', () => { serverPublicKey: '05123456789', serverUrl: null as any, }) - ).to.throw('getCompleteUrlFromRoom needs serverPublicKey, roomid and serverUrl to be set'); + ).to.throw('getCompleteUrlFromRoom needs serverPublicKey, roomId and serverUrl to be set'); }); it('throws if roomId is null', () => { @@ -145,7 +145,7 @@ describe('OpenGroupUtils', () => { serverPublicKey: '05123456789', serverUrl: 'https://example.org', }) - ).to.throw('getCompleteUrlFromRoom needs serverPublicKey, roomid and serverUrl to be set'); + ).to.throw('getCompleteUrlFromRoom needs serverPublicKey, roomId and serverUrl to be set'); }); }); }); diff --git a/ts/util/logging.ts b/ts/util/logging.ts index c281f7363..add76b2ae 100644 --- a/ts/util/logging.ts +++ b/ts/util/logging.ts @@ -110,6 +110,12 @@ const development = window && window?.getEnvironment && window?.getEnvironment() // The Bunyan API: https://github.com/trentm/node-bunyan#log-method-api function logAtLevel(level: string, prefix: string, ...args: any) { + // when unit testing with mocha, we just log whatever we get to the console.log + if (typeof (global as any).it === 'function') { + (console as any)._log(prefix, now(), ...args); + return + } + if (prefix === 'DEBUG' && !window.sessionFeatureFlags.debug.debugLogging) { return; }