Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions src/app/components/editor/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { isUserId } from '$utils/matrix';
import type { CustomElement } from './slate';
import { BlockType } from './types';
import { getMarkdownCodeSpanRanges, isInsideMarkdownCodeSpan } from './utils';
import { MATRIX_TO_BASE } from '$plugins/matrix-to';

export type OutputOptions = {
/**
Expand Down Expand Up @@ -294,6 +295,8 @@ export const getLinks = (serialized: Descendant | Descendant[]): string[] | unde
continue;
}

if (url.startsWith(MATRIX_TO_BASE)) continue;

finalList.add(url);
}

Expand Down
5 changes: 3 additions & 2 deletions src/app/components/message/MsgTypeRenderers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
import { MessageTextBody } from './layout';
import { unwrapForwardedContent } from './modals/MessageForward';
import { LINKINPUTREGEX } from '$components/editor';
import { MATRIX_TO_BASE } from '$plugins/matrix-to';

export interface BundleContent extends IPreviewUrlResponse {
matched_url: string;
Expand Down Expand Up @@ -118,7 +119,7 @@ const getUrlsFromContent = (
const safeHtml = customBody
.replace(/<pre[^>]*>.*?<\/pre>/gs, '')
.replace(/<code[^>]*>.*?<\/code>/gs, '');
const safeText = safeHtml.replace(/<[^>]*>/g, '');
const safeText = safeHtml.replace(/<[^a][^>]*>/g, '');
const safeUrlsMatch = safeText.match(LINKINPUTREGEX);
let safeUrls = safeUrlsMatch ? [...new Set(safeUrlsMatch)] : [];
safeUrls = safeUrls.map(
Expand All @@ -129,7 +130,7 @@ const getUrlsFromContent = (
url
);
const safeUrlsSet = new Set(safeUrls);
urls = urls.filter((url) => safeUrlsSet.has(url));
urls = urls.filter((url) => safeUrlsSet.has(url) && !url.startsWith(MATRIX_TO_BASE));
}

let bundleContent = content['com.beeper.linkpreviews'] as BundleContent[];
Expand Down
60 changes: 30 additions & 30 deletions src/app/components/user-profile/UserRoomProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -631,42 +631,42 @@ export function UserRoomProfile({ userId, initialProfile }: Readonly<UserRoomPro
/>
)}
</Box>
</Box>
{ignored && <IgnoredUserAlert />}
{member && membership === bannedMembership && (
<UserBanAlert
userId={userId}
reason={member.events.member?.getContent().reason}
canUnban={canUnban}
bannedBy={member.events.member?.getSender()}
ts={member.events.member?.getTs()}
/>
)}
{member &&
membership === leftMembership &&
member.events.member &&
member.events.member.getSender() !== userId && (
<UserKickAlert
{ignored && <IgnoredUserAlert />}
{member && membership === bannedMembership && (
<UserBanAlert
userId={userId}
reason={member.events.member?.getContent().reason}
canUnban={canUnban}
bannedBy={member.events.member?.getSender()}
ts={member.events.member?.getTs()}
/>
)}
{member &&
membership === leftMembership &&
member.events.member &&
member.events.member.getSender() !== userId && (
<UserKickAlert
reason={member.events.member?.getContent().reason}
kickedBy={member.events.member?.getSender()}
ts={member.events.member?.getTs()}
/>
)}
{member && membership === invitedMembership && (
<UserInviteAlert
userId={userId}
reason={member.events.member?.getContent().reason}
kickedBy={member.events.member?.getSender()}
canKick={canKickUser}
invitedBy={member.events.member?.getSender()}
ts={member.events.member?.getTs()}
/>
)}
{member && membership === invitedMembership && (
<UserInviteAlert
<UserModeration
userId={userId}
reason={member.events.member?.getContent().reason}
canKick={canKickUser}
invitedBy={member.events.member?.getSender()}
ts={member.events.member?.getTs()}
canInvite={canInvite && membership === leftMembership}
canKick={canKickUser && membership === joinedMembership}
canBan={canBanUser && membership !== bannedMembership}
/>
)}
<UserModeration
userId={userId}
canInvite={canInvite && membership === leftMembership}
canKick={canKickUser && membership === joinedMembership}
canBan={canBanUser && membership !== bannedMembership}
/>
</Box>
</Box>
</Box>
);
Expand Down
3 changes: 2 additions & 1 deletion src/app/features/room/message/MessageEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ export const MessageEditor = as<'div', MessageEditorProps>(
const isHidden =
(bundleContent?.length === 0 ||
bundleContent.filter((b) => s.includes(b.matched_url)).length === 0) &&
strippedS.match(LINKINPUTREGEX) !== null;
strippedS.match(LINKINPUTREGEX) !== null &&
strippedS.startsWith('https://matrix.to/');
newBody += `${isHidden ? (isHTML && ((s.startsWith('<a') && `&lt;${s[0]}`) || `${s[0]}&lt;`)) || `${s[0]}<` : s[0]}${strippedS}${isHidden ? (isHTML && '&gt;') || '>' : ''}`;
});
return newBody;
Expand Down
2 changes: 1 addition & 1 deletion src/app/features/settings/account/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ function ProfileExtended({ profile, userId }: Readonly<ProfileProps>) {
onSave={(color) =>
handleSaveField('chat.commet.profile_color_scheme', {
color,
brightness: profile?.heroColorScheme?.brightness,
brightness: color ? profile?.heroColorScheme?.brightness : null,
})
}
/>
Expand Down
22 changes: 11 additions & 11 deletions src/app/plugins/matrix-to.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('getMatrixToUser', () => {
});

it('uses custom base when configured', () => {
setMatrixToBase('https://matrix.example.org');
setMatrixToBase('https://matrix.example.org/');
expect(getMatrixToUser('@alice:example.com')).toBe(
'https://matrix.example.org/#/@alice:example.com'
);
Expand All @@ -51,7 +51,7 @@ describe('getMatrixToRoom', () => {
});

it('uses custom base when configured', () => {
setMatrixToBase('https://matrix.example.org');
setMatrixToBase('https://matrix.example.org/');
expect(getMatrixToRoom('#general:example.com')).toBe(
'https://matrix.example.org/#/#general:example.com'
);
Expand All @@ -72,7 +72,7 @@ describe('getMatrixToRoomEvent', () => {
});

it('uses custom base when configured', () => {
setMatrixToBase('https://matrix.example.org');
setMatrixToBase('https://matrix.example.org/');
expect(getMatrixToRoomEvent('!room:example.com', '$event123')).toBe(
'https://matrix.example.org/#/!room:example.com/$event123'
);
Expand All @@ -97,12 +97,12 @@ describe('testMatrixTo', () => {
});

it('matches custom base URLs after setMatrixToBase', () => {
setMatrixToBase('https://matrix.example.org');
setMatrixToBase('https://matrix.example.org/');
expect(testMatrixTo('https://matrix.example.org/#/@alice:example.com')).toBe(true);
});

it('still matches standard matrix.to after setMatrixToBase (cross-client compat)', () => {
setMatrixToBase('https://matrix.example.org');
setMatrixToBase('https://matrix.example.org/');
expect(testMatrixTo('https://matrix.to/#/@alice:example.com')).toBe(true);
});
});
Expand All @@ -121,14 +121,14 @@ describe('parseMatrixToUser', () => {
});

it('parses user links from custom base', () => {
setMatrixToBase('https://matrix.example.org');
setMatrixToBase('https://matrix.example.org/');
expect(parseMatrixToUser('https://matrix.example.org/#/@alice:example.com')).toBe(
'@alice:example.com'
);
});

it('parses standard matrix.to user links even after custom base is set', () => {
setMatrixToBase('https://matrix.example.org');
setMatrixToBase('https://matrix.example.org/');
expect(parseMatrixToUser('https://matrix.to/#/@alice:example.com')).toBe('@alice:example.com');
});
});
Expand Down Expand Up @@ -166,15 +166,15 @@ describe('parseMatrixToRoom', () => {
});

it('parses room links from custom base', () => {
setMatrixToBase('https://matrix.example.org');
setMatrixToBase('https://matrix.example.org/');
expect(parseMatrixToRoom('https://matrix.example.org/#/!room:example.com')).toEqual({
roomIdOrAlias: '!room:example.com',
viaServers: undefined,
});
});

it('still parses standard matrix.to room links after custom base is set', () => {
setMatrixToBase('https://matrix.example.org');
setMatrixToBase('https://matrix.example.org/');
expect(parseMatrixToRoom('https://matrix.to/#/!room:example.com')).toEqual({
roomIdOrAlias: '!room:example.com',
viaServers: undefined,
Expand Down Expand Up @@ -210,7 +210,7 @@ describe('parseMatrixToRoomEvent', () => {
});

it('parses event links from custom base', () => {
setMatrixToBase('https://matrix.example.org');
setMatrixToBase('https://matrix.example.org/');
expect(
parseMatrixToRoomEvent('https://matrix.example.org/#/!room:example.com/$event123')
).toEqual({
Expand All @@ -221,7 +221,7 @@ describe('parseMatrixToRoomEvent', () => {
});

it('still parses standard matrix.to event links after custom base is set', () => {
setMatrixToBase('https://matrix.example.org');
setMatrixToBase('https://matrix.example.org/');
expect(parseMatrixToRoomEvent('https://matrix.to/#/!room:example.com/$event123')).toEqual({
roomIdOrAlias: '!room:example.com',
eventId: '$event123',
Expand Down
20 changes: 10 additions & 10 deletions src/app/plugins/matrix-to.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
let MATRIX_TO_BASE = 'https://matrix.to';
export let MATRIX_TO_BASE = 'https://matrix.to/';

/**
* Override the default matrix.to base URL (configurable per deployment).
* Must be called before any getMatrixTo* functions are used.
*/
export const setMatrixToBase = (baseUrl?: string): void => {
MATRIX_TO_BASE = baseUrl ? baseUrl.replace(/\/$/, '') : 'https://matrix.to';
MATRIX_TO_BASE = baseUrl ? baseUrl.replace(/\/?$/, '/') : 'https://matrix.to/';
};

export const getMatrixToUser = (userId: string): string => `${MATRIX_TO_BASE}/#/${userId}`;
export const getMatrixToUser = (userId: string): string => `${MATRIX_TO_BASE}#/${userId}`;

const withViaServers = (fragment: string, viaServers: string[]): string =>
`${fragment}?${viaServers.map((server) => `via=${server}`).join('&')}`;
Expand All @@ -20,7 +20,7 @@ export const getMatrixToRoom = (roomIdOrAlias: string, viaServers?: string[]): s
fragment = withViaServers(fragment, viaServers);
}

