summaryrefslogtreecommitdiff
path: root/src/misc/user
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-04-02 04:15:27 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-04-02 04:15:27 +0900
commitcd2542e0fd8578f6e41114ffebbda1f16f7d04ce (patch)
treec339b7808fc2a3d72ae30cb86ddb7b9c21852652 /src/misc/user
parentRefactor (diff)
downloadsharkey-cd2542e0fd8578f6e41114ffebbda1f16f7d04ce.tar.gz
sharkey-cd2542e0fd8578f6e41114ffebbda1f16f7d04ce.tar.bz2
sharkey-cd2542e0fd8578f6e41114ffebbda1f16f7d04ce.zip
Refactor
Diffstat (limited to 'src/misc/user')
-rw-r--r--src/misc/user/get-acct.ts3
-rw-r--r--src/misc/user/get-summary.ts18
-rw-r--r--src/misc/user/parse-acct.ts4
3 files changed, 25 insertions, 0 deletions
diff --git a/src/misc/user/get-acct.ts b/src/misc/user/get-acct.ts
new file mode 100644
index 0000000000..9afb03d88b
--- /dev/null
+++ b/src/misc/user/get-acct.ts
@@ -0,0 +1,3 @@
+export default user => {
+ return user.host === null ? user.username : `${user.username}@${user.host}`;
+};
diff --git a/src/misc/user/get-summary.ts b/src/misc/user/get-summary.ts
new file mode 100644
index 0000000000..2c71d3eae9
--- /dev/null
+++ b/src/misc/user/get-summary.ts
@@ -0,0 +1,18 @@
+import { IUser, isLocalUser } from '../../models/user';
+import getAcct from './get-acct';
+
+/**
+ * ユーザーを表す文字列を取得します。
+ * @param user ユーザー
+ */
+export default function(user: IUser): string {
+ let string = `${user.name} (@${getAcct(user)})\n` +
+ `${user.postsCount}投稿、${user.followingCount}フォロー、${user.followersCount}フォロワー\n`;
+
+ if (isLocalUser(user)) {
+ const account = user.account;
+ string += `場所: ${account.profile.location}、誕生日: ${account.profile.birthday}\n`;
+ }
+
+ return string + `「${user.description}」`;
+}
diff --git a/src/misc/user/parse-acct.ts b/src/misc/user/parse-acct.ts
new file mode 100644
index 0000000000..ef1f55405d
--- /dev/null
+++ b/src/misc/user/parse-acct.ts
@@ -0,0 +1,4 @@
+export default acct => {
+ const splitted = acct.split('@', 2);
+ return { username: splitted[0], host: splitted[1] || null };
+};