strictNullChecks (#4666)
* wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip
This commit is contained in:
@ -9,7 +9,7 @@ export default class extends Channel {
|
||||
@autobind
|
||||
public async init(params: any) {
|
||||
// Subscribe admin stream
|
||||
this.subscriber.on(`adminStream:${this.user.id}`, data => {
|
||||
this.subscriber.on(`adminStream:${this.user!.id}`, data => {
|
||||
this.send(data);
|
||||
});
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ export default class extends Channel {
|
||||
@autobind
|
||||
public async init(params: any) {
|
||||
// Subscribe drive stream
|
||||
this.subscriber.on(`driveStream:${this.user.id}`, data => {
|
||||
this.subscriber.on(`driveStream:${this.user!.id}`, data => {
|
||||
this.send(data);
|
||||
});
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ export default class extends Channel {
|
||||
public static shouldShare = false;
|
||||
public static requireCredential = false;
|
||||
|
||||
private gameId: ReversiGame['id'];
|
||||
private gameId: ReversiGame['id'] | null = null;
|
||||
|
||||
@autobind
|
||||
public async init(params: any) {
|
||||
@ -40,7 +40,10 @@ export default class extends Channel {
|
||||
|
||||
@autobind
|
||||
private async updateSettings(key: string, value: any) {
|
||||
const game = await ReversiGames.findOne(this.gameId);
|
||||
if (this.user == null) return;
|
||||
|
||||
const game = await ReversiGames.findOne(this.gameId!);
|
||||
if (game == null) throw 'game not found';
|
||||
|
||||
if (game.isStarted) return;
|
||||
if ((game.user1Id !== this.user.id) && (game.user2Id !== this.user.id)) return;
|
||||
@ -49,11 +52,11 @@ export default class extends Channel {
|
||||
|
||||
if (!['map', 'bw', 'isLlotheo', 'canPutEverywhere', 'loopedBoard'].includes(key)) return;
|
||||
|
||||
await ReversiGames.update({ id: this.gameId }, {
|
||||
await ReversiGames.update(this.gameId!, {
|
||||
[key]: value
|
||||
});
|
||||
|
||||
publishReversiGameStream(this.gameId, 'updateSettings', {
|
||||
publishReversiGameStream(this.gameId!, 'updateSettings', {
|
||||
key: key,
|
||||
value: value
|
||||
});
|
||||
@ -61,7 +64,10 @@ export default class extends Channel {
|
||||
|
||||
@autobind
|
||||
private async initForm(form: any) {
|
||||
const game = await ReversiGames.findOne(this.gameId);
|
||||
if (this.user == null) return;
|
||||
|
||||
const game = await ReversiGames.findOne(this.gameId!);
|
||||
if (game == null) throw 'game not found';
|
||||
|
||||
if (game.isStarted) return;
|
||||
if ((game.user1Id !== this.user.id) && (game.user2Id !== this.user.id)) return;
|
||||
@ -72,9 +78,9 @@ export default class extends Channel {
|
||||
form2: form
|
||||
};
|
||||
|
||||
await ReversiGames.update({ id: this.gameId }, set);
|
||||
await ReversiGames.update(this.gameId!, set);
|
||||
|
||||
publishReversiGameStream(this.gameId, 'initForm', {
|
||||
publishReversiGameStream(this.gameId!, 'initForm', {
|
||||
userId: this.user.id,
|
||||
form
|
||||
});
|
||||
@ -82,7 +88,10 @@ export default class extends Channel {
|
||||
|
||||
@autobind
|
||||
private async updateForm(id: string, value: any) {
|
||||
const game = await ReversiGames.findOne({ id: this.gameId });
|
||||
if (this.user == null) return;
|
||||
|
||||
const game = await ReversiGames.findOne(this.gameId!);
|
||||
if (game == null) throw 'game not found';
|
||||
|
||||
if (game.isStarted) return;
|
||||
if ((game.user1Id !== this.user.id) && (game.user2Id !== this.user.id)) return;
|
||||
@ -101,9 +110,9 @@ export default class extends Channel {
|
||||
form1: form
|
||||
};
|
||||
|
||||
await ReversiGames.update({ id: this.gameId }, set);
|
||||
await ReversiGames.update(this.gameId!, set);
|
||||
|
||||
publishReversiGameStream(this.gameId, 'updateForm', {
|
||||
publishReversiGameStream(this.gameId!, 'updateForm', {
|
||||
userId: this.user.id,
|
||||
id,
|
||||
value
|
||||
@ -112,8 +121,10 @@ export default class extends Channel {
|
||||
|
||||
@autobind
|
||||
private async message(message: any) {
|
||||
if (this.user == null) return;
|
||||
|
||||
message.id = Math.random();
|
||||
publishReversiGameStream(this.gameId, 'message', {
|
||||
publishReversiGameStream(this.gameId!, 'message', {
|
||||
userId: this.user.id,
|
||||
message
|
||||
});
|
||||
@ -121,29 +132,32 @@ export default class extends Channel {
|
||||
|
||||
@autobind
|
||||
private async accept(accept: boolean) {
|
||||
const game = await ReversiGames.findOne(this.gameId);
|
||||
if (this.user == null) return;
|
||||
|
||||
const game = await ReversiGames.findOne(this.gameId!);
|
||||
if (game == null) throw 'game not found';
|
||||
|
||||
if (game.isStarted) return;
|
||||
|
||||
let bothAccepted = false;
|
||||
|
||||
if (game.user1Id === this.user.id) {
|
||||
await ReversiGames.update({ id: this.gameId }, {
|
||||
await ReversiGames.update(this.gameId!, {
|
||||
user1Accepted: accept
|
||||
});
|
||||
|
||||
publishReversiGameStream(this.gameId, 'changeAccepts', {
|
||||
publishReversiGameStream(this.gameId!, 'changeAccepts', {
|
||||
user1: accept,
|
||||
user2: game.user2Accepted
|
||||
});
|
||||
|
||||
if (accept && game.user2Accepted) bothAccepted = true;
|
||||
} else if (game.user2Id === this.user.id) {
|
||||
await ReversiGames.update({ id: this.gameId }, {
|
||||
await ReversiGames.update(this.gameId!, {
|
||||
user2Accepted: accept
|
||||
});
|
||||
|
||||
publishReversiGameStream(this.gameId, 'changeAccepts', {
|
||||
publishReversiGameStream(this.gameId!, 'changeAccepts', {
|
||||
user1: game.user1Accepted,
|
||||
user2: accept
|
||||
});
|
||||
@ -156,7 +170,7 @@ export default class extends Channel {
|
||||
if (bothAccepted) {
|
||||
// 3秒後、まだacceptされていたらゲーム開始
|
||||
setTimeout(async () => {
|
||||
const freshGame = await ReversiGames.findOne(this.gameId);
|
||||
const freshGame = await ReversiGames.findOne(this.gameId!);
|
||||
if (freshGame == null || freshGame.isStarted || freshGame.isEnded) return;
|
||||
if (!freshGame.user1Accepted || !freshGame.user2Accepted) return;
|
||||
|
||||
@ -175,7 +189,7 @@ export default class extends Channel {
|
||||
|
||||
const map = freshGame.map != null ? freshGame.map : getRandomMap();
|
||||
|
||||
await ReversiGames.update({ id: this.gameId }, {
|
||||
await ReversiGames.update(this.gameId!, {
|
||||
startedAt: new Date(),
|
||||
isStarted: true,
|
||||
black: bw,
|
||||
@ -199,22 +213,20 @@ export default class extends Channel {
|
||||
winner = null;
|
||||
}
|
||||
|
||||
await ReversiGames.update({
|
||||
id: this.gameId
|
||||
}, {
|
||||
await ReversiGames.update(this.gameId!, {
|
||||
isEnded: true,
|
||||
winnerId: winner
|
||||
});
|
||||
|
||||
publishReversiGameStream(this.gameId, 'ended', {
|
||||
publishReversiGameStream(this.gameId!, 'ended', {
|
||||
winnerId: winner,
|
||||
game: await ReversiGames.pack(this.gameId, this.user)
|
||||
game: await ReversiGames.pack(this.gameId!, this.user)
|
||||
});
|
||||
}
|
||||
//#endregion
|
||||
|
||||
publishReversiGameStream(this.gameId, 'started',
|
||||
await ReversiGames.pack(this.gameId, this.user));
|
||||
publishReversiGameStream(this.gameId!, 'started',
|
||||
await ReversiGames.pack(this.gameId!, this.user));
|
||||
}, 3000);
|
||||
}
|
||||
}
|
||||
@ -222,7 +234,10 @@ export default class extends Channel {
|
||||
// 石を打つ
|
||||
@autobind
|
||||
private async set(pos: number) {
|
||||
const game = await ReversiGames.findOne(this.gameId);
|
||||
if (this.user == null) return;
|
||||
|
||||
const game = await ReversiGames.findOne(this.gameId!);
|
||||
if (game == null) throw 'game not found';
|
||||
|
||||
if (!game.isStarted) return;
|
||||
if (game.isEnded) return;
|
||||
@ -267,30 +282,29 @@ export default class extends Channel {
|
||||
|
||||
game.logs.push(log);
|
||||
|
||||
await ReversiGames.update({
|
||||
id: this.gameId
|
||||
}, {
|
||||
await ReversiGames.update(this.gameId!, {
|
||||
crc32,
|
||||
isEnded: o.isEnded,
|
||||
winnerId: winner,
|
||||
logs: game.logs
|
||||
});
|
||||
|
||||
publishReversiGameStream(this.gameId, 'set', Object.assign(log, {
|
||||
publishReversiGameStream(this.gameId!, 'set', Object.assign(log, {
|
||||
next: o.turn
|
||||
}));
|
||||
|
||||
if (o.isEnded) {
|
||||
publishReversiGameStream(this.gameId, 'ended', {
|
||||
publishReversiGameStream(this.gameId!, 'ended', {
|
||||
winnerId: winner,
|
||||
game: await ReversiGames.pack(this.gameId, this.user)
|
||||
game: await ReversiGames.pack(this.gameId!, this.user)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@autobind
|
||||
private async check(crc32: string) {
|
||||
const game = await ReversiGames.findOne(this.gameId);
|
||||
const game = await ReversiGames.findOne(this.gameId!);
|
||||
if (game == null) throw 'game not found';
|
||||
|
||||
if (!game.isStarted) return;
|
||||
|
||||
|
@ -11,7 +11,7 @@ export default class extends Channel {
|
||||
@autobind
|
||||
public async init(params: any) {
|
||||
// Subscribe reversi stream
|
||||
this.subscriber.on(`reversiStream:${this.user.id}`, data => {
|
||||
this.subscriber.on(`reversiStream:${this.user!.id}`, data => {
|
||||
this.send(data);
|
||||
});
|
||||
}
|
||||
@ -22,7 +22,7 @@ export default class extends Channel {
|
||||
case 'ping':
|
||||
if (body.id == null) return;
|
||||
const matching = await ReversiMatchings.findOne({
|
||||
parentId: this.user.id,
|
||||
parentId: this.user!.id,
|
||||
childId: body.id
|
||||
});
|
||||
if (matching == null) return;
|
||||
|
@ -17,10 +17,10 @@ export default class extends Channel {
|
||||
@autobind
|
||||
private async onNote(note: any) {
|
||||
// その投稿のユーザーをフォローしていなかったら弾く
|
||||
if (this.user.id !== note.userId && !this.following.includes(note.userId)) return;
|
||||
if (this.user!.id !== note.userId && !this.following.includes(note.userId)) return;
|
||||
|
||||
if (['followers', 'specified'].includes(note.visibility)) {
|
||||
note = await Notes.pack(note.id, this.user, {
|
||||
note = await Notes.pack(note.id, this.user!, {
|
||||
detail: true
|
||||
});
|
||||
|
||||
@ -30,13 +30,13 @@ export default class extends Channel {
|
||||
} else {
|
||||
// リプライなら再pack
|
||||
if (note.replyId != null) {
|
||||
note.reply = await Notes.pack(note.replyId, this.user, {
|
||||
note.reply = await Notes.pack(note.replyId, this.user!, {
|
||||
detail: true
|
||||
});
|
||||
}
|
||||
// Renoteなら再pack
|
||||
if (note.renoteId != null) {
|
||||
note.renote = await Notes.pack(note.renoteId, this.user, {
|
||||
note.renote = await Notes.pack(note.renoteId, this.user!, {
|
||||
detail: true
|
||||
});
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ export default class extends Channel {
|
||||
@autobind
|
||||
public async init(params: any) {
|
||||
const meta = await fetchMeta();
|
||||
if (meta.disableLocalTimeline && !this.user.isAdmin && !this.user.isModerator) return;
|
||||
if (meta.disableLocalTimeline && !this.user!.isAdmin && !this.user!.isModerator) return;
|
||||
|
||||
// Subscribe events
|
||||
this.subscriber.on('notesStream', this.onNote);
|
||||
@ -22,13 +22,13 @@ export default class extends Channel {
|
||||
private async onNote(note: any) {
|
||||
// 自分自身の投稿 または その投稿のユーザーをフォローしている または ローカルの投稿 の場合だけ
|
||||
if (!(
|
||||
this.user.id === note.userId ||
|
||||
this.user!.id === note.userId ||
|
||||
this.following.includes(note.userId) ||
|
||||
note.user.host == null
|
||||
)) return;
|
||||
|
||||
if (['followers', 'specified'].includes(note.visibility)) {
|
||||
note = await Notes.pack(note.id, this.user, {
|
||||
note = await Notes.pack(note.id, this.user!, {
|
||||
detail: true
|
||||
});
|
||||
|
||||
@ -38,13 +38,13 @@ export default class extends Channel {
|
||||
} else {
|
||||
// リプライなら再pack
|
||||
if (note.replyId != null) {
|
||||
note.reply = await Notes.pack(note.replyId, this.user, {
|
||||
note.reply = await Notes.pack(note.replyId, this.user!, {
|
||||
detail: true
|
||||
});
|
||||
}
|
||||
// Renoteなら再pack
|
||||
if (note.renoteId != null) {
|
||||
note.renote = await Notes.pack(note.renoteId, this.user, {
|
||||
note.renote = await Notes.pack(note.renoteId, this.user!, {
|
||||
detail: true
|
||||
});
|
||||
}
|
||||
|
@ -9,10 +9,10 @@ export default class extends Channel {
|
||||
|
||||
@autobind
|
||||
public async init(params: any) {
|
||||
const mute = await Mutings.find({ muterId: this.user.id });
|
||||
const mute = await Mutings.find({ muterId: this.user!.id });
|
||||
|
||||
// Subscribe main stream channel
|
||||
this.subscriber.on(`mainStream:${this.user.id}`, async data => {
|
||||
this.subscriber.on(`mainStream:${this.user!.id}`, async data => {
|
||||
const { type, body } = data;
|
||||
|
||||
switch (type) {
|
||||
|
@ -9,7 +9,7 @@ export default class extends Channel {
|
||||
@autobind
|
||||
public async init(params: any) {
|
||||
// Subscribe messaging index stream
|
||||
this.subscriber.on(`messagingIndexStream:${this.user.id}`, data => {
|
||||
this.subscriber.on(`messagingIndexStream:${this.user!.id}`, data => {
|
||||
this.send(data);
|
||||
});
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ export default class extends Channel {
|
||||
this.otherpartyId = params.otherparty as string;
|
||||
|
||||
// Subscribe messaging stream
|
||||
this.subscriber.on(`messagingStream:${this.user.id}-${this.otherpartyId}`, data => {
|
||||
this.subscriber.on(`messagingStream:${this.user!.id}-${this.otherpartyId}`, data => {
|
||||
this.send(data);
|
||||
});
|
||||
}
|
||||
@ -23,7 +23,7 @@ export default class extends Channel {
|
||||
public onMessage(type: string, body: any) {
|
||||
switch (type) {
|
||||
case 'read':
|
||||
read(this.user.id, this.otherpartyId, body.id);
|
||||
read(this.user!.id, this.otherpartyId, body.id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -28,13 +28,13 @@ export default class Connection {
|
||||
constructor(
|
||||
wsConnection: websocket.connection,
|
||||
subscriber: EventEmitter,
|
||||
user: User,
|
||||
app: App
|
||||
user: User | null | undefined,
|
||||
app: App | null | undefined
|
||||
) {
|
||||
this.wsConnection = wsConnection;
|
||||
this.user = user;
|
||||
this.app = app;
|
||||
this.subscriber = subscriber;
|
||||
if (user) this.user = user;
|
||||
if (app) this.app = app;
|
||||
|
||||
this.wsConnection.on('message', this.onWsConnectionMessage);
|
||||
|
||||
@ -52,6 +52,8 @@ export default class Connection {
|
||||
*/
|
||||
@autobind
|
||||
private async onWsConnectionMessage(data: websocket.IMessage) {
|
||||
if (data.utf8Data == null) return;
|
||||
|
||||
const { type, body } = JSON.parse(data.utf8Data);
|
||||
|
||||
switch (type) {
|
||||
@ -89,7 +91,7 @@ export default class Connection {
|
||||
@autobind
|
||||
private onReadNotification(payload: any) {
|
||||
if (!payload.id) return;
|
||||
readNotification(this.user.id, [payload.id]);
|
||||
readNotification(this.user!.id, [payload.id]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -109,7 +111,7 @@ export default class Connection {
|
||||
this.subscriber.on(`noteStream:${payload.id}`, this.onNoteStreamMessage);
|
||||
}
|
||||
|
||||
if (payload.read) {
|
||||
if (payload.read && this.user) {
|
||||
readNote(this.user.id, payload.id);
|
||||
}
|
||||
}
|
||||
@ -221,7 +223,7 @@ export default class Connection {
|
||||
private async updateFollowing() {
|
||||
const followings = await Followings.find({
|
||||
where: {
|
||||
followerId: this.user.id
|
||||
followerId: this.user!.id
|
||||
},
|
||||
select: ['followeeId']
|
||||
});
|
||||
@ -233,7 +235,7 @@ export default class Connection {
|
||||
private async updateMuting() {
|
||||
const mutings = await Mutings.find({
|
||||
where: {
|
||||
muterId: this.user.id
|
||||
muterId: this.user!.id
|
||||
},
|
||||
select: ['muteeId']
|
||||
});
|
||||
@ -247,7 +249,7 @@ export default class Connection {
|
||||
@autobind
|
||||
public dispose() {
|
||||
for (const c of this.channels.filter(c => c.dispose)) {
|
||||
c.dispose();
|
||||
if (c.dispose) c.dispose();
|
||||
}
|
||||
|
||||
if (this.followingClock) clearInterval(this.followingClock);
|
||||
|
Reference in New Issue
Block a user