Skip to content

Commit

Permalink
Display account name when display name is blank. (#119)
Browse files Browse the repository at this point in the history
* Display account name when display name is blank.

Closes #71.

* Update test to match this update.

We no longer user "display_name".

* Include real name if set.

When you DM someone, it uses display_name if set, then real_name, then name. So let's follow the same hierarchy.
  • Loading branch information
jonthegeek authored Mar 22, 2024
1 parent 801e75e commit a7a62d2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion R/app_server.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
observeEvent(
input$submit,
.submit_availability(
slack_user_info()[["display_name"]],
slack_user_info()[["user_name"]],
slack_user_info()[["user_id"]],
selected_book(),
timezone(),
Expand Down
29 changes: 26 additions & 3 deletions R/user.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,42 @@
#' @keywords internal
.user_server <- function(id = "user_name") {
moduleServer(id, function(input, output, session) {
slack_user_info <- .shinyslack_user_info(c("display_name", "user_id"))
user_info <- .bookclubber_user_info()
output$user_name <- renderText(
paste(
strong("Logged in as"),
br(),
slack_user_info()[["display_name"]]
user_info()[["user_name"]]
)
)
return(slack_user_info)
return(user_info)
})
}

.bookclubber_user_info <- function() {
slack_user_info <- .shinyslack_user_info(
c("user_id", "display_name", "real_name", "user_name")
)
return(
shiny::reactive({
list(
user_id = slack_user_info()[["user_id"]],
user_name = slack_user_info()[["display_name"]] %|"|%
slack_user_info()[["real_name"]] %|"|%
slack_user_info()[["user_name"]]
)
})
)
}

# Abstract for mocking.
.shinyslack_user_info <- function(components) {
shinyslack::user_info(components) # nocov
}

`%|"|%` <- function(x, y) {
if (is.null(x) || !isTRUE(as.logical(nchar(x)))) {
return(y)
}
return(x)
}
2 changes: 1 addition & 1 deletion tests/testthat/test-user.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test_that("user server builds expected output", {
})

test_that("user server returns expected object", {
test_user_info <- list(display_name = "test_user", user_id = "test_user_id")
test_user_info <- list(user_id = "test_user_id", user_name = "test_user")
local_mocked_bindings(
.shinyslack_user_info = function(components) {
# Return a function to simulate a reactive.
Expand Down

0 comments on commit a7a62d2

Please sign in to comment.