Better type guard parseTopicContent (#3165)

This commit is contained in:
Michael Telatynski
2023-02-20 10:29:33 +00:00
committed by GitHub
parent 1a91ba59a6
commit decac58a18
+3
View File
@@ -202,6 +202,9 @@ export type TopicState = {
export const parseTopicContent = (content: MRoomTopicEventContent): TopicState => {
const mtopic = M_TOPIC.findIn<MTopicContent>(content);
if (!Array.isArray(mtopic)) {
return { text: content.topic };
}
const text = mtopic?.find((r) => !isProvided(r.mimetype) || r.mimetype === "text/plain")?.body ?? content.topic;
const html = mtopic?.find((r) => r.mimetype === "text/html")?.body;
return { text, html };