Merge branch 'clearnet' into move-models-to-ts-2

pull/1495/head
Audric Ackermann 4 years ago
commit 7a3a12ccdc

@ -2,7 +2,7 @@
"name": "session-desktop", "name": "session-desktop",
"productName": "Session", "productName": "Session",
"description": "Private messaging from your desktop", "description": "Private messaging from your desktop",
"version": "1.4.8", "version": "1.4.9",
"license": "GPL-3.0", "license": "GPL-3.0",
"author": { "author": {
"name": "Loki Project", "name": "Loki Project",

@ -32,11 +32,13 @@ export class MessageView extends React.Component {
// //////////// Management ///////////// // //////////// Management /////////////
// ///////////////////////////////////// // /////////////////////////////////////
/**
* Returns true if the group was indead created
*/
async function createClosedGroup( async function createClosedGroup(
groupName: string, groupName: string,
groupMembers: Array<ContactType>, groupMembers: Array<ContactType>
onSuccess: any ): Promise<boolean> {
) {
// Validate groupName and groupMembers length // Validate groupName and groupMembers length
if (groupName.length === 0) { if (groupName.length === 0) {
ToastUtils.pushToastError( ToastUtils.pushToastError(
@ -44,13 +46,13 @@ async function createClosedGroup(
window.i18n('invalidGroupNameTooShort') window.i18n('invalidGroupNameTooShort')
); );
return; return false;
} else if (groupName.length > window.CONSTANTS.MAX_GROUP_NAME_LENGTH) { } else if (groupName.length > window.CONSTANTS.MAX_GROUP_NAME_LENGTH) {
ToastUtils.pushToastError( ToastUtils.pushToastError(
'invalidGroupName', 'invalidGroupName',
window.i18n('invalidGroupNameTooLong') window.i18n('invalidGroupNameTooLong')
); );
return; return false;
} }
// >= because we add ourself as a member AFTER this. so a 10 group is already invalid as it will be 11 with ourself // >= because we add ourself as a member AFTER this. so a 10 group is already invalid as it will be 11 with ourself
@ -61,23 +63,19 @@ async function createClosedGroup(
'pickClosedGroupMember', 'pickClosedGroupMember',
window.i18n('pickClosedGroupMember') window.i18n('pickClosedGroupMember')
); );
return; return false;
} else if (groupMembers.length >= window.CONSTANTS.CLOSED_GROUP_SIZE_LIMIT) { } else if (groupMembers.length >= window.CONSTANTS.CLOSED_GROUP_SIZE_LIMIT) {
ToastUtils.pushToastError( ToastUtils.pushToastError(
'closedGroupMaxSize', 'closedGroupMaxSize',
window.i18n('closedGroupMaxSize') window.i18n('closedGroupMaxSize')
); );
return; return false;
} }
const groupMemberIds = groupMembers.map(m => m.id); const groupMemberIds = groupMembers.map(m => m.id);
await createClosedGroupV2(groupName, groupMemberIds); await createClosedGroupV2(groupName, groupMemberIds);
if (onSuccess) {
onSuccess();
}
return true; return true;
} }

@ -469,8 +469,20 @@ export class LeftPaneMessageSection extends React.Component<Props, State> {
groupName: string, groupName: string,
groupMembers: Array<ContactType> groupMembers: Array<ContactType>
) { ) {
await MainViewController.createClosedGroup(groupName, groupMembers, () => { if (this.state.loading) {
this.handleToggleOverlay(undefined); window.log.warn('Closed group creation already in progress');
return;
}
this.setState({ loading: true }, async () => {
const groupCreated = await MainViewController.createClosedGroup(
groupName,
groupMembers
);
if (groupCreated) {
this.handleToggleOverlay(undefined);
}
this.setState({ loading: false });
}); });
} }

@ -742,9 +742,23 @@ async function handleClosedGroupMemberLeft(
} }
if (didAdminLeave) { if (didAdminLeave) {
window.SwarmPolling.removePubkey(groupPublicKey);
await removeAllClosedGroupEncryptionKeyPairs(groupPublicKey);
// Disable typing
// if the admin was remove and we are the admin, it can only be voluntary
if (isCurrentUserAdmin) {
convo.set('left', true);
} else {
convo.set('isKickedFromGroup', true);
}
}
const didWeLeaveFromAnotherDevice = !members.includes(ourPubkey);
if (didWeLeaveFromAnotherDevice) {
await removeAllClosedGroupEncryptionKeyPairs(groupPublicKey); await removeAllClosedGroupEncryptionKeyPairs(groupPublicKey);
// Disable typing: // Disable typing:
convo.set('isKickedFromGroup', true); convo.set('left', true);
window.SwarmPolling.removePubkey(groupPublicKey); window.SwarmPolling.removePubkey(groupPublicKey);
} }

@ -35,9 +35,6 @@ export async function updateProfile(
!prevPointer || !_.isEqual(prevPointer, profile.profilePicture); !prevPointer || !_.isEqual(prevPointer, profile.profilePicture);
if (needsUpdate) { if (needsUpdate) {
conversation.set('avatarPointer', profile.profilePicture);
conversation.set('profileKey', profileKey);
const downloaded = await downloadAttachment({ const downloaded = await downloadAttachment({
url: profile.profilePicture, url: profile.profilePicture,
isRaw: true, isRaw: true,
@ -61,6 +58,9 @@ export async function updateProfile(
...downloaded, ...downloaded,
data: decryptedData, data: decryptedData,
}); });
// Only update the convo if the download and decrypt is a success
conversation.set('avatarPointer', profile.profilePicture);
conversation.set('profileKey', profileKey);
({ path } = upgraded); ({ path } = upgraded);
} catch (e) { } catch (e) {
window.log.error(`Could not decrypt profile image: ${e}`); window.log.error(`Could not decrypt profile image: ${e}`);

@ -72,9 +72,16 @@ export class ChatMessage extends DataMessage {
this.quote = params.quote; this.quote = params.quote;
this.expireTimer = params.expireTimer; this.expireTimer = params.expireTimer;
if (params.lokiProfile && params.lokiProfile.profileKey) { if (params.lokiProfile && params.lokiProfile.profileKey) {
this.profileKey = new Uint8Array( if (
ByteBuffer.wrap(params.lokiProfile.profileKey).toArrayBuffer() params.lokiProfile.profileKey instanceof Uint8Array ||
); (params.lokiProfile.profileKey as any) instanceof ByteBuffer
) {
this.profileKey = new Uint8Array(params.lokiProfile.profileKey);
} else {
this.profileKey = new Uint8Array(
ByteBuffer.wrap(params.lokiProfile.profileKey).toArrayBuffer()
);
}
} }
this.displayName = params.lokiProfile && params.lokiProfile.displayName; this.displayName = params.lokiProfile && params.lokiProfile.displayName;
@ -88,8 +95,11 @@ export class ChatMessage extends DataMessage {
syncTarget: string, syncTarget: string,
sentTimestamp: number sentTimestamp: number
) { ) {
// the dataMessage.profileKey is of type ByteBuffer. We need to make it a Uint8Array
const lokiProfile: any = { const lokiProfile: any = {
profileKey: dataMessage.profileKey, profileKey: new Uint8Array(
(dataMessage.profileKey as any).toArrayBuffer()
),
}; };
if ( if (

Loading…
Cancel
Save