Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2721,6 +2721,7 @@ _permissions:
"write:calls": "Misskey Callsへの参加と音声通話を操作する"

_calls:
openChat: "チャットを開く"
audioSettings: "通話設定"
settings: "Callsの設定"
systemDefaultDevice: "システムの既定"
Expand Down
18 changes: 18 additions & 0 deletions packages/backend/migration/1791148387720-CallsRoomChannel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/

export class CallsRoomChannel1791148387720 {
name = 'CallsRoomChannel1791148387720';

async up(queryRunner) {
await queryRunner.query(`ALTER TABLE "calls_room" ADD "channelId" character varying(32)`);
await queryRunner.query(`ALTER TABLE "calls_room" ADD CONSTRAINT "FK_calls_room_channel" FOREIGN KEY ("channelId") REFERENCES "channel"("id") ON DELETE SET NULL ON UPDATE NO ACTION`);
}

async down(queryRunner) {
await queryRunner.query(`ALTER TABLE "calls_room" DROP CONSTRAINT "FK_calls_room_channel"`);
await queryRunner.query(`ALTER TABLE "calls_room" DROP COLUMN "channelId"`);
}
}
121 changes: 84 additions & 37 deletions packages/backend/src/core/calls/CallsRoomService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ import type {
CallsRoomsRepository,
MiCallsModerationLog,
ChatRoomsRepository,
ChannelsRepository,
MiCallsParticipant,
MiCallsRoom,
MiChatRoom,
MiUser,
} from '@/models/_.js';
import { MiChannel } from '@/models/Channel.js';
import type { MiLocalUser } from '@/models/User.js';
import { ChannelFollowingService } from '@/core/ChannelFollowingService.js';
import type { CallsModerationAction } from '@/models/CallsModerationLog.js';
import type { CallsParticipantRole } from '@/models/CallsParticipant.js';
import type { CallsRoomMode, CallsRoomVisibility } from '@/models/CallsRoom.js';
Expand Down Expand Up @@ -79,6 +83,9 @@ export class CallsRoomService implements OnModuleInit, OnApplicationShutdown {
private callsEventService: CallsEventService,
private callsMediaRevocationService: CallsMediaRevocationService,
private callsTelemetryService: CallsTelemetryService,
@Inject(DI.channelsRepository)
private channelsRepository: ChannelsRepository,
private channelFollowingService: ChannelFollowingService,
) {}

