diff --git a/changelog.d/737.bugfix b/changelog.d/737.bugfix new file mode 100644 index 00000000..565184c0 --- /dev/null +++ b/changelog.d/737.bugfix @@ -0,0 +1 @@ +Fix feed message format when the item does not contain a title or link. diff --git a/src/Connections/FeedConnection.ts b/src/Connections/FeedConnection.ts index ed403834..401f9f4c 100644 --- a/src/Connections/FeedConnection.ts +++ b/src/Connections/FeedConnection.ts @@ -41,6 +41,7 @@ const MAX_TEMPLATE_LENGTH = 1024; const DEFAULT_TEMPLATE = "New post in $FEEDNAME"; const DEFAULT_TEMPLATE_WITH_CONTENT = "New post in $FEEDNAME: $LINK" +const DEFAULT_TEMPLATE_WITH_ONLY_TITLE = "New post in $FEEDNAME: $TITLE" @Connection export class FeedConnection extends BaseConnection implements IConnection { @@ -145,6 +146,8 @@ export class FeedConnection extends BaseConnection implements IConnection { return entry.title || ""; case "$LINK": return entry.link ? `[${entry.title ?? entry.link}](${entry.link})` : ""; + case "$URL": + return entry.link || ""; case "$AUTHOR": return entry.author || ""; case "$DATE": @@ -183,8 +186,10 @@ export class FeedConnection extends BaseConnection implements IConnection { let message; if (this.state.template) { message = this.templateFeedEntry(this.state.template, entry); - } else if (entry.title && entry.link) { + } else if (entry.link) { message = this.templateFeedEntry(DEFAULT_TEMPLATE_WITH_CONTENT, entry); + } else if (entry.title) { + message = this.templateFeedEntry(DEFAULT_TEMPLATE_WITH_ONLY_TITLE, entry); } else { message = this.templateFeedEntry(DEFAULT_TEMPLATE, entry); } diff --git a/tests/connections/FeedTest.spec.ts b/tests/connections/FeedTest.spec.ts index 4bde19aa..e58ee18a 100644 --- a/tests/connections/FeedTest.spec.ts +++ b/tests/connections/FeedTest.spec.ts @@ -54,6 +54,32 @@ describe("FeedConnection", () => { expect(matrixEvt.content.external_url).to.be.undefined; expect(matrixEvt.content.body).to.equal("New post in Test feed"); }); + it("will handle simple feed message with a missing title ", async () => { + const [connection, intent] = createFeed({ + url: FEED_URL, + }); + await connection.handleFeedEntry({ + ...FEED_ENTRY_DEFAULTS, + title: null, + }); + const matrixEvt =intent.sentEvents[0]; + expect(matrixEvt).to.not.be.undefined; + expect(matrixEvt.roomId).to.equal(ROOM_ID); + expect(matrixEvt.content.body).to.equal("New post in Test feed: [foo/bar](foo/bar)"); + }); + it("will handle simple feed message with a missing link ", async () => { + const [connection, intent] = createFeed({ + url: FEED_URL, + }); + await connection.handleFeedEntry({ + ...FEED_ENTRY_DEFAULTS, + link: null, + }); + const matrixEvt =intent.sentEvents[0]; + expect(matrixEvt).to.not.be.undefined; + expect(matrixEvt.roomId).to.equal(ROOM_ID); + expect(matrixEvt.content.body).to.equal("New post in Test feed: Foo"); + }); it("will handle simple feed message with all the template options possible ", async () => { const [connection, intent] = createFeed({ url: FEED_URL,