Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: E2EE messages mentions #5744

Merged
merged 5 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions app/lib/constants/defaultSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,16 @@ export const defaultSettings = {
CDN_PREFIX: {
type: 'valueAsString'
},
Accounts_RequirePasswordConfirmation:{
Accounts_RequirePasswordConfirmation: {
type: 'valueAsBoolean'
},
Accounts_ConfirmPasswordPlaceholder:{
Accounts_ConfirmPasswordPlaceholder: {
type: 'valueAsString'
},
E2E_Enabled_Mentions: {
type: 'valueAsBoolean'
},
UTF8_User_Names_Validation: {
type: 'valueAsString'
},
...deprecatedSettings
Expand Down
4 changes: 3 additions & 1 deletion app/lib/encryption/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
bufferToB64,
bufferToB64URI,
bufferToUtf8,
getE2EEMentions,
joinVectorData,
splitVectorData,
toString,
Expand Down Expand Up @@ -234,7 +235,8 @@ export default class EncryptionRoom {
...message,
t: E2E_MESSAGE_TYPE,
e2e: E2E_STATUS.PENDING,
msg
msg,
e2eMentions: getE2EEMentions(message.msg)
};
} catch {
// Do nothing
Expand Down
20 changes: 20 additions & 0 deletions app/lib/encryption/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import SimpleCrypto from 'react-native-simple-crypto';

import { random } from '../methods/helpers';
import { fromByteArray, toByteArray } from './helpers/base64-js';
import { store } from '../store/auxStore';

const BASE64URI = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';

Expand Down Expand Up @@ -58,3 +59,22 @@ export const toString = (thing: string | ByteBuffer | Buffer | ArrayBuffer | Uin
return new ByteBuffer.wrap(thing).toString('binary');
};
export const randomPassword = (): string => `${random(3)}-${random(3)}-${random(3)}`.toLowerCase();

// https://github.com/RocketChat/Rocket.Chat/blob/b94db45cab297a3bcbafca4d135d83c898222380/apps/meteor/app/mentions/lib/MentionsParser.ts#L50
const userMentionRegex = (pattern: string) => new RegExp(`(^|\\s|>)@(${pattern}(@(${pattern}))?(:([0-9a-zA-Z-_.]+))?)`, 'gm');
const channelMentionRegex = (pattern: string) => new RegExp(`(^|\\s|>)#(${pattern}(@(${pattern}))?)`, 'gm');

export const getE2EEMentions = (message?: string) => {
const e2eEnabledMentions = store.getState().settings.E2E_Enabled_Mentions;
if (!e2eEnabledMentions || !message) {
return undefined;
}
const utf8UserNamesValidation = store.getState().settings.UTF8_User_Names_Validation as string;

return {
e2eUserMentions: (message.match(userMentionRegex(utf8UserNamesValidation)) || []).map(match => match.trim()),
e2eUserMentionse2eChannelMentions: (message.match(channelMentionRegex(utf8UserNamesValidation)) || []).map(match =>
match.trim()
)
};
};