mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-26 11:57:34 -07:00
みつけるの人気のタグを第2ソートで連合含めたユーザー数にしたりユーザーのタグ以外は除外するように
This commit is contained in:
parent
a5d37c02c6
commit
8e164abb97
4 changed files with 91 additions and 8 deletions
|
@ -11,7 +11,8 @@
|
|||
<template #header><fa :icon="faHashtag" fixed-width/>{{ $t('popular-tags') }}</template>
|
||||
|
||||
<div class="vxjfqztj">
|
||||
<router-link v-for="tag in tags" :to="`/explore/tags/${tag.tag}`" :key="tag.tag">{{ tag.tag }}</router-link>
|
||||
<router-link v-for="tag in tagsLocal" :to="`/explore/tags/${tag.tag}`" :key="tag.tag" class="local">{{ tag.tag }}</router-link>
|
||||
<router-link v-for="tag in tagsRemote" :to="`/explore/tags/${tag.tag}`" :key="tag.tag">{{ tag.tag }}</router-link>
|
||||
</div>
|
||||
</ui-container>
|
||||
|
||||
|
@ -73,7 +74,8 @@ export default Vue.extend({
|
|||
sort: '+createdAt',
|
||||
limit: 10
|
||||
}),
|
||||
tags: [],
|
||||
tagsLocal: [],
|
||||
tagsRemote: [],
|
||||
faBookmark, faChartLine, faCommentAlt, faPlus, faHashtag
|
||||
};
|
||||
},
|
||||
|
@ -103,9 +105,17 @@ export default Vue.extend({
|
|||
created() {
|
||||
this.$root.api('hashtags/list', {
|
||||
sort: '+attachedLocalUsers',
|
||||
attachedToLocalUserOnly: true,
|
||||
limit: 30
|
||||
}).then(tags => {
|
||||
this.tags = tags;
|
||||
this.tagsLocal = tags;
|
||||
});
|
||||
this.$root.api('hashtags/list', {
|
||||
sort: '+attachedRemoteUsers',
|
||||
attachedToRemoteUserOnly: true,
|
||||
limit: 30
|
||||
}).then(tags => {
|
||||
this.tagsRemote = tags;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -118,4 +128,7 @@ export default Vue.extend({
|
|||
> *
|
||||
margin-right 16px
|
||||
|
||||
&.local
|
||||
font-weight bold
|
||||
|
||||
</style>
|
||||
|
|
|
@ -5,8 +5,10 @@ const Hashtag = db.get<IHashtags>('hashtags');
|
|||
Hashtag.createIndex('tag', { unique: true });
|
||||
Hashtag.createIndex('mentionedUsersCount');
|
||||
Hashtag.createIndex('mentionedLocalUsersCount');
|
||||
Hashtag.createIndex('mentionedRemoteUsersCount');
|
||||
Hashtag.createIndex('attachedUsersCount');
|
||||
Hashtag.createIndex('attachedLocalUsersCount');
|
||||
Hashtag.createIndex('attachedRemoteUsersCount');
|
||||
export default Hashtag;
|
||||
|
||||
// 後方互換性のため
|
||||
|
@ -29,6 +31,20 @@ Hashtag.findOne({ attachedUserIds: { $exists: false }}).then(h => {
|
|||
});
|
||||
}
|
||||
});
|
||||
Hashtag.findOne({ attachedRemoteUserIds: { $exists: false }}).then(h => {
|
||||
if (h != null) {
|
||||
Hashtag.update({}, {
|
||||
$set: {
|
||||
mentionedRemoteUserIds: [],
|
||||
mentionedRemoteUsersCount: 0,
|
||||
attachedRemoteUserIds: [],
|
||||
attachedRemoteUsersCount: 0,
|
||||
}
|
||||
}, {
|
||||
multi: true
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
export interface IHashtags {
|
||||
tag: string;
|
||||
|
@ -36,8 +52,12 @@ export interface IHashtags {
|
|||
mentionedUsersCount: number;
|
||||
mentionedLocalUserIds: mongo.ObjectID[];
|
||||
mentionedLocalUsersCount: number;
|
||||
mentionedRemoteUserIds: mongo.ObjectID[];
|
||||
mentionedRemoteUsersCount: number;
|
||||
attachedUserIds: mongo.ObjectID[];
|
||||
attachedUsersCount: number;
|
||||
attachedLocalUserIds: mongo.ObjectID[];
|
||||
attachedLocalUsersCount: number;
|
||||
attachedRemoteUserIds: mongo.ObjectID[];
|
||||
attachedRemoteUsersCount: number;
|
||||
}
|
||||
|
|
|
@ -11,16 +11,35 @@ export const meta = {
|
|||
default: 10
|
||||
},
|
||||
|
||||
attachedToUserOnly: {
|
||||
validator: $.optional.bool,
|
||||
default: false
|
||||
},
|
||||
|
||||
attachedToLocalUserOnly: {
|
||||
validator: $.optional.bool,
|
||||
default: false
|
||||
},
|
||||
|
||||
attachedToRemoteUserOnly: {
|
||||
validator: $.optional.bool,
|
||||
default: false
|
||||
},
|
||||
|
||||
sort: {
|
||||
validator: $.str.or([
|
||||
'+mentionedUsers',
|
||||
'-mentionedUsers',
|
||||
'+mentionedLocalUsers',
|
||||
'-mentionedLocalUsers',
|
||||
'+mentionedRemoteUsers',
|
||||
'-mentionedRemoteUsers',
|
||||
'+attachedUsers',
|
||||
'-attachedUsers',
|
||||
'+attachedLocalUsers',
|
||||
'-attachedLocalUsers',
|
||||
'+attachedRemoteUsers',
|
||||
'-attachedRemoteUsers',
|
||||
]),
|
||||
},
|
||||
}
|
||||
|
@ -31,23 +50,33 @@ const sort: any = {
|
|||
'-mentionedUsers': { mentionedUsersCount: 1 },
|
||||
'+mentionedLocalUsers': { mentionedLocalUsersCount: -1 },
|
||||
'-mentionedLocalUsers': { mentionedLocalUsersCount: 1 },
|
||||
'+mentionedRemoteUsers': { mentionedRemoteUsersCount: -1 },
|
||||
'-mentionedRemoteUsers': { mentionedRemoteUsersCount: 1 },
|
||||
'+attachedUsers': { attachedUsersCount: -1 },
|
||||
'-attachedUsers': { attachedUsersCount: 1 },
|
||||
'+attachedLocalUsers': { attachedLocalUsersCount: -1 },
|
||||
'-attachedLocalUsers': { attachedLocalUsersCount: 1 },
|
||||
'+attachedRemoteUsers': { attachedRemoteUsersCount: -1 },
|
||||
'-attachedRemoteUsers': { attachedRemoteUsersCount: 1 },
|
||||
};
|
||||
|
||||
export default define(meta, (ps, me) => new Promise(async (res, rej) => {
|
||||
const q = {} as any;
|
||||
if (ps.attachedToUserOnly) q.attachedUsersCount = { $ne: 0 };
|
||||
if (ps.attachedToLocalUserOnly) q.attachedLocalUsersCount = { $ne: 0 };
|
||||
if (ps.attachedToRemoteUserOnly) q.attachedRemoteUsersCount = { $ne: 0 };
|
||||
const tags = await Hashtag
|
||||
.find({}, {
|
||||
.find(q, {
|
||||
limit: ps.limit,
|
||||
sort: sort[ps.sort],
|
||||
fields: {
|
||||
tag: true,
|
||||
mentionedUsersCount: true,
|
||||
mentionedLocalUsersCount: true,
|
||||
mentionedRemoteUsersCount: true,
|
||||
attachedUsersCount: true,
|
||||
attachedLocalUsersCount: true
|
||||
attachedLocalUsersCount: true,
|
||||
attachedRemoteUsersCount: true
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { IUser, isLocalUser } from '../models/user';
|
||||
import { IUser, isLocalUser, isRemoteUser } from '../models/user';
|
||||
import Hashtag from '../models/hashtag';
|
||||
import hashtagChart from './chart/hashtag';
|
||||
|
||||
|
@ -26,12 +26,20 @@ export async function updateHashtag(user: IUser, tag: string, isUserAttached = f
|
|||
$push.attachedLocalUserIds = user._id;
|
||||
$inc.attachedLocalUsersCount = 1;
|
||||
}
|
||||
// 自分が(リモートで)初めてこのタグを使ったなら
|
||||
if (isRemoteUser(user) && !index.attachedRemoteUserIds.some(id => id.equals(user._id))) {
|
||||
$push.attachedRemoteUserIds = user._id;
|
||||
$inc.attachedRemoteUsersCount = 1;
|
||||
}
|
||||
} else {
|
||||
$pull.attachedUserIds = user._id;
|
||||
$inc.attachedUsersCount = -1;
|
||||
if (isLocalUser(user)) {
|
||||
$pull.attachedLocalUserIds = user._id;
|
||||
$inc.attachedLocalUsersCount = -1;
|
||||
} else {
|
||||
$pull.attachedRemoteUserIds = user._id;
|
||||
$inc.attachedRemoteUsersCount = -1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -45,6 +53,11 @@ export async function updateHashtag(user: IUser, tag: string, isUserAttached = f
|
|||
$push.mentionedLocalUserIds = user._id;
|
||||
$inc.mentionedLocalUsersCount = 1;
|
||||
}
|
||||
// 自分が(リモートで)初めてこのタグを使ったなら
|
||||
if (isRemoteUser(user) && !index.mentionedRemoteUserIds.some(id => id.equals(user._id))) {
|
||||
$push.mentionedRemoteUserIds = user._id;
|
||||
$inc.mentionedRemoteUsersCount = 1;
|
||||
}
|
||||
}
|
||||
|
||||
const q = {} as any;
|
||||
|
@ -60,10 +73,14 @@ export async function updateHashtag(user: IUser, tag: string, isUserAttached = f
|
|||
mentionedUsersCount: 0,
|
||||
mentionedLocalUserIds: [],
|
||||
mentionedLocalUsersCount: 0,
|
||||
mentionedRemoteUserIds: [],
|
||||
mentionedRemoteUsersCount: 0,
|
||||
attachedUserIds: [user._id],
|
||||
attachedUsersCount: 1,
|
||||
attachedLocalUserIds: isLocalUser(user) ? [user._id] : [],
|
||||
attachedLocalUsersCount: isLocalUser(user) ? 1 : 0
|
||||
attachedLocalUsersCount: isLocalUser(user) ? 1 : 0,
|
||||
attachedRemoteUserIds: isRemoteUser(user) ? [user._id] : [],
|
||||
attachedRemoteUsersCount: isRemoteUser(user) ? 1 : 0,
|
||||
});
|
||||
} else {
|
||||
Hashtag.insert({
|
||||
|
@ -72,10 +89,14 @@ export async function updateHashtag(user: IUser, tag: string, isUserAttached = f
|
|||
mentionedUsersCount: 1,
|
||||
mentionedLocalUserIds: isLocalUser(user) ? [user._id] : [],
|
||||
mentionedLocalUsersCount: isLocalUser(user) ? 1 : 0,
|
||||
mentionedRemoteUserIds: isRemoteUser(user) ? [user._id] : [],
|
||||
mentionedRemoteUsersCount: isRemoteUser(user) ? 1 : 0,
|
||||
attachedUserIds: [],
|
||||
attachedUsersCount: 0,
|
||||
attachedLocalUserIds: [],
|
||||
attachedLocalUsersCount: 0
|
||||
attachedLocalUsersCount: 0,
|
||||
attachedRemoteUserIds: [],
|
||||
attachedRemoteUsersCount: 0,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue