Enable offline posting

You can now post, like, repost, reply offline

Changelog-Added: Enable offline posting
This commit is contained in:
William Casarin
2023-03-31 15:14:55 -07:00
parent 915f3901a7
commit 2596542cb6
25 changed files with 196 additions and 31 deletions

View File

@@ -140,7 +140,7 @@ func follow_user(pool: RelayPool, our_contacts: NostrEvent?, pubkey: String, pri
return ev
}
func unfollow_user(pool: RelayPool, our_contacts: NostrEvent?, pubkey: String, privkey: String, unfollow: String) -> NostrEvent? {
func unfollow_user(postbox: PostBox, our_contacts: NostrEvent?, pubkey: String, privkey: String, unfollow: String) -> NostrEvent? {
guard let cs = our_contacts else {
return nil
}
@@ -149,7 +149,7 @@ func unfollow_user(pool: RelayPool, our_contacts: NostrEvent?, pubkey: String, p
ev.calculate_id()
ev.sign(privkey: privkey)
pool.send(.event(ev))
postbox.send(ev)
return ev
}

View File

@@ -26,6 +26,7 @@ struct DamusState {
let drafts: Drafts
let events: EventCache
let bookmarks: BookmarksManager
let postbox: PostBox
var pubkey: String {
return keypair.pubkey
@@ -36,6 +37,6 @@ struct DamusState {
}
static var empty: DamusState {
return DamusState.init(pool: RelayPool(), keypair: Keypair(pubkey: "", privkey: ""), likes: EventCounter(our_pubkey: ""), boosts: EventCounter(our_pubkey: ""), contacts: Contacts(our_pubkey: ""), tips: TipCounter(our_pubkey: ""), profiles: Profiles(), dms: DirectMessagesModel(our_pubkey: ""), previews: PreviewCache(), zaps: Zaps(our_pubkey: ""), lnurls: LNUrls(), settings: UserSettingsStore(), relay_filters: RelayFilters(our_pubkey: ""), relay_metadata: RelayMetadatas(), drafts: Drafts(), events: EventCache(), bookmarks: BookmarksManager(pubkey: ""))
return DamusState.init(pool: RelayPool(), keypair: Keypair(pubkey: "", privkey: ""), likes: EventCounter(our_pubkey: ""), boosts: EventCounter(our_pubkey: ""), contacts: Contacts(our_pubkey: ""), tips: TipCounter(our_pubkey: ""), profiles: Profiles(), dms: DirectMessagesModel(our_pubkey: ""), previews: PreviewCache(), zaps: Zaps(our_pubkey: ""), lnurls: LNUrls(), settings: UserSettingsStore(), relay_filters: RelayFilters(our_pubkey: ""), relay_metadata: RelayMetadatas(), drafts: Drafts(), events: EventCache(), bookmarks: BookmarksManager(pubkey: ""), postbox: PostBox(pool: RelayPool()))
}
}

View File

@@ -64,6 +64,8 @@ class EventsModel: ObservableObject {
handle_event(relay_id: relay_id, ev: ev)
case .notice(_):
break
case .ok:
break
case .eose(_):
load_profiles(profiles_subid: profiles_id, relay_id: relay_id, load: .from_events(events), damus_state: state)
}

View File

@@ -94,6 +94,9 @@ class FollowersModel: ObservableObject {
} else if sub_id == self.profiles_id {
damus_state.pool.unsubscribe(sub_id: profiles_id, to: [relay_id])
}
case .ok:
break
}
}
}

View File

@@ -58,6 +58,8 @@ class FollowingModel {
break
case .nostr_event(let nev):
switch nev {
case .ok:
break
case .event(_, let ev):
if ev.kind == 0 {
process_metadata_event(our_pubkey: damus_state.pubkey, profiles: damus_state.profiles, ev: ev)

View File

@@ -333,7 +333,11 @@ class HomeModel: ObservableObject {
self.loading = false
break
case .ok:
break
}
}
}

View File

@@ -133,6 +133,8 @@ class ProfileModel: ObservableObject, Equatable {
return
}
switch resp {
case .ok:
break
case .event(_, let ev):
add_event(ev)
case .notice(let notice):

View File

@@ -68,6 +68,8 @@ class SearchHomeModel: ObservableObject {
}
case .notice(let msg):
print("search home notice: \(msg)")
case .ok:
break
case .eose(let sub_id):
loading = false

View File

@@ -131,6 +131,9 @@ func handle_subid_event(pool: RelayPool, relay_id: String, ev: NostrConnectionEv
case .event(let ev_subid, let ev):
handle(ev_subid, ev)
return (ev_subid, false)
case .ok:
return (nil, false)
case .notice(let note):
if note.contains("Too many subscription filters") {

View File

@@ -46,6 +46,8 @@ class ZapsModel: ObservableObject {
}
switch resp {
case .ok:
break
case .notice:
break
case .eose: