fix: use getTags() async iterator and instanceof checks for Mention/Hashtag
This commit is contained in:
+11
-8
@@ -14,7 +14,9 @@ import {
|
|||||||
Create,
|
Create,
|
||||||
Delete,
|
Delete,
|
||||||
Follow,
|
Follow,
|
||||||
|
Hashtag,
|
||||||
Like,
|
Like,
|
||||||
|
Mention,
|
||||||
Move,
|
Move,
|
||||||
Note,
|
Note,
|
||||||
Reject,
|
Reject,
|
||||||
@@ -450,8 +452,7 @@ export function registerInboxListeners(inboxChain, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check for mentions of our actor
|
// Check for mentions of our actor
|
||||||
if (object.tag) {
|
{
|
||||||
const tags = Array.isArray(object.tag) ? object.tag : [object.tag];
|
|
||||||
const ourActorUrl = ctx.getActorUri(handle).href;
|
const ourActorUrl = ctx.getActorUri(handle).href;
|
||||||
|
|
||||||
// Detect direct/private visibility: no public collection in `to` or `cc`
|
// Detect direct/private visibility: no public collection in `to` or `cc`
|
||||||
@@ -462,8 +463,8 @@ export function registerInboxListeners(inboxChain, options) {
|
|||||||
!toHrefs.includes(PUBLIC_COLLECTION) &&
|
!toHrefs.includes(PUBLIC_COLLECTION) &&
|
||||||
!ccHrefs.includes(PUBLIC_COLLECTION);
|
!ccHrefs.includes(PUBLIC_COLLECTION);
|
||||||
|
|
||||||
for (const tag of tags) {
|
for await (const tag of object.getTags()) {
|
||||||
if (tag.type === "Mention" && tag.href?.href === ourActorUrl) {
|
if (tag instanceof Mention && tag.href?.href === ourActorUrl) {
|
||||||
const actorInfo = await extractActorInfo(actorObj, { documentLoader: authLoader });
|
const actorInfo = await extractActorInfo(actorObj, { documentLoader: authLoader });
|
||||||
const rawMentionHtml = object.content?.toString() || "";
|
const rawMentionHtml = object.content?.toString() || "";
|
||||||
const mentionHtml = sanitizeContent(rawMentionHtml);
|
const mentionHtml = sanitizeContent(rawMentionHtml);
|
||||||
@@ -525,10 +526,12 @@ export function registerInboxListeners(inboxChain, options) {
|
|||||||
// Not a followed account — check if the post's hashtags match any followed tags
|
// Not a followed account — check if the post's hashtags match any followed tags
|
||||||
// so tagged posts from across the fediverse appear in the timeline
|
// so tagged posts from across the fediverse appear in the timeline
|
||||||
try {
|
try {
|
||||||
const objectTags = Array.isArray(object.tag) ? object.tag : (object.tag ? [object.tag] : []);
|
const postHashtags = [];
|
||||||
const postHashtags = objectTags
|
for await (const t of object.getTags()) {
|
||||||
.filter((t) => t.type === "Hashtag" && t.name)
|
if (t instanceof Hashtag && t.name) {
|
||||||
.map((t) => t.name.toString().replace(/^#/, "").toLowerCase());
|
postHashtags.push(t.name.toString().replace(/^#/, "").toLowerCase());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (postHashtags.length > 0) {
|
if (postHashtags.length > 0) {
|
||||||
const followedTags = await getFollowedTags(collections);
|
const followedTags = await getFollowedTags(collections);
|
||||||
|
|||||||
Reference in New Issue
Block a user