mirror of
https://github.com/SableClient/Sable.git
synced 2026-12-01 22:32:32 -08:00
Fix pmp /me rendering
This commit is contained in:
1 parent
a9ac09e56a
commit
8b1e7c058e
7 files changed
+67
-19
No files matched your search
@@ -54,6 +54,12 @@ import { PollEvent } from './message/PollEvent';
|
||||
import { M_POLL_START, M_TEXT } from 'matrix-js-sdk';
|
||||
import type { IImageInfo, IGalleryContent } from '$types/matrix/common';
|
||||
import { GALLERY_MSGTYPE } from '$types/matrix/common';
|
||||
import {
|
||||
convertBeeperFormatToOurPerMessageProfile,
|
||||
type PerMessageProfileBeeperFormat,
|
||||
stripPerMessageProfileFormattedBody,
|
||||
stripPerMessageProfilePlainBody,
|
||||
} from '$hooks/usePerMessageProfile';
|
||||
|
||||
type RenderMessageContentProps = {
|
||||
displayName: string;
|
||||
@@ -209,7 +215,7 @@ function RenderMessageContentInternal({
|
||||
),
|
||||
[urlPreview]
|
||||
);
|
||||
const messageUrlsPreview = urlPreview ? renderUrlsPreview : undefined;
|
||||
const messageUrlsPreview = urlPreview || themeChatSableWidgets ? renderUrlsPreview : undefined;
|
||||
const messageBundlePreview = bundledPreview ? renderBundledPreviews : undefined;
|
||||
|
||||
const renderCaption = () => {
|
||||
@@ -339,6 +345,21 @@ function RenderMessageContentInternal({
|
||||
}
|
||||
|
||||
if (msgType === (MsgType.Emote as string)) {
|
||||
const beeperProfile = content['com.beeper.per_message_profile'] as
|
||||
| PerMessageProfileBeeperFormat
|
||||
| undefined;
|
||||
const pmp = beeperProfile
|
||||
? convertBeeperFormatToOurPerMessageProfile(beeperProfile)
|
||||
: undefined;
|
||||
|
||||
const strippedContent = pmp
|
||||
? {
|
||||
...content,
|
||||
formatted_body: stripPerMessageProfileFormattedBody(content['formatted_body'] as string),
|
||||
body: stripPerMessageProfilePlainBody(content['body'] as string),
|
||||
}
|
||||
: content;
|
||||
|
||||
if ((content as { 'fyi.cisnt.headpat'?: boolean })['fyi.cisnt.headpat']) {
|
||||
return (
|
||||
<MCuteEvent
|
||||
@@ -352,9 +373,9 @@ function RenderMessageContentInternal({
|
||||
}
|
||||
return (
|
||||
<MEmote
|
||||
displayName={displayName}
|
||||
displayName={pmp?.displayname ?? displayName}
|
||||
edited={edited}
|
||||
content={content}
|
||||
content={strippedContent}
|
||||
renderBody={renderBody}
|
||||
renderUrlsPreview={messageUrlsPreview}
|
||||
renderBundledPreviews={messageBundlePreview}
|
||||
|
||||
@@ -21,7 +21,11 @@ import { FALLBACK_MIMETYPE, getBlobSafeMimeType } from '$utils/mimeTypes';
|
||||
import { parseGeoUri, scaleYDimension } from '$utils/common';
|
||||
import { useSetting } from '$state/hooks/settings';
|
||||
import { settingsAtom } from '$state/settings';
|
||||
import type { PerMessageProfileBeeperFormat } from '$hooks/usePerMessageProfile';
|
||||
import {
|
||||
stripPerMessageProfileFormattedBody,
|
||||
stripPerMessageProfilePlainBody,
|
||||
type PerMessageProfileBeeperFormat,
|
||||
} from '$hooks/usePerMessageProfile';
|
||||
import { Attachment, AttachmentBox, AttachmentContent, AttachmentHeader } from './attachment';
|
||||
import { FileHeader, FileDownloadButton } from './FileHeader';
|
||||
import {
|
||||
@@ -223,13 +227,15 @@ export function MText({
|
||||
);
|
||||
// the html body, with PMP fallback removed
|
||||
const unwrappedPmpCustomBody = useMemo(
|
||||
() =>
|
||||
cleanedMessage?.replace(/<strong[^>]*data-mx-profile-fallback[^>]*>(.*?):\s*<\/strong>/i, ''),
|
||||
() => (cleanedMessage ? stripPerMessageProfileFormattedBody(cleanedMessage) : undefined),
|
||||
[cleanedMessage]
|
||||
);
|
||||
// the plain body, with PMP fallback removed
|
||||
const unwrappedPmpBody = useMemo(
|
||||
() => (hadPerMessageProfileFallback ? trimmedBody?.replace(/(.*?):/i, '') : trimmedBody),
|
||||
() =>
|
||||
hadPerMessageProfileFallback
|
||||
? stripPerMessageProfilePlainBody(trimmedBody ?? '')
|
||||
: trimmedBody,
|
||||
[trimmedBody, hadPerMessageProfileFallback]
|
||||
);
|
||||
|
||||
|
||||
@@ -63,7 +63,10 @@ import { LinePlaceholder } from './placeholder';
|
||||
import { ReactionKeyInline } from './ReactionKeyInline';
|
||||
import { M_POLL_START, M_TEXT } from 'matrix-js-sdk';
|
||||
import type { PerMessageProfileBeeperFormat } from '$hooks/usePerMessageProfile';
|
||||
import { convertBeeperFormatToOurPerMessageProfile } from '$hooks/usePerMessageProfile';
|
||||
import {
|
||||
convertBeeperFormatToOurPerMessageProfile,
|
||||
stripPerMessageProfileFormattedBody,
|
||||
} from '$hooks/usePerMessageProfile';
|
||||
|
||||
const ROOM_REPLY_TIMELINE_EVENT_TYPES = new Set<string>([
|
||||
EventType.RoomMessage as string,
|
||||
@@ -272,7 +275,7 @@ export const Reply = as<'div', ReplyProps>(
|
||||
|
||||
// strip the PMP fallback if it's there, to avoid displaying the PMP name twice
|
||||
const formattedBodyStripped: string = pmp
|
||||
? formattedBody?.replace(/^<strong\s+data-mx-profile-fallback[^>]*>.*?<\/strong>/, '')
|
||||
? stripPerMessageProfileFormattedBody(formattedBody ?? '')
|
||||
: formattedBody;
|
||||
|
||||
const extensibleContent = contentForPreview[M_TEXT.name] as
|
||||
|
||||
@@ -152,6 +152,7 @@ import {
|
||||
getCurrentlyUsedPerMessageProfileForRoom,
|
||||
type PerMessageProfileMsc4461,
|
||||
setCurrentlyUsedPerMessageProfileIdForRoom,
|
||||
stripPerMessageProfileFormattedBody,
|
||||
} from '$hooks/usePerMessageProfile';
|
||||
import {
|
||||
Bell,
|
||||
@@ -640,7 +641,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
}
|
||||
}
|
||||
const editableHtml = pmpDisplayname
|
||||
? customHtml?.replace(/^<strong\s+data-mx-profile-fallback[^>]*>.*?<\/strong>/, '')
|
||||
? stripPerMessageProfileFormattedBody(customHtml ?? '')
|
||||
: customHtml;
|
||||
|
||||
const mentionOptions = {
|
||||
|
||||
@@ -3,7 +3,10 @@ import { MsgType, RelationType } from '$types/matrix-sdk';
|
||||
import { customHtmlEqualsPlainText } from '$components/editor';
|
||||
import { sanitizeText } from '$utils/sanitize';
|
||||
import type { PerMessageProfileMsc4461 } from '$hooks/usePerMessageProfile';
|
||||
import { convertPerMessageProfileToBeeperFormat } from '$hooks/usePerMessageProfile';
|
||||
import {
|
||||
convertPerMessageProfileToBeeperFormat,
|
||||
stripPerMessageProfileFormattedBody,
|
||||
} from '$hooks/usePerMessageProfile';
|
||||
import { MATRIX_UNSTABLE_PER_MESSAGE_PROFILE_PROPERTY_NAME } from '$unstable/prefixes';
|
||||
|
||||
/**
|
||||
@@ -111,10 +114,9 @@ export function buildReplacementPmpContent(
|
||||
let newPlainBody = plainBody?.replace(/^.*?: /, '');
|
||||
|
||||
const formattedBody = oldContent.formatted_body;
|
||||
let newFormattedBody = formattedBody?.replace(
|
||||
/^<strong\s+data-mx-profile-fallback[^>]*>.*?<\/strong>/,
|
||||
''
|
||||
);
|
||||
let newFormattedBody = formattedBody
|
||||
? stripPerMessageProfileFormattedBody(formattedBody)
|
||||
: undefined;
|
||||
|
||||
oldContent.formatted_body = newFormattedBody;
|
||||
oldContent.body = newPlainBody;
|
||||
|
||||
@@ -81,6 +81,7 @@ import {
|
||||
readdAngleBracketsForHiddenPreviews,
|
||||
stripMarkdownEscapesForHiddenPreviews,
|
||||
} from './hiddenLinkPreviews';
|
||||
import { stripPerMessageProfileFormattedBody } from '$hooks/usePerMessageProfile';
|
||||
|
||||
// Wraps the mobile emoji-board overlay so the Android back action closes it
|
||||
// instead of navigating away. Hooks can't run inside the UseStateProvider
|
||||
@@ -164,10 +165,7 @@ export const MessageEditor = as<'div', MessageEditorProps>(
|
||||
}
|
||||
|
||||
if (pmpDisplayname && typeof customHtml === 'string') {
|
||||
customHtml = customHtml.replace(
|
||||
/^<strong\s+data-mx-profile-fallback[^>]*>.*?<\/strong>/,
|
||||
''
|
||||
);
|
||||
customHtml = stripPerMessageProfileFormattedBody(customHtml);
|
||||
}
|
||||
|
||||
const bundleContent =
|
||||
|
||||
@@ -825,3 +825,20 @@ export async function getCurrentlyUsedPerMessageProfileForAccount(
|
||||
const pmp = profileId ? await getPerMessageProfileById(mx, profileId) : undefined;
|
||||
return profileId ? pmp : undefined;
|
||||
}
|
||||
|
||||
/*
|
||||
* If you don't supply a profile, it may fail if the displayname has a colon.
|
||||
*/
|
||||
export function stripPerMessageProfilePlainBody(
|
||||
formatted_body: string,
|
||||
profile?: PerMessageProfileMsc4461
|
||||
): string {
|
||||
if (profile) {
|
||||
return formatted_body.replace(`${profile.displayname}: `, '');
|
||||
} else {
|
||||
return formatted_body.replace(/^.*?: /, '');
|
||||
}
|
||||
}
|
||||
export function stripPerMessageProfileFormattedBody(formatted_body: string): string {
|
||||
return formatted_body.replace(/^<strong\s+data-mx-profile-fallback[^>]*>.*?<\/strong>/, '');
|
||||
}
|
||||
Reference in new issue
Block a user