From 6ec200adcff2dd973b64485c238405a377bb7b91 Mon Sep 17 00:00:00 2001 From: Johannes Marbach Date: Fri, 25 Apr 2025 14:35:18 +0200 Subject: [PATCH] Stabilise MSC3765 (#4767) * Stabilise MSC3765 Signed-off-by: Johannes Marbach * Remove unstable content and hardcode property name --------- Signed-off-by: Johannes Marbach --- spec/unit/content-helpers.spec.ts | 8 ++++---- src/@types/topic.ts | 9 +++------ src/content-helpers.ts | 8 +++++--- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/spec/unit/content-helpers.spec.ts b/spec/unit/content-helpers.spec.ts index 79c2f7726..623288d7b 100644 --- a/spec/unit/content-helpers.spec.ts +++ b/spec/unit/content-helpers.spec.ts @@ -196,14 +196,14 @@ describe("Topic content helpers", () => { expect(makeTopicContent("pizza", "pizza")).toEqual({ topic: "pizza", [M_TOPIC.name]: [ - { - body: "pizza", - mimetype: "text/plain", - }, { body: "pizza", mimetype: "text/html", }, + { + body: "pizza", + mimetype: "text/plain", + }, ], }); }); diff --git a/src/@types/topic.ts b/src/@types/topic.ts index fd6e81a41..b11bf3bc4 100644 --- a/src/@types/topic.ts +++ b/src/@types/topic.ts @@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -import { UnstableValue } from "../NamespacedValue.ts"; +import { NamespacedValue } from "../NamespacedValue.ts"; import { type IMessageRendering } from "./extensible_events.ts"; /** @@ -42,20 +42,17 @@ import { type IMessageRendering } from "./extensible_events.ts"; /** * The event type for an m.topic event (in content) */ -export const M_TOPIC = new UnstableValue("m.topic", "org.matrix.msc3765.topic"); +export const M_TOPIC = new NamespacedValue("m.topic"); /** * The event content for an m.topic event (in content) */ export type MTopicContent = IMessageRendering[]; -type MTopicStable = { [M_TOPIC.altName]: MTopicContent }; -type MTopicUnstable = { [M_TOPIC.name]: MTopicContent }; - /** * The event definition for an m.topic event (in content) */ -export type MTopicEvent = (MTopicStable & MTopicUnstable) | MTopicStable | MTopicUnstable; +export type MTopicEvent = { "m.topic": MTopicContent }; /** * The event content for an m.room.topic event diff --git a/src/content-helpers.ts b/src/content-helpers.ts index 16b3731e1..6ebc1f659 100644 --- a/src/content-helpers.ts +++ b/src/content-helpers.ts @@ -189,12 +189,14 @@ export type MakeTopicContent = (topic: string | null | undefined, htmlTopic?: st export const makeTopicContent: MakeTopicContent = (topic, htmlTopic) => { const renderings = []; - if (isProvided(topic)) { - renderings.push({ body: topic, mimetype: "text/plain" }); - } + // Put HTML first because clients will render the first type in + // the array that they understand if (isProvided(htmlTopic)) { renderings.push({ body: htmlTopic, mimetype: "text/html" }); } + if (isProvided(topic)) { + renderings.push({ body: topic, mimetype: "text/plain" }); + } return { topic, [M_TOPIC.name]: renderings }; };