Making WordPress.org

Changeset 9216


Ignore:
Timestamp:
10/21/2019 06:00:38 AM (5 years ago)
Author:
dd32
Message:

Slack: Broadcast /here messages in subchannels such as #core-privacy into thei parent channel (#core).

The message into the parent channel shouldn't contain any pinging content or be itself a here broadcast, and is trimmed to 100char if needed.

Fixes #4747.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/common/includes/slack/announce/lib.php

    r9121 r9216  
    110110    // By sending the channel ID, we can post to private groups.
    111111    $send->send( $data['channel_id'] );
     112
     113    // Broadcast this message as a non-@here to the "parent" channel too.
     114    list( $parent_channel, ) = explode( '-', $channel, 2 );
     115    if (
     116        // Skip for private groups.
     117        'privategroup' === $parent_channel ||
     118        // If this message was posted in the "parent" channel, nothing to do.
     119        $parent_channel === $channel ||
     120        // Is it an actual channel? Assume that there'll always be at least one whitelisted user for the parent channel
     121        ! get_whitelist_for_channel( $parent_channel )
     122    ) {
     123        return;
     124    }
     125
     126    $text = $data['text'];
     127    // Remove any @here or @channel
     128    $text = str_ireplace( [ '@here', '@channel', '@group' ], '', $text );
     129    if ( mb_strlen( $text ) > 103 ) {
     130        $text = mb_subsr( $text, 0, 100 ) . '...';
     131    }
     132
     133    $send->set_text( 'In #' . $channel . ': ' . $text );
     134    $send->send( '#' . $parent_channel );
     135
    112136}
    113137
Note: See TracChangeset for help on using the changeset viewer.