mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-18 16:01:40 +03:00
81c4b46977
fixes https://github.com/TryGhost/Team/issues/2625 - Adds an unique option to the mentions API. Enabling this will only return the latest mention from each source. - The frontend can fetch the related sources for each page by doing an extra request to the mentions API.
55 lines
1.6 KiB
JavaScript
55 lines
1.6 KiB
JavaScript
import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
|
|
import InfinityModel from 'ember-infinity/lib/infinity-model';
|
|
import RSVP from 'rsvp';
|
|
import classic from 'ember-classic-decorator';
|
|
import {inject as service} from '@ember/service';
|
|
|
|
@classic
|
|
class LoadSourceMentions extends InfinityModel {
|
|
@service mentionUtils;
|
|
|
|
async afterInfinityModel(mentions) {
|
|
return await this.mentionUtils.loadGroupedMentions(mentions);
|
|
}
|
|
}
|
|
|
|
export default class MentionsRoute extends AuthenticatedRoute {
|
|
@service store;
|
|
@service feature;
|
|
@service infinity;
|
|
|
|
perPage = 10;
|
|
|
|
beforeModel() {
|
|
super.beforeModel(...arguments);
|
|
if (!this.feature.webmentions) {
|
|
return this.transitionTo('dashboard');
|
|
}
|
|
}
|
|
|
|
model(params) {
|
|
const perPage = this.perPage;
|
|
const paginationParams = {
|
|
perPageParam: 'limit',
|
|
totalPagesParam: 'meta.pagination.pages',
|
|
countParam: 'meta.pagination.total'
|
|
};
|
|
|
|
const paginationSettings = {perPage, startingPage: 1, order: 'created_at desc', ...paginationParams};
|
|
let extension = undefined;
|
|
|
|
if (params.post_id) {
|
|
paginationSettings.filter = `resource_id:${params.post_id}+resource_type:post`;
|
|
} else {
|
|
// Only return mentions with the same source once
|
|
paginationSettings.unique = true;
|
|
extension = LoadSourceMentions;
|
|
}
|
|
|
|
return RSVP.hash({
|
|
mentions: this.infinity.model('mention', paginationSettings, extension),
|
|
post: params.post_id ? this.store.findRecord('post', params.post_id) : null
|
|
});
|
|
}
|
|
}
|