diff --git a/adapters/matrix/src/bot.ts b/adapters/matrix/src/bot.ts index e69ad6b7..4a931d89 100644 --- a/adapters/matrix/src/bot.ts +++ b/adapters/matrix/src/bot.ts @@ -87,9 +87,8 @@ export class MatrixBot extends Bot { async deleteFriend(): Promise { } async getGuild(guildId: string): Promise { - const events = await this.internal.getState(guildId) - const guildName = (events.find(event => event.type === 'm.room.name')?.content as Matrix.M_ROOM_NAME)?.name - return { guildId, guildName } + const { channelName } = await this.getChannel(guildId) + return { guildId, guildName: channelName } } async getChannel(channelId: string): Promise { @@ -99,31 +98,11 @@ export class MatrixBot extends Bot { } async getGuildList(): Promise { - const sync = await this.syncRooms() - const joined = sync?.rooms?.join - if (!joined) return [] - const result: Universal.Guild[] = [] - for (const roomId of Object.keys(joined)) { - const state = await this.internal.getState(roomId) - const create = state.find(state => state.type === 'm.room.create') - const name = state.find(state => state.type === 'm.room.name')?.content as Matrix.M_ROOM_NAME - if (!create) continue - if (create.content['type'] !== 'm.space') continue - result.push({ - guildId: roomId, - guildName: name?.name, - }) - } - return result + return await Promise.all(this.rooms.map(roomId => this.getGuild(roomId))) } async getChannelList(guildId: string): Promise { - const state = await this.internal.getState(guildId) - const children = state - .filter(event => event.type === 'm.space.child') - .map(event => event.state_key) - .filter(roomId => this.rooms.includes(roomId)) - return await Promise.all(children.map(this.getChannel.bind(this))) + return await Promise.all(this.rooms.map(roomId => this.getChannel(roomId))) } async getGuildMemberList(guildId: string): Promise { diff --git a/adapters/matrix/src/utils.ts b/adapters/matrix/src/utils.ts index 76024d0f..9302f9c6 100644 --- a/adapters/matrix/src/utils.ts +++ b/adapters/matrix/src/utils.ts @@ -15,9 +15,11 @@ export async function adaptMessage(bot: MatrixBot, event: Matrix.ClientEvent, re result.subtype = 'group' result.messageId = event.event_id result.channelId = event.room_id + result.guildId = event.room_id result.userId = event.sender result.timestamp = event.origin_server_ts result.author = adaptAuthor(bot, event) + result.isDirect = false const content = event.content as Matrix.M_ROOM_MESSAGE const reply = content['m.relates_to']?.['m.in_reply_to'] if (reply) { @@ -68,6 +70,7 @@ export async function adaptSession(bot: MatrixBot, event: Matrix.ClientEvent): P session.messageId = event.event_id session.timestamp = event.origin_server_ts session.author = adaptAuthor(bot, event) + session.isDirect = false switch (event.type) { case 'm.room.redaction': { session.type = 'message-deleted'