Skip to content

Commit

Permalink
Merge pull request #2582 from oxen-io/clearnet
Browse files Browse the repository at this point in the history
Session 1.10.4
  • Loading branch information
Bilb authored Oct 27, 2022
2 parents 2e364ad + 8f426a5 commit 991ddd1
Show file tree
Hide file tree
Showing 22 changed files with 174 additions and 140 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "session-desktop",
"productName": "Session",
"description": "Private messaging from your desktop",
"version": "1.10.3",
"version": "1.10.4",
"license": "GPL-3.0",
"author": {
"name": "Oxen Labs",
Expand Down Expand Up @@ -306,7 +306,8 @@
"libnss3",
"libasound2",
"libxss1"
]
],
"packageCategory": "net"
},
"files": [
"package.json",
Expand Down
40 changes: 22 additions & 18 deletions ts/components/dialog/SessionPasswordDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,18 @@ export class SessionPasswordDialog extends React.Component<Props, State> {
}

public componentDidMount() {
document.addEventListener('keyup', this.onEnterPressed);

setTimeout(() => {
// tslint:disable-next-line: no-unused-expression
this.passportInput && this.passportInput.focus();
}, 1);
}

public componentWillUnmount() {
document.removeEventListener('keyup', this.onEnterPressed);
}

public render() {
const { passwordAction } = this.props;
let placeholders: Array<string> = [];
Expand Down Expand Up @@ -93,15 +99,17 @@ export class SessionPasswordDialog extends React.Component<Props, State> {
this.passportInput = input;
}}
placeholder={placeholders[0]}
onKeyUp={this.onPasswordInput}
onChange={this.onPasswordInput}
onPaste={this.onPasswordInput}
data-testid="password-input"
/>
{passwordAction !== 'enter' && passwordAction !== 'remove' && (
<input
type="password"
id="password-modal-input-confirm"
placeholder={placeholders[1]}
onKeyUp={this.onPasswordConfirmInput}
onChange={this.onPasswordConfirmInput}
onPaste={this.onPasswordConfirmInput}
data-testid="password-input-confirm"
/>
)}
Expand All @@ -110,7 +118,8 @@ export class SessionPasswordDialog extends React.Component<Props, State> {
type="password"
id="password-modal-input-reconfirm"
placeholder={placeholders[2]}
onKeyUp={this.onPasswordRetypeInput}
onPaste={this.onPasswordRetypeInput}
onChange={this.onPasswordRetypeInput}
data-testid="password-input-reconfirm"
/>
)}
Expand Down Expand Up @@ -258,6 +267,13 @@ export class SessionPasswordDialog extends React.Component<Props, State> {
this.closeDialog();
}

private async onEnterPressed(event: any) {
if (event.key === 'Enter') {
event.stopPropagation();
return this.setPassword();
}
}

