Skip to content

Commit

Permalink
Remove usage of optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Half-Shot committed Jan 31, 2025
1 parent f2028d4 commit 278a512
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/@types/topic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { EitherAnd, Optional } from "matrix-events-sdk";
import { EitherAnd } from "matrix-events-sdk";

import { UnstableValue } from "../NamespacedValue.ts";
import { IMessageRendering } from "./extensible_events.ts";
Expand Down Expand Up @@ -60,4 +60,4 @@ export type MTopicEvent = EitherAnd<{ [M_TOPIC.name]: MTopicContent }, { [M_TOPI
/**
* The event content for an m.room.topic event
*/
export type MRoomTopicEventContent = { topic: Optional<string> } & MTopicEvent;
export type MRoomTopicEventContent = { topic: string | null | undefined } & MTopicEvent;
11 changes: 5 additions & 6 deletions src/content-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { Optional } from "matrix-events-sdk";

import { MBeaconEventContent, MBeaconInfoContent, MBeaconInfoEventContent } from "./@types/beacon.ts";
import { MsgType } from "./@types/event.ts";
import { M_TEXT, REFERENCE_RELATION } from "./@types/extensible_events.ts";
Expand Down Expand Up @@ -187,7 +185,7 @@ export const parseLocationEvent = (wireEventContent: LocationEventWireContent):
/**
* Topic event helpers
*/
export type MakeTopicContent = (topic: Optional<string>, htmlTopic?: string) => MRoomTopicEventContent;
export type MakeTopicContent = (topic: string | null | undefined, htmlTopic?: string) => MRoomTopicEventContent;

export const makeTopicContent: MakeTopicContent = (topic, htmlTopic) => {
const renderings = [];
Expand All @@ -201,16 +199,17 @@ export const makeTopicContent: MakeTopicContent = (topic, htmlTopic) => {
};

export type TopicState = {
text: Optional<string>;
text?: string;
html?: string;
};

export const parseTopicContent = (content: MRoomTopicEventContent): TopicState => {
const mtopic = M_TOPIC.findIn<MTopicContent>(content);
if (!Array.isArray(mtopic)) {
return { text: content.topic };
return { text: content.topic ?? undefined };
}
const text = mtopic?.find((r) => !isProvided(r.mimetype) || r.mimetype === "text/plain")?.body ?? content.topic;
const text =
mtopic?.find((r) => !isProvided(r.mimetype) || r.mimetype === "text/plain")?.body ?? content.topic ?? undefined;
const html = mtopic?.find((r) => r.mimetype === "text/html")?.body;
return { text, html };
};
Expand Down

0 comments on commit 278a512

Please sign in to comment.