Skip to content

Commit ca3e45e

Browse files
Bug fixes
1 parent 8f69641 commit ca3e45e

4 files changed

Lines changed: 42 additions & 12 deletions

File tree

src/coffeeChats/coffeeChatActions.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
setTrioPairingPreference,
99
getTrioPairingPreference,
1010
} from "./coffeeChatService";
11+
import { CoffeeChatPairingModel } from "./coffeeChatModels";
1112

1213
export function registerCoffeeChatActions(slackbot: App) {
1314
// Action handler for opting out of coffee chats
@@ -126,9 +127,27 @@ export function registerCoffeeChatActions(slackbot: App) {
126127
await ack();
127128

128129
try {
130+
const userId = body.user.id;
129131
const action = body.actions[0];
130132
const pairingId = ("value" in action ? action.value : "") as string;
131133

134+
// Verify the user clicking the button is actually part of this pairing
135+
const pairing = await CoffeeChatPairingModel.findById(pairingId);
136+
if (!pairing) {
137+
await respond({
138+
text: `❌ Pairing not found.`,
139+
replace_original: false,
140+
});
141+
return;
142+
}
143+
if (!pairing.userIds.includes(userId)) {
144+
await respond({
145+
text: `❌ You can only confirm meetups that you are part of.`,
146+
replace_original: false,
147+
});
148+
return;
149+
}
150+
132151
await confirmMeetup(pairingId);
133152

134153
const confirmationSections: KnownBlock[] = [

src/coffeeChats/coffeeChatCommands.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ import { DEFAULT_PAIRING_FREQUENCY_DAYS } from "../app";
1818
const isUserAdmin = async (slackbot: App, userId: string): Promise<boolean> => {
1919
try {
2020
const userInfo = await slackbot.client.users.info({ user: userId });
21-
return (
21+
return !!(
2222
userInfo.user?.is_admin ||
2323
userInfo.user?.is_owner ||
24-
userInfo.user?.is_primary_owner ||
25-
false
24+
userInfo.user?.is_primary_owner
2625
);
2726
} catch {
2827
return false;

src/coffeeChats/coffeeChatService.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,28 @@ const getRandomActivity = (): string => {
8282
export const getChannelMembers = async (
8383
channelId: string,
8484
): Promise<string[]> => {
85-
const result = await slackbot.client.conversations.members({
86-
channel: channelId,
87-
});
85+
const allMemberIds: string[] = [];
86+
let cursor: string | undefined = undefined;
87+
88+
// Paginate through all members using Slack's cursor-based pagination
89+
do {
90+
const result = await slackbot.client.conversations.members({
91+
channel: channelId,
92+
limit: 200,
93+
...(cursor ? { cursor } : {}),
94+
});
8895

89-
if (!result.ok || !result.members) {
90-
throw new Error(`Failed to get members for channel ${channelId}`);
91-
}
96+
if (!result.ok || !result.members) {
97+
throw new Error(`Failed to get members for channel ${channelId}`);
98+
}
99+
100+
allMemberIds.push(...result.members);
101+
cursor = result.response_metadata?.next_cursor || undefined;
102+
} while (cursor);
92103

93104
// Filter out bots
94105
const memberDetails = await Promise.all(
95-
result.members.map(async (userId) => {
106+
allMemberIds.map(async (userId) => {
96107
const userInfo = await slackbot.client.users.info({ user: userId });
97108
return {
98109
id: userId,
@@ -481,6 +492,8 @@ export const createCoffeeChatsForChannel = async (
481492
logWithTime(
482493
`Not enough members in ${config.channelName} for coffee chats (need at least 2)`,
483494
);
495+
// Still clear skip flags so users who skipped this round aren't permanently excluded
496+
await clearSkipFlags(config.channelId);
484497
return;
485498
}
486499

tests/coffeeChats/coffeeChatService.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -989,8 +989,7 @@ describe("coffeeChatService", () => {
989989

990990
const commandsBlock = blocks.find(
991991
(b) =>
992-
b.type === "section" &&
993-
b.text?.text.includes("Available Commands"),
992+
b.type === "section" && b.text?.text.includes("Available Commands"),
994993
);
995994
expect(commandsBlock).toBeDefined();
996995
expect(commandsBlock?.text?.text).toContain("/coffee-chat-status");

0 commit comments

Comments
 (0)