return `${MATRIX_TO_BASE}/#/${fragment}`;
return `${MATRIX_TO_BASE}#/${fragment}`;
};

export const getMatrixToRoomEvent = (
Expand All @@ -34,7 +34,7 @@ export const getMatrixToRoomEvent = (
fragment = withViaServers(fragment, viaServers);
}

return `${MATRIX_TO_BASE}/#/${fragment}`;
return `${MATRIX_TO_BASE}#/${fragment}`;
};

export type MatrixToRoom = {
Expand Down Expand Up @@ -65,16 +65,16 @@ const getMatchRegexes = () => {
if (cachedRegexBase === MATRIX_TO_BASE && cachedRegexes) return cachedRegexes;
cachedRegexBase = MATRIX_TO_BASE;
// Use https? so both http:// and https://matrix.to are accepted (original behaviour).
const standard = `https?://${escapeForRegex('matrix.to')}`;
const standard = `https?://${escapeForRegex('matrix.to/')}`;
const b =
MATRIX_TO_BASE !== 'https://matrix.to'
MATRIX_TO_BASE !== 'https://matrix.to/'
? `(?:${standard}|${escapeForRegex(MATRIX_TO_BASE)})`
: standard;
cachedRegexes = {
any: new RegExp(`^${b}\\S*$`),
user: new RegExp(`^${b}/#/(@[^:\\s]+:[^?/\\s]+)\\/?$`),
room: new RegExp(`^${b}/#/([#!][^?/\\s]+)\\/?(\\?[\\S]*)?$`),
event: new RegExp(`^${b}/#/([#!][^?/\\s]+)/(\\$[^?/\\s]+)\\/?([?\\S]*)?$`),
user: new RegExp(`^${b}#/(@[^:\\s]+:[^?/\\s]+)\\/?$`),
room: new RegExp(`^${b}#/([#!][^?/\\s]+)\\/?(\\?[\\S]*)?$`),
event: new RegExp(`^${b}#/([#!][^?/\\s]+)/(\\$[^?/\\s]+)\\/?([?\\S]*)?$`),
};
return cachedRegexes;
};
Expand Down
Loading