Skip to content

Receiving a webmention without any updates #32

@benjifs

Description

@benjifs

While running processMention, an existing webmention from source would get deleted and, if it still exists, get added again.

async processMention(mention: SimpleMention): Promise<Mention[] | null> {
const {html, status, error} = await fetchHtml(mention.source);
// Delete exisiting webmentions with the current source and target to avoid duplication
await this.storageHandler.deleteMention(mention);
// A status of 410 indicates that the webmention that previously existed was deleted
// If we got an error or there was no html body, then the source is invalid and
// we should delete any stored version of the webmention as per the specification without
// adding new ones
if(error || !html || status === 410) return null;
const hEntries = parseHtml(html, mention.source, mention.target);
let mentionedUrls = hEntries.find(({type}) => type && type.includes("mention-of"));
// If the page does not include any mention of the target, then we can return
// early as we have already deleted any stored mentions with this target and source
if(!mentionedUrls) return null;
// Not every post has an author, some pages also have authors on a
// seperate page, as such we should normalize it a local author if possible
await Promise.all(hEntries.map(async (entry, index) => {
if(!entry.author) return;
hEntries[index].author = await normalizeAuthors(entry.author);
}))
let mentions = hEntries.map(h => convertHEntryToMention(h, mention.source, mention.target));
// if there are only basic mentions, use the first (most complete mention)
// otherwsise, get rid of any basic mentions as we have a better type
if(mentions.find(m => m.type !== 'mention')) mentions = mentions.filter(m => m.type !== 'mention');
else mentions = [mentions.find(m => m.type === 'mention')!];
const storedMentions = mentions.map(m => this.storageHandler.storeMentionForPage(m.target, m));
return Promise.all(storedMentions);
}

I am seeing some cases where I am receiving daily webmentions from the same source as part of their site rebuild which this treats it as a new webmention because of this process. While it seems like the sender should not be resending non-updated webmentions, the suggestions I'm getting are that the endpoint should still process this but since the only value changes from old wm to new wm is the parsed date then it should probably just ignore them.

Does that seem like an ok change for me to make for this project?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions