Skip to content

feat(invite_users_to_channel): skip users already in the channel (supersedes #1)#2

Open
VincentGuyader wants to merge 1 commit intomasterfrom
feat/skip-users-already-in-channel
Open

feat(invite_users_to_channel): skip users already in the channel (supersedes #1)#2
VincentGuyader wants to merge 1 commit intomasterfrom
feat/skip-users-already-in-channel

Conversation

@VincentGuyader
Copy link
Copy Markdown
Member

Summary

Supersedes #1, which had the right intent but was 4 years stale, in conflict with master, and had a precedence bug (length(users_a_inviter > 0) instead of length(users_a_inviter) > 0, so the else branch was never reached).

  • New helper get_users_in_channel() wraps Slack's conversations.members endpoint and is exported with roxygen.
  • invite_users_to_channel() now setdiff()s its target list with both current_user (already there) and the channel's existing members, so a repeated invitation is a no-op + message rather than a noisy already_in_channel from the API + a re-notification to existing members.
  • Bootstraps a tests/testthat/ folder. Tests use testthat::with_mocked_bindings() on httr::POST and on the slackr::* lookups, so the suite runs offline.

Test plan

  • testthat::test_local(): 6 PASS / 0 FAIL.
  • Mock paths covered: members returned, channel unknown, partial overlap (only the missing user invited), full overlap (no POST sent + message).

Closes #1

Adds get_users_in_channel() (wraps Slack's conversations.members
endpoint) and uses its result alongside current_user in the setdiff
that builds the invite list, so calling invite_users_to_channel()
twice with the same audience no longer:
  - emits a Slack 'already_in_channel' error,
  - re-sends a join notification to people who are already there.

When the resulting invite list is empty, the function short-circuits
with a message and a no-op. The httr::POST stays as a single call
(no per-user loop).

Also bootstraps a tests/testthat/ folder. Tests exercise both the new
helper and the modified inviter via testthat::with_mocked_bindings()
on httr::POST + slackr::slackr_users / slackr_channels / auth_test —
no real Slack connection needed.

Supersedes the never-merged PR #1, which had the right intent but was
buggy (length(x > 0) instead of length(x) > 0) and 4 years stale on a
heavily refactored function.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant