Compare commits
26 Commits
11.0.0-bet
...
11.0.0-bet
Author | SHA1 | Date | |
---|---|---|---|
![]() |
60a11f8da5 | ||
![]() |
1181fcdceb | ||
![]() |
8cb9852058 | ||
![]() |
53d46d1cbe | ||
![]() |
275e1c8de9 | ||
![]() |
d46eca4c87 | ||
![]() |
2927fb1597 | ||
![]() |
8c72e011d2 | ||
![]() |
69662e24c3 | ||
![]() |
96099ffe98 | ||
![]() |
ae16b45c11 | ||
![]() |
cfee87d3ef | ||
![]() |
5fcf5bc635 | ||
![]() |
14bcb813cc | ||
![]() |
6af19794b6 | ||
![]() |
8316186695 | ||
![]() |
85d3023cd5 | ||
![]() |
78414dee29 | ||
![]() |
084135141f | ||
![]() |
467a21f028 | ||
![]() |
6e284c44d6 | ||
![]() |
daf9a449e8 | ||
![]() |
960268fd33 | ||
![]() |
8c331da315 | ||
![]() |
b0d626d862 | ||
![]() |
a51fbd7316 |
@@ -130,6 +130,40 @@ const users = userIds.length > 0 ? await Users.find({
|
|||||||
}) : [];
|
}) : [];
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### 配列のインデックス in SQL
|
||||||
|
SQLでは配列のインデックスは**1始まり**。
|
||||||
|
`[a, b, c]`の `a`にアクセスしたいなら`[0]`ではなく`[1]`と書く
|
||||||
|
|
||||||
### `undefined`にご用心
|
### `undefined`にご用心
|
||||||
MongoDBの時とは違い、findOneでレコードを取得する時に対象レコードが存在しない場合 **`undefined`** が返ってくるので注意。
|
MongoDBの時とは違い、findOneでレコードを取得する時に対象レコードが存在しない場合 **`undefined`** が返ってくるので注意。
|
||||||
MongoDBは`null`で返してきてたので、その感覚で`if (x === null)`とか書くとバグる。代わりに`if (x == null)`と書いてください
|
MongoDBは`null`で返してきてたので、その感覚で`if (x === null)`とか書くとバグる。代わりに`if (x == null)`と書いてください
|
||||||
|
|
||||||
|
### 簡素な`undefined`チェック
|
||||||
|
データベースからレコードを取得するときに、プログラムの流れ的に(ほぼ)絶対`undefined`にはならない場合でも、`undefined`チェックしないとTypeScriptに怒られます。
|
||||||
|
でもいちいち複数行を費やして、発生するはずのない`undefined`をチェックするのも面倒なので、`ensure`というユーティリティ関数を用意しています。
|
||||||
|
例えば、
|
||||||
|
``` ts
|
||||||
|
const user = await Users.findOne(userId);
|
||||||
|
// この時点で user の型は User | undefined
|
||||||
|
if (user == null) {
|
||||||
|
throw 'missing user';
|
||||||
|
}
|
||||||
|
// この時点で user の型は User
|
||||||
|
```
|
||||||
|
という処理を`ensure`を使うと
|
||||||
|
``` ts
|
||||||
|
const user = await Users.findOne(userId).then(ensure);
|
||||||
|
// この時点で user の型は User
|
||||||
|
```
|
||||||
|
という風に書けます。
|
||||||
|
もちろん`ensure`内部でエラーを握りつぶすようなことはしておらず、万が一`undefined`だった場合はPromiseがRejectされ後続の処理は実行されません。
|
||||||
|
``` ts
|
||||||
|
const user = await Users.findOne(userId).then(ensure);
|
||||||
|
// 万が一 Users.findOne の結果が undefined だったら、ensure でエラーが発生するので
|
||||||
|
// この行に到達することは無い
|
||||||
|
// なので、.then(ensure) は
|
||||||
|
// if (user == null) {
|
||||||
|
// throw 'missing user';
|
||||||
|
// }
|
||||||
|
// の糖衣構文のような扱いです
|
||||||
|
```
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "misskey",
|
"name": "misskey",
|
||||||
"author": "syuilo <i@syuilo.com>",
|
"author": "syuilo <i@syuilo.com>",
|
||||||
"version": "11.0.0-beta.5",
|
"version": "11.0.0-beta.10",
|
||||||
"codename": "daybreak",
|
"codename": "daybreak",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
@@ -24,9 +24,14 @@ import { UserPublickey } from './models/entities/user-publickey';
|
|||||||
import { UserKeypair } from './models/entities/user-keypair';
|
import { UserKeypair } from './models/entities/user-keypair';
|
||||||
import { extractPublic } from './crypto_key';
|
import { extractPublic } from './crypto_key';
|
||||||
import { Emoji } from './models/entities/emoji';
|
import { Emoji } from './models/entities/emoji';
|
||||||
import { toPuny } from './misc/convert-host';
|
import { toPuny as _toPuny } from './misc/convert-host';
|
||||||
import { UserProfile } from './models/entities/user-profile';
|
import { UserProfile } from './models/entities/user-profile';
|
||||||
|
|
||||||
|
function toPuny(x: string | null): string | null {
|
||||||
|
if (x == null) return null;
|
||||||
|
return _toPuny(x);
|
||||||
|
}
|
||||||
|
|
||||||
const u = (config as any).mongodb.user ? encodeURIComponent((config as any).mongodb.user) : null;
|
const u = (config as any).mongodb.user ? encodeURIComponent((config as any).mongodb.user) : null;
|
||||||
const p = (config as any).mongodb.pass ? encodeURIComponent((config as any).mongodb.pass) : null;
|
const p = (config as any).mongodb.pass ? encodeURIComponent((config as any).mongodb.pass) : null;
|
||||||
|
|
||||||
|
@@ -19,3 +19,8 @@ export function extractDbHost(uri: string) {
|
|||||||
export function toPuny(host: string) {
|
export function toPuny(host: string) {
|
||||||
return toASCII(host.toLowerCase());
|
return toASCII(host.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function toPunyNullable(host: string | null | undefined): string | null {
|
||||||
|
if (host == null) return null;
|
||||||
|
return toASCII(host.toLowerCase());
|
||||||
|
}
|
||||||
|
@@ -20,7 +20,7 @@ export async function getFallbackReaction(): Promise<string> {
|
|||||||
return meta.useStarForReactionFallback ? 'star' : 'like';
|
return meta.useStarForReactionFallback ? 'star' : 'like';
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function toDbReaction(reaction: string, enableEmoji = true): Promise<string> {
|
export async function toDbReaction(reaction?: string | null, enableEmoji = true): Promise<string> {
|
||||||
if (reaction == null) return await getFallbackReaction();
|
if (reaction == null) return await getFallbackReaction();
|
||||||
|
|
||||||
// 既存の文字列リアクションはそのまま
|
// 既存の文字列リアクションはそのまま
|
||||||
|
@@ -148,7 +148,7 @@ export class NoteRepository extends Repository<Note> {
|
|||||||
return reaction.reaction;
|
return reaction.reaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
let text = note.text;
|
let text = note.text;
|
||||||
@@ -162,15 +162,15 @@ export class NoteRepository extends Repository<Note> {
|
|||||||
const packed = await rap({
|
const packed = await rap({
|
||||||
id: note.id,
|
id: note.id,
|
||||||
createdAt: note.createdAt,
|
createdAt: note.createdAt,
|
||||||
app: note.appId ? Apps.pack(note.appId) : null,
|
app: note.appId ? Apps.pack(note.appId) : undefined,
|
||||||
userId: note.userId,
|
userId: note.userId,
|
||||||
user: Users.pack(note.user || note.userId, meId),
|
user: Users.pack(note.user || note.userId, meId),
|
||||||
text: text,
|
text: text,
|
||||||
cw: note.cw,
|
cw: note.cw,
|
||||||
visibility: note.visibility,
|
visibility: note.visibility,
|
||||||
localOnly: note.localOnly,
|
localOnly: note.localOnly || undefined,
|
||||||
visibleUserIds: note.visibleUserIds,
|
visibleUserIds: note.visibility === 'specified' ? note.visibleUserIds : undefined,
|
||||||
viaMobile: note.viaMobile,
|
viaMobile: note.viaMobile || undefined,
|
||||||
renoteCount: note.renoteCount,
|
renoteCount: note.renoteCount,
|
||||||
repliesCount: note.repliesCount,
|
repliesCount: note.repliesCount,
|
||||||
reactions: note.reactions,
|
reactions: note.reactions,
|
||||||
@@ -188,13 +188,13 @@ export class NoteRepository extends Repository<Note> {
|
|||||||
...(opts.detail ? {
|
...(opts.detail ? {
|
||||||
reply: note.replyId ? this.pack(note.replyId, meId, {
|
reply: note.replyId ? this.pack(note.replyId, meId, {
|
||||||
detail: false
|
detail: false
|
||||||
}) : null,
|
}) : undefined,
|
||||||
|
|
||||||
renote: note.renoteId ? this.pack(note.renoteId, meId, {
|
renote: note.renoteId ? this.pack(note.renoteId, meId, {
|
||||||
detail: true
|
detail: true
|
||||||
}) : null,
|
}) : undefined,
|
||||||
|
|
||||||
poll: note.hasPoll ? populatePoll() : null,
|
poll: note.hasPoll ? populatePoll() : undefined,
|
||||||
|
|
||||||
...(meId ? {
|
...(meId ? {
|
||||||
myReaction: populateMyReaction()
|
myReaction: populateMyReaction()
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
import { EntityRepository, Repository } from 'typeorm';
|
import { EntityRepository, Repository } from 'typeorm';
|
||||||
import { UserList } from '../entities/user-list';
|
import { UserList } from '../entities/user-list';
|
||||||
import { ensure } from '../../prelude/ensure';
|
import { ensure } from '../../prelude/ensure';
|
||||||
|
import { UserListJoinings } from '..';
|
||||||
|
|
||||||
@EntityRepository(UserList)
|
@EntityRepository(UserList)
|
||||||
export class UserListRepository extends Repository<UserList> {
|
export class UserListRepository extends Repository<UserList> {
|
||||||
@@ -9,9 +10,14 @@ export class UserListRepository extends Repository<UserList> {
|
|||||||
) {
|
) {
|
||||||
const userList = typeof src === 'object' ? src : await this.findOne(src).then(ensure);
|
const userList = typeof src === 'object' ? src : await this.findOne(src).then(ensure);
|
||||||
|
|
||||||
|
const users = await UserListJoinings.find({
|
||||||
|
userListId: userList.id
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: userList.id,
|
id: userList.id,
|
||||||
name: userList.name
|
name: userList.name,
|
||||||
|
userIds: users.map(x => x.userId)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -89,13 +89,11 @@ export class UserRepository extends Repository<User> {
|
|||||||
username: user.username,
|
username: user.username,
|
||||||
host: user.host,
|
host: user.host,
|
||||||
avatarUrl: user.avatarUrl,
|
avatarUrl: user.avatarUrl,
|
||||||
bannerUrl: user.bannerUrl,
|
|
||||||
avatarColor: user.avatarColor,
|
avatarColor: user.avatarColor,
|
||||||
bannerColor: user.bannerColor,
|
isAdmin: user.isAdmin || undefined,
|
||||||
isAdmin: user.isAdmin,
|
isBot: user.isBot || undefined,
|
||||||
isBot: user.isBot,
|
isCat: user.isCat || undefined,
|
||||||
isCat: user.isCat,
|
isVerified: user.isVerified || undefined,
|
||||||
isVerified: user.isVerified,
|
|
||||||
|
|
||||||
// カスタム絵文字添付
|
// カスタム絵文字添付
|
||||||
emojis: user.emojis.length > 0 ? Emojis.find({
|
emojis: user.emojis.length > 0 ? Emojis.find({
|
||||||
@@ -121,6 +119,8 @@ export class UserRepository extends Repository<User> {
|
|||||||
url: profile!.url,
|
url: profile!.url,
|
||||||
createdAt: user.createdAt,
|
createdAt: user.createdAt,
|
||||||
updatedAt: user.updatedAt,
|
updatedAt: user.updatedAt,
|
||||||
|
bannerUrl: user.bannerUrl,
|
||||||
|
bannerColor: user.bannerColor,
|
||||||
description: profile!.description,
|
description: profile!.description,
|
||||||
location: profile!.location,
|
location: profile!.location,
|
||||||
birthday: profile!.birthday,
|
birthday: profile!.birthday,
|
||||||
|
@@ -1,3 +1,6 @@
|
|||||||
|
/**
|
||||||
|
* 値が null または undefined の場合はエラーを発生させ、そうでない場合は値をそのまま返します
|
||||||
|
*/
|
||||||
export function ensure<T>(x: T): NonNullable<T> {
|
export function ensure<T>(x: T): NonNullable<T> {
|
||||||
if (x == null) {
|
if (x == null) {
|
||||||
throw 'ぬるぽ';
|
throw 'ぬるぽ';
|
||||||
|
@@ -12,7 +12,7 @@ import { Instances, Users, UserPublickeys } from '../../models';
|
|||||||
import { instanceChart } from '../../services/chart';
|
import { instanceChart } from '../../services/chart';
|
||||||
import { UserPublickey } from '../../models/entities/user-publickey';
|
import { UserPublickey } from '../../models/entities/user-publickey';
|
||||||
import fetchMeta from '../../misc/fetch-meta';
|
import fetchMeta from '../../misc/fetch-meta';
|
||||||
import { toPuny } from '../../misc/convert-host';
|
import { toPuny, toPunyNullable } from '../../misc/convert-host';
|
||||||
import { validActor } from '../../remote/activitypub/type';
|
import { validActor } from '../../remote/activitypub/type';
|
||||||
import { ensure } from '../../prelude/ensure';
|
import { ensure } from '../../prelude/ensure';
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ export default async (job: Bull.Job): Promise<void> => {
|
|||||||
|
|
||||||
if (keyIdLower.startsWith('acct:')) {
|
if (keyIdLower.startsWith('acct:')) {
|
||||||
const acct = parseAcct(keyIdLower.slice('acct:'.length));
|
const acct = parseAcct(keyIdLower.slice('acct:'.length));
|
||||||
const host = acct.host ? toPuny(acct.host) : null;
|
const host = toPunyNullable(acct.host);
|
||||||
const username = toPuny(acct.username);
|
const username = toPuny(acct.username);
|
||||||
|
|
||||||
if (host === null) {
|
if (host === null) {
|
||||||
|
@@ -120,13 +120,15 @@ export async function createNote(value: any, resolver?: Resolver, silent = false
|
|||||||
: [];
|
: [];
|
||||||
|
|
||||||
// リプライ
|
// リプライ
|
||||||
const reply: Note | undefined | null = note.inReplyTo
|
const reply: Note | null = note.inReplyTo
|
||||||
? await resolveNote(note.inReplyTo, resolver).catch(e => {
|
? await resolveNote(note.inReplyTo, resolver).then(x => {
|
||||||
// 4xxの場合はリプライしてないことにする
|
if (x == null) {
|
||||||
if (e.statusCode >= 400 && e.statusCode < 500) {
|
logger.warn(`Specified inReplyTo, but nout found`);
|
||||||
logger.warn(`Ignored inReplyTo ${note.inReplyTo} - ${e.statusCode} `);
|
throw 'inReplyTo not found';
|
||||||
return null;
|
} else {
|
||||||
|
return x;
|
||||||
}
|
}
|
||||||
|
}).catch(e => {
|
||||||
logger.warn(`Error in inReplyTo ${note.inReplyTo} - ${e.statusCode || e}`);
|
logger.warn(`Error in inReplyTo ${note.inReplyTo} - ${e.statusCode || e}`);
|
||||||
throw e;
|
throw e;
|
||||||
})
|
})
|
||||||
@@ -150,11 +152,11 @@ export async function createNote(value: any, resolver?: Resolver, silent = false
|
|||||||
const cw = note.summary === '' ? null : note.summary;
|
const cw = note.summary === '' ? null : note.summary;
|
||||||
|
|
||||||
// テキストのパース
|
// テキストのパース
|
||||||
const text = note._misskey_content || fromHtml(note.content);
|
const text = note._misskey_content || (note.content ? fromHtml(note.content) : null);
|
||||||
|
|
||||||
// vote
|
// vote
|
||||||
if (reply && reply.hasPoll) {
|
if (reply && reply.hasPoll) {
|
||||||
const poll = await Polls.findOne({ noteId: reply.id }).then(ensure);
|
const poll = await Polls.findOne(reply.id).then(ensure);
|
||||||
|
|
||||||
const tryCreateVote = async (name: string, index: number): Promise<null> => {
|
const tryCreateVote = async (name: string, index: number): Promise<null> => {
|
||||||
if (poll.expiresAt && Date.now() > new Date(poll.expiresAt).getTime()) {
|
if (poll.expiresAt && Date.now() > new Date(poll.expiresAt).getTime()) {
|
||||||
|
@@ -12,7 +12,7 @@ export interface IObject {
|
|||||||
attachment?: any[];
|
attachment?: any[];
|
||||||
inReplyTo?: any;
|
inReplyTo?: any;
|
||||||
replies?: ICollection;
|
replies?: ICollection;
|
||||||
content: string;
|
content?: string;
|
||||||
name?: string;
|
name?: string;
|
||||||
startTime?: Date;
|
startTime?: Date;
|
||||||
endTime?: Date;
|
endTime?: Date;
|
||||||
@@ -44,16 +44,16 @@ export interface IOrderedCollection extends IObject {
|
|||||||
|
|
||||||
export interface INote extends IObject {
|
export interface INote extends IObject {
|
||||||
type: 'Note' | 'Question';
|
type: 'Note' | 'Question';
|
||||||
_misskey_content: string;
|
_misskey_content?: string;
|
||||||
_misskey_quote: string;
|
_misskey_quote?: string;
|
||||||
_misskey_question: string;
|
_misskey_question?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IQuestion extends IObject {
|
export interface IQuestion extends IObject {
|
||||||
type: 'Note' | 'Question';
|
type: 'Note' | 'Question';
|
||||||
_misskey_content: string;
|
_misskey_content?: string;
|
||||||
_misskey_quote: string;
|
_misskey_quote?: string;
|
||||||
_misskey_question: string;
|
_misskey_question?: string;
|
||||||
oneOf?: IQuestionChoice[];
|
oneOf?: IQuestionChoice[];
|
||||||
anyOf?: IQuestionChoice[];
|
anyOf?: IQuestionChoice[];
|
||||||
endTime?: Date;
|
endTime?: Date;
|
||||||
@@ -129,7 +129,7 @@ export interface IRemove extends IActivity {
|
|||||||
|
|
||||||
export interface ILike extends IActivity {
|
export interface ILike extends IActivity {
|
||||||
type: 'Like';
|
type: 'Like';
|
||||||
_misskey_reaction: string;
|
_misskey_reaction?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IAnnounce extends IActivity {
|
export interface IAnnounce extends IActivity {
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import $ from 'cafy';
|
import $ from 'cafy';
|
||||||
import define from '../../../define';
|
import define from '../../../define';
|
||||||
import { Emojis } from '../../../../../models';
|
import { Emojis } from '../../../../../models';
|
||||||
import { toPuny } from '../../../../../misc/convert-host';
|
import { toPunyNullable } from '../../../../../misc/convert-host';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
desc: {
|
desc: {
|
||||||
@@ -23,7 +23,7 @@ export const meta = {
|
|||||||
|
|
||||||
export default define(meta, async (ps) => {
|
export default define(meta, async (ps) => {
|
||||||
const emojis = await Emojis.find({
|
const emojis = await Emojis.find({
|
||||||
host: ps.host ? toPuny(ps.host) : null
|
host: toPunyNullable(ps.host)
|
||||||
});
|
});
|
||||||
|
|
||||||
return emojis.map(e => ({
|
return emojis.map(e => ({
|
||||||
|
@@ -34,7 +34,7 @@ export default define(meta, async (ps) => {
|
|||||||
|
|
||||||
if (ps.domain) {
|
if (ps.domain) {
|
||||||
const whiteDomains = ps.domain.split(' ').filter(x => !x.startsWith('-'));
|
const whiteDomains = ps.domain.split(' ').filter(x => !x.startsWith('-'));
|
||||||
const blackDomains = ps.domain.split(' ').filter(x => x.startsWith('-'));
|
const blackDomains = ps.domain.split(' ').filter(x => x.startsWith('-')).map(x => x.substr(1));
|
||||||
|
|
||||||
if (whiteDomains.length > 0) {
|
if (whiteDomains.length > 0) {
|
||||||
query.andWhere(new Brackets(qb => {
|
query.andWhere(new Brackets(qb => {
|
||||||
@@ -53,11 +53,17 @@ export default define(meta, async (ps) => {
|
|||||||
if (blackDomains.length > 0) {
|
if (blackDomains.length > 0) {
|
||||||
query.andWhere(new Brackets(qb => {
|
query.andWhere(new Brackets(qb => {
|
||||||
for (const blackDomain of blackDomains) {
|
for (const blackDomain of blackDomains) {
|
||||||
|
const subDomains = blackDomain.split('.');
|
||||||
let i = 0;
|
let i = 0;
|
||||||
for (const subDomain of blackDomain.split('.')) {
|
for (const subDomain of subDomains) {
|
||||||
const p = `blackSubDomain_${subDomain}_${i}`;
|
const p = `blackSubDomain_${subDomain}_${i}`;
|
||||||
|
if (i === subDomains.length - 1) {
|
||||||
// SQL is 1 based, so we need '+ 1'
|
// SQL is 1 based, so we need '+ 1'
|
||||||
qb.andWhere(`log.domain[${i + 1}] != :${p}`, { [p]: subDomain });
|
qb.andWhere(`log.domain[${i + 1}] != :${p}`, { [p]: subDomain });
|
||||||
|
} else {
|
||||||
|
// SQL is 1 based, so we need '+ 1'
|
||||||
|
qb.andWhere(`log.domain[${i + 1}] = :${p}`, { [p]: subDomain });
|
||||||
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -76,12 +76,12 @@ export default define(meta, async (ps, user) => {
|
|||||||
user: meta.smtpUser,
|
user: meta.smtpUser,
|
||||||
pass: meta.smtpPass
|
pass: meta.smtpPass
|
||||||
} : undefined
|
} : undefined
|
||||||
});
|
} as any);
|
||||||
|
|
||||||
const link = `${config.url}/verify-email/${code}`;
|
const link = `${config.url}/verify-email/${code}`;
|
||||||
|
|
||||||
transporter.sendMail({
|
transporter.sendMail({
|
||||||
from: meta.email,
|
from: meta.email!,
|
||||||
to: ps.email,
|
to: ps.email,
|
||||||
subject: meta.name || 'Misskey',
|
subject: meta.name || 'Misskey',
|
||||||
text: `To verify email, please click this link: ${link}`
|
text: `To verify email, please click this link: ${link}`
|
||||||
|
@@ -124,7 +124,7 @@ export default define(meta, async (ps, user) => {
|
|||||||
|
|
||||||
// Increment votes count
|
// Increment votes count
|
||||||
const index = ps.choice + 1; // In SQL, array index is 1 based
|
const index = ps.choice + 1; // In SQL, array index is 1 based
|
||||||
await Polls.query(`UPDATE poll SET votes[${index}] = votes[${index}] + 1 WHERE noteId = '${poll.noteId}'`);
|
await Polls.query(`UPDATE poll SET votes[${index}] = votes[${index}] + 1 WHERE "noteId" = '${poll.noteId}'`);
|
||||||
|
|
||||||
publishNoteStream(note.id, 'pollVoted', {
|
publishNoteStream(note.id, 'pollVoted', {
|
||||||
choice: ps.choice,
|
choice: ps.choice,
|
||||||
|
@@ -4,7 +4,7 @@ import define from '../../define';
|
|||||||
import { ApiError } from '../../error';
|
import { ApiError } from '../../error';
|
||||||
import { Users, Followings } from '../../../../models';
|
import { Users, Followings } from '../../../../models';
|
||||||
import { makePaginationQuery } from '../../common/make-pagination-query';
|
import { makePaginationQuery } from '../../common/make-pagination-query';
|
||||||
import { toPuny } from '../../../../misc/convert-host';
|
import { toPunyNullable } from '../../../../misc/convert-host';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
desc: {
|
desc: {
|
||||||
@@ -66,7 +66,7 @@ export const meta = {
|
|||||||
export default define(meta, async (ps, me) => {
|
export default define(meta, async (ps, me) => {
|
||||||
const user = await Users.findOne(ps.userId != null
|
const user = await Users.findOne(ps.userId != null
|
||||||
? { id: ps.userId }
|
? { id: ps.userId }
|
||||||
: { usernameLower: ps.username!.toLowerCase(), host: toPuny(ps.host!) });
|
: { usernameLower: ps.username!.toLowerCase(), host: toPunyNullable(ps.host) });
|
||||||
|
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
throw new ApiError(meta.errors.noSuchUser);
|
throw new ApiError(meta.errors.noSuchUser);
|
||||||
|
@@ -4,7 +4,7 @@ import define from '../../define';
|
|||||||
import { ApiError } from '../../error';
|
import { ApiError } from '../../error';
|
||||||
import { Users, Followings } from '../../../../models';
|
import { Users, Followings } from '../../../../models';
|
||||||
import { makePaginationQuery } from '../../common/make-pagination-query';
|
import { makePaginationQuery } from '../../common/make-pagination-query';
|
||||||
import { toPuny } from '../../../../misc/convert-host';
|
import { toPunyNullable } from '../../../../misc/convert-host';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
desc: {
|
desc: {
|
||||||
@@ -66,7 +66,7 @@ export const meta = {
|
|||||||
export default define(meta, async (ps, me) => {
|
export default define(meta, async (ps, me) => {
|
||||||
const user = await Users.findOne(ps.userId != null
|
const user = await Users.findOne(ps.userId != null
|
||||||
? { id: ps.userId }
|
? { id: ps.userId }
|
||||||
: { usernameLower: ps.username!.toLowerCase(), host: toPuny(ps.host!) });
|
: { usernameLower: ps.username!.toLowerCase(), host: toPunyNullable(ps.host) });
|
||||||
|
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
throw new ApiError(meta.errors.noSuchUser);
|
throw new ApiError(meta.errors.noSuchUser);
|
||||||
|
@@ -10,7 +10,7 @@ import { genId } from '../../../misc/gen-id';
|
|||||||
import { usersChart } from '../../../services/chart';
|
import { usersChart } from '../../../services/chart';
|
||||||
import { User } from '../../../models/entities/user';
|
import { User } from '../../../models/entities/user';
|
||||||
import { UserKeypair } from '../../../models/entities/user-keypair';
|
import { UserKeypair } from '../../../models/entities/user-keypair';
|
||||||
import { toPuny } from '../../../misc/convert-host';
|
import { toPunyNullable } from '../../../misc/convert-host';
|
||||||
import { UserProfile } from '../../../models/entities/user-profile';
|
import { UserProfile } from '../../../models/entities/user-profile';
|
||||||
import { getConnection } from 'typeorm';
|
import { getConnection } from 'typeorm';
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ export default async (ctx: Koa.BaseContext) => {
|
|||||||
|
|
||||||
const username = body['username'];
|
const username = body['username'];
|
||||||
const password = body['password'];
|
const password = body['password'];
|
||||||
const host = process.env.NODE_ENV === 'test' ? (body['host'] || null) : null;
|
const host: string | null = process.env.NODE_ENV === 'test' ? (body['host'] || null) : null;
|
||||||
const invitationCode = body['invitationCode'];
|
const invitationCode = body['invitationCode'];
|
||||||
|
|
||||||
if (instance && instance.disableRegistration) {
|
if (instance && instance.disableRegistration) {
|
||||||
@@ -96,7 +96,7 @@ export default async (ctx: Koa.BaseContext) => {
|
|||||||
cipher: undefined,
|
cipher: undefined,
|
||||||
passphrase: undefined
|
passphrase: undefined
|
||||||
}
|
}
|
||||||
}, (e, publicKey, privateKey) =>
|
} as any, (e, publicKey, privateKey) =>
|
||||||
e ? j(e) : s([publicKey, privateKey])
|
e ? j(e) : s([publicKey, privateKey])
|
||||||
));
|
));
|
||||||
|
|
||||||
@@ -109,7 +109,7 @@ export default async (ctx: Koa.BaseContext) => {
|
|||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
username: username,
|
username: username,
|
||||||
usernameLower: username.toLowerCase(),
|
usernameLower: username.toLowerCase(),
|
||||||
host: toPuny(host),
|
host: toPunyNullable(host),
|
||||||
token: secret,
|
token: secret,
|
||||||
isAdmin: config.autoAdmin && usersCount === 0,
|
isAdmin: config.autoAdmin && usersCount === 0,
|
||||||
}));
|
}));
|
||||||
|
@@ -8,7 +8,7 @@ import { genId } from '../../../misc/gen-id';
|
|||||||
import { createNotification } from '../../create-notification';
|
import { createNotification } from '../../create-notification';
|
||||||
|
|
||||||
export default async function(user: User, note: Note, choice: number) {
|
export default async function(user: User, note: Note, choice: number) {
|
||||||
const poll = await Polls.findOne({ noteId: note.id });
|
const poll = await Polls.findOne(note.id);
|
||||||
|
|
||||||
if (poll == null) throw 'poll not found';
|
if (poll == null) throw 'poll not found';
|
||||||
|
|
||||||
|
@@ -16,7 +16,7 @@ import { NoteReaction } from '../../../models/entities/note-reaction';
|
|||||||
import { createNotification } from '../../create-notification';
|
import { createNotification } from '../../create-notification';
|
||||||
import { isDuplicateKeyValueError } from '../../../misc/is-duplicate-key-value-error';
|
import { isDuplicateKeyValueError } from '../../../misc/is-duplicate-key-value-error';
|
||||||
|
|
||||||
export default async (user: User, note: Note, reaction: string) => {
|
export default async (user: User, note: Note, reaction?: string) => {
|
||||||
// Myself
|
// Myself
|
||||||
if (note.userId === user.id) {
|
if (note.userId === user.id) {
|
||||||
throw new IdentifiableError('2d8e7297-1873-4c00-8404-792c68d7bef0', 'cannot react to my note');
|
throw new IdentifiableError('2d8e7297-1873-4c00-8404-792c68d7bef0', 'cannot react to my note');
|
||||||
|
@@ -63,7 +63,9 @@ export async function updateHashtag(user: User, tag: string, isUserAttached = fa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Object.keys(set).length > 0) {
|
||||||
q.execute();
|
q.execute();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (isUserAttached) {
|
if (isUserAttached) {
|
||||||
Hashtags.save({
|
Hashtags.save({
|
||||||
|
Reference in New Issue
Block a user