Changeset 12396
- Timestamp:
- 02/13/2023 11:31:27 PM (3 years ago)
- Location:
- sites/trunk/common/includes/slack/props
- Files:
-
- 2 added
- 2 edited
-
lib.php (modified) (4 diffs)
-
readme.md (added)
-
tests/mentions-in-list.json (added)
-
tests/test-lib.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/common/includes/slack/props/lib.php
r11927 r12396 8 8 * Adds props in Slack to w.org profiles. 9 9 * 10 * Receives webhook notifications for all new messages in `#props` ,10 * Receives webhook notifications for all new messages in `#props`. See `dotorg/slack/props.php` for the caller. 11 11 */ 12 12 function handle_props_message( object $request ) : string { … … 87 87 /** 88 88 * Parse the mentioned Slack user IDs from a message event. 89 *90 * This assumes that the app is configured to escape usernames.91 89 */ 92 90 function get_recipient_slack_ids( array $blocks ) : array { … … 95 93 foreach ( $blocks as $block ) { 96 94 foreach ( $block->elements as $element ) { 97 foreach ( $element->elements as $inner_element ) { 98 if ( 'user' !== $inner_element->type ) { 99 continue; 100 } 101 102 $ids[] = $inner_element->user_id; 103 } 95 $ids = array_merge( $ids, get_user_ids_from_element( $element ) ); 104 96 } 105 97 } … … 107 99 return array_unique( $ids ); 108 100 } 101 102 /** 103 * Recursively parse any mentioned Slack user IDs from a message element. 104 * 105 * This assumes that the app is configured to escape usernames. 106 */ 107 function get_user_ids_from_element( object $element ) : array { 108 $ids = array(); 109 110 if ( 'user' === $element->type ) { 111 $ids[] = $element->user_id; 112 } 113 114 if ( isset( $element->elements ) ) { 115 foreach ( $element->elements as $inner_element ) { 116 $ids = array_merge( $ids, get_user_ids_from_element( $inner_element ) ); 117 } 118 } 119 120 return $ids; 121 } 122 109 123 110 124 /** -
sites/trunk/common/includes/slack/props/tests/test-lib.php
r11927 r12396 125 125 ); 126 126 127 $mentions_in_list = json_decode( file_get_contents( __DIR__ . '/mentions-in-list.json' ) ); 128 127 129 $cases = array( 128 130 'empty' => array( … … 133 135 'user mentioned twice' => array( 134 136 'blocks' => $mentioned_twice, 137 'expected' => $valid_users, 138 ), 139 140 'mentions in a list' => array( 141 'blocks' => $mentions_in_list, 135 142 'expected' => $valid_users, 136 143 ),
Note: See TracChangeset
for help on using the changeset viewer.