Fix: ピン留め投稿の表示順がおかしい (#4906)

* Fix: syuilo#4904

* fix comment
This commit is contained in:
MeiMei 2019-05-12 09:37:00 +09:00 committed by syuilo
parent db846a96e3
commit 55616b16e1
3 changed files with 15 additions and 3 deletions

View file

@ -72,7 +72,10 @@ export class UserRepository extends Repository<User> {
const meId = me ? typeof me === 'string' ? me : me.id : null; const meId = me ? typeof me === 'string' ? me : me.id : null;
const relation = meId && (meId !== user.id) && opts.detail ? await this.getRelation(meId, user.id) : null; const relation = meId && (meId !== user.id) && opts.detail ? await this.getRelation(meId, user.id) : null;
const pins = opts.detail ? await UserNotePinings.find({ userId: user.id }) : []; const pins = opts.detail ? await UserNotePinings.find({
where: { userId: user.id },
order: { id: 'DESC' }
}) : [];
const profile = opts.detail ? await UserProfiles.findOne(user.id).then(ensure) : null; const profile = opts.detail ? await UserProfiles.findOne(user.id).then(ensure) : null;
const falsy = opts.detail ? false : undefined; const falsy = opts.detail ? false : undefined;

View file

@ -474,9 +474,15 @@ export async function updateFeatured(userId: User['id']) {
.slice(0, 5) .slice(0, 5)
.map(item => limit(() => resolveNote(item, resolver)))); .map(item => limit(() => resolveNote(item, resolver))));
// delete
await UserNotePinings.delete({ userId: user.id });
// とりあえずidを別の時間で生成して順番を維持
let td = 0;
for (const note of featuredNotes.filter(note => note != null)) { for (const note of featuredNotes.filter(note => note != null)) {
td -= 1000;
UserNotePinings.save({ UserNotePinings.save({
id: genId(), id: genId(new Date(Date.now() + td)),
createdAt: new Date(), createdAt: new Date(),
userId: user.id, userId: user.id,
noteId: note!.id noteId: note!.id

View file

@ -21,7 +21,10 @@ export default async (ctx: Router.IRouterContext) => {
return; return;
} }
const pinings = await UserNotePinings.find({ userId: user.id }); const pinings = await UserNotePinings.find({
where: { userId: user.id },
order: { id: 'DESC' }
});
const pinnedNotes = await Promise.all(pinings.map(pining => const pinnedNotes = await Promise.all(pinings.map(pining =>
Notes.findOne(pining.noteId).then(ensure))); Notes.findOne(pining.noteId).then(ensure)));