Skip to main content

check_visibility

Function check_visibility 

Source
async fn check_visibility(
    channel: &Channel,
    dest_perm: &Channel,
    source_channel: &Channel,
    guild_id: Id<GuildMarker>,
    ctx: &BotContext,
) -> Result<(), PreviewError>
Expand description

Validates that everyone who can read source_channel could also read the linked message in channel.

The expanded content is posted as a single message that all members of source_channel can read, so the linked channel must be at least as readable as the source channel to avoid leaking restricted content. “Readable” means what read_source_requirement asks for on the source, and what read_target_requirement asks for on the target; a link back into source_channel is judged with that channel as both. Permissions are evaluated by Visibility the way Discord does, so roles, role combinations, per-member overwrites and ADMINISTRATOR need no special cases.

What remains is refused because it cannot be evaluated:

  • Links into another guild, refused by Preview::get before this runs: roles and overwrites are guild-local, and the bot may not be in that guild.
  • Private threads (and DMs), unless quoted from within the same private thread (see has_unlisted_readers).
  • Overwrites of a kind this library does not know.
  • More than MAX_MEMBER_LOOKUPS members needing a lookup.

Threads have no overwrites of their own and are judged by their parent. For a public thread that is exact; for a private thread used as the source it over-approximates the readers, which can only cause a refusal. dest_perm is channel resolved by permission_channel.