Merge branch 'master' into improve-wallet-selector
This commit is contained in:
16
CHANGELOG.md
16
CHANGELOG.md
@@ -1,3 +1,18 @@
|
|||||||
|
## [0.1.8-9] - 2022-12-29
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Show recommended relays in config. Currently just a fixed set. (William Casarin)
|
||||||
|
- Ensure contact relay list is kept in sync with internal relay pool (William Casarin)
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fixed issue where contact list would sometimes revert to an older version (William Casarin)
|
||||||
|
- Don't show boosts in threads (Thomas)
|
||||||
|
|
||||||
|
|
||||||
|
[0.1.8-9]: https://github.com/damus-io/damus/releases/tag/v0.1.8-9
|
||||||
|
|
||||||
## [0.1.8-6] - 2022-12-28
|
## [0.1.8-6] - 2022-12-28
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
@@ -218,4 +233,3 @@
|
|||||||
|
|
||||||
[0.1.2]: https://github.com/damus-io/damus/releases/tag/v0.1.2
|
[0.1.2]: https://github.com/damus-io/damus/releases/tag/v0.1.2
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -109,6 +109,8 @@
|
|||||||
4CA2EFA0280E37AC0044ACD8 /* TimelineView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CA2EF9F280E37AC0044ACD8 /* TimelineView.swift */; };
|
4CA2EFA0280E37AC0044ACD8 /* TimelineView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CA2EF9F280E37AC0044ACD8 /* TimelineView.swift */; };
|
||||||
4CACA9D5280C31E100D9BBE8 /* ReplyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CACA9D4280C31E100D9BBE8 /* ReplyView.swift */; };
|
4CACA9D5280C31E100D9BBE8 /* ReplyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CACA9D4280C31E100D9BBE8 /* ReplyView.swift */; };
|
||||||
4CACA9DC280C38C000D9BBE8 /* Profiles.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CACA9DB280C38C000D9BBE8 /* Profiles.swift */; };
|
4CACA9DC280C38C000D9BBE8 /* Profiles.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CACA9DB280C38C000D9BBE8 /* Profiles.swift */; };
|
||||||
|
4CB55EF3295E5D59007FD187 /* RecommendedRelayView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CB55EF2295E5D59007FD187 /* RecommendedRelayView.swift */; };
|
||||||
|
4CB55EF5295E679D007FD187 /* UserRelaysView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CB55EF4295E679D007FD187 /* UserRelaysView.swift */; };
|
||||||
4CD7641B28A1641400B6928F /* EndBlock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CD7641A28A1641400B6928F /* EndBlock.swift */; };
|
4CD7641B28A1641400B6928F /* EndBlock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CD7641A28A1641400B6928F /* EndBlock.swift */; };
|
||||||
4CE4F8CD281352B30009DFBB /* Notifications.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE4F8CC281352B30009DFBB /* Notifications.swift */; };
|
4CE4F8CD281352B30009DFBB /* Notifications.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE4F8CC281352B30009DFBB /* Notifications.swift */; };
|
||||||
4CE4F9DE2852768D00C00DD9 /* ConfigView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE4F9DD2852768D00C00DD9 /* ConfigView.swift */; };
|
4CE4F9DE2852768D00C00DD9 /* ConfigView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE4F9DD2852768D00C00DD9 /* ConfigView.swift */; };
|
||||||
@@ -290,6 +292,8 @@
|
|||||||
4CA2EF9F280E37AC0044ACD8 /* TimelineView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineView.swift; sourceTree = "<group>"; };
|
4CA2EF9F280E37AC0044ACD8 /* TimelineView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineView.swift; sourceTree = "<group>"; };
|
||||||
4CACA9D4280C31E100D9BBE8 /* ReplyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReplyView.swift; sourceTree = "<group>"; };
|
4CACA9D4280C31E100D9BBE8 /* ReplyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReplyView.swift; sourceTree = "<group>"; };
|
||||||
4CACA9DB280C38C000D9BBE8 /* Profiles.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Profiles.swift; sourceTree = "<group>"; };
|
4CACA9DB280C38C000D9BBE8 /* Profiles.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Profiles.swift; sourceTree = "<group>"; };
|
||||||
|
4CB55EF2295E5D59007FD187 /* RecommendedRelayView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecommendedRelayView.swift; sourceTree = "<group>"; };
|
||||||
|
4CB55EF4295E679D007FD187 /* UserRelaysView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserRelaysView.swift; sourceTree = "<group>"; };
|
||||||
4CD7641A28A1641400B6928F /* EndBlock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EndBlock.swift; sourceTree = "<group>"; };
|
4CD7641A28A1641400B6928F /* EndBlock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EndBlock.swift; sourceTree = "<group>"; };
|
||||||
4CE4F8CC281352B30009DFBB /* Notifications.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Notifications.swift; sourceTree = "<group>"; };
|
4CE4F8CC281352B30009DFBB /* Notifications.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Notifications.swift; sourceTree = "<group>"; };
|
||||||
4CE4F9DD2852768D00C00DD9 /* ConfigView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigView.swift; sourceTree = "<group>"; };
|
4CE4F9DD2852768D00C00DD9 /* ConfigView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigView.swift; sourceTree = "<group>"; };
|
||||||
@@ -492,6 +496,8 @@
|
|||||||
E990020E2955F837003BBC5A /* EditMetadataView.swift */,
|
E990020E2955F837003BBC5A /* EditMetadataView.swift */,
|
||||||
BAB68BEC29543FA3007BA466 /* SelectWalletView.swift */,
|
BAB68BEC29543FA3007BA466 /* SelectWalletView.swift */,
|
||||||
E9E4ED0A295867B900DD7078 /* ThreadV2View.swift */,
|
E9E4ED0A295867B900DD7078 /* ThreadV2View.swift */,
|
||||||
|
4CB55EF2295E5D59007FD187 /* RecommendedRelayView.swift */,
|
||||||
|
4CB55EF4295E679D007FD187 /* UserRelaysView.swift */,
|
||||||
);
|
);
|
||||||
path = Views;
|
path = Views;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@@ -784,6 +790,7 @@
|
|||||||
4CE6DEE927F7A08100C66700 /* ContentView.swift in Sources */,
|
4CE6DEE927F7A08100C66700 /* ContentView.swift in Sources */,
|
||||||
4CEE2AF5280B29E600AB5EEF /* TimeAgo.swift in Sources */,
|
4CEE2AF5280B29E600AB5EEF /* TimeAgo.swift in Sources */,
|
||||||
4C75EFAD28049CFB0006080F /* PostButton.swift in Sources */,
|
4C75EFAD28049CFB0006080F /* PostButton.swift in Sources */,
|
||||||
|
4CB55EF5295E679D007FD187 /* UserRelaysView.swift in Sources */,
|
||||||
4C363AA228296A7E006E126D /* SearchView.swift in Sources */,
|
4C363AA228296A7E006E126D /* SearchView.swift in Sources */,
|
||||||
4C285C8A2838B985008A31F1 /* ProfilePictureSelector.swift in Sources */,
|
4C285C8A2838B985008A31F1 /* ProfilePictureSelector.swift in Sources */,
|
||||||
4C75EFB92804A2740006080F /* EventView.swift in Sources */,
|
4C75EFB92804A2740006080F /* EventView.swift in Sources */,
|
||||||
@@ -867,6 +874,7 @@
|
|||||||
4C3BEFDA281DCA1400B3DE84 /* LikeCounter.swift in Sources */,
|
4C3BEFDA281DCA1400B3DE84 /* LikeCounter.swift in Sources */,
|
||||||
4C3AC79B28306D7B00E1F516 /* Contacts.swift in Sources */,
|
4C3AC79B28306D7B00E1F516 /* Contacts.swift in Sources */,
|
||||||
4C3EA63D28FF52D600C48A62 /* bolt11.c in Sources */,
|
4C3EA63D28FF52D600C48A62 /* bolt11.c in Sources */,
|
||||||
|
4CB55EF3295E5D59007FD187 /* RecommendedRelayView.swift in Sources */,
|
||||||
4C5F9118283D88E40052CD1C /* FollowingModel.swift in Sources */,
|
4C5F9118283D88E40052CD1C /* FollowingModel.swift in Sources */,
|
||||||
4C3EA67D28FFBBA300C48A62 /* InvoicesView.swift in Sources */,
|
4C3EA67D28FFBBA300C48A62 /* InvoicesView.swift in Sources */,
|
||||||
4C363A8E28236FE4006E126D /* NoteContentView.swift in Sources */,
|
4C363A8E28236FE4006E126D /* NoteContentView.swift in Sources */,
|
||||||
@@ -1047,7 +1055,7 @@
|
|||||||
CLANG_ENABLE_MODULES = YES;
|
CLANG_ENABLE_MODULES = YES;
|
||||||
CODE_SIGN_ENTITLEMENTS = damus/damus.entitlements;
|
CODE_SIGN_ENTITLEMENTS = damus/damus.entitlements;
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 7;
|
CURRENT_PROJECT_VERSION = 9;
|
||||||
DEVELOPMENT_ASSET_PATHS = "\"damus/Preview Content\"";
|
DEVELOPMENT_ASSET_PATHS = "\"damus/Preview Content\"";
|
||||||
DEVELOPMENT_TEAM = XK7H4JAB3D;
|
DEVELOPMENT_TEAM = XK7H4JAB3D;
|
||||||
ENABLE_PREVIEWS = YES;
|
ENABLE_PREVIEWS = YES;
|
||||||
@@ -1086,7 +1094,7 @@
|
|||||||
CLANG_ENABLE_MODULES = YES;
|
CLANG_ENABLE_MODULES = YES;
|
||||||
CODE_SIGN_ENTITLEMENTS = damus/damus.entitlements;
|
CODE_SIGN_ENTITLEMENTS = damus/damus.entitlements;
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 7;
|
CURRENT_PROJECT_VERSION = 9;
|
||||||
DEVELOPMENT_ASSET_PATHS = "\"damus/Preview Content\"";
|
DEVELOPMENT_ASSET_PATHS = "\"damus/Preview Content\"";
|
||||||
DEVELOPMENT_TEAM = XK7H4JAB3D;
|
DEVELOPMENT_TEAM = XK7H4JAB3D;
|
||||||
ENABLE_PREVIEWS = YES;
|
ENABLE_PREVIEWS = YES;
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ struct InvoicesView: View {
|
|||||||
.id(invoice.string)
|
.id(invoice.string)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.frame(height: 200)
|
.frame(height: 240)
|
||||||
.tabViewStyle(PageTabViewStyle())
|
.tabViewStyle(PageTabViewStyle())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -31,5 +31,6 @@ struct InvoicesView: View {
|
|||||||
struct InvoicesView_Previews: PreviewProvider {
|
struct InvoicesView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
InvoicesView(invoices: [Invoice.init(description: "description", amount: 10000, string: "invstr", expiry: 100000, payment_hash: Data(), created_at: 1000000)])
|
InvoicesView(invoices: [Invoice.init(description: "description", amount: 10000, string: "invstr", expiry: 100000, payment_hash: Data(), created_at: 1000000)])
|
||||||
|
.frame(width: 300)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,10 @@ var BOOTSTRAP_RELAYS = [
|
|||||||
"wss://relay.damus.io",
|
"wss://relay.damus.io",
|
||||||
"wss://nostr-relay.wlvs.space",
|
"wss://nostr-relay.wlvs.space",
|
||||||
"wss://nostr.fmt.wiz.biz",
|
"wss://nostr.fmt.wiz.biz",
|
||||||
|
"wss://relay.nostr.bg",
|
||||||
"wss://nostr.oxtr.dev",
|
"wss://nostr.oxtr.dev",
|
||||||
|
"wss://nostr.v0l.io",
|
||||||
|
"wss://nostr-2.zebedee.cloud",
|
||||||
]
|
]
|
||||||
|
|
||||||
struct TimestampedProfile {
|
struct TimestampedProfile {
|
||||||
@@ -229,7 +232,7 @@ struct ContentView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TabBar(new_events: $home.new_events, selected: $selected_timeline, action: switch_timeline)
|
TabBar(new_events: $home.new_events, selected: $selected_timeline, action: switch_timeline)
|
||||||
.padding()
|
.padding([.bottom], 8)
|
||||||
}
|
}
|
||||||
.onAppear() {
|
.onAppear() {
|
||||||
self.connect()
|
self.connect()
|
||||||
|
|||||||
@@ -139,16 +139,12 @@ func decode_json_relays(_ content: String) -> [String: RelayInfo]? {
|
|||||||
return decode_json(content)
|
return decode_json(content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func remove_relay(ev: NostrEvent, privkey: String, relay: String) -> NostrEvent? {
|
func remove_relay(ev: NostrEvent, current_relays: [RelayDescriptor], privkey: String, relay: String) -> NostrEvent? {
|
||||||
let damus_relay = RelayDescriptor(url: URL(string: "wss://relay.damus.io")!, info: .rw)
|
var relays = ensure_relay_info(relays: current_relays, content: ev.content)
|
||||||
|
|
||||||
var relays = ensure_relay_info(relays: [damus_relay], content: ev.content)
|
|
||||||
guard relays.index(forKey: relay) != nil else {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
relays.removeValue(forKey: relay)
|
relays.removeValue(forKey: relay)
|
||||||
|
|
||||||
|
print("remove_relay \(relays)")
|
||||||
guard let content = encode_json(relays) else {
|
guard let content = encode_json(relays) else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -159,10 +155,9 @@ func remove_relay(ev: NostrEvent, privkey: String, relay: String) -> NostrEvent?
|
|||||||
return new_ev
|
return new_ev
|
||||||
}
|
}
|
||||||
|
|
||||||
func add_relay(ev: NostrEvent, privkey: String, relay: String, info: RelayInfo) -> NostrEvent? {
|
func add_relay(ev: NostrEvent, privkey: String, current_relays: [RelayDescriptor], relay: String, info: RelayInfo) -> NostrEvent? {
|
||||||
let damus_relay = RelayDescriptor(url: URL(string: "wss://relay.damus.io")!, info: .rw)
|
var relays = ensure_relay_info(relays: current_relays, content: ev.content)
|
||||||
|
|
||||||
var relays = ensure_relay_info(relays: [damus_relay], content: ev.content)
|
|
||||||
guard relays.index(forKey: relay) == nil else {
|
guard relays.index(forKey: relay) == nil else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -260,6 +260,9 @@ class HomeModel: ObservableObject {
|
|||||||
|
|
||||||
var contacts_filter = NostrFilter.filter_kinds([0])
|
var contacts_filter = NostrFilter.filter_kinds([0])
|
||||||
contacts_filter.authors = friends
|
contacts_filter.authors = friends
|
||||||
|
|
||||||
|
var our_contacts_filter = NostrFilter.filter_kinds([3, 0])
|
||||||
|
our_contacts_filter.authors = [damus_state.pubkey]
|
||||||
|
|
||||||
var dms_filter = NostrFilter.filter_kinds([
|
var dms_filter = NostrFilter.filter_kinds([
|
||||||
NostrKind.dm.rawValue,
|
NostrKind.dm.rawValue,
|
||||||
@@ -297,7 +300,7 @@ class HomeModel: ObservableObject {
|
|||||||
|
|
||||||
var home_filters = [home_filter]
|
var home_filters = [home_filter]
|
||||||
var notifications_filters = [notifications_filter]
|
var notifications_filters = [notifications_filter]
|
||||||
var contacts_filters = [contacts_filter]
|
var contacts_filters = [contacts_filter, our_contacts_filter]
|
||||||
var dms_filters = [dms_filter, our_dms_filter]
|
var dms_filters = [dms_filter, our_dms_filter]
|
||||||
|
|
||||||
let last_of_kind = relay_id.flatMap { last_event_of_kind[$0] } ?? [:]
|
let last_of_kind = relay_id.flatMap { last_event_of_kind[$0] } ?? [:]
|
||||||
@@ -443,18 +446,33 @@ func add_contact_if_friend(contacts: Contacts, ev: NostrEvent) {
|
|||||||
contacts.add_friend_contact(ev)
|
contacts.add_friend_contact(ev)
|
||||||
}
|
}
|
||||||
|
|
||||||
func load_our_contacts(contacts: Contacts, our_pubkey: String, ev: NostrEvent) {
|
func load_our_contacts(contacts: Contacts, our_pubkey: String, m_old_ev: NostrEvent?, ev: NostrEvent) {
|
||||||
guard ev.pubkey == our_pubkey else {
|
var new_pks = Set<String>()
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
contacts.event = ev
|
|
||||||
|
|
||||||
// our contacts
|
// our contacts
|
||||||
for tag in ev.tags {
|
for tag in ev.tags {
|
||||||
if tag.count > 1 && tag[0] == "p" {
|
if tag.count >= 2 && tag[0] == "p" {
|
||||||
// TODO: validate pubkey?
|
new_pks.insert(tag[1])
|
||||||
contacts.add_friend_pubkey(tag[1])
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var old_pks = Set<String>()
|
||||||
|
// find removed contacts
|
||||||
|
if let old_ev = m_old_ev {
|
||||||
|
for tag in old_ev.tags {
|
||||||
|
if tag.count >= 2 && tag[0] == "p" {
|
||||||
|
old_pks.insert(tag[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let diff = new_pks.symmetricDifference(old_pks)
|
||||||
|
for pk in diff {
|
||||||
|
if new_pks.contains(pk) {
|
||||||
|
notify(.followed, pk)
|
||||||
|
contacts.add_friend_pubkey(pk)
|
||||||
|
} else {
|
||||||
|
notify(.unfollowed, pk)
|
||||||
|
contacts.remove_friend(pk)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -540,51 +558,68 @@ func robohash(_ pk: String) -> String {
|
|||||||
return "https://robohash.org/" + pk
|
return "https://robohash.org/" + pk
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func load_our_stuff(pool: RelayPool, contacts: Contacts, pubkey: String, ev: NostrEvent) {
|
||||||
|
guard ev.pubkey == pubkey else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// only use new stuff
|
||||||
|
if let current_ev = contacts.event {
|
||||||
|
guard ev.created_at > current_ev.created_at else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let m_old_ev = contacts.event
|
||||||
|
contacts.event = ev
|
||||||
|
|
||||||
|
load_our_contacts(contacts: contacts, our_pubkey: pubkey, m_old_ev: m_old_ev, ev: ev)
|
||||||
|
load_our_relays(contacts: contacts, our_pubkey: pubkey, pool: pool, m_old_ev: m_old_ev, ev: ev)
|
||||||
|
}
|
||||||
|
|
||||||
func process_contact_event(pool: RelayPool, contacts: Contacts, pubkey: String, ev: NostrEvent) {
|
func process_contact_event(pool: RelayPool, contacts: Contacts, pubkey: String, ev: NostrEvent) {
|
||||||
load_our_contacts(contacts: contacts, our_pubkey: pubkey, ev: ev)
|
load_our_stuff(pool: pool, contacts: contacts, pubkey: pubkey, ev: ev)
|
||||||
load_our_relays(our_pubkey: pubkey, pool: pool, ev: ev)
|
|
||||||
add_contact_if_friend(contacts: contacts, ev: ev)
|
add_contact_if_friend(contacts: contacts, ev: ev)
|
||||||
}
|
}
|
||||||
|
|
||||||
func load_our_relays(our_pubkey: String, pool: RelayPool, ev: NostrEvent) {
|
func load_our_relays(contacts: Contacts, our_pubkey: String, pool: RelayPool, m_old_ev: NostrEvent?, ev: NostrEvent) {
|
||||||
guard ev.pubkey == our_pubkey else {
|
let bootstrap_dict: [String: RelayInfo] = [:]
|
||||||
return
|
let old_decoded = m_old_ev.flatMap { decode_json_relays($0.content) } ?? BOOTSTRAP_RELAYS.reduce(into: bootstrap_dict) { (d, r) in
|
||||||
|
d[r] = .rw
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let decoded = decode_json_relays(ev.content) else {
|
guard let decoded = decode_json_relays(ev.content) else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var changed = false
|
||||||
|
|
||||||
|
var new = Set<String>()
|
||||||
for key in decoded.keys {
|
for key in decoded.keys {
|
||||||
if let url = URL(string: key) {
|
new.insert(key)
|
||||||
if let _ = try? pool.add_relay(url, info: decoded[key]!) {
|
}
|
||||||
pool.connect(to: [key])
|
|
||||||
|
var old = Set<String>()
|
||||||
|
for key in old_decoded.keys {
|
||||||
|
old.insert(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
let diff = old.symmetricDifference(new)
|
||||||
|
|
||||||
|
for d in diff {
|
||||||
|
changed = true
|
||||||
|
if new.contains(d) {
|
||||||
|
if let url = URL(string: d) {
|
||||||
|
try? pool.add_relay(url, info: decoded[d] ?? .rw)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
pool.remove_relay(d)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if changed {
|
||||||
|
notify(.relays_changed, ())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func remove_bootstrap_nodes(_ damus_state: DamusState) {
|
|
||||||
guard let contacts = damus_state.contacts.event else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
guard let relays = decode_json_relays(contacts.content) else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
let descriptors = relays.reduce(into: []) { arr, kv in
|
|
||||||
guard let url = URL(string: kv.key) else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
arr.append(RelayDescriptor(url: url, info: kv.value))
|
|
||||||
}
|
|
||||||
|
|
||||||
for relay in BOOTSTRAP_RELAYS {
|
|
||||||
if !(descriptors.contains { ($0 as! RelayDescriptor).url.absoluteString == relay }) {
|
|
||||||
damus_state.pool.remove_relay(relay)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ class ProfileModel: ObservableObject, Equatable {
|
|||||||
@Published var events: [NostrEvent] = []
|
@Published var events: [NostrEvent] = []
|
||||||
@Published var contacts: NostrEvent? = nil
|
@Published var contacts: NostrEvent? = nil
|
||||||
@Published var following: Int = 0
|
@Published var following: Int = 0
|
||||||
|
@Published var relays: [String: RelayInfo]? = nil
|
||||||
|
|
||||||
let pubkey: String
|
let pubkey: String
|
||||||
let damus: DamusState
|
let damus: DamusState
|
||||||
@@ -71,6 +72,7 @@ class ProfileModel: ObservableObject, Equatable {
|
|||||||
func handle_profile_contact_event(_ ev: NostrEvent) {
|
func handle_profile_contact_event(_ ev: NostrEvent) {
|
||||||
self.contacts = ev
|
self.contacts = ev
|
||||||
self.following = count_pubkeys(ev.tags)
|
self.following = count_pubkeys(ev.tags)
|
||||||
|
self.relays = decode_json_relays(ev.content)
|
||||||
if damus.contacts.is_friend(ev.pubkey) {
|
if damus.contacts.is_friend(ev.pubkey) {
|
||||||
self.damus.contacts.add_friend_contact(ev)
|
self.damus.contacts.add_friend_contact(ev)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,12 +28,14 @@ class Relay: Identifiable {
|
|||||||
let descriptor: RelayDescriptor
|
let descriptor: RelayDescriptor
|
||||||
let connection: RelayConnection
|
let connection: RelayConnection
|
||||||
|
|
||||||
|
var last_pong: UInt32
|
||||||
var flags: Int
|
var flags: Int
|
||||||
|
|
||||||
init(descriptor: RelayDescriptor, connection: RelayConnection) {
|
init(descriptor: RelayDescriptor, connection: RelayConnection) {
|
||||||
self.flags = 0
|
self.flags = 0
|
||||||
self.descriptor = descriptor
|
self.descriptor = descriptor
|
||||||
self.connection = connection
|
self.connection = connection
|
||||||
|
self.last_pong = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func mark_broken() {
|
func mark_broken() {
|
||||||
|
|||||||
@@ -179,8 +179,23 @@ class RelayPool {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func record_last_pong(relay_id: String, event: NostrConnectionEvent) {
|
||||||
|
if case .ws_event(let ws_event) = event {
|
||||||
|
if case .pong = ws_event {
|
||||||
|
for relay in relays {
|
||||||
|
if relay.id == relay_id {
|
||||||
|
relay.last_pong = UInt32(Date.now.timeIntervalSince1970)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func handle_event(relay_id: String, event: NostrConnectionEvent) {
|
func handle_event(relay_id: String, event: NostrConnectionEvent) {
|
||||||
|
record_last_pong(relay_id: relay_id, event: event)
|
||||||
|
|
||||||
// handle reconnect logic, etc?
|
// handle reconnect logic, etc?
|
||||||
for handler in handlers {
|
for handler in handlers {
|
||||||
handler.callback(relay_id, event)
|
handler.callback(relay_id, event)
|
||||||
@@ -193,3 +208,4 @@ func add_rw_relay(_ pool: RelayPool, _ url: String) {
|
|||||||
try? pool.add_relay(url_, info: RelayInfo.rw)
|
try? pool.add_relay(url_, info: RelayInfo.rw)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,12 @@ extension Notification.Name {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension Notification.Name {
|
||||||
|
static var relays_changed: Notification.Name {
|
||||||
|
return Notification.Name("relays_changed")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
extension Notification.Name {
|
extension Notification.Name {
|
||||||
static var select_event: Notification.Name {
|
static var select_event: Notification.Name {
|
||||||
return Notification.Name("select_event")
|
return Notification.Name("select_event")
|
||||||
|
|||||||
@@ -17,15 +17,16 @@ struct ConfigView: View {
|
|||||||
@State var privkey: String
|
@State var privkey: String
|
||||||
@State var privkey_copied: Bool = false
|
@State var privkey_copied: Bool = false
|
||||||
@State var pubkey_copied: Bool = false
|
@State var pubkey_copied: Bool = false
|
||||||
|
@State var allWallets: [Wallet] = Wallet.allCases
|
||||||
|
@State var relays: [RelayDescriptor]
|
||||||
@EnvironmentObject var user_settings: UserSettingsStore
|
@EnvironmentObject var user_settings: UserSettingsStore
|
||||||
|
|
||||||
@State var allWallets: [Wallet] = Wallet.allCases
|
|
||||||
|
|
||||||
let generator = UIImpactFeedbackGenerator(style: .light)
|
let generator = UIImpactFeedbackGenerator(style: .light)
|
||||||
|
|
||||||
init(state: DamusState) {
|
init(state: DamusState) {
|
||||||
self.state = state
|
self.state = state
|
||||||
_privkey = State(initialValue: self.state.keypair.privkey_bech32 ?? "")
|
_privkey = State(initialValue: self.state.keypair.privkey_bech32 ?? "")
|
||||||
|
_relays = State(initialValue: state.pool.descriptors)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: (jb55) could be more general but not gonna worry about it atm
|
// TODO: (jb55) could be more general but not gonna worry about it atm
|
||||||
@@ -41,16 +42,28 @@ struct ConfigView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var recommended: [RelayDescriptor] {
|
||||||
|
let rs: [RelayDescriptor] = []
|
||||||
|
return BOOTSTRAP_RELAYS.reduce(into: rs) { (xs, x) in
|
||||||
|
if let _ = state.pool.get_relay(x) {
|
||||||
|
} else {
|
||||||
|
xs.append(RelayDescriptor(url: URL(string: x)!, info: .rw))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
ZStack(alignment: .leading) {
|
ZStack(alignment: .leading) {
|
||||||
Form {
|
Form {
|
||||||
if let ev = state.contacts.event {
|
Section("Relays") {
|
||||||
Section("Relays") {
|
List(Array(relays), id: \.url) { relay in
|
||||||
if let relays = decode_json_relays(ev.content) {
|
RelayView(state: state, relay: relay.url.absoluteString)
|
||||||
List(Array(relays.keys.sorted()), id: \.self) { relay in
|
}
|
||||||
RelayView(state: state, ev: ev, relay: relay)
|
}
|
||||||
}
|
|
||||||
}
|
Section("Recommended Relays") {
|
||||||
|
List(recommended, id: \.url) { r in
|
||||||
|
RecommendedRelayView(damus: state, relay: r.url.absoluteString)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,7 +140,6 @@ struct ConfigView: View {
|
|||||||
}
|
}
|
||||||
.sheet(isPresented: $show_add_relay) {
|
.sheet(isPresented: $show_add_relay) {
|
||||||
AddRelayView(show_add_relay: $show_add_relay, relay: $new_relay) { m_relay in
|
AddRelayView(show_add_relay: $show_add_relay, relay: $new_relay) { m_relay in
|
||||||
|
|
||||||
guard let relay = m_relay else {
|
guard let relay = m_relay else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -152,17 +164,21 @@ struct ConfigView: View {
|
|||||||
|
|
||||||
state.pool.connect(to: [new_relay])
|
state.pool.connect(to: [new_relay])
|
||||||
|
|
||||||
guard let new_ev = add_relay(ev: ev, privkey: privkey, relay: new_relay, info: info) else {
|
guard let new_ev = add_relay(ev: ev, privkey: privkey, current_relays: state.pool.descriptors, relay: new_relay, info: info) else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
state.contacts.event = new_ev
|
process_contact_event(pool: state.pool, contacts: state.contacts, pubkey: state.pubkey, ev: ev)
|
||||||
|
|
||||||
state.pool.send(.event(new_ev))
|
state.pool.send(.event(new_ev))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onReceive(handle_notify(.switched_timeline)) { _ in
|
.onReceive(handle_notify(.switched_timeline)) { _ in
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
|
.onReceive(handle_notify(.relays_changed)) { _ in
|
||||||
|
self.relays = state.pool.descriptors
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -76,10 +76,9 @@ struct ProfileName: View {
|
|||||||
Text(prefix + String(display_name ?? Profile.displayName(profile: profile, pubkey: pubkey)))
|
Text(prefix + String(display_name ?? Profile.displayName(profile: profile, pubkey: pubkey)))
|
||||||
.font(.body)
|
.font(.body)
|
||||||
.fontWeight(prefix == "@" ? .none : .bold)
|
.fontWeight(prefix == "@" ? .none : .bold)
|
||||||
if let frend = friend_icon {
|
if let friend = friend_icon {
|
||||||
Label("", systemImage: frend)
|
Image(systemName: friend)
|
||||||
.foregroundColor(.gray)
|
.foregroundColor(.gray)
|
||||||
.font(.footnote)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onReceive(handle_notify(.profile_updated)) { notif in
|
.onReceive(handle_notify(.profile_updated)) { notif in
|
||||||
|
|||||||
@@ -242,6 +242,17 @@ struct ProfileView: View {
|
|||||||
followers.subscribe()
|
followers.subscribe()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let relays = profile.relays {
|
||||||
|
NavigationLink(destination: UserRelaysView(state: damus_state, pubkey: profile.pubkey, relays: Array(relays.keys).sorted())) {
|
||||||
|
Text("\(relays.keys.count)")
|
||||||
|
.font(.subheadline.weight(.medium))
|
||||||
|
Text("Relays")
|
||||||
|
.font(.subheadline)
|
||||||
|
.foregroundColor(.gray)
|
||||||
|
}
|
||||||
|
.buttonStyle(PlainButtonStyle())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
50
damus/Views/RecommendedRelayView.swift
Normal file
50
damus/Views/RecommendedRelayView.swift
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
//
|
||||||
|
// RecommendedRelayView.swift
|
||||||
|
// damus
|
||||||
|
//
|
||||||
|
// Created by William Casarin on 2022-12-29.
|
||||||
|
//
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct RecommendedRelayView: View {
|
||||||
|
let damus: DamusState
|
||||||
|
let relay: String
|
||||||
|
let add_button: Bool
|
||||||
|
|
||||||
|
init(damus: DamusState, relay: String) {
|
||||||
|
self.damus = damus
|
||||||
|
self.relay = relay
|
||||||
|
self.add_button = true
|
||||||
|
}
|
||||||
|
|
||||||
|
init(damus: DamusState, relay: String, add_button: Bool) {
|
||||||
|
self.damus = damus
|
||||||
|
self.relay = relay
|
||||||
|
self.add_button = add_button
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
HStack {
|
||||||
|
Text(relay)
|
||||||
|
Spacer()
|
||||||
|
if let ev = damus.contacts.event, add_button {
|
||||||
|
if let privkey = damus.keypair.privkey {
|
||||||
|
Button("Add") {
|
||||||
|
guard let ev = add_relay(ev: ev, privkey: privkey, current_relays: damus.pool.descriptors, relay: relay, info: .rw) else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
process_contact_event(pool: damus.pool, contacts: damus.contacts, pubkey: damus.pubkey, ev: ev)
|
||||||
|
damus.pool.send(.event(ev))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct RecommendedRelayView_Previews: PreviewProvider {
|
||||||
|
static var previews: some View {
|
||||||
|
RecommendedRelayView(damus: test_damus_state(), relay: "wss://relay.damus.io")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,7 +9,6 @@ import SwiftUI
|
|||||||
|
|
||||||
struct RelayView: View {
|
struct RelayView: View {
|
||||||
let state: DamusState
|
let state: DamusState
|
||||||
let ev: NostrEvent
|
|
||||||
let relay: String
|
let relay: String
|
||||||
|
|
||||||
let timer = Timer.publish(every: 2, on: .main, in: .common).autoconnect()
|
let timer = Timer.publish(every: 2, on: .main, in: .common).autoconnect()
|
||||||
@@ -45,25 +44,43 @@ struct RelayView: View {
|
|||||||
}
|
}
|
||||||
.swipeActions {
|
.swipeActions {
|
||||||
if let privkey = state.keypair.privkey {
|
if let privkey = state.keypair.privkey {
|
||||||
Button {
|
RemoveAction(privkey: privkey)
|
||||||
guard let new_ev = remove_relay( ev: ev, privkey: privkey, relay: relay) else {
|
}
|
||||||
return
|
}
|
||||||
}
|
.contextMenu {
|
||||||
|
if let privkey = state.keypair.privkey {
|
||||||
state.contacts.event = new_ev
|
RemoveAction(privkey: privkey)
|
||||||
state.pool.send(.event(new_ev))
|
|
||||||
} label: {
|
|
||||||
Label("Delete", systemImage: "trash")
|
|
||||||
}
|
|
||||||
.tint(.red)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func RemoveAction(privkey: String) -> some View {
|
||||||
|
Button {
|
||||||
|
guard let ev = state.contacts.event else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let descriptors = state.pool.descriptors
|
||||||
|
guard let new_ev = remove_relay( ev: ev, current_relays: descriptors, privkey: privkey, relay: relay) else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
process_contact_event(pool: state.pool, contacts: state.contacts, pubkey: state.pubkey, ev: new_ev)
|
||||||
|
state.pool.send(.event(new_ev))
|
||||||
|
} label: {
|
||||||
|
Label("Delete", systemImage: "trash")
|
||||||
|
}
|
||||||
|
.tint(.red)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fileprivate func remove_action() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct RelayView_Previews: PreviewProvider {
|
struct RelayView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
RelayView(state: test_damus_state(), ev: NostrEvent(content: "content", pubkey: "pk"), relay: "wss://relay.damus.io", conn_color: .red)
|
RelayView(state: test_damus_state(), relay: "wss://relay.damus.io", conn_color: .red)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -130,6 +130,7 @@ struct BuildThreadV2View: View {
|
|||||||
|
|
||||||
// Ask for children
|
// Ask for children
|
||||||
let childs_events = NostrFilter(
|
let childs_events = NostrFilter(
|
||||||
|
kinds: [1],
|
||||||
referenced_ids: [self.event_id],
|
referenced_ids: [self.event_id],
|
||||||
limit: 50
|
limit: 50
|
||||||
)
|
)
|
||||||
|
|||||||
46
damus/Views/UserRelaysView.swift
Normal file
46
damus/Views/UserRelaysView.swift
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
//
|
||||||
|
// UserRelaysView.swift
|
||||||
|
// damus
|
||||||
|
//
|
||||||
|
// Created by William Casarin on 2022-12-29.
|
||||||
|
//
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct UserRelaysView: View {
|
||||||
|
let state: DamusState
|
||||||
|
let pubkey: String
|
||||||
|
let relays: [String]
|
||||||
|
|
||||||
|
@State var relay_state: [(String, Bool)]
|
||||||
|
|
||||||
|
init (state: DamusState, pubkey: String, relays: [String]) {
|
||||||
|
self.state = state
|
||||||
|
self.pubkey = pubkey
|
||||||
|
self.relays = relays
|
||||||
|
let relay_state = UserRelaysView.make_relay_state(pool: state.pool, relays: relays)
|
||||||
|
self._relay_state = State(initialValue: relay_state)
|
||||||
|
}
|
||||||
|
|
||||||
|
static func make_relay_state(pool: RelayPool, relays: [String]) -> [(String, Bool)] {
|
||||||
|
return relays.map({ r in
|
||||||
|
return (r, pool.get_relay(r) == nil)
|
||||||
|
}).sorted { (a, b) in a.0 < b.0 }
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
List(relay_state, id: \.0) { (r, add) in
|
||||||
|
RecommendedRelayView(damus: state, relay: r, add_button: add)
|
||||||
|
}
|
||||||
|
.onReceive(handle_notify(.relays_changed)) { _ in
|
||||||
|
self.relay_state = UserRelaysView.make_relay_state(pool: state.pool, relays: self.relays)
|
||||||
|
}
|
||||||
|
.navigationBarTitle("Relays")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct UserRelaysView_Previews: PreviewProvider {
|
||||||
|
static var previews: some View {
|
||||||
|
UserRelaysView(state: test_damus_state(), pubkey: "", relays: [])
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user