Skip to content

Commit

Permalink
handle channel_archive event
Browse files Browse the repository at this point in the history
  • Loading branch information
ashfame committed Oct 10, 2023
1 parent c274bee commit 17505ea
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/SlackEventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ export class SlackEventHandler extends BaseSlackHandler {
break;
case "channel_created":
case "channel_deleted":
case "channel_archived":
case "user_change":
case "team_join":
await this.handleTeamSyncEvent(event as ISlackTeamSyncEvent, teamId);
Expand Down Expand Up @@ -367,6 +368,8 @@ export class SlackEventHandler extends BaseSlackHandler {
await this.main.teamSyncer.onChannelAdded(teamId, eventDetails.channel.id, eventDetails.channel.name, eventDetails.channel.creator);
} else if (event.type === "channel_deleted") {
await this.main.teamSyncer.onChannelDeleted(teamId, event.channel);
} else if (event.type === "channel_archive") {
await this.main.teamSyncer.onChannelArchived(teamId, event.channel);
} else if (event.type === "team_join" || event.type === "user_change") {
const user = event.user!;
const domain = (await this.main.datastore.getTeam(teamId))!.domain;
Expand Down
42 changes: 42 additions & 0 deletions src/TeamSyncer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,48 @@ export class TeamSyncer {
}
}

public async onChannelArchived(teamId: string, channelId: string): Promise<void> {
log.info(`${teamId} archived channel ${channelId}`);
if (!this.getTeamSyncConfig(teamId, "channel", channelId)) {
return;
}
const room = this.main.rooms.getBySlackChannelId(channelId);
if (!room) {
log.warn("Not unlinking channel, no room found");
return;
}

// notify admins
if (this.adminRoom) {
await this.main.botIntent.sendMessage(this.adminRoom, {
msgtype: "m.notice",
body: `${teamId} archived channel ${channelId}, bridged room: ${room.MatrixRoomId}`,
});
}

try {
await this.main.botIntent.sendMessage(room.MatrixRoomId, {
msgtype: "m.notice",
body: "The Slack channel bridged to this room has been archived.",
});
} catch (ex) {
log.warn("Failed to send archived notice into the room:", ex);
}

// Hide deleted channels in the room directory.
try {
await this.main.botIntent.setRoomDirectoryVisibility(room.MatrixRoomId, "private");
} catch (ex) {
log.warn("Failed to hide room from the room directory:", ex);
}

try {
await this.main.actionUnlink({ matrix_room_id: room.MatrixRoomId });
} catch (ex) {
log.warn("Tried to unlink room but failed:", ex);
}
}

public async syncMembershipForRoom(roomId: string, channelId: string, teamId: string, client: WebClient): Promise<void> {
const existingGhosts = await this.main.listGhostUsers(roomId);
// We assume that we have this
Expand Down

0 comments on commit 17505ea

Please sign in to comment.