1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-08-07 23:02:56 +03:00

Stabilise MSC3765 (#4767)

* Stabilise MSC3765

Signed-off-by: Johannes Marbach <n0-0ne+github@mailbox.org>

* Remove unstable content and hardcode property name

---------

Signed-off-by: Johannes Marbach <n0-0ne+github@mailbox.org>
This commit is contained in:
Johannes Marbach
2025-04-25 14:35:18 +02:00
committed by GitHub
parent 19b1b901f5
commit 6ec200adcf
3 changed files with 12 additions and 13 deletions

View File

@@ -196,14 +196,14 @@ describe("Topic content helpers", () => {
expect(makeTopicContent("pizza", "<b>pizza</b>")).toEqual({ expect(makeTopicContent("pizza", "<b>pizza</b>")).toEqual({
topic: "pizza", topic: "pizza",
[M_TOPIC.name]: [ [M_TOPIC.name]: [
{
body: "pizza",
mimetype: "text/plain",
},
{ {
body: "<b>pizza</b>", body: "<b>pizza</b>",
mimetype: "text/html", mimetype: "text/html",
}, },
{
body: "pizza",
mimetype: "text/plain",
},
], ],
}); });
}); });

View File

@@ -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 See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import { UnstableValue } from "../NamespacedValue.ts"; import { NamespacedValue } from "../NamespacedValue.ts";
import { type IMessageRendering } from "./extensible_events.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) * 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) * The event content for an m.topic event (in content)
*/ */
export type MTopicContent = IMessageRendering[]; 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) * 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 * The event content for an m.room.topic event

View File

@@ -189,12 +189,14 @@ export type MakeTopicContent = (topic: string | null | undefined, htmlTopic?: st
export const makeTopicContent: MakeTopicContent = (topic, htmlTopic) => { export const makeTopicContent: MakeTopicContent = (topic, htmlTopic) => {
const renderings = []; const renderings = [];
if (isProvided(topic)) { // Put HTML first because clients will render the first type in
renderings.push({ body: topic, mimetype: "text/plain" }); // the array that they understand
}
if (isProvided(htmlTopic)) { if (isProvided(htmlTopic)) {
renderings.push({ body: htmlTopic, mimetype: "text/html" }); renderings.push({ body: htmlTopic, mimetype: "text/html" });
} }
if (isProvided(topic)) {
renderings.push({ body: topic, mimetype: "text/plain" });
}
return { topic, [M_TOPIC.name]: renderings }; return { topic, [M_TOPIC.name]: renderings };
}; };