Skip to content

Commit

Permalink
Better type guard parseTopicContent (#3165)
Browse files Browse the repository at this point in the history
  • Loading branch information
t3chguy committed Feb 20, 2023
1 parent 1a91ba5 commit decac58
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/content-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down

0 comments on commit decac58

Please sign in to comment.