diff --git a/src/app/components/editor/output.ts b/src/app/components/editor/output.ts index e4b6d01d7..074edd6cd 100644 --- a/src/app/components/editor/output.ts +++ b/src/app/components/editor/output.ts @@ -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 = { /** @@ -294,6 +295,8 @@ export const getLinks = (serialized: Descendant | Descendant[]): string[] | unde continue; } + if (url.startsWith(MATRIX_TO_BASE)) continue; + finalList.add(url); } diff --git a/src/app/components/message/MsgTypeRenderers.tsx b/src/app/components/message/MsgTypeRenderers.tsx index db1e5b050..303c90313 100644 --- a/src/app/components/message/MsgTypeRenderers.tsx +++ b/src/app/components/message/MsgTypeRenderers.tsx @@ -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; @@ -118,7 +119,7 @@ const getUrlsFromContent = ( const safeHtml = customBody .replace(/
]*>.*?<\/pre>/gs, '')
.replace(/]*>.*?<\/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(
@@ -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[];
diff --git a/src/app/components/user-profile/UserRoomProfile.tsx b/src/app/components/user-profile/UserRoomProfile.tsx
index f1d2ebca7..8d791d943 100644
--- a/src/app/components/user-profile/UserRoomProfile.tsx
+++ b/src/app/components/user-profile/UserRoomProfile.tsx
@@ -631,42 +631,42 @@ export function UserRoomProfile({ userId, initialProfile }: Readonly
)}
-
- {ignored && }
- {member && membership === bannedMembership && (
-
- )}
- {member &&
- membership === leftMembership &&
- member.events.member &&
- member.events.member.getSender() !== userId && (
- }
+ {member && membership === bannedMembership && (
+
)}
- {member && membership === invitedMembership && (
-
+ )}
+ {member && membership === invitedMembership && (
+
+ )}
+
- )}
-
+
);
diff --git a/src/app/features/room/message/MessageEditor.tsx b/src/app/features/room/message/MessageEditor.tsx
index 3d58f92f1..7c3283b31 100644
--- a/src/app/features/room/message/MessageEditor.tsx
+++ b/src/app/features/room/message/MessageEditor.tsx
@@ -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('' : ''}`;
});
return newBody;
diff --git a/src/app/features/settings/account/Profile.tsx b/src/app/features/settings/account/Profile.tsx
index dfc3873c4..0fefcbaf6 100644
--- a/src/app/features/settings/account/Profile.tsx
+++ b/src/app/features/settings/account/Profile.tsx
@@ -642,7 +642,7 @@ function ProfileExtended({ profile, userId }: Readonly) {
onSave={(color) =>
handleSaveField('chat.commet.profile_color_scheme', {
color,
- brightness: profile?.heroColorScheme?.brightness,
+ brightness: color ? profile?.heroColorScheme?.brightness : null,
})
}
/>
diff --git a/src/app/plugins/matrix-to.test.ts b/src/app/plugins/matrix-to.test.ts
index 519ecd825..d1956370f 100644
--- a/src/app/plugins/matrix-to.test.ts
+++ b/src/app/plugins/matrix-to.test.ts
@@ -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'
);
@@ -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'
);
@@ -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'
);
@@ -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);
});
});
@@ -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');
});
});
@@ -166,7 +166,7 @@ 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,
@@ -174,7 +174,7 @@ describe('parseMatrixToRoom', () => {
});
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,
@@ -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({
@@ -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',
diff --git a/src/app/plugins/matrix-to.ts b/src/app/plugins/matrix-to.ts
index 42162654b..2677351d2 100644
--- a/src/app/plugins/matrix-to.ts
+++ b/src/app/plugins/matrix-to.ts
@@ -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('&')}`;
@@ -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 = (
@@ -34,7 +34,7 @@ export const getMatrixToRoomEvent = (
fragment = withViaServers(fragment, viaServers);
}
- return `${MATRIX_TO_BASE}/#/${fragment}`;
+ return `${MATRIX_TO_BASE}#/${fragment}`;
};
export type MatrixToRoom = {
@@ -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;
};