2023-01-17 15:16:18 +03:00
|
|
|
import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
|
2023-03-01 14:15:29 +03:00
|
|
|
import InfinityModel from 'ember-infinity/lib/infinity-model';
|
2023-02-22 12:48:15 +03:00
|
|
|
import RSVP from 'rsvp';
|
2023-03-01 14:15:29 +03:00
|
|
|
import classic from 'ember-classic-decorator';
|
2023-01-17 15:16:18 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
|
|
|
|
2023-03-01 14:15:29 +03:00
|
|
|
@classic
|
|
|
|
class LoadSourceMentions extends InfinityModel {
|
|
|
|
@service mentionUtils;
|
|
|
|
|
|
|
|
async afterInfinityModel(mentions) {
|
|
|
|
return await this.mentionUtils.loadGroupedMentions(mentions);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-17 15:16:18 +03:00
|
|
|
export default class MentionsRoute extends AuthenticatedRoute {
|
|
|
|
@service store;
|
|
|
|
@service feature;
|
2023-02-20 14:27:01 +03:00
|
|
|
@service infinity;
|
|
|
|
|
|
|
|
perPage = 10;
|
2023-01-17 15:16:18 +03:00
|
|
|
|
|
|
|
beforeModel() {
|
|
|
|
super.beforeModel(...arguments);
|
|
|
|
if (!this.feature.webmentions) {
|
|
|
|
return this.transitionTo('dashboard');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-22 12:48:15 +03:00
|
|
|
model(params) {
|
2023-02-20 14:27:01 +03:00
|
|
|
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};
|
2023-03-01 14:15:29 +03:00
|
|
|
let extension = undefined;
|
2023-02-20 14:27:01 +03:00
|
|
|
|
2023-02-22 12:48:15 +03:00
|
|
|
if (params.post_id) {
|
|
|
|
paginationSettings.filter = `resource_id:${params.post_id}+resource_type:post`;
|
2023-03-01 14:15:29 +03:00
|
|
|
} else {
|
|
|
|
// Only return mentions with the same source once
|
|
|
|
paginationSettings.unique = true;
|
|
|
|
extension = LoadSourceMentions;
|
2023-02-22 12:48:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return RSVP.hash({
|
2023-03-01 14:15:29 +03:00
|
|
|
mentions: this.infinity.model('mention', paginationSettings, extension),
|
2023-02-22 12:48:15 +03:00
|
|
|
post: params.post_id ? this.store.findRecord('post', params.post_id) : null
|
|
|
|
});
|
2023-01-17 15:16:18 +03:00
|
|
|
}
|
|
|
|
}
|