Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polls with non-empty own_votes #115

Closed
davidbody opened this issue Nov 28, 2022 · 2 comments
Closed

Polls with non-empty own_votes #115

davidbody opened this issue Nov 28, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@davidbody
Copy link

davidbody commented Nov 28, 2022

The parse_poll function doesn't properly parse polls with non-empty own_votes.

When own_votes is not empty, the following error occurs:

Error in `dplyr::bind_rows()` at rtoot/R/datastructure.R:117:8:
! Argument 1 must have names.
Run `rlang::last_error()` to see where the error occurred.

The JSON looks like this:

{
  "id": "34830",
  "expires_at": "2019-12-05T04:05:08.302Z",
  "expired": true,
  "multiple": false,
  "votes_count": 10,
  "voters_count": null,
  "voted": true,
  "own_votes": [
    1
  ],
  "options": [
    {
      "title": "accept",
      "votes_count": 6
    },
    {
      "title": "deny",
      "votes_count": 4
    }
  ],
  "emojis": []
}

Copied from https://docs.joinmastodon.org/entities/Poll/#example

I would be happy to work on a fix, but I'm not sure how to add a failing test for this in keeping with the project's existing tests. I see the vcr fixtures, and the .Rds files under tests\testdata, but I'm not quite sure how to proceed.

@chainsawriot
Copy link
Collaborator

@davidbody Thanks for reporting this. I can confirm this and the following is a reprex. A fix is forthcoming.

poll <- list(id = "615", expires_at = "2022-11-27T11:06:56.000Z", expired = TRUE, 
    multiple = TRUE, votes_count = 86L, voters_count = 84L, voted = TRUE, 
    own_votes = list(0L), options = list(list(title = "mu4e", 
        votes_count = 50L), list(title = "notmuch", votes_count = 20L), 
        list(title = "gnus", votes_count = 13L), list(title = "other (please comment)", 
                                                      votes_count = 3L)), emojis = list())

rtoot:::parse_poll(poll)
#> Error in `dplyr::bind_rows()`:
#> ! Argument 1 must have names.

poll$own_votes <- list()
rtoot:::parse_poll(poll)
#> # A tibble: 1 × 10
#>   id    expires_at          expired multiple votes_count voters_…¹ voted own_v…²
#>   <chr> <dttm>              <lgl>   <lgl>          <int>     <int> <lgl> <I<lis>
#> 1 615   2022-11-27 11:06:56 TRUE    TRUE              86        84 TRUE  <list> 
#> # … with 2 more variables: options <list>, emojis <I<list>>, and abbreviated
#> #   variable names ¹​voters_count, ²​own_votes

Created on 2022-11-28 by the reprex package (v2.0.1)

@davidbody
Copy link
Author

👍 Package reinstalled and working. Thanks!

@chainsawriot chainsawriot added the bug Something isn't working label Nov 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants