Merge branch 'clearnet' into fix/undefined-country

pull/2676/head
unknown 2 years ago
commit eaf61ae25d

@ -408,7 +408,7 @@ export class SessionConversation extends React.Component<Props, State> {
blob: file, blob: file,
}); });
if (blob.blob.size >= MAX_ATTACHMENT_FILESIZE_BYTES) { if (blob.blob.size > MAX_ATTACHMENT_FILESIZE_BYTES) {
ToastUtils.pushFileSizeErrorAsByte(MAX_ATTACHMENT_FILESIZE_BYTES); ToastUtils.pushFileSizeErrorAsByte(MAX_ATTACHMENT_FILESIZE_BYTES);
return; return;
} }

@ -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: cyclomatic-complexity
// tslint:disable: max-func-body-length // tslint:disable: max-func-body-length
export const SessionRightPanelWithDetails = () => { export const SessionRightPanelWithDetails = () => {
@ -276,7 +281,7 @@ export const SessionRightPanelWithDetails = () => {
return ( return (
<div className="group-settings"> <div className="group-settings">
<HeaderItem /> <HeaderItem />
<h2 data-testid="right-panel-group-name">{displayNameInProfile}</h2> <StyledName data-testid="right-panel-group-name">{displayNameInProfile}</StyledName>
{showMemberCount && ( {showMemberCount && (
<> <>
<SpacerLG /> <SpacerLG />

@ -8,13 +8,15 @@ import { SessionButtonColor } from '../../../basic/SessionButton';
import { SessionIcon } from '../../../icon'; import { SessionIcon } from '../../../icon';
const StyledTrustSenderUI = styled.div` const StyledTrustSenderUI = styled.div`
padding-inline: var(--margins-sm); padding-inline: var(--margins-lg);
display: flex; display: flex;
align-items: center; align-items: center;
width: fit-content; width: fit-content;
border-radius: var(--border-radius-message-box); border-radius: var(--border-radius-message-box);
background-color: var(--message-bubbles-received-background-color); background-color: var(--message-bubbles-received-background-color);
height: 35px;
margin-left: var(--margins-xs);
`; `;
const ClickToDownload = styled.div` const ClickToDownload = styled.div`

@ -150,7 +150,7 @@ export const MessageAttachment = (props: Props) => {
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
}} }}
style={{ padding: '5px 10px' }} style={{ padding: 'var(--margins-xs) 0px' }}
> >
<AudioPlayerWithEncryptedFile <AudioPlayerWithEncryptedFile
src={firstAttachment.url} src={firstAttachment.url}

@ -113,6 +113,8 @@ export async function shutdown() {
// No outstanding jobs, return immediately // No outstanding jobs, return immediately
if (jobKeys.length === 0) { if (jobKeys.length === 0) {
window?.log?.info('data.shutdown: No outstanding jobs');
return null; return null;
} }
@ -246,6 +248,8 @@ function removeJob(id: number) {
if (_shutdownCallback) { if (_shutdownCallback) {
const keys = Object.keys(jobs); const keys = Object.keys(jobs);
window?.log?.info(`removeJob: _shutdownCallback and we still have ${keys.length} jobs to run`);
if (keys.length === 0) { if (keys.length === 0) {
_shutdownCallback(); _shutdownCallback();
} }

@ -438,6 +438,10 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
return undefined; return undefined;
} }
if (this.getConversation()?.get('left')) {
return 'sent';
}
const readBy = this.get('read_by') || []; const readBy = this.get('read_by') || [];
if (Storage.get(SettingsKey.settingsReadReceipt) && readBy.length > 0) { if (Storage.get(SettingsKey.settingsReadReceipt) && readBy.length > 0) {
return 'read'; return 'read';
@ -690,7 +694,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
height: height || 0, height: height || 0,
path, path,
fileName, fileName,
fileSize: size ? filesize(size) : null, fileSize: size ? filesize(size, { base: 10 }) : null,
isVoiceMessage: isVoiceMessageBool, isVoiceMessage: isVoiceMessageBool,
pending: Boolean(pending), pending: Boolean(pending),
url: path ? getAbsoluteAttachmentPath(path) : '', url: path ? getAbsoluteAttachmentPath(path) : '',

@ -626,11 +626,9 @@ async function handleMessageRequestResponse(
unblindedConvoId, unblindedConvoId,
ConversationTypeEnum.PRIVATE ConversationTypeEnum.PRIVATE
); );
let mostRecentActiveAt = let mostRecentActiveAt = Math.max(...compact(convosToMerge.map(m => m.get('active_at'))));
Math.max(...compact(convosToMerge.map(m => m.get('active_at')))) || Date.now(); if (!isFinite(mostRecentActiveAt) || mostRecentActiveAt <= 0) {
mostRecentActiveAt = toNumber(envelope.timestamp);
if (!isFinite(mostRecentActiveAt)) {
mostRecentActiveAt = Date.now();
} }
conversationToApprove.set({ conversationToApprove.set({

@ -38,9 +38,9 @@ export type OpenGroupV2InfoJoinable = OpenGroupV2Info & {
// tslint:disable: no-http-string // 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'; 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. * This function returns true if the server url given matches any of the sogs run by Session.

@ -3,7 +3,12 @@ import { ConversationModel } from '../../../../models/conversation';
import { getConversationController } from '../../../conversations'; import { getConversationController } from '../../../conversations';
import { allowOnlyOneAtATime } from '../../../utils/Promise'; import { allowOnlyOneAtATime } from '../../../utils/Promise';
import { getOpenGroupV2ConversationId } from '../utils/OpenGroupUtils'; import { getOpenGroupV2ConversationId } from '../utils/OpenGroupUtils';
import { OpenGroupRequestCommonType } from './ApiUtil'; import {
defaultServer,
defaultServerHost,
legacyDefaultServerIP,
OpenGroupRequestCommonType,
} from './ApiUtil';
import { OpenGroupServerPoller } from './OpenGroupServerPoller'; import { OpenGroupServerPoller } from './OpenGroupServerPoller';
import _, { clone, isEqual } from 'lodash'; import _, { clone, isEqual } from 'lodash';
@ -46,9 +51,16 @@ export class OpenGroupManagerV2 {
roomId: string, roomId: string,
publicKey: string publicKey: string
): Promise<ConversationModel | undefined> { ): Promise<ConversationModel | undefined> {
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 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); const poller = this.pollers.get(groupedRoomsServerUrl);
if (!poller) { if (!poller) {
const uniqGroupedRooms = _.uniqBy(groupedRooms, r => r.roomId); const uniqGroupedRooms = _.uniqBy(groupedRooms, r => r.roomId);
this.pollers.set(groupedRoomsServerUrl, new OpenGroupServerPoller(uniqGroupedRooms)); this.pollers.set(groupedRoomsServerUrl, new OpenGroupServerPoller(uniqGroupedRooms));
} else { } else {
// this won't do a thing if the room is already polled for // this won't do a thing if the room is already polled for
roomInfos.forEach(poller.addRoomToPoll); groupedRooms.forEach(poller.addRoomToPoll);
} }
} }
} }

@ -41,9 +41,12 @@ export const CONVERSATION = {
MAX_VOICE_MESSAGE_DURATION: 300, MAX_VOICE_MESSAGE_DURATION: 300,
MAX_UNREAD_COUNT: 9999, 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 = { export const VALIDATION = {
MAX_GROUP_NAME_LENGTH: 30, MAX_GROUP_NAME_LENGTH: 30,

@ -1,3 +1,5 @@
import { MAX_ATTACHMENT_FILESIZE_BYTES } from '../constants';
/** /**
* This file is used to pad message buffer and attachments * 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); const originalUInt = new Uint8Array(data);
window?.log?.info('Adding attachment padding...'); window?.log?.info('Adding attachment padding...');
const paddedSize = Math.max( let paddedSize = Math.max(
541, 541,
Math.floor(Math.pow(1.05, Math.ceil(Math.log(originalUInt.length) / Math.log(1.05)))) 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 paddedData = new ArrayBuffer(paddedSize);
const paddedUInt = new Uint8Array(paddedData); const paddedUInt = new Uint8Array(paddedData);

@ -10,6 +10,7 @@ import {
getUnpaddedAttachment, getUnpaddedAttachment,
removeMessagePadding, removeMessagePadding,
} from '../../../../session/crypto/BufferPadding'; } from '../../../../session/crypto/BufferPadding';
import { MAX_ATTACHMENT_FILESIZE_BYTES } from '../../../../session/constants';
chai.use(chaiAsPromised as any); chai.use(chaiAsPromised as any);
chai.should(); 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', () => { it('remove padding', () => {
// padding can be anything after the expected size // padding can be anything after the expected size
const expectedSize = 10; const expectedSize = 10;

Loading…
Cancel
Save