Skip to content

Commit 5e69e33

Browse files
authored
Use mentor role for reactions (#83)
* Update documentation. Oops, that parameter hasn't been used for ages. * Safer reactions If the user is a mentor, only count reactions from mentors (or the original poster).
1 parent 89c743f commit 5e69e33

File tree

2 files changed

+58
-22
lines changed

2 files changed

+58
-22
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: mentordash
22
Title: Dashboard for the R4DS Online Learning Community
3-
Version: 0.3.8
3+
Version: 0.3.9
44
Authors@R: c(
55
person(
66
'Jon', 'Harmon', email = '[email protected]', role = c('cre', 'aut')

R/app_server.R

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,21 @@
104104
return(question_channels)
105105
}
106106

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+
107122
#' Get Question Threads
108123
#'
109124
#' @return A tidy tibble of question information.
@@ -128,9 +143,6 @@
128143
#' Rectangle Conversation Data
129144
#'
130145
#' @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.
134146
#'
135147
#' @return A tibble of question data.
136148
#' @keywords internal
@@ -172,6 +184,8 @@
172184
reply_count = tidyr::replace_na(.data$reply_count, 0)
173185
)
174186

187+
mentors <- .get_mentors()
188+
175189
convos_tbl <- convos_tbl %>%
176190
# Get rid of channel_join and channel_name.
177191
dplyr::filter(
@@ -190,20 +204,26 @@
190204
)
191205
) %>%
192206
dplyr::filter(
193-
latest_activity >= (lubridate::now() - keep_timeframe)
207+
.data$latest_activity >= (lubridate::now() - keep_timeframe)
194208
) %>%
195209
dplyr::mutate(
196210
heavy_check_mark = .has_reaction(
197211
.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
199215
),
200216
thread_tag = .has_reaction(
201217
.data$reactions,
202-
"thread"
218+
"thread",
219+
.data$user,
220+
mentors
203221
),
204222
nevermind = .has_reaction(
205223
.data$reactions,
206-
c("question-nevermind", "octagonal_sign", "nevermind")
224+
c("question-nevermind", "octagonal_sign", "nevermind"),
225+
.data$user,
226+
mentors
207227
)
208228
) %>%
209229
dplyr::filter(
@@ -214,7 +234,9 @@
214234
dplyr::mutate(
215235
speech_balloon = .has_reaction(
216236
.data$reactions,
217-
c("speech_balloon", "question-more-info")
237+
c("speech_balloon", "question-more-info"),
238+
.data$user,
239+
mentors
218240
),
219241
answerable = .is_answerable(
220242
.data$speech_balloon, .data$user, .data$reply_users,
@@ -278,24 +300,38 @@
278300
#' @param reactions A list of reaction lists.
279301
#' @param reaction_name A character vector with the name of one or more target
280302
#' 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.
281306
#'
282307
#' @return A logical vector the same length as reactions.
283308
#' @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+
)
295331
)
296-
)
332+
}
297333
}
298-
})
334+
)
299335
}
300336

301337
#' Check Whether a Question is Answerable

0 commit comments

Comments
 (0)