From bb0112c6c54253c70a065d1def6566c3bc2fe423 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Tue, 7 Feb 2023 11:03:19 +1100 Subject: [PATCH 1/4] feat: increase max upload size to 10MB --- .../conversation/SessionConversation.tsx | 2 +- ts/data/dataInit.ts | 4 +++ ts/models/message.ts | 2 +- ts/session/constants.ts | 7 ++-- ts/session/crypto/BufferPadding.ts | 11 +++++- ts/test/session/unit/padding/Padding_test.ts | 36 +++++++++++++++++++ 6 files changed, 57 insertions(+), 5 deletions(-) diff --git a/ts/components/conversation/SessionConversation.tsx b/ts/components/conversation/SessionConversation.tsx index c202e0c79..be0c5b4d6 100644 --- a/ts/components/conversation/SessionConversation.tsx +++ b/ts/components/conversation/SessionConversation.tsx @@ -408,7 +408,7 @@ export class SessionConversation extends React.Component { blob: file, }); - if (blob.blob.size >= MAX_ATTACHMENT_FILESIZE_BYTES) { + if (blob.blob.size > MAX_ATTACHMENT_FILESIZE_BYTES) { ToastUtils.pushFileSizeErrorAsByte(MAX_ATTACHMENT_FILESIZE_BYTES); return; } diff --git a/ts/data/dataInit.ts b/ts/data/dataInit.ts index f838adfcc..71db245ab 100644 --- a/ts/data/dataInit.ts +++ b/ts/data/dataInit.ts @@ -113,6 +113,8 @@ export async function shutdown() { // No outstanding jobs, return immediately if (jobKeys.length === 0) { + window?.log?.info('data.shutdown: No outstanding jobs'); + return null; } @@ -246,6 +248,8 @@ function removeJob(id: number) { if (_shutdownCallback) { const keys = Object.keys(jobs); + window?.log?.info(`removeJob: _shutdownCallback and we still have ${keys.length} jobs to run`); + if (keys.length === 0) { _shutdownCallback(); } diff --git a/ts/models/message.ts b/ts/models/message.ts index 2096133ee..e3072dde5 100644 --- a/ts/models/message.ts +++ b/ts/models/message.ts @@ -690,7 +690,7 @@ export class MessageModel extends Backbone.Model { height: height || 0, path, fileName, - fileSize: size ? filesize(size) : null, + fileSize: size ? filesize(size, { base: 10 }) : null, isVoiceMessage: isVoiceMessageBool, pending: Boolean(pending), url: path ? getAbsoluteAttachmentPath(path) : '', diff --git a/ts/session/constants.ts b/ts/session/constants.ts index 72b546a9d..a6d71bf0d 100644 --- a/ts/session/constants.ts +++ b/ts/session/constants.ts @@ -41,9 +41,12 @@ export const CONVERSATION = { MAX_VOICE_MESSAGE_DURATION: 300, MAX_UNREAD_COUNT: 9999, }; -// Max attachment size: 6 MB -export const MAX_ATTACHMENT_FILESIZE_BYTES = 6 * 1000 * 1000; // 6MB +/** + * The file server and onion request max upload size is 10MB precisely. + * 10MB is still ok, but one byte more is not. + */ +export const MAX_ATTACHMENT_FILESIZE_BYTES = 10 * 1000 * 1000; export const VALIDATION = { MAX_GROUP_NAME_LENGTH: 30, diff --git a/ts/session/crypto/BufferPadding.ts b/ts/session/crypto/BufferPadding.ts index 6d3588df7..23931e9c7 100644 --- a/ts/session/crypto/BufferPadding.ts +++ b/ts/session/crypto/BufferPadding.ts @@ -1,3 +1,5 @@ +import { MAX_ATTACHMENT_FILESIZE_BYTES } from '../constants'; + /** * This file is used to pad message buffer and attachments */ @@ -73,10 +75,17 @@ export function addAttachmentPadding(data: ArrayBuffer): ArrayBuffer { const originalUInt = new Uint8Array(data); window?.log?.info('Adding attachment padding...'); - const paddedSize = Math.max( + let paddedSize = Math.max( 541, Math.floor(Math.pow(1.05, Math.ceil(Math.log(originalUInt.length) / Math.log(1.05)))) ); + + if ( + paddedSize > MAX_ATTACHMENT_FILESIZE_BYTES && + originalUInt.length <= MAX_ATTACHMENT_FILESIZE_BYTES + ) { + paddedSize = MAX_ATTACHMENT_FILESIZE_BYTES; + } const paddedData = new ArrayBuffer(paddedSize); const paddedUInt = new Uint8Array(paddedData); diff --git a/ts/test/session/unit/padding/Padding_test.ts b/ts/test/session/unit/padding/Padding_test.ts index 783fe6b60..17828955e 100644 --- a/ts/test/session/unit/padding/Padding_test.ts +++ b/ts/test/session/unit/padding/Padding_test.ts @@ -10,6 +10,7 @@ import { getUnpaddedAttachment, removeMessagePadding, } from '../../../../session/crypto/BufferPadding'; +import { MAX_ATTACHMENT_FILESIZE_BYTES } from '../../../../session/constants'; chai.use(chaiAsPromised as any); chai.should(); @@ -30,6 +31,41 @@ describe('Padding', () => { ); }); + it('no padding if attachment has the max size', () => { + //if the attachment is already of the max size, we do not pad it more + const bufferIn = new Uint8Array(MAX_ATTACHMENT_FILESIZE_BYTES); + const paddedBuffer = addAttachmentPadding(bufferIn); + expect(paddedBuffer.byteLength).to.equal(MAX_ATTACHMENT_FILESIZE_BYTES); + expect(new Uint8Array(paddedBuffer)).to.equalBytes(bufferIn); + }); + + it('add padding is limited to max attachment size', () => { + // there is only enough room to add one byte as padding. + const bufferIn = new Uint8Array(MAX_ATTACHMENT_FILESIZE_BYTES - 1); + const paddedBuffer = addAttachmentPadding(bufferIn); + expect(paddedBuffer.byteLength).to.equal(MAX_ATTACHMENT_FILESIZE_BYTES); + expect(new Uint8Array(paddedBuffer.slice(0, bufferIn.length))).to.equalBytes(bufferIn); + // this makes sure that the padding is just the 0 bytes + expect(paddedBuffer.slice(bufferIn.length).byteLength).to.eq(1); + expect(new Uint8Array(paddedBuffer.slice(bufferIn.length))).to.equalBytes( + new Uint8Array([0]) + ); + }); + + it('add padding if the attachment is already too big', () => { + // we just want to make sure we do not overide attachment data. The file upload will fail, but at least make sure to keep the user data. + const bufferIn = new Uint8Array(MAX_ATTACHMENT_FILESIZE_BYTES + 1); + const paddedBuffer = addAttachmentPadding(bufferIn); + const expectedPaddedSize = Math.floor( + Math.pow(1.05, Math.ceil(Math.log(bufferIn.length) / Math.log(1.05))) + ); + expect(new Uint8Array(paddedBuffer.slice(0, bufferIn.length))).to.equalBytes(bufferIn); + // this makes sure that the padding is just the 0 bytes + expect(new Uint8Array(paddedBuffer.slice(bufferIn.length))).to.equalBytes( + new Uint8Array(expectedPaddedSize - bufferIn.length) + ); + }); + it('remove padding', () => { // padding can be anything after the expected size const expectedSize = 10; From 6d57bce10393a52b7caa5810712b716b1ec46a59 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Tue, 7 Feb 2023 16:36:18 +1100 Subject: [PATCH 2/4] fix: reduce font size of group name and add padding --- ts/components/conversation/SessionRightPanel.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ts/components/conversation/SessionRightPanel.tsx b/ts/components/conversation/SessionRightPanel.tsx index 7a836dbb7..eefa5970d 100644 --- a/ts/components/conversation/SessionRightPanel.tsx +++ b/ts/components/conversation/SessionRightPanel.tsx @@ -181,6 +181,11 @@ const StyledGroupSettingsItem = styled.div` } `; +const StyledName = styled.h4` + padding-inline: var(--margins-md); + font-size: var(--font-size-md); +`; + // tslint:disable: cyclomatic-complexity // tslint:disable: max-func-body-length export const SessionRightPanelWithDetails = () => { @@ -276,7 +281,7 @@ export const SessionRightPanelWithDetails = () => { return (
-

{displayNameInProfile}

+ {displayNameInProfile} {showMemberCount && ( <> From d512a1a13106012402e0ca4d1db7f0850df93a97 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Tue, 7 Feb 2023 16:37:03 +1100 Subject: [PATCH 3/4] fix: various UI margins and dedup official sogs join --- .../message-content/ClickToTrustSender.tsx | 4 +++- .../message-content/MessageAttachment.tsx | 2 +- ts/models/message.ts | 4 ++++ .../open_group_api/opengroupV2/ApiUtil.ts | 4 ++-- .../opengroupV2/OpenGroupManagerV2.ts | 21 +++++++++++++++---- 5 files changed, 27 insertions(+), 8 deletions(-) diff --git a/ts/components/conversation/message/message-content/ClickToTrustSender.tsx b/ts/components/conversation/message/message-content/ClickToTrustSender.tsx index 8a20ddcea..1d5e7e8ac 100644 --- a/ts/components/conversation/message/message-content/ClickToTrustSender.tsx +++ b/ts/components/conversation/message/message-content/ClickToTrustSender.tsx @@ -8,13 +8,15 @@ import { SessionButtonColor } from '../../../basic/SessionButton'; import { SessionIcon } from '../../../icon'; const StyledTrustSenderUI = styled.div` - padding-inline: var(--margins-sm); + padding-inline: var(--margins-lg); display: flex; align-items: center; width: fit-content; border-radius: var(--border-radius-message-box); background-color: var(--message-bubbles-received-background-color); + height: 35px; + margin-left: var(--margins-xs); `; const ClickToDownload = styled.div` diff --git a/ts/components/conversation/message/message-content/MessageAttachment.tsx b/ts/components/conversation/message/message-content/MessageAttachment.tsx index f636c6ebb..95b773b6a 100644 --- a/ts/components/conversation/message/message-content/MessageAttachment.tsx +++ b/ts/components/conversation/message/message-content/MessageAttachment.tsx @@ -150,7 +150,7 @@ export const MessageAttachment = (props: Props) => { e.stopPropagation(); e.preventDefault(); }} - style={{ padding: '5px 10px' }} + style={{ padding: 'var(--margins-xs) 0px' }} > { return undefined; } + if (this.getConversation()?.get('left')) { + return 'sent'; + } + const readBy = this.get('read_by') || []; if (Storage.get(SettingsKey.settingsReadReceipt) && readBy.length > 0) { return 'read'; diff --git a/ts/session/apis/open_group_api/opengroupV2/ApiUtil.ts b/ts/session/apis/open_group_api/opengroupV2/ApiUtil.ts index e1aedf677..dc7d48b26 100644 --- a/ts/session/apis/open_group_api/opengroupV2/ApiUtil.ts +++ b/ts/session/apis/open_group_api/opengroupV2/ApiUtil.ts @@ -38,9 +38,9 @@ export type OpenGroupV2InfoJoinable = OpenGroupV2Info & { // tslint:disable: no-http-string -const legacyDefaultServerIP = '116.203.70.33'; +export const legacyDefaultServerIP = '116.203.70.33'; export const defaultServer = 'https://open.getsession.org'; -const defaultServerHost = new window.URL(defaultServer).host; +export const defaultServerHost = new window.URL(defaultServer).host; /** * This function returns true if the server url given matches any of the sogs run by Session. diff --git a/ts/session/apis/open_group_api/opengroupV2/OpenGroupManagerV2.ts b/ts/session/apis/open_group_api/opengroupV2/OpenGroupManagerV2.ts index e003a6b2b..409ccd856 100644 --- a/ts/session/apis/open_group_api/opengroupV2/OpenGroupManagerV2.ts +++ b/ts/session/apis/open_group_api/opengroupV2/OpenGroupManagerV2.ts @@ -3,7 +3,12 @@ import { ConversationModel } from '../../../../models/conversation'; import { getConversationController } from '../../../conversations'; import { allowOnlyOneAtATime } from '../../../utils/Promise'; import { getOpenGroupV2ConversationId } from '../utils/OpenGroupUtils'; -import { OpenGroupRequestCommonType } from './ApiUtil'; +import { + defaultServer, + defaultServerHost, + legacyDefaultServerIP, + OpenGroupRequestCommonType, +} from './ApiUtil'; import { OpenGroupServerPoller } from './OpenGroupServerPoller'; import _, { clone, isEqual } from 'lodash'; @@ -46,9 +51,16 @@ export class OpenGroupManagerV2 { roomId: string, publicKey: string ): Promise { - const oneAtaTimeStr = `oneAtaTimeOpenGroupV2Join:${serverUrl}${roomId}`; + // make sure to use the https version of our official sogs + const overridenUrl = + (serverUrl.includes(`://${defaultServerHost}`) && !serverUrl.startsWith('https')) || + serverUrl.includes(`://${legacyDefaultServerIP}`) + ? defaultServer + : serverUrl; + + const oneAtaTimeStr = `oneAtaTimeOpenGroupV2Join:${overridenUrl}${roomId}`; return allowOnlyOneAtATime(oneAtaTimeStr, async () => { - return this.attemptConnectionV2(serverUrl, roomId, publicKey); + return this.attemptConnectionV2(overridenUrl, roomId, publicKey); }); } @@ -82,10 +94,11 @@ export class OpenGroupManagerV2 { const poller = this.pollers.get(groupedRoomsServerUrl); if (!poller) { const uniqGroupedRooms = _.uniqBy(groupedRooms, r => r.roomId); + this.pollers.set(groupedRoomsServerUrl, new OpenGroupServerPoller(uniqGroupedRooms)); } else { // this won't do a thing if the room is already polled for - roomInfos.forEach(poller.addRoomToPoll); + groupedRooms.forEach(poller.addRoomToPoll); } } } From d2d2a418ebf2247b3406af36ddee04fdb2a699aa Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Wed, 8 Feb 2023 16:00:10 +1100 Subject: [PATCH 4/4] fix: use envelope time when dont have msg request response timestamp --- ts/receiver/contentMessage.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/ts/receiver/contentMessage.ts b/ts/receiver/contentMessage.ts index ff29d76a3..aa8dc813a 100644 --- a/ts/receiver/contentMessage.ts +++ b/ts/receiver/contentMessage.ts @@ -626,11 +626,9 @@ async function handleMessageRequestResponse( unblindedConvoId, ConversationTypeEnum.PRIVATE ); - let mostRecentActiveAt = - Math.max(...compact(convosToMerge.map(m => m.get('active_at')))) || Date.now(); - - if (!isFinite(mostRecentActiveAt)) { - mostRecentActiveAt = Date.now(); + let mostRecentActiveAt = Math.max(...compact(convosToMerge.map(m => m.get('active_at')))); + if (!isFinite(mostRecentActiveAt) || mostRecentActiveAt <= 0) { + mostRecentActiveAt = toNumber(envelope.timestamp); } conversationToApprove.set({