private async handleActionEnter(enteredPassword: string) {
// be sure the password is valid
if (!this.validatePassword(enteredPassword)) {
Expand Down Expand Up @@ -321,30 +337,18 @@ export class SessionPasswordDialog extends React.Component<Props, State> {
window.inboxStore?.dispatch(sessionPassword(null));
}

private async onPasswordInput(event: any) {
if (event.key === 'Enter') {
return this.setPassword();
}
private onPasswordInput(event: any) {
const currentPasswordEntered = event.target.value;

this.setState({ currentPasswordEntered });
}

private async onPasswordConfirmInput(event: any) {
if (event.key === 'Enter') {
return this.setPassword();
}
private onPasswordConfirmInput(event: any) {
const currentPasswordConfirmEntered = event.target.value;

this.setState({ currentPasswordConfirmEntered });
}

private async onPasswordRetypeInput(event: any) {
if (event.key === 'Enter') {
return this.setPassword();
}
private onPasswordRetypeInput(event: any) {
const currentPasswordRetypeEntered = event.target.value;

this.setState({ currentPasswordRetypeEntered });
}
}
10 changes: 4 additions & 6 deletions ts/components/icon/SessionNotificationCount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ type Props = {

const StyledCountContainer = styled.div<{ shouldRender: boolean }>`
position: absolute;
width: 24px;
height: 12px;
font-size: 18px;
top: 27px;
right: 8px;
padding: 3px;
padding: 0 6px;
opacity: 1;
display: flex;
align-items: center;
Expand All @@ -29,19 +27,19 @@ const StyledCountContainer = styled.div<{ shouldRender: boolean }>`

const StyledCount = styled.div`
position: relative;
font-size: 0.6em;
font-size: 0.6rem;
`;

export const SessionNotificationCount = (props: Props) => {
const { count } = props;
const overflow = Boolean(count && count > 9);
const overflow = Boolean(count && count > 99);
const shouldRender = Boolean(count && count > 0);

if (overflow) {
return (
<StyledCountContainer shouldRender={shouldRender}>
<StyledCount>
{9}
{99}
<span>+</span>
</StyledCount>
</StyledCountContainer>
Expand Down
2 changes: 0 additions & 2 deletions ts/components/leftpane/ActionsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ const Section = (props: { type: SectionType }) => {
iconSize="medium"
dataTestId="settings-section"
iconType={'gear'}
notificationCount={unreadToShow}
onClick={handleClick}
isSelected={isSelected}
/>
Expand All @@ -138,7 +137,6 @@ const Section = (props: { type: SectionType }) => {
iconSize="medium"
iconType={isDarkMode ? 'moon' : 'sun'}
dataTestId="theme-section"
notificationCount={unreadToShow}
onClick={handleClick}
isSelected={isSelected}
/>
Expand Down
2 changes: 2 additions & 0 deletions ts/components/settings/section/CategoryPrivacy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export const SettingsCategoryPrivacy = (props: {
displayPasswordModal('change', props.onPasswordUpdated);
}}
buttonText={window.i18n('changePassword')}
dataTestId="change-password-settings-button"
/>
)}
{props.hasPassword && (
Expand All @@ -108,6 +109,7 @@ export const SettingsCategoryPrivacy = (props: {
}}
buttonColor={SessionButtonColor.Danger}
buttonText={window.i18n('removePassword')}
dataTestId="remove-password-settings-button"
/>
)}
</>
Expand Down
49 changes: 23 additions & 26 deletions ts/session/apis/open_group_api/opengroupV2/ApiUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,36 +142,33 @@ const defaultServerPublicKey = 'a03c383cf63c3c4efe67acc52112a6dd734b3a946b9545f4
const defaultRoom = `${defaultServer}/main?public_key=${defaultServerPublicKey}`;

const loadDefaultRoomsSingle = () =>
allowOnlyOneAtATime(
'loadDefaultRoomsSingle',
async (): Promise<Array<OpenGroupV2InfoJoinable>> => {
const roomInfos = parseOpenGroupV2(defaultRoom);
if (roomInfos) {
try {
const roomsGot = await getAllRoomInfos(roomInfos);

if (!roomsGot) {
return [];
}

return roomsGot.map(room => {
return {
...room,
completeUrl: getCompleteUrlFromRoom({
serverUrl: roomInfos.serverUrl,
serverPublicKey: roomInfos.serverPublicKey,
roomId: room.id,
}),
};
});
} catch (e) {
window?.log?.warn('loadDefaultRoomloadDefaultRoomssIfNeeded failed', e);
allowOnlyOneAtATime('loadDefaultRoomsSingle', async () => {
const roomInfos = parseOpenGroupV2(defaultRoom);
if (roomInfos) {
try {
const roomsGot = await getAllRoomInfos(roomInfos);

if (!roomsGot) {
return [];
}
return [];

return roomsGot.map(room => {
return {
...room,
completeUrl: getCompleteUrlFromRoom({
serverUrl: roomInfos.serverUrl,
serverPublicKey: roomInfos.serverPublicKey,
roomId: room.id,
}),
};
});
} catch (e) {
window?.log?.warn('loadDefaultRoomloadDefaultRoomssIfNeeded failed', e);
}
return [];
}
);
return [];
});

/**
* Load to the cache all the details of the room of the default opengroupv2 server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class OpenGroupManagerV2 {
serverUrl: string,
roomId: string,
publicKey: string
): Promise<ConversationModel> {
): Promise<ConversationModel | undefined> {
const oneAtaTimeStr = `oneAtaTimeOpenGroupV2Join:${serverUrl}${roomId}`;
return allowOnlyOneAtATime(oneAtaTimeStr, async () => {
return this.attemptConnectionV2(serverUrl, roomId, publicKey);
Expand Down
6 changes: 3 additions & 3 deletions ts/session/apis/open_group_api/sogsv3/sogsV3Capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ import { OpenGroupData, OpenGroupV2Room } from '../../../../data/opengroups';
import AbortController, { AbortSignal } from 'abort-controller';
import { batchGlobalIsSuccess } from './sogsV3BatchPoll';

export const capabilitiesFetchForServer = async (
const capabilitiesFetchForServer = async (
serverUrl: string,
serverPubKey: string,
abortSignal: AbortSignal
): Promise<Array<string> | null> => {
const endpoint = '/capabilities';
const method = 'GET';
const serverPubkey = serverPubKey;
const blinded = false; // for capabilities, blinding is always false as the request will fail if the server requires blinding
// for the capabilities call, we require blinded to be ON now. A sogs with blinding disabled will still allow this call and verify the blinded signature
const blinded = true;
const capabilityHeaders = await OpenGroupPollingUtils.getOurOpenGroupHeaders(
serverPubkey,
endpoint,
Expand All @@ -33,7 +34,6 @@ export const capabilitiesFetchForServer = async (
serverPubkey,
serverUrl,
stringifiedBody: null,
doNotIncludeOurSogsHeaders: true, // the first capabilities needs to not have any authentification to pass on a blinding-required sogs,
headers: null,
throwErrors: false,
});
Expand Down
44 changes: 23 additions & 21 deletions ts/session/apis/open_group_api/sogsv3/sogsV3FetchFile.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import AbortController, { AbortSignal } from 'abort-controller';
import { isUndefined, toNumber } from 'lodash';
import { OpenGroupV2Room, OpenGroupV2RoomWithImageID } from '../../../../data/opengroups';
import {
OpenGroupData,
OpenGroupV2Room,
OpenGroupV2RoomWithImageID,
} from '../../../../data/opengroups';
import { MIME } from '../../../../types';
import { processNewAttachment } from '../../../../types/MessageAttachment';
import { callUtilsWorker } from '../../../../webworker/workers/util_worker_interface';
Expand All @@ -16,7 +20,6 @@ export async function fetchBinaryFromSogsWithOnionV4(sendOptions: {
serverPubkey: string;
blinded: boolean;
abortSignal: AbortSignal;
doNotIncludeOurSogsHeaders?: boolean;
headers: Record<string, any> | null;
roomId: string;
fileId: string;
Expand All @@ -28,7 +31,6 @@ export async function fetchBinaryFromSogsWithOnionV4(sendOptions: {
blinded,
abortSignal,
headers: includedHeaders,
doNotIncludeOurSogsHeaders,
roomId,
fileId,
throwError,
Expand All @@ -41,15 +43,13 @@ export async function fetchBinaryFromSogsWithOnionV4(sendOptions: {
throw new Error('endpoint needs a leading /');
}
const builtUrl = new URL(`${serverUrl}${endpoint}`);
let headersWithSogsHeadersIfNeeded = doNotIncludeOurSogsHeaders
? {}
: await OpenGroupPollingUtils.getOurOpenGroupHeaders(
serverPubkey,
endpoint,
method,
blinded,
stringifiedBody
);
let headersWithSogsHeadersIfNeeded = await OpenGroupPollingUtils.getOurOpenGroupHeaders(
serverPubkey,
endpoint,
method,
blinded,
stringifiedBody
);

if (isUndefined(headersWithSogsHeadersIfNeeded)) {
return null;
Expand Down Expand Up @@ -98,12 +98,15 @@ export async function sogsV3FetchPreviewAndSaveIt(roomInfos: OpenGroupV2RoomWith
return;
}

const room = OpenGroupData.getV2OpenGroupRoom(convoId);
const blinded = roomHasBlindEnabled(room);

// make sure this runs only once for each rooms.
// we don't want to trigger one of those on each setPollInfo resultsas it happens on each batch poll.
const oneAtAtimeResult = (await allowOnlyOneAtATime(
// we don't want to trigger one of those on each setPollInfo results as it happens on each batch poll.
const oneAtAtimeResult = await allowOnlyOneAtATime(
`sogsV3FetchPreview-${serverUrl}-${roomId}`,
() => sogsV3FetchPreview(roomInfos)
)) as Uint8Array | null; // force the return type as allowOnlyOneAtATime does not keep it
() => sogsV3FetchPreview(roomInfos, blinded)
);

if (!oneAtAtimeResult || !oneAtAtimeResult?.byteLength) {
window?.log?.warn('sogsV3FetchPreviewAndSaveIt failed for room: ', roomId);
Expand Down Expand Up @@ -139,7 +142,7 @@ export async function sogsV3FetchPreviewAndSaveIt(roomInfos: OpenGroupV2RoomWith
* @returns the fetchedData in base64
*/
export async function sogsV3FetchPreviewBase64(roomInfos: OpenGroupV2RoomWithImageID) {
const fetched = await sogsV3FetchPreview(roomInfos);
const fetched = await sogsV3FetchPreview(roomInfos, true); // left pane are session official default rooms, which do require blinded
if (fetched && fetched.byteLength) {
return callUtilsWorker('arrayBufferToStringBase64', fetched);
}
Expand All @@ -155,7 +158,8 @@ export async function sogsV3FetchPreviewBase64(roomInfos: OpenGroupV2RoomWithIma
* Those default rooms do not have a conversation associated with them, as they are not joined yet
*/
const sogsV3FetchPreview = async (
roomInfos: OpenGroupV2RoomWithImageID
roomInfos: OpenGroupV2RoomWithImageID,
blinded: boolean
): Promise<Uint8Array | null> => {
if (!roomInfos || !roomInfos.imageID) {
return null;
Expand All @@ -164,11 +168,10 @@ const sogsV3FetchPreview = async (
// not a batch call yet as we need to exclude headers for this call for now
const fetched = await fetchBinaryFromSogsWithOnionV4({
abortSignal: new AbortController().signal,
blinded: false,
blinded,
headers: null,
serverPubkey: roomInfos.serverPublicKey,
serverUrl: roomInfos.serverUrl,
doNotIncludeOurSogsHeaders: true,
roomId: roomInfos.roomId,
fileId: roomInfos.imageID,
throwError: false,
Expand Down Expand Up @@ -198,7 +201,6 @@ export const sogsV3FetchFileByFileID = async (
headers: null,
serverPubkey: roomInfos.serverPublicKey,
serverUrl: roomInfos.serverUrl,
doNotIncludeOurSogsHeaders: true,
roomId: roomInfos.roomId,
fileId,
throwError: true,
Expand Down
Loading

0 comments on commit 991ddd1

Please sign in to comment.