mirror of
https://github.com/matrix-org/matrix-hookshot.git
synced 2025-03-10 21:19:13 +00:00
Fix message format for feed items with no title or link (#737)
* Allow empty title on feed item * Allow bare URL * Add tests for new format. * changelog
This commit is contained in:
parent
2110e88210
commit
7223a86b2b
1
changelog.d/737.bugfix
Normal file
1
changelog.d/737.bugfix
Normal file
@ -0,0 +1 @@
|
|||||||
|
Fix feed message format when the item does not contain a title or link.
|
@ -41,6 +41,7 @@ const MAX_TEMPLATE_LENGTH = 1024;
|
|||||||
|
|
||||||
const DEFAULT_TEMPLATE = "New post in $FEEDNAME";
|
const DEFAULT_TEMPLATE = "New post in $FEEDNAME";
|
||||||
const DEFAULT_TEMPLATE_WITH_CONTENT = "New post in $FEEDNAME: $LINK"
|
const DEFAULT_TEMPLATE_WITH_CONTENT = "New post in $FEEDNAME: $LINK"
|
||||||
|
const DEFAULT_TEMPLATE_WITH_ONLY_TITLE = "New post in $FEEDNAME: $TITLE"
|
||||||
|
|
||||||
@Connection
|
@Connection
|
||||||
export class FeedConnection extends BaseConnection implements IConnection {
|
export class FeedConnection extends BaseConnection implements IConnection {
|
||||||
@ -145,6 +146,8 @@ export class FeedConnection extends BaseConnection implements IConnection {
|
|||||||
return entry.title || "";
|
return entry.title || "";
|
||||||
case "$LINK":
|
case "$LINK":
|
||||||
return entry.link ? `[${entry.title ?? entry.link}](${entry.link})` : "";
|
return entry.link ? `[${entry.title ?? entry.link}](${entry.link})` : "";
|
||||||
|
case "$URL":
|
||||||
|
return entry.link || "";
|
||||||
case "$AUTHOR":
|
case "$AUTHOR":
|
||||||
return entry.author || "";
|
return entry.author || "";
|
||||||
case "$DATE":
|
case "$DATE":
|
||||||
@ -183,8 +186,10 @@ export class FeedConnection extends BaseConnection implements IConnection {
|
|||||||
let message;
|
let message;
|
||||||
if (this.state.template) {
|
if (this.state.template) {
|
||||||
message = this.templateFeedEntry(this.state.template, entry);
|
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);
|
message = this.templateFeedEntry(DEFAULT_TEMPLATE_WITH_CONTENT, entry);
|
||||||
|
} else if (entry.title) {
|
||||||
|
message = this.templateFeedEntry(DEFAULT_TEMPLATE_WITH_ONLY_TITLE, entry);
|
||||||
} else {
|
} else {
|
||||||
message = this.templateFeedEntry(DEFAULT_TEMPLATE, entry);
|
message = this.templateFeedEntry(DEFAULT_TEMPLATE, entry);
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,32 @@ describe("FeedConnection", () => {
|
|||||||
expect(matrixEvt.content.external_url).to.be.undefined;
|
expect(matrixEvt.content.external_url).to.be.undefined;
|
||||||
expect(matrixEvt.content.body).to.equal("New post in Test feed");
|
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 () => {
|
it("will handle simple feed message with all the template options possible ", async () => {
|
||||||
const [connection, intent] = createFeed({
|
const [connection, intent] = createFeed({
|
||||||
url: FEED_URL,
|
url: FEED_URL,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user