Revert "Add screen to select individual relays when posting/broadcasting"
This reverts commit 04759107a2.
This commit is contained in:
@@ -28,14 +28,12 @@ enum Sheets: Identifiable {
|
||||
case post
|
||||
case report(ReportTarget)
|
||||
case reply(NostrEvent)
|
||||
case broadcast(NostrEvent)
|
||||
|
||||
var id: String {
|
||||
switch self {
|
||||
case .report: return "report"
|
||||
case .post: return "post"
|
||||
case .reply(let ev): return "reply-" + ev.id
|
||||
case .broadcast(let ev): return "broadcast-" + ev.id
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -300,8 +298,6 @@ struct ContentView: View {
|
||||
PostView(replying_to: nil, references: [], damus_state: damus_state!)
|
||||
case .reply(let event):
|
||||
ReplyView(replying_to: event, damus: damus_state!)
|
||||
case .broadcast(let event):
|
||||
BroadcastToRelaysView(state: .init(state: damus_state!), broadCastEvent: event)
|
||||
}
|
||||
}
|
||||
.onOpenURL { url in
|
||||
@@ -359,7 +355,7 @@ struct ContentView: View {
|
||||
}
|
||||
.onReceive(handle_notify(.broadcast_event)) { obj in
|
||||
let ev = obj.object as! NostrEvent
|
||||
self.active_sheet = .broadcast(ev)
|
||||
self.damus_state?.pool.send(.event(ev))
|
||||
}
|
||||
.onReceive(handle_notify(.unfollow)) { notif in
|
||||
guard let privkey = self.privkey else {
|
||||
@@ -419,10 +415,10 @@ struct ContentView: View {
|
||||
|
||||
let post_res = obj.object as! NostrPostResult
|
||||
switch post_res {
|
||||
case .post(let post, onlyToRelayIds: let relayIds):
|
||||
case .post(let post):
|
||||
print("post \(post.content)")
|
||||
let new_ev = post_to_event(post: post, privkey: privkey, pubkey: pubkey)
|
||||
self.damus_state?.pool.send(.event(new_ev), to: relayIds)
|
||||
self.damus_state?.pool.send(.event(new_ev))
|
||||
case .cancel:
|
||||
active_sheet = nil
|
||||
print("post cancelled")
|
||||
|
||||
@@ -7,14 +7,14 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct RelayInfo: Codable, Hashable {
|
||||
public struct RelayInfo: Codable {
|
||||
let read: Bool
|
||||
let write: Bool
|
||||
|
||||
static let rw = RelayInfo(read: true, write: true)
|
||||
}
|
||||
|
||||
public struct RelayDescriptor: Codable, Hashable {
|
||||
public struct RelayDescriptor: Codable {
|
||||
public let url: URL
|
||||
public let info: RelayInfo
|
||||
}
|
||||
|
||||
@@ -133,8 +133,8 @@ struct DMChatView: View {
|
||||
|
||||
message = ""
|
||||
|
||||
end_editing()
|
||||
damus_state.pool.send(.event(dm))
|
||||
end_editing()
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
|
||||
@@ -8,15 +8,13 @@
|
||||
import SwiftUI
|
||||
|
||||
enum NostrPostResult {
|
||||
case post(NostrPost, onlyToRelayIds: [String]?)
|
||||
case post(NostrPost)
|
||||
case cancel
|
||||
}
|
||||
|
||||
let POST_PLACEHOLDER = NSLocalizedString("Type your post here...", comment: "Text box prompt to ask user to type their post.")
|
||||
|
||||
struct PostView: View {
|
||||
@State var isPresentingRelaysScreen: Bool = false
|
||||
@StateObject var relaysScreenState: BroadcastToRelaysView.ViewState
|
||||
@State var post: String = ""
|
||||
@FocusState var focus: Bool
|
||||
@State var showPrivateKeyWarning: Bool = false
|
||||
@@ -27,14 +25,6 @@ struct PostView: View {
|
||||
|
||||
@Environment(\.presentationMode) var presentationMode
|
||||
|
||||
init(replying_to: NostrEvent?, references: [ReferencedId], damus_state: DamusState) {
|
||||
_relaysScreenState = StateObject(wrappedValue: BroadcastToRelaysView.ViewState(state: damus_state))
|
||||
|
||||
self.replying_to = replying_to
|
||||
self.references = references
|
||||
self.damus_state = damus_state
|
||||
}
|
||||
|
||||
enum FocusField: Hashable {
|
||||
case post
|
||||
}
|
||||
@@ -56,9 +46,7 @@ struct PostView: View {
|
||||
let content = self.post.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
|
||||
let new_post = NostrPost(content: content, references: references, kind: kind)
|
||||
|
||||
NotificationCenter.default.post(name: .post,
|
||||
object: NostrPostResult.post(new_post,
|
||||
onlyToRelayIds: relaysScreenState.limitingRelayIds))
|
||||
NotificationCenter.default.post(name: .post, object: NostrPostResult.post(new_post))
|
||||
dismiss()
|
||||
}
|
||||
|
||||
@@ -67,55 +55,16 @@ struct PostView: View {
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
VStack {
|
||||
ZStack(alignment: .topLeading) {
|
||||
TextEditor(text: $post)
|
||||
.focused($focus)
|
||||
.textInputAutocapitalization(.sentences)
|
||||
|
||||
if post.isEmpty {
|
||||
Text(POST_PLACEHOLDER)
|
||||
.padding(.top, 8)
|
||||
.padding(.leading, 4)
|
||||
.foregroundColor(Color(uiColor: .placeholderText))
|
||||
.allowsHitTesting(false)
|
||||
}
|
||||
VStack {
|
||||
HStack {
|
||||
Button(NSLocalizedString("Cancel", comment: "Button to cancel out of posting a note.")) {
|
||||
self.cancel()
|
||||
}
|
||||
|
||||
// This if-block observes @ for tagging
|
||||
if let searching = get_searching_string(post) {
|
||||
VStack {
|
||||
Spacer()
|
||||
UserSearch(damus_state: damus_state, search: searching, post: $post)
|
||||
}.zIndex(1)
|
||||
}
|
||||
}
|
||||
.onAppear() {
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
||||
self.focus = true
|
||||
}
|
||||
}
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .navigationBarLeading) {
|
||||
Button(NSLocalizedString("Cancel", comment: "Button to cancel out of posting a note.")) {
|
||||
self.cancel()
|
||||
}
|
||||
.foregroundColor(.primary)
|
||||
}
|
||||
ToolbarItemGroup(placement: .navigationBarTrailing) {
|
||||
HStack {
|
||||
Button(action: { isPresentingRelaysScreen.toggle() }) {
|
||||
Image(systemName: "network")
|
||||
.foregroundColor(.primary)
|
||||
.overlay {
|
||||
if relaysScreenState.hasExcludedRelays {
|
||||
Circle()
|
||||
.stroke(style: StrokeStyle(lineWidth: 2, lineCap: .round, dash: [8, 5]))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.foregroundColor(.primary)
|
||||
|
||||
Spacer()
|
||||
|
||||
if !is_post_empty {
|
||||
Button(NSLocalizedString("Post", comment: "Button to post a note.")) {
|
||||
showPrivateKeyWarning = contentContainsPrivateKey(self.post)
|
||||
|
||||
@@ -123,13 +72,31 @@ struct PostView: View {
|
||||
self.send_post()
|
||||
}
|
||||
}
|
||||
.disabled(is_post_empty)
|
||||
}
|
||||
}
|
||||
.sheet(isPresented: $isPresentingRelaysScreen, content: {
|
||||
BroadcastToRelaysView(state: relaysScreenState, broadCastEvent: nil)
|
||||
})
|
||||
.padding()
|
||||
.padding([.top, .bottom], 4)
|
||||
|
||||
ZStack(alignment: .topLeading) {
|
||||
TextEditor(text: $post)
|
||||
.focused($focus)
|
||||
.textInputAutocapitalization(.sentences)
|
||||
|
||||
if post.isEmpty {
|
||||
Text(POST_PLACEHOLDER)
|
||||
.padding(.top, 8)
|
||||
.padding(.leading, 4)
|
||||
.foregroundColor(Color(uiColor: .placeholderText))
|
||||
.allowsHitTesting(false)
|
||||
}
|
||||
}
|
||||
|
||||
// This if-block observes @ for tagging
|
||||
if let searching = get_searching_string(post) {
|
||||
VStack {
|
||||
Spacer()
|
||||
UserSearch(damus_state: damus_state, search: searching, post: $post)
|
||||
}.zIndex(1)
|
||||
}
|
||||
}
|
||||
.onAppear() {
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
|
||||
|
||||
@@ -1,123 +0,0 @@
|
||||
//
|
||||
// BroadcastToRelaysView.swift
|
||||
// damus
|
||||
//
|
||||
// Created by devandsev on 2/4/23.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
extension BroadcastToRelaysView {
|
||||
|
||||
class ViewState: ObservableObject {
|
||||
let damusState: DamusState
|
||||
@Published var relayRows: [RowState] = []
|
||||
|
||||
var hasExcludedRelays: Bool { relayRows.contains { !$0.isSelected } }
|
||||
var selectedRelays: [RelayDescriptor] { relayRows.filter { $0.isSelected }.map { $0.relay } }
|
||||
var limitingRelayIds: [String]? {
|
||||
guard hasExcludedRelays else {
|
||||
return nil
|
||||
}
|
||||
return selectedRelays.map { get_relay_id($0.url) }
|
||||
}
|
||||
|
||||
init(state: DamusState) {
|
||||
damusState = state
|
||||
relayRows = state.pool.descriptors.map { RowState(relay: $0, isSelected: true) }
|
||||
}
|
||||
}
|
||||
|
||||
struct RowState: Equatable {
|
||||
let relay: RelayDescriptor
|
||||
var isSelected: Bool
|
||||
}
|
||||
}
|
||||
|
||||
/// A list of relays you can select to send your event to
|
||||
///
|
||||
/// Can be presented in 2 modes:
|
||||
/// - If `broadCastEvent` is nil, user selects relays, goes to the previous screen and the post/reply will be sent to selected relays only. Presented in this mode from `PostView` and `ReplyView` by tapping relays button.
|
||||
/// - If `broadCastEvent` is not nil, there will be a "Broadcast" button in the navBar to broadcast this event to selected relays. Presented in this mode by long-pressing a post and choosing "Broadcast".
|
||||
struct BroadcastToRelaysView: View {
|
||||
@ObservedObject var state: ViewState
|
||||
|
||||
let broadCastEvent: NostrEvent?
|
||||
|
||||
@Environment(\.presentationMode) var presentationMode
|
||||
|
||||
func selectAll() {
|
||||
$state.relayRows.forEach { $0.wrappedValue.isSelected = true }
|
||||
}
|
||||
|
||||
func selectOne() {
|
||||
guard let firstSelectedRow = $state.relayRows.first(where: { $0.wrappedValue.isSelected }) else {
|
||||
$state.relayRows.forEach { $0.wrappedValue.isSelected = false }
|
||||
$state.relayRows.first?.wrappedValue.isSelected = true
|
||||
return
|
||||
}
|
||||
|
||||
$state.relayRows.forEach { $0.wrappedValue.isSelected = false }
|
||||
firstSelectedRow.wrappedValue.isSelected = true
|
||||
}
|
||||
|
||||
func dismiss() {
|
||||
self.presentationMode.wrappedValue.dismiss()
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
Form {
|
||||
Section {
|
||||
List(Array($state.relayRows), id: \.wrappedValue.relay.url) { $relayRow in
|
||||
SelectableRowView(isSelected: $relayRow.isSelected,
|
||||
shouldChangeSelection: {
|
||||
return !relayRow.isSelected || $state.relayRows.filter { $0.wrappedValue.isSelected }.count > 1
|
||||
|
||||
} ) {
|
||||
RelayView(state: state.damusState, relay: relayRow.relay.url.absoluteString)
|
||||
}
|
||||
}
|
||||
}
|
||||
header: {
|
||||
HStack {
|
||||
Text("Relays to send to", comment: "Section header text for relay server list. On this screen user can select to which specific relays the post should be sent.")
|
||||
Spacer()
|
||||
Button(NSLocalizedString("All", comment: "Button to select all relays in the list to which the post will be sent")) {
|
||||
self.selectAll()
|
||||
}
|
||||
.disabled(!state.hasExcludedRelays)
|
||||
Button(NSLocalizedString("One", comment: "Button to select only one relay from the list to which the post will be sent")) {
|
||||
self.selectOne()
|
||||
}
|
||||
.disabled(state.selectedRelays.count == 1)
|
||||
}
|
||||
.buttonStyle(.bordered)
|
||||
}
|
||||
}
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .navigationBarLeading) {
|
||||
if broadCastEvent != nil {
|
||||
Button(action: {
|
||||
dismiss()
|
||||
}) {
|
||||
Text("Cancel", comment: "Navigation bar button to cancel broadcasting the user's note to all of the user's connected relay servers.")
|
||||
}.foregroundColor(.primary)
|
||||
}
|
||||
}
|
||||
ToolbarItem(placement: .navigationBarTrailing) {
|
||||
if broadCastEvent != nil {
|
||||
Button(action: {
|
||||
if let broadCastEvent = broadCastEvent {
|
||||
state.damusState.pool.send(.event(broadCastEvent), to: state.limitingRelayIds)
|
||||
dismiss()
|
||||
}
|
||||
}) {
|
||||
Text("Broadcast", comment: "Navigation bar button to confirm broadcasting the user's note to all of the user's connected relay servers.")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
//
|
||||
// File.swift
|
||||
// damus
|
||||
//
|
||||
// Created by devandsev on 2/4/23.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct SelectableRowView <Content: View>: View {
|
||||
|
||||
@Binding var isSelected: Bool
|
||||
var shouldChangeSelection: () -> Bool
|
||||
var content: () -> Content
|
||||
|
||||
@available(iOS, deprecated: 16, message: "In iOS 15 List rows selection works only in editing mode; with iOS 16 selection doesn't require Edit button at all. Consider using standard selection mechanism when deployment target is iOS 16")
|
||||
init(isSelected: Binding<Bool>, shouldChangeSelection: @escaping () -> Bool = { true }, @ViewBuilder content: @escaping () -> Content) {
|
||||
_isSelected = isSelected
|
||||
self.shouldChangeSelection = shouldChangeSelection
|
||||
self.content = content
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
content()
|
||||
Spacer()
|
||||
Image(systemName: isSelected ? "checkmark.circle.fill" : "circle")
|
||||
}
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture {
|
||||
if shouldChangeSelection() {
|
||||
isSelected.toggle()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user