You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-08-07 23:02:56 +03:00
Handle empty m.room.topic (#4673)
* Define topic as optional. * Change isProvided so that types work better. * allow makeTopicContent and parseTopicContent to handle optional values for plain text * linting * Remove usage of optional * Topic key may only contain legacy key. * Add tests for other branches.
This commit is contained in:
@@ -207,6 +207,17 @@ describe("Topic content helpers", () => {
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("creates an empty event when the topic is falsey", () => {
|
||||
expect(makeTopicContent(undefined)).toEqual({
|
||||
topic: undefined,
|
||||
[M_TOPIC.name]: [],
|
||||
});
|
||||
expect(makeTopicContent(null)).toEqual({
|
||||
topic: null,
|
||||
[M_TOPIC.name]: [],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("parseTopicContent()", () => {
|
||||
@@ -257,5 +268,26 @@ describe("Topic content helpers", () => {
|
||||
html: "<b>pizza</b>",
|
||||
});
|
||||
});
|
||||
|
||||
it("parses legacy event content", () => {
|
||||
expect(
|
||||
parseTopicContent({
|
||||
topic: "pizza",
|
||||
}),
|
||||
).toEqual({
|
||||
text: "pizza",
|
||||
});
|
||||
});
|
||||
|
||||
it("uses legacy event content when new topic key is invalid", () => {
|
||||
expect(
|
||||
parseTopicContent({
|
||||
"topic": "pizza",
|
||||
"m.topic": {} as any,
|
||||
}),
|
||||
).toEqual({
|
||||
text: "pizza",
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user