- Timestamp:
- 09/09/2026 10:34:02 AM (2 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/api.wordpress.org/public_html/dotorg/slack/subgroup.php
r14848 r15161 15 15 16 16 function invalidate_channel_lists() { 17 wp_cache_delete( ' bot_active_channels', CACHE_GROUP );17 wp_cache_delete( 'active_channels', CACHE_GROUP ); 18 18 wp_cache_delete( 'archived_channels', CACHE_GROUP ); 19 19 } … … 846 846 847 847 function list_all_private_channels( $include_archived = false ) { 848 $active = wp_cache_get( ' bot_active_channels', CACHE_GROUP );848 $active = wp_cache_get( 'active_channels', CACHE_GROUP ); 849 849 if ( false === $active ) { 850 $r = api_call( 'conversations.list', [ 850 // The bot token only lists channels the bot was invited to. Merge in the 851 // owner's listing, as the archived branch below already does. 852 $params = [ 851 853 'exclude_archived' => true, 852 854 'types' => 'private_channel', 853 855 'limit' => 999, 856 ]; 857 [ $bot_active, $user_active ] = api_multi_call( [ 858 [ 'conversations.list', $params, null ], 859 [ 'conversations.list', $params, SUBGROUP_USER_TOKEN ], 854 860 ] ); 855 $active = $r['channels'] ?? []; 856 wp_cache_set( 'bot_active_channels', $active, CACHE_GROUP, CACHE_TTL_ACTIVE_CHANNELS ); 861 862 // Tag what the bot is in: it cannot act on anything else. 863 $active = []; 864 foreach ( $bot_active['channels'] ?? [] as $g ) { 865 $g['bot_member'] = true; 866 $active[ $g['id'] ] = $g; 867 } 868 foreach ( $user_active['channels'] ?? [] as $g ) { 869 if ( ! isset( $active[ $g['id'] ] ) ) { 870 $g['bot_member'] = false; 871 $active[ $g['id'] ] = $g; 872 } 873 } 874 $active = array_values( $active ); 875 wp_cache_set( 'active_channels', $active, CACHE_GROUP, CACHE_TTL_ACTIVE_CHANNELS ); 857 876 } 858 877 … … 879 898 foreach ( $bot['channels'] ?? [] as $g ) { 880 899 if ( ! empty( $g['is_archived'] ) ) { 900 $g['bot_member'] = true; 881 901 $archived[ $g['id'] ] = $g; 882 902 } … … 884 904 foreach ( $user['channels'] ?? [] as $g ) { 885 905 if ( ! empty( $g['is_archived'] ) && ! isset( $archived[ $g['id'] ] ) ) { 906 $g['bot_member'] = false; 886 907 $archived[ $g['id'] ] = $g; 887 908 } … … 907 928 if ( $g['id'] === $channel_id ) { 908 929 return $g; 930 } 931 } 932 return null; 933 } 934 935 /* 936 * Read member lists with the bot token where the bot is a member, and with the 937 * owner token everywhere else. 938 */ 939 function members_token( $channel_id ) { 940 foreach ( list_all_private_channels() as $g ) { 941 if ( $g['id'] === $channel_id ) { 942 return empty( $g['bot_member'] ) ? SUBGROUP_USER_TOKEN : null; 909 943 } 910 944 } … … 929 963 $calls = []; 930 964 foreach ( $to_fetch as $id ) { 931 $calls[] = [ 'conversations.members', [ 'channel' => $id, 'limit' => 999 ], null];965 $calls[] = [ 'conversations.members', [ 'channel' => $id, 'limit' => 999 ], members_token( $id ) ]; 932 966 } 933 967 $results = api_multi_call( $calls ); … … 945 979 'channel' => $channel_id, 946 980 'limit' => 999, 947 ] );981 ], members_token( $channel_id ) ); 948 982 $members = $r['members'] ?? []; 949 983 wp_cache_set( $key, $members, CACHE_GROUP, CACHE_TTL_MEMBERS ); … … 1039 1073 'text' => [ 'type' => 'mrkdwn', 'text' => implode( "\n", $lines ) ], 1040 1074 ]; 1041 if ( ! $is_member ) { 1075 // Joining runs as the bot, so only offer it where the bot can invite. 1076 if ( ! $is_member && ! empty( $g['bot_member'] ) ) { 1042 1077 $block['accessory'] = [ 1043 1078 'type' => 'button', … … 1129 1164 'text' => [ 'type' => 'mrkdwn', 'text' => implode( "\n", $lines ) ], 1130 1165 ]; 1131 $blocks[] = [ 1132 'type' => 'actions', 1133 'elements' => [ 1134 [ 1135 'type' => 'button', 1136 'text' => [ 'type' => 'plain_text', 'text' => 'Rename' ], 1137 'action_id' => 'rename_subgroup', 1138 'value' => $g['id'], 1139 ], 1140 [ 1141 'type' => 'button', 1142 'text' => [ 'type' => 'plain_text', 'text' => 'Rotate' ], 1143 'action_id' => 'rotate_subgroup', 1144 'value' => $g['id'], 1145 'confirm' => [ 1146 'title' => [ 'type' => 'plain_text', 'text' => 'Rotate channel?' ], 1147 'text' => [ 'type' => 'mrkdwn', 'text' => "Archive `{$g['name']}` with a year suffix and create a fresh copy with only you as a member." ], 1148 'confirm' => [ 'type' => 'plain_text', 'text' => 'Rotate' ], 1149 'deny' => [ 'type' => 'plain_text', 'text' => 'Cancel' ], 1166 // Rename, Rotate and Archive act on the channel, so they need the bot in it. 1167 if ( ! empty( $g['bot_member'] ) ) { 1168 $blocks[] = [ 1169 'type' => 'actions', 1170 'elements' => [ 1171 [ 1172 'type' => 'button', 1173 'text' => [ 'type' => 'plain_text', 'text' => 'Rename' ], 1174 'action_id' => 'rename_subgroup', 1175 'value' => $g['id'], 1176 ], 1177 [ 1178 'type' => 'button', 1179 'text' => [ 'type' => 'plain_text', 'text' => 'Rotate' ], 1180 'action_id' => 'rotate_subgroup', 1181 'value' => $g['id'], 1182 'confirm' => [ 1183 'title' => [ 'type' => 'plain_text', 'text' => 'Rotate channel?' ], 1184 'text' => [ 'type' => 'mrkdwn', 'text' => "Archive `{$g['name']}` with a year suffix and create a fresh copy with only you as a member." ], 1185 'confirm' => [ 'type' => 'plain_text', 'text' => 'Rotate' ], 1186 'deny' => [ 'type' => 'plain_text', 'text' => 'Cancel' ], 1187 ], 1188 ], 1189 [ 1190 'type' => 'button', 1191 'text' => [ 'type' => 'plain_text', 'text' => 'Archive' ], 1192 'style' => 'danger', 1193 'action_id' => 'archive_subgroup', 1194 'value' => $g['id'], 1195 'confirm' => [ 1196 'title' => [ 'type' => 'plain_text', 'text' => 'Archive channel?' ], 1197 'text' => [ 'type' => 'mrkdwn', 'text' => "Archive `{$g['name']}`?" ], 1198 'confirm' => [ 'type' => 'plain_text', 'text' => 'Archive' ], 1199 'deny' => [ 'type' => 'plain_text', 'text' => 'Cancel' ], 1200 'style' => 'danger', 1201 ], 1150 1202 ], 1151 1203 ], 1152 [ 1153 'type' => 'button', 1154 'text' => [ 'type' => 'plain_text', 'text' => 'Archive' ], 1155 'style' => 'danger', 1156 'action_id' => 'archive_subgroup', 1157 'value' => $g['id'], 1158 'confirm' => [ 1159 'title' => [ 'type' => 'plain_text', 'text' => 'Archive channel?' ], 1160 'text' => [ 'type' => 'mrkdwn', 'text' => "Archive `{$g['name']}`?" ], 1161 'confirm' => [ 'type' => 'plain_text', 'text' => 'Archive' ], 1162 'deny' => [ 'type' => 'plain_text', 'text' => 'Cancel' ], 1163 'style' => 'danger', 1164 ], 1165 ], 1166 ], 1167 ]; 1204 ]; 1205 } 1168 1206 } 1169 1207 }
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)