feditext / feditext

A free, open-source iOS client for Mastodon, Glitch, GotoSocial, Iceshrimp, Akkoma, and other Mastodon-API-compatible Fediverse instance servers.
https://mastodon.social/@Feditext
GNU General Public License v3.0
180 stars 8 forks source link

Poll results displaying weird #390

Open Yayroos opened 7 months ago

Yayroos commented 7 months ago

Describe the bug On an akkoma instance, when viewing the results of polls from other instances, all the options show a full bar and hundreds of thousands of % rather than the actual results. Viewing the same poll on the web view of my instance shows correctly.

To Reproduce Steps to reproduce the behavior:

  1. See a post with a poll in in, that has come from another server (seems to be all other servers, not limited by software)
  2. Vote in the poll (or have the poll time be ended)
  3. All options will show full bars and hundreds of percent

Expected behavior Poll results should show accurately.

Screenshots On feditext: image

On my instance's web view: image

(please complete the following information):

Additional context This doesn't seem to happen when viewing from my other account, which is on a glitch mastodon instance, so i think it's an akkoma related thing.

Yayroos commented 7 months ago

can confirm, when viewed through feditext logged into the glitch mastodon instance, the same poll appears correct. The other difference I noticed is the akkoma version always seems to say only one person voted, while the glitch mastodon one shows 290 people in this particular case, so i think the number of votes doesn't federate into akkoma correctly even though the actual votes do.

Yayroos commented 7 months ago

which i suppose makes it mostly akkoma's problem, but at least for single choice polls feditext could work around it by counting the number of total votes and doing the render math based on that rather than the reported vote count. doesn't solve for multi choice polls though. hmmm.

VyrCossont commented 7 months ago

@Yayroos I've seen cases like this while viewing remote polls on my GtS instance through Semaphore, and I think also Phanpy. I'll check if we're doing anything stupid but I'm reasonably sure this is a server bug. We might be able to compensate for it; I'm not actually sure how polls work yet.

Yayroos commented 7 months ago

I can't read swift well enough to say for certain, but I'm pretty sure if you were going to work around it, the thing to do would be be at about like 58 in Views/UIKit/PollView.swift if you ran through the options and got the vote count of each, then compared that to the provided votes count. on single select polls at least then you pass in the sum of votes on options rather than the given vote count if they don't match. Gimme a minute to load up my laptop and i'll see if i can name the variables in any more detail

Yayroos commented 7 months ago

Ok so i dont have a mac on which to try and write this properly, nor the time to learn swift properly so this is inferred from nearby syntax and a quick google but.

this is the current line 57-69 of Views/UIKit/PollView.swift

} else {
     for (index, option) in viewModel.pollOptions.enumerated() {
         let resultView = PollResultView(
             option: option,
             emojis: viewModel.pollEmojis,
             selected: viewModel.pollOwnVotes.contains(index),
             multipleSelection: viewModel.isPollMultipleSelection,
             votersCount: viewModel.pollVotersCount,
             identityContext: viewModel.identityContext)
         stackView.addArrangedSubview(resultView)
     }
}

and i think if you checked before this for the case where the poll is reporting only 1 vote (which seems to be what happens on the ones that show weird) and did something like this:

} else {
    var actualVotersCount = viewModel.pollVotersCount
    if !viewModel.isPollMultipleSelection && viewModel.pollVotersCount == 1 {
        var sumOfVotes = 0
        for (index, option) in viewModel.pollOptions.enumerated() {
            sumOfVotes += option.votesCount
        }
        actualVotersCount = sumofVotes
    }
    for (index, option) in viewModel.pollOptions.enumerated() {
        let resultView = PollResultView(
            option: option,
            emojis: viewModel.pollEmojis,
            selected: viewModel.pollOwnVotes.contains(index),
            multipleSelection: viewModel.isPollMultipleSelection,
            votersCount: actualVotersCount,
            identityContext: viewModel.identityContext)
        stackView.addArrangedSubview(resultView)
    }
}

im sure you can read it but basically added another loop before the one that was already there to gather up the correct voter count, and then used that new value actualVotersCount in place of the previously used viewModel.pollVotersCount in the call to PollResultView - quick and dirty, but should a) work and b) only be more than one extra var and condition in the case where the poll is reporting only one voter and it's a single select poll (i dont know if this could be used to fix multi select polls, because there's no way to extract the number of voters from the number of votes in that case)

Yayroos commented 7 months ago

that did not format itself properly. cool and good. I'm gonna try and edit that to be readable i guess.

grrr github is eating the newlines. you'd think a platform like this would coherently format text in a code block...

there we go. readable now.