diff --git a/src/client/app/common/views/pages/explore.vue b/src/client/app/common/views/pages/explore.vue
index 8f40e42e83..63a9a47035 100644
--- a/src/client/app/common/views/pages/explore.vue
+++ b/src/client/app/common/views/pages/explore.vue
@@ -11,7 +11,8 @@
{{ $t('popular-tags') }}
- {{ tag.tag }}
+ {{ tag.tag }}
+ {{ tag.tag }}
@@ -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
+
diff --git a/src/models/hashtag.ts b/src/models/hashtag.ts
index 742e4a254c..c1de42086e 100644
--- a/src/models/hashtag.ts
+++ b/src/models/hashtag.ts
@@ -5,8 +5,10 @@ const Hashtag = db.get('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;
}
diff --git a/src/server/api/endpoints/hashtags/list.ts b/src/server/api/endpoints/hashtags/list.ts
index 5c37dbd6b5..5f197a8726 100644
--- a/src/server/api/endpoints/hashtags/list.ts
+++ b/src/server/api/endpoints/hashtags/list.ts
@@ -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
}
});
diff --git a/src/services/update-hashtag.ts b/src/services/update-hashtag.ts
index e5de7c10c6..23c39312c0 100644
--- a/src/services/update-hashtag.ts
+++ b/src/services/update-hashtag.ts
@@ -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,
});
}
}