2023-03-01 14:15:29 +03:00
|
|
|
import Service, {inject as service} from '@ember/service';
|
|
|
|
|
|
|
|
export default class MentionUtilsService extends Service {
|
|
|
|
@service store;
|
|
|
|
|
|
|
|
async loadGroupedMentions(mentions) {
|
|
|
|
// Fetch mentions with the same source
|
|
|
|
const sources = mentions.mapBy('source').uniq();
|
2023-03-16 18:49:56 +03:00
|
|
|
let filter;
|
|
|
|
if (sources.length > 0) {
|
|
|
|
filter = `source:[${sources.map(s => `'${s}'`).join(',')}]`;
|
|
|
|
}
|
|
|
|
|
|
|
|
const sourceMentions = await this.store.query('mention', {filter});
|
2023-03-01 14:15:29 +03:00
|
|
|
mentions.forEach((mention) => {
|
|
|
|
mention.set('mentions', sourceMentions.filterBy('source', mention.source));
|
|
|
|
});
|
|
|
|
return mentions;
|
|
|
|
}
|
|
|
|
}
|