Updated logic for whether a site is recommending you back (#18426)
refs https://github.com/TryGhost/Product/issues/3958 - `url:~a.com` matches a.com, sub.a.com and a.com/path - added a stricter check based on hostname and pathname, but that ignores www, protocol, query parameters and hash fragments
This commit is contained in:
parent
043c9bb35d
commit
8ed0c19a1c
@ -97,10 +97,8 @@ export class IncomingRecommendationService {
|
||||
const url = new URL(mention.source.toString().replace(/\/.well-known\/recommendations\.json$/, ''));
|
||||
|
||||
// Check if we are also recommending this URL
|
||||
const existing = await this.#recommendationService.countRecommendations({
|
||||
filter: `url:~'${url}'`
|
||||
});
|
||||
const recommendingBack = existing > 0;
|
||||
const existing = await this.#recommendationService.readRecommendationByUrl(url);
|
||||
const recommendingBack = !!existing;
|
||||
|
||||
return {
|
||||
title: mention.sourceTitle,
|
||||
|
@ -183,4 +183,13 @@ export class RecommendationService {
|
||||
const subscribeEvent = SubscribeEvent.create({recommendationId: id, memberId});
|
||||
await this.subscribeEventRepository.save(subscribeEvent);
|
||||
}
|
||||
|
||||
async readRecommendationByUrl(url: URL): Promise<RecommendationPlain|null> {
|
||||
const recommendation = await this.repository.getByUrl(url);
|
||||
|
||||
if (!recommendation) {
|
||||
return null;
|
||||
}
|
||||
return recommendation.plain;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user