From 68ce6d574882c1badbb4a3d2772451534014dd01 Mon Sep 17 00:00:00 2001 From: Akihiko Odaki Date: Tue, 27 Mar 2018 16:51:12 +0900 Subject: Implement remote account resolution --- src/api/bot/core.ts | 14 +++++++------- src/api/bot/interfaces/line.ts | 12 +++++++----- 2 files changed, 14 insertions(+), 12 deletions(-) (limited to 'src/api/bot') diff --git a/src/api/bot/core.ts b/src/api/bot/core.ts index ad29f1003e..77a68aaee6 100644 --- a/src/api/bot/core.ts +++ b/src/api/bot/core.ts @@ -1,10 +1,11 @@ import * as EventEmitter from 'events'; import * as bcrypt from 'bcryptjs'; -import User, { IUser, init as initUser } from '../models/user'; +import User, { ILocalAccount, IUser, init as initUser } from '../models/user'; import getPostSummary from '../../common/get-post-summary'; -import getUserSummary from '../../common/get-user-summary'; +import getUserSummary from '../../common/user/get-summary'; +import parseAcct from '../../common/user/parse-acct'; import getNotificationSummary from '../../common/get-notification-summary'; const hmm = [ @@ -163,9 +164,7 @@ export default class BotCore extends EventEmitter { public async showUserCommand(q: string): Promise { try { - const user = await require('../endpoints/users/show')({ - username: q.substr(1) - }, this.user); + const user = await require('../endpoints/users/show')(parseAcct(q.substr(1)), this.user); const text = getUserSummary(user); @@ -209,7 +208,8 @@ class SigninContext extends Context { if (this.temporaryUser == null) { // Fetch user const user: IUser = await User.findOne({ - username_lower: query.toLowerCase() + username_lower: query.toLowerCase(), + host: null }, { fields: { data: false @@ -225,7 +225,7 @@ class SigninContext extends Context { } } else { // Compare password - const same = await bcrypt.compare(query, this.temporaryUser.account.password); + const same = await bcrypt.compare(query, (this.temporaryUser.account as ILocalAccount).password); if (same) { this.bot.signin(this.temporaryUser); diff --git a/src/api/bot/interfaces/line.ts b/src/api/bot/interfaces/line.ts index 6b2ebdec88..8036b2fde4 100644 --- a/src/api/bot/interfaces/line.ts +++ b/src/api/bot/interfaces/line.ts @@ -7,6 +7,8 @@ import config from '../../../conf'; import BotCore from '../core'; import _redis from '../../../db/redis'; import prominence = require('prominence'); +import getAcct from '../../../common/user/get-acct'; +import parseAcct from '../../../common/user/parse-acct'; import getPostSummary from '../../../common/get-post-summary'; const redis = prominence(_redis); @@ -98,10 +100,9 @@ class LineBot extends BotCore { } public async showUserCommand(q: string) { - const user = await require('../../endpoints/users/show')({ - username: q.substr(1) - }, this.user); + const user = await require('../../endpoints/users/show')(parseAcct(q.substr(1)), this.user); + const acct = getAcct(user); const actions = []; actions.push({ @@ -121,7 +122,7 @@ class LineBot extends BotCore { actions.push({ type: 'uri', label: 'Webで見る', - uri: `${config.url}/@${user.username}` + uri: `${config.url}/@${acct}` }); this.reply([{ @@ -130,7 +131,7 @@ class LineBot extends BotCore { template: { type: 'buttons', thumbnailImageUrl: `${user.avatar_url}?thumbnail&size=1024`, - title: `${user.name} (@${user.username})`, + title: `${user.name} (@${acct})`, text: user.description || '(no description)', actions: actions } @@ -171,6 +172,7 @@ module.exports = async (app: express.Application) => { if (session == null) { const user = await User.findOne({ + host: null, 'account.line': { user_id: sourceId } -- cgit v1.2.3-freya