summaryrefslogtreecommitdiff
path: root/src/services
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-07-18 07:19:24 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-07-18 07:19:24 +0900
commitdf20f5063dd5f93235307e5fca6fc7b17625bea9 (patch)
tree4adfc17a5ea5794e4d70fe1fe6fbc40812277e3d /src/services
parent:v: (diff)
downloadsharkey-df20f5063dd5f93235307e5fca6fc7b17625bea9.tar.gz
sharkey-df20f5063dd5f93235307e5fca6fc7b17625bea9.tar.bz2
sharkey-df20f5063dd5f93235307e5fca6fc7b17625bea9.zip
#1720 #59
Diffstat (limited to 'src/services')
-rw-r--r--src/services/note/create.ts7
-rw-r--r--src/services/register-hashtag.ts28
2 files changed, 33 insertions, 2 deletions
diff --git a/src/services/note/create.ts b/src/services/note/create.ts
index aec0e78964..6629e691b7 100644
--- a/src/services/note/create.ts
+++ b/src/services/note/create.ts
@@ -20,6 +20,7 @@ import UserList from '../../models/user-list';
import resolveUser from '../../remote/resolve-user';
import Meta from '../../models/meta';
import config from '../../config';
+import registerHashtag from '../register-hashtag';
type Type = 'reply' | 'renote' | 'quote' | 'mention';
@@ -64,7 +65,6 @@ export default async (user: IUser, data: {
geo?: any;
poll?: any;
viaMobile?: boolean;
- tags?: string[];
cw?: string;
visibility?: string;
visibleUsers?: IUser[];
@@ -75,7 +75,7 @@ export default async (user: IUser, data: {
if (data.visibility == null) data.visibility = 'public';
if (data.viaMobile == null) data.viaMobile = false;
- let tags = data.tags || [];
+ let tags: string[] = [];
let tokens: any[] = null;
@@ -149,6 +149,9 @@ export default async (user: IUser, data: {
res(note);
+ // ハッシュタグ登録
+ tags.map(tag => registerHashtag(user, tag));
+
//#region Increment notes count
if (isLocalUser(user)) {
Meta.update({}, {
diff --git a/src/services/register-hashtag.ts b/src/services/register-hashtag.ts
new file mode 100644
index 0000000000..ca6b74783b
--- /dev/null
+++ b/src/services/register-hashtag.ts
@@ -0,0 +1,28 @@
+import { IUser } from '../models/user';
+import Hashtag from '../models/hashtag';
+
+export default async function(user: IUser, tag: string) {
+ tag = tag.toLowerCase();
+
+ const index = await Hashtag.findOne({ tag });
+
+ if (index != null) {
+ // 自分が初めてこのタグを使ったなら
+ if (!index.mentionedUserIds.some(id => id.equals(user._id))) {
+ Hashtag.update({ tag }, {
+ $push: {
+ mentionedUserIds: user._id
+ },
+ $inc: {
+ mentionedUserIdsCount: 1
+ }
+ });
+ }
+ } else {
+ Hashtag.insert({
+ tag,
+ mentionedUserIds: [user._id],
+ mentionedUserIdsCount: 1
+ });
+ }
+}