|
104 | 104 | return(question_channels) |
105 | 105 | } |
106 | 106 |
|
| 107 | +.get_mentors <- function() { |
| 108 | + mentors <- slackcalls::post_slack( |
| 109 | + "conversations.members", |
| 110 | + channel = "GAJ8D7YKA" |
| 111 | + ) |
| 112 | + |
| 113 | + if (mentors$ok && "members" %in% names(mentors)) { |
| 114 | + return(unlist(mentors$members)) |
| 115 | + } else { |
| 116 | + # Figure out logging here so we can see who is using mentordash but isn't in |
| 117 | + # mentors_chat. |
| 118 | + return(character()) |
| 119 | + } |
| 120 | +} |
| 121 | + |
107 | 122 | #' Get Question Threads |
108 | 123 | #' |
109 | 124 | #' @return A tidy tibble of question information. |
|
128 | 143 | #' Rectangle Conversation Data |
129 | 144 | #' |
130 | 145 | #' @param convos A list returned by slackthreads::conversations. |
131 | | -#' @param question_channels A named character vector, where the name is the |
132 | | -#' user-friendly name of the channel, and the internal character is the |
133 | | -#' channel ID. |
134 | 146 | #' |
135 | 147 | #' @return A tibble of question data. |
136 | 148 | #' @keywords internal |
|
172 | 184 | reply_count = tidyr::replace_na(.data$reply_count, 0) |
173 | 185 | ) |
174 | 186 |
|
| 187 | + mentors <- .get_mentors() |
| 188 | + |
175 | 189 | convos_tbl <- convos_tbl %>% |
176 | 190 | # Get rid of channel_join and channel_name. |
177 | 191 | dplyr::filter( |
|
190 | 204 | ) |
191 | 205 | ) %>% |
192 | 206 | dplyr::filter( |
193 | | - latest_activity >= (lubridate::now() - keep_timeframe) |
| 207 | + .data$latest_activity >= (lubridate::now() - keep_timeframe) |
194 | 208 | ) %>% |
195 | 209 | dplyr::mutate( |
196 | 210 | heavy_check_mark = .has_reaction( |
197 | 211 | .data$reactions, |
198 | | - c("heavy_check_mark", "question-answered", "white_check_mark") |
| 212 | + c("heavy_check_mark", "question-answered", "white_check_mark"), |
| 213 | + .data$user, |
| 214 | + mentors |
199 | 215 | ), |
200 | 216 | thread_tag = .has_reaction( |
201 | 217 | .data$reactions, |
202 | | - "thread" |
| 218 | + "thread", |
| 219 | + .data$user, |
| 220 | + mentors |
203 | 221 | ), |
204 | 222 | nevermind = .has_reaction( |
205 | 223 | .data$reactions, |
206 | | - c("question-nevermind", "octagonal_sign", "nevermind") |
| 224 | + c("question-nevermind", "octagonal_sign", "nevermind"), |
| 225 | + .data$user, |
| 226 | + mentors |
207 | 227 | ) |
208 | 228 | ) %>% |
209 | 229 | dplyr::filter( |
|
214 | 234 | dplyr::mutate( |
215 | 235 | speech_balloon = .has_reaction( |
216 | 236 | .data$reactions, |
217 | | - c("speech_balloon", "question-more-info") |
| 237 | + c("speech_balloon", "question-more-info"), |
| 238 | + .data$user, |
| 239 | + mentors |
218 | 240 | ), |
219 | 241 | answerable = .is_answerable( |
220 | 242 | .data$speech_balloon, .data$user, .data$reply_users, |
|
278 | 300 | #' @param reactions A list of reaction lists. |
279 | 301 | #' @param reaction_name A character vector with the name of one or more target |
280 | 302 | #' reactions. |
| 303 | +#' @param users The character vector of user ids of the person who posted each |
| 304 | +#' message. |
| 305 | +#' @param mentors A character vector of mentors to use for filtering. |
281 | 306 | #' |
282 | 307 | #' @return A logical vector the same length as reactions. |
283 | 308 | #' @keywords internal |
284 | | -.has_reaction <- function(reactions, reaction_name) { |
285 | | - purrr::map_lgl(reactions, function(rxns) { |
286 | | - if (all(is.na(rxns))) { |
287 | | - FALSE |
288 | | - } else { |
289 | | - any( |
290 | | - purrr::map_lgl( |
291 | | - rxns, |
292 | | - function(rxn) { |
293 | | - rxn$name %in% reaction_name |
294 | | - } |
| 309 | +.has_reaction <- function(reactions, |
| 310 | + reaction_name, |
| 311 | + users, |
| 312 | + mentors = character()) { |
| 313 | + purrr::map2_lgl( |
| 314 | + reactions, users, |
| 315 | + function(rxns, user) { |
| 316 | + if (all(is.na(rxns))) { |
| 317 | + FALSE |
| 318 | + } else { |
| 319 | + any( |
| 320 | + purrr::map_lgl( |
| 321 | + rxns, |
| 322 | + function(rxn) { |
| 323 | + rxn$name %in% reaction_name && |
| 324 | + ( |
| 325 | + !length(mentors) || |
| 326 | + user %in% rxn$users || |
| 327 | + any(rxn$users %in% mentors) |
| 328 | + ) |
| 329 | + } |
| 330 | + ) |
295 | 331 | ) |
296 | | - ) |
| 332 | + } |
297 | 333 | } |
298 | | - }) |
| 334 | + ) |
299 | 335 | } |
300 | 336 |
|
301 | 337 | #' Check Whether a Question is Answerable |
|
0 commit comments