public async onModuleInit(): Promise<void> {
Expand Down Expand Up @@ -164,38 +171,57 @@ export class CallsRoomService implements OnModuleInit, OnApplicationShutdown {
if (activeAttachment != null) throw new CallsRoomError('active-attachment');

const now = new Date();
const room = await this.callsRoomsRepository.insertOne({
id: this.idService.gen(),
attachmentType: params.attachmentType,
ownerUserId: owner.id,
chatRoomId: params.attachmentType === 'chatRoom' ? params.chatRoomId : null,
title,
description,
mode: params.mode ?? 'open',
visibility: params.attachmentType === 'chatRoom' ? 'specified' : (params.visibility ?? 'specified'),
visibleUserIds: params.attachmentType === 'personal' && params.visibility === 'specified' ? [...new Set(params.visibleUserIds ?? [])] : [],
moderatorUserIds: [],
state: 'scheduled',
scheduledAt: params.scheduledAt ?? null,
startedAt: null,
endedAt: null,
revision: 0,
createdAt: now,
updatedAt: now,
});
const room = await this.callsRoomsRepository.manager.transaction(async manager => {
const channel = params.attachmentType === 'personal' && params.visibility === 'public'
? await manager.getRepository(MiChannel).save({
id: this.idService.gen(), userId: owner.id, name: title.slice(0, 128),
description, isUnlisted: true, isLocalOnly: true, allowRenoteToExternal: false,
})
: null;
Comment thread
mattyatea marked this conversation as resolved.
const room = await manager.getRepository<MiCallsRoom>(this.callsRoomsRepository.target).save({
id: this.idService.gen(),
attachmentType: params.attachmentType,
ownerUserId: owner.id,
chatRoomId: params.attachmentType === 'chatRoom' ? params.chatRoomId : null,
channelId: channel?.id ?? null,
title,
description,
mode: params.mode ?? 'open',
visibility: params.attachmentType === 'chatRoom' ? 'specified' : (params.visibility ?? 'specified'),
visibleUserIds: params.attachmentType === 'personal' && params.visibility === 'specified' ? [...new Set(params.visibleUserIds ?? [])] : [],
moderatorUserIds: [],
state: 'scheduled',
scheduledAt: params.scheduledAt ?? null,
startedAt: null,
endedAt: null,
revision: 0,
createdAt: now,
updatedAt: now,
});

await this.callsParticipantsRepository.insertOne({
id: this.idService.gen(),
roomId: room.id,
userId: owner.id,
role: 'host',
state: 'active',
isMuted: false,
joinedAt: now,
leftAt: null,
speakerRequestedAt: null,
updatedAt: now,
await manager.getRepository<MiCallsParticipant>(this.callsParticipantsRepository.target).save({
id: this.idService.gen(),
roomId: room.id,
userId: owner.id,
role: 'host',
state: 'active',
isMuted: false,
joinedAt: now,
leftAt: null,
speakerRequestedAt: null,
updatedAt: now,
});
return room;
});
try {
await this.followRoomChannel(owner, room);
} catch (error) {
await this.callsRoomsRepository.manager.transaction(async manager => {
await manager.getRepository<MiCallsRoom>(this.callsRoomsRepository.target).delete(room.id);
if (room.channelId != null) await manager.getRepository(MiChannel).delete(room.channelId);
});
throw error;
}
this.callsTelemetryService.lifecycle({ action: 'room-created', roomId: room.id });
this.callsEventService.publishRoomsList('created', { roomId: room.id });

Expand Down Expand Up @@ -400,10 +426,14 @@ export class CallsRoomService implements OnModuleInit, OnApplicationShutdown {
if (room.state !== 'open') throw new CallsRoomError('invalid-state');

const current = await this.callsParticipantsRepository.findOneBy({ roomId, userId: user.id });
if (current?.state === 'active') return current;
if (current?.state === 'active') {
await this.followRoomChannel(user, room);
return current;
}
const role = current?.role === 'host' ? 'host' : room.mode === 'open' ? 'speaker' : 'listener';
await this.assertCapacity(room, role);

await this.followRoomChannel(user, room);
const now = new Date();
let joined: MiCallsParticipant;
if (current != null) {
Expand Down Expand Up @@ -435,6 +465,12 @@ export class CallsRoomService implements OnModuleInit, OnApplicationShutdown {
return joined;
}

private async followRoomChannel(user: MiUser, room: MiCallsRoom): Promise<void> {
if (room.channelId == null) return;
const channel = await this.channelsRepository.findOneByOrFail({ id: room.channelId });
await this.channelFollowingService.followOrRequest(user as MiLocalUser, channel, true);
Comment thread
mattyatea marked this conversation as resolved.
}

@bindThis
public async confirmReady(user: MiUser, roomId: string, identity: CallsConnectionIdentity): Promise<void> {
await this.callsLiveConnectionService.withRoomLock(roomId, async () => {
Expand Down Expand Up @@ -659,12 +695,16 @@ export class CallsRoomService implements OnModuleInit, OnApplicationShutdown {
if (room.state !== 'scheduled' && room.state !== 'open') throw new CallsRoomError('invalid-state');
const sanitizedTitle = this.sanitizeMetadata(title);
if (sanitizedTitle.length === 0) throw new CallsRoomError('invalid-metadata');
const result = await this.callsRoomsRepository.createQueryBuilder().update()
.set({ title: sanitizedTitle, revision: () => '"revision" + 1', updatedAt: new Date() })
.where('id = :roomId AND revision = :expectedRevision AND state = :state', { roomId, expectedRevision, state: room.state })
.returning('*').execute();
if (result.affected !== 1) throw new CallsRoomError('stale-revision');
const updated = result.raw[0] as MiCallsRoom;
const updated = await this.callsRoomsRepository.manager.transaction(async manager => {
const result = await manager.getRepository<MiCallsRoom>(this.callsRoomsRepository.target).createQueryBuilder().update()
.set({ title: sanitizedTitle, revision: () => '"revision" + 1', updatedAt: new Date() })
.where('id = :roomId AND revision = :expectedRevision AND state = :state', { roomId, expectedRevision, state: room.state })
.returning('*').execute();
if (result.affected !== 1) throw new CallsRoomError('stale-revision');
const updated = result.raw[0] as MiCallsRoom;
if (updated.channelId != null) await manager.getRepository(MiChannel).update(updated.channelId, { name: updated.title.slice(0, 128) });
return updated;
});
await this.callsEventService.publish(roomId, updated.revision, 'title', { title: updated.title });
this.callsEventService.publishRoomsList('updated', { roomId, action: 'title' });
return updated;
Expand Down Expand Up @@ -707,6 +747,13 @@ export class CallsRoomService implements OnModuleInit, OnApplicationShutdown {
const promoted = await participants.update({ id: participant.id, state: 'active' }, { role: 'host', speakerRequestedAt: null, updatedAt: now });
if (promoted.affected !== 1) throw new CallsRoomError('participant-not-found');
const updated = result.raw[0] as MiCallsRoom;
if (room.channelId != null) {
const channels = manager.getRepository(MiChannel);
const channel = await channels.findOneByOrFail({ id: room.channelId });
const collaboratorIds = channel.collaboratorIds.filter(id => id !== participant.userId);
if (channel.userId != null && !collaboratorIds.includes(channel.userId)) collaboratorIds.push(channel.userId);
await channels.update(channel.id, { userId: participant.userId, collaboratorIds });
}
await logs.insert({ id: this.idService.gen(), roomId, actorUserId: host.id, targetParticipantId: participant.id, action: 'promote', previousRole: participant.role, nextRole: 'host', reason: 'host-transfer', roomRevision: updated.revision, createdAt: now });
return { room: updated, formerHostParticipantId: formerHost.id, formerHostRole: 'speaker' as const };
});
Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/core/entities/CallsEntityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class CallsEntityService {
} : {
type: 'chatRoom', ownerUserId: room.ownerUserId, chatRoomId: room.chatRoomId!,
},
channelId: room.channelId ?? null,
title: room.title,
description: room.description,
moderatorUserIds: room.moderatorUserIds,
Expand Down
8 changes: 8 additions & 0 deletions packages/backend/src/models/CallsRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import { Check, Column, Entity, Index, JoinColumn, ManyToOne, PrimaryColumn } from 'typeorm';
import { MiChannel } from './Channel.js';
import { MiChatRoom } from './ChatRoom.js';
import { MiUser } from './User.js';
import { id } from './util/id.js';
Expand Down Expand Up @@ -54,6 +55,13 @@ export class MiCallsRoom {
@JoinColumn({ name: 'chatRoomId' })
public chatRoom: MiChatRoom | null;

@Column({ ...id(), nullable: true })
public channelId: MiChannel['id'] | null;

@ManyToOne(() => MiChannel, { onDelete: 'SET NULL' })
@JoinColumn({ name: 'channelId', foreignKeyConstraintName: 'FK_calls_room_channel' })
public channel: MiChannel | null;

@Column('varchar', { length: 256 })
public title: string;

Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/models/json-schema/calls-room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const packedCallsRoomSchema = {
{ type: 'object', properties: { type: { type: 'string', enum: ['chatRoom'], optional: false, nullable: false }, ownerUserId: { type: 'string', format: 'id', optional: false, nullable: false }, chatRoomId: { type: 'string', format: 'id', optional: false, nullable: false } } },
],
},
channelId: { type: 'string', format: 'id', optional: false, nullable: true },
title: { type: 'string', optional: false, nullable: false },
description: { type: 'string', optional: false, nullable: false },
moderatorUserIds: { type: 'array', items: { type: 'string', format: 'id' }, optional: false, nullable: false },
Expand Down
3 changes: 2 additions & 1 deletion packages/backend/src/server/api/endpoints/channels/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
) {
super(meta, paramDef, async (ps, me) => {
const query = this.queryService.makePaginationQuery(this.channelsRepository.createQueryBuilder('channel'), ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate)
.andWhere('channel.isArchived = FALSE');
.andWhere('channel.isArchived = FALSE')
.andWhere('NOT EXISTS (SELECT 1 FROM calls_room WHERE calls_room."channelId" = channel.id)');

if (ps.query !== '') {
if (ps.type === 'nameAndDescription') {
Expand Down
Loading
Loading