Browse Source

POC - Removing Participants on a Thread Reply

remove-participants
Joel Klabo 2 years ago
parent
commit
a0bc08779b
  1. 4
      damus.xcodeproj/project.pbxproj
  2. 53
      damus/Views/ParicipantsView.swift
  3. 17
      damus/Views/ReplyView.swift

4
damus.xcodeproj/project.pbxproj

@ -161,6 +161,7 @@
E990020F2955F837003BBC5A /* EditMetadataView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E990020E2955F837003BBC5A /* EditMetadataView.swift */; };
E9E4ED0B295867B900DD7078 /* ThreadV2View.swift in Sources */ = {isa = PBXBuildFile; fileRef = E9E4ED0A295867B900DD7078 /* ThreadV2View.swift */; };
F7F0BA25297892BD009531F3 /* SwipeToDismiss.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7F0BA24297892BD009531F3 /* SwipeToDismiss.swift */; };
F7F0BA272978E54D009531F3 /* ParicipantsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7F0BA262978E54D009531F3 /* ParicipantsView.swift */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@ -368,6 +369,7 @@
E990020E2955F837003BBC5A /* EditMetadataView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditMetadataView.swift; sourceTree = "<group>"; };
E9E4ED0A295867B900DD7078 /* ThreadV2View.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThreadV2View.swift; sourceTree = "<group>"; };
F7F0BA24297892BD009531F3 /* SwipeToDismiss.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwipeToDismiss.swift; sourceTree = "<group>"; };
F7F0BA262978E54D009531F3 /* ParicipantsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParicipantsView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -538,6 +540,7 @@
4C06670028FC7C5900038D2A /* RelayView.swift */,
4C0A3F94280F6C78000448DE /* ReplyQuoteView.swift */,
4CACA9D4280C31E100D9BBE8 /* ReplyView.swift */,
F7F0BA262978E54D009531F3 /* ParicipantsView.swift */,
4C285C8D28399BFD008A31F1 /* SaveKeysView.swift */,
4C3AC7A628369BA200E1F516 /* SearchHomeView.swift */,
4C5C7E69284EDE2E00A22DF5 /* SearchResultsView.swift */,
@ -900,6 +903,7 @@
4C0A3F8C280F5FCA000448DE /* ChatroomView.swift in Sources */,
4C477C9E282C3A4800033AA3 /* TipCounter.swift in Sources */,
647D9A8D2968520300A295DE /* SideMenuView.swift in Sources */,
F7F0BA272978E54D009531F3 /* ParicipantsView.swift in Sources */,
4C0A3F91280F6528000448DE /* ChatView.swift in Sources */,
4C216F362870A9A700040376 /* InputDismissKeyboard.swift in Sources */,
4C216F382871EDE300040376 /* DirectMessageModel.swift in Sources */,

53
damus/Views/ParicipantsView.swift

@ -0,0 +1,53 @@
//
// ParicipantsView.swift
// damus
//
// Created by Joel Klabo on 1/18/23.
//
import SwiftUI
struct ParticipantsView: View {
let damus: DamusState
@Binding var participants: [ReferencedId]
@Binding var originalParticipants: [ReferencedId]
var body: some View {
VStack {
ForEach(originalParticipants) { participant in
ParticipantView(damus: damus, participant: participant) { participant, added in
if added {
participants.append(participant)
} else {
participants = participants.filter { $0 != participant }
}
}
}
}
}
}
struct ParticipantView: View {
let damus: DamusState
let participant: ReferencedId
let onRemove: (ReferencedId, Bool) -> ()
@State var isParticipating: Bool = true
var body: some View {
HStack {
let pk = participant.ref_id
let prof = damus.profiles.lookup(id: pk)
Text(Profile.displayName(profile: prof, pubkey: pk))
Spacer()
Image(systemName: "checkmark.circle.fill")
.foregroundColor(isParticipating ? .purple : .gray)
}
.onTapGesture {
isParticipating.toggle()
onRemove(participant, isParticipating)
}
}
}

17
damus/Views/ReplyView.swift

@ -18,11 +18,14 @@ struct ReplyView: View {
let replying_to: NostrEvent
let damus: DamusState
@State var originalParticipants: [ReferencedId] = []
@State var participants: [ReferencedId] = []
var body: some View {
VStack {
Text("Replying to:", comment: "Indicating that the user is replying to the following listed people.")
HStack(alignment: .top) {
let names = all_referenced_pubkeys(replying_to)
let names = participants
.map { pubkey in
let pk = pubkey.ref_id
let prof = damus.profiles.lookup(id: pk)
@ -34,12 +37,16 @@ struct ReplyView: View {
.font(.footnote)
}
ScrollView {
EventView(event: replying_to, highlight: .none, has_action_bar: false, damus: damus, show_friend_icon: true)
EventView(event: replying_to, highlight: .none, has_action_bar: false, damus: damus, show_friend_icon: true)
ParticipantsView(damus: damus, participants: $participants, originalParticipants: $originalParticipants)
}
PostView(replying_to: replying_to, references: gather_reply_ids(our_pubkey: damus.pubkey, from: replying_to))
PostView(replying_to: replying_to, references: participants)
}
.onAppear {
participants = all_referenced_pubkeys(replying_to)
originalParticipants = participants
}
.padding()
}
@ -47,6 +54,6 @@ struct ReplyView: View {
struct ReplyView_Previews: PreviewProvider {
static var previews: some View {
ReplyView(replying_to: NostrEvent(content: "hi", pubkey: "pubkey"), damus: test_damus_state())
ReplyView(replying_to: NostrEvent(content: "hi", pubkey: "pubkey"), damus: test_damus_state(), participants: [])
}
}

Loading…
Cancel
Save