boosts: always register boost, add confirmation
Changelog-Added: Add boost confirmation alert Changelog-Fixed: Fixed boosts sometimes not registering after click Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
@@ -228,12 +228,6 @@ struct ContentView: View {
|
|||||||
self.active_sheet = .reply(ev)
|
self.active_sheet = .reply(ev)
|
||||||
}
|
}
|
||||||
.onReceive(handle_notify(.like)) { like in
|
.onReceive(handle_notify(.like)) { like in
|
||||||
guard let privkey = self.privkey else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
let ev = like.object as! NostrEvent
|
|
||||||
let like_ev = make_like_event(pubkey: pubkey, privkey: privkey, liked: ev)
|
|
||||||
self.damus_state?.pool.send(.event(like_ev))
|
|
||||||
}
|
}
|
||||||
.onReceive(handle_notify(.broadcast_event)) { obj in
|
.onReceive(handle_notify(.broadcast_event)) { obj in
|
||||||
let ev = obj.object as! NostrEvent
|
let ev = obj.object as! NostrEvent
|
||||||
|
|||||||
@@ -114,11 +114,7 @@ struct ChatView: View {
|
|||||||
|
|
||||||
if is_active || next_ev == nil || next_ev!.pubkey != event.pubkey {
|
if is_active || next_ev == nil || next_ev!.pubkey != event.pubkey {
|
||||||
let bar = make_actionbar_model(ev: event, damus: damus)
|
let bar = make_actionbar_model(ev: event, damus: damus)
|
||||||
EventActionBar(event: event,
|
EventActionBar(damus_state: damus, event: event, bar: bar)
|
||||||
keypair: damus.keypair,
|
|
||||||
profiles: damus.profiles,
|
|
||||||
bar: bar
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Spacer()
|
//Spacer()
|
||||||
|
|||||||
@@ -18,10 +18,10 @@ enum ActionBarSheet: Identifiable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct EventActionBar: View {
|
struct EventActionBar: View {
|
||||||
|
let damus_state: DamusState
|
||||||
let event: NostrEvent
|
let event: NostrEvent
|
||||||
let keypair: Keypair
|
|
||||||
@State var sheet: ActionBarSheet? = nil
|
@State var sheet: ActionBarSheet? = nil
|
||||||
let profiles: Profiles
|
@State var confirm_boost: Bool = false
|
||||||
@StateObject var bar: ActionBarModel
|
@StateObject var bar: ActionBarModel
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
@@ -34,7 +34,7 @@ struct EventActionBar: View {
|
|||||||
Spacer()
|
Spacer()
|
||||||
|
|
||||||
*/
|
*/
|
||||||
if keypair.privkey != nil {
|
if damus_state.keypair.privkey != nil {
|
||||||
EventActionButton(img: "bubble.left", col: nil) {
|
EventActionButton(img: "bubble.left", col: nil) {
|
||||||
notify(.reply, event)
|
notify(.reply, event)
|
||||||
}
|
}
|
||||||
@@ -49,7 +49,7 @@ struct EventActionBar: View {
|
|||||||
if bar.liked {
|
if bar.liked {
|
||||||
notify(.delete, bar.our_like)
|
notify(.delete, bar.our_like)
|
||||||
} else {
|
} else {
|
||||||
notify(.like, event)
|
send_like()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -63,7 +63,7 @@ struct EventActionBar: View {
|
|||||||
if bar.boosted {
|
if bar.boosted {
|
||||||
notify(.delete, bar.our_boost)
|
notify(.delete, bar.our_boost)
|
||||||
} else {
|
} else {
|
||||||
notify(.boost, event)
|
self.confirm_boost = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -83,17 +83,51 @@ struct EventActionBar: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.padding(.top, 1)
|
.padding(.top, 1)
|
||||||
|
.alert("Boost", isPresented: $confirm_boost) {
|
||||||
|
Button("Boost") {
|
||||||
|
send_boost()
|
||||||
|
}
|
||||||
|
Button("Cancel") {
|
||||||
|
confirm_boost = false
|
||||||
|
}
|
||||||
|
} message: {
|
||||||
|
Text("Are you sure you want to boost this post?")
|
||||||
|
}
|
||||||
.onReceive(handle_notify(.liked)) { n in
|
.onReceive(handle_notify(.liked)) { n in
|
||||||
let liked = n.object as! Counted
|
let liked = n.object as! Counted
|
||||||
if liked.id != event.id {
|
if liked.id != event.id {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
self.bar.likes = liked.total
|
self.bar.likes = liked.total
|
||||||
if liked.event.pubkey == keypair.pubkey {
|
if liked.event.pubkey == damus_state.keypair.pubkey {
|
||||||
self.bar.our_like = liked.event
|
self.bar.our_like = liked.event
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func send_boost() {
|
||||||
|
guard let privkey = self.damus_state.keypair.privkey else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let boost = make_boost_event(pubkey: damus_state.keypair.pubkey, privkey: privkey, boosted: self.event)
|
||||||
|
|
||||||
|
self.bar.our_boost = boost
|
||||||
|
|
||||||
|
damus_state.pool.send(.event(boost))
|
||||||
|
}
|
||||||
|
|
||||||
|
func send_like() {
|
||||||
|
guard let privkey = damus_state.keypair.privkey else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let like_ev = make_like_event(pubkey: damus_state.pubkey, privkey: privkey, liked: event)
|
||||||
|
|
||||||
|
self.bar.our_like = like_ev
|
||||||
|
|
||||||
|
damus_state.pool.send(.event(like_ev))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -110,10 +144,9 @@ func EventActionButton(img: String, col: Color?, action: @escaping () -> ()) ->
|
|||||||
struct EventActionBar_Previews: PreviewProvider {
|
struct EventActionBar_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
let pk = "pubkey"
|
let pk = "pubkey"
|
||||||
let kp = Keypair(pubkey: pk, privkey: nil)
|
|
||||||
let ds = test_damus_state()
|
let ds = test_damus_state()
|
||||||
let bar = ActionBarModel(likes: 0, boosts: 0, tips: 0, our_like: nil, our_boost: nil, our_tip: nil)
|
let bar = ActionBarModel(likes: 0, boosts: 0, tips: 0, our_like: nil, our_boost: nil, our_tip: nil)
|
||||||
let ev = NostrEvent(content: "hi", pubkey: pk)
|
let ev = NostrEvent(content: "hi", pubkey: pk)
|
||||||
EventActionBar(event: ev, keypair: kp, profiles: ds.profiles, bar: bar)
|
EventActionBar(damus_state: ds, event: ev, bar: bar)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ struct EventView: View {
|
|||||||
|
|
||||||
if has_action_bar {
|
if has_action_bar {
|
||||||
let bar = make_actionbar_model(ev: event, damus: damus)
|
let bar = make_actionbar_model(ev: event, damus: damus)
|
||||||
EventActionBar(event: event, keypair: damus.keypair, profiles: damus.profiles, bar: bar)
|
EventActionBar(damus_state: damus, event: event, bar: bar)
|
||||||
}
|
}
|
||||||
|
|
||||||
Divider()
|
Divider()
|
||||||
|
|||||||
Reference in New Issue
Block a user