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

New feature: Polls #243

Closed
wants to merge 37 commits into from
Closed

New feature: Polls #243

wants to merge 37 commits into from

Conversation

0xtlt
Copy link
Contributor

@0xtlt 0xtlt commented Jan 4, 2023

Hello everyone,

I have developed a poll feature for Damus that uses Nostr's reaction kind 7 to allow for voting.

In Damus options, the user can choose to see the votes of their friends as well as their friends' friends, or from everyone. By default, it is set to friends + friends' friends to prevent bots from spamming opinions.

It is now possible to create polls directly from the post writing panel.

I have also included a fix in this PR that prevents Damus from associating any reaction to a like, which was previously the case even if it was a thumbs down for the example.

I hope you enjoy it, I have also included a screenshot here:

Simulator Screen Shot - iPhone 14 Pro - 2023-01-04 at 17 13 30

@BenGWeeks
Copy link
Contributor

Nice :-)

@0xtlt 0xtlt changed the title Polls New feature: Polls Jan 5, 2023
@jb55
Copy link
Collaborator

jb55 commented Jan 5, 2023

interesting...

@jb55
Copy link
Collaborator

jb55 commented Jan 5, 2023

why not just make it a different kind? it feels wrong using reactions for this.

@jb55
Copy link
Collaborator

jb55 commented Jan 5, 2023

we don't need a NIP yet, we just can just choose something and spec it after

@jb55
Copy link
Collaborator

jb55 commented Jan 5, 2023

but if you want to go for it lol

@0xtlt
Copy link
Contributor Author

0xtlt commented Jan 5, 2023

agreed, go and we gonna support both in the future if poll nip is accepted @jb55

@0xtlt
Copy link
Contributor Author

0xtlt commented Jan 6, 2023

I added the code of the NIP 41, when it will be accepted, I will change again the code if needed it will be ready to be merged :)

@0xtlt
Copy link
Contributor Author

0xtlt commented Jan 6, 2023

NIP 41 ref: nostr-protocol/nips#148

@BenGWeeks
Copy link
Contributor

Would look cool with the linear gradient for the bars :-)

LinearGradient(gradient: Gradient(colors: [
    Color("DamusPurple"),
    Color("DamusBlue")
]), startPoint: .topTrailing, endPoint: .bottomTrailing)

@0xtlt
Copy link
Contributor Author

0xtlt commented Jan 9, 2023

Would look cool with the linear gradient for the bars :-)

LinearGradient(gradient: Gradient(colors: [
    Color("DamusPurple"),
    Color("DamusBlue")
]), startPoint: .topTrailing, endPoint: .bottomTrailing)

Will add it today, thanks :)

@BenGWeeks
Copy link
Contributor

What does the Ui look like whilst creating the poll?

@0xtlt
Copy link
Contributor Author

0xtlt commented Jan 9, 2023

simulator_screenshot_EF8E53E7-0C0D-4963-B9A2-656095C0DD71

@BenGWeeks

@BenGWeeks
Copy link
Contributor

With regards to the post button - was thinking better UX/UI would be to display but greyed out until created a message? (As apposed to hide, where I've thought to myself "if i write this message how will I be able to post it?")

@0xtlt
Copy link
Contributor Author

0xtlt commented Jan 9, 2023

With regards to the post button - was thinking better UX/UI would be to display but greyed out until created a message? (As apposed to hide, where I've thought to myself "if i write this message how will I be able to post it?")

Will add it too :)

@BenGWeeks
Copy link
Contributor

(That's generic to all posts)

@jb55
Copy link
Collaborator

jb55 commented Jan 10, 2023

this needs to be its own view instead of putting in eventview

damus/Views/EventView.swift Outdated Show resolved Hide resolved
let filtered_choices = choices.filter({ poll_results_everyone ? true : damus.contacts.is_in_friendosphere($0.0) })
let total_count = filtered_choices.count == 0 ? 1 : filtered_choices.count

VStack(alignment: .leading, spacing: 15) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be its own view

@@ -21,6 +21,10 @@ struct ConfigView: View {
@State var relays: [RelayDescriptor]
@EnvironmentObject var user_settings: UserSettingsStore

/// True = poll will display votes from everyone, false = poll will display votes from friends only (and friends of friends)
/// This option is included because of the potential problem with bots.
@AppStorage("poll_results_everyone") var poll_results_everyone: Bool = false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've never used AppStorage before. Does this just save it in UserSettings? I eventually want to scope user settings by pubkey so maybe its best to have it in there

Comment on lines +181 to +185
let likes_content = ["👍", "+", "🤙"]

if !likes_content.contains(ev.content) {
return
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this should be removed?



if displayPolls {
VStack(alignment: .leading, spacing: 15) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs its own view

@jb55
Copy link
Collaborator

jb55 commented Jul 31, 2023

closing this for now since it's pretty out of date

@jb55 jb55 closed this Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants