Add partial support for different repost variants
Changelog-Added: Add partial support for different repost variants
This commit is contained in:
@@ -229,7 +229,7 @@ class HomeModel: ObservableObject {
|
|||||||
func handle_boost_event(sub_id: String, _ ev: NostrEvent) {
|
func handle_boost_event(sub_id: String, _ ev: NostrEvent) {
|
||||||
var boost_ev_id = ev.last_refid()?.ref_id
|
var boost_ev_id = ev.last_refid()?.ref_id
|
||||||
|
|
||||||
if let inner_ev = ev.inner_event {
|
if let inner_ev = ev.get_inner_event(cache: damus_state.events) {
|
||||||
boost_ev_id = inner_ev.id
|
boost_ev_id = inner_ev.id
|
||||||
|
|
||||||
guard validate_event(ev: inner_ev) == .ok else {
|
guard validate_event(ev: inner_ev) == .ok else {
|
||||||
@@ -488,7 +488,7 @@ class HomeModel: ObservableObject {
|
|||||||
|
|
||||||
damus_state.events.insert(ev)
|
damus_state.events.insert(ev)
|
||||||
|
|
||||||
if let inner_ev = ev.inner_event {
|
if let inner_ev = ev.get_inner_event(cache: damus_state.events) {
|
||||||
damus_state.events.insert(inner_ev)
|
damus_state.events.insert(inner_ev)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1104,7 +1104,7 @@ func process_local_notification(damus_state: DamusState, event ev: NostrEvent) {
|
|||||||
let notify = LocalNotification(type: .mention, event: ev, target: ev, content: content)
|
let notify = LocalNotification(type: .mention, event: ev, target: ev, content: content)
|
||||||
create_local_notification(profiles: damus_state.profiles, notify: notify )
|
create_local_notification(profiles: damus_state.profiles, notify: notify )
|
||||||
}
|
}
|
||||||
} else if type == .boost && damus_state.settings.repost_notification, let inner_ev = ev.inner_event {
|
} else if type == .boost && damus_state.settings.repost_notification, let inner_ev = ev.get_inner_event(cache: damus_state.events) {
|
||||||
let notify = LocalNotification(type: .repost, event: ev, target: inner_ev, content: inner_ev.content)
|
let notify = LocalNotification(type: .repost, event: ev, target: inner_ev, content: inner_ev.content)
|
||||||
create_local_notification(profiles: damus_state.profiles, notify: notify)
|
create_local_notification(profiles: damus_state.profiles, notify: notify)
|
||||||
} else if type == .like && damus_state.settings.like_notification,
|
} else if type == .like && damus_state.settings.like_notification,
|
||||||
|
|||||||
@@ -192,8 +192,8 @@ class NotificationsModel: ObservableObject, ScrollQueue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private func insert_repost(_ ev: NostrEvent) -> Bool {
|
private func insert_repost(_ ev: NostrEvent, cache: EventCache) -> Bool {
|
||||||
guard let reposted_ev = ev.inner_event else {
|
guard let reposted_ev = ev.get_inner_event(cache: cache) else {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,9 +235,9 @@ class NotificationsModel: ObservableObject, ScrollQueue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func insert_event_immediate(_ ev: NostrEvent) -> Bool {
|
private func insert_event_immediate(_ ev: NostrEvent, cache: EventCache) -> Bool {
|
||||||
if ev.known_kind == .boost {
|
if ev.known_kind == .boost {
|
||||||
return insert_repost(ev)
|
return insert_repost(ev, cache: cache)
|
||||||
} else if ev.known_kind == .like {
|
} else if ev.known_kind == .like {
|
||||||
return insert_reaction(ev)
|
return insert_reaction(ev)
|
||||||
} else if ev.known_kind == .text {
|
} else if ev.known_kind == .text {
|
||||||
@@ -269,7 +269,7 @@ class NotificationsModel: ObservableObject, ScrollQueue {
|
|||||||
return insert_uniq_sorted_event_created(events: &incoming_events, new_ev: ev)
|
return insert_uniq_sorted_event_created(events: &incoming_events, new_ev: ev)
|
||||||
}
|
}
|
||||||
|
|
||||||
if insert_event_immediate(ev) {
|
if insert_event_immediate(ev, cache: damus_state.events) {
|
||||||
self.notifications = build_notifications()
|
self.notifications = build_notifications()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -339,7 +339,7 @@ class NotificationsModel: ObservableObject, ScrollQueue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for event in incoming_events {
|
for event in incoming_events {
|
||||||
inserted = insert_event_immediate(event) || inserted
|
inserted = insert_event_immediate(event, cache: damus_state.events) || inserted
|
||||||
}
|
}
|
||||||
|
|
||||||
if inserted {
|
if inserted {
|
||||||
|
|||||||
@@ -101,10 +101,10 @@ func find_profiles_to_fetch_pk(profiles: Profiles, event_pubkeys: [String]) -> [
|
|||||||
return Array(pubkeys)
|
return Array(pubkeys)
|
||||||
}
|
}
|
||||||
|
|
||||||
func find_profiles_to_fetch(profiles: Profiles, load: PubkeysToLoad) -> [String] {
|
func find_profiles_to_fetch(profiles: Profiles, load: PubkeysToLoad, cache: EventCache) -> [String] {
|
||||||
switch load {
|
switch load {
|
||||||
case .from_events(let events):
|
case .from_events(let events):
|
||||||
return find_profiles_to_fetch_from_events(profiles: profiles, events: events)
|
return find_profiles_to_fetch_from_events(profiles: profiles, events: events, cache: cache)
|
||||||
case .from_keys(let pks):
|
case .from_keys(let pks):
|
||||||
return find_profiles_to_fetch_from_keys(profiles: profiles, pks: pks)
|
return find_profiles_to_fetch_from_keys(profiles: profiles, pks: pks)
|
||||||
}
|
}
|
||||||
@@ -124,12 +124,12 @@ func find_profiles_to_fetch_from_keys(profiles: Profiles, pks: [String]) -> [Str
|
|||||||
return Array(pubkeys)
|
return Array(pubkeys)
|
||||||
}
|
}
|
||||||
|
|
||||||
func find_profiles_to_fetch_from_events(profiles: Profiles, events: [NostrEvent]) -> [String] {
|
func find_profiles_to_fetch_from_events(profiles: Profiles, events: [NostrEvent], cache: EventCache) -> [String] {
|
||||||
var pubkeys = Set<String>()
|
var pubkeys = Set<String>()
|
||||||
|
|
||||||
for ev in events {
|
for ev in events {
|
||||||
// lookup profiles from boosted events
|
// lookup profiles from boosted events
|
||||||
if ev.known_kind == .boost, let bev = ev.inner_event, profiles.lookup(id: bev.pubkey) == nil {
|
if ev.known_kind == .boost, let bev = ev.get_inner_event(cache: cache), profiles.lookup(id: bev.pubkey) == nil {
|
||||||
pubkeys.insert(bev.pubkey)
|
pubkeys.insert(bev.pubkey)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,7 +148,7 @@ enum PubkeysToLoad {
|
|||||||
|
|
||||||
func load_profiles(profiles_subid: String, relay_id: String, load: PubkeysToLoad, damus_state: DamusState) {
|
func load_profiles(profiles_subid: String, relay_id: String, load: PubkeysToLoad, damus_state: DamusState) {
|
||||||
var filter = NostrFilter.filter_profiles
|
var filter = NostrFilter.filter_profiles
|
||||||
let authors = find_profiles_to_fetch(profiles: damus_state.profiles, load: load)
|
let authors = find_profiles_to_fetch(profiles: damus_state.profiles, load: load, cache: damus_state.events)
|
||||||
filter.authors = authors
|
filter.authors = authors
|
||||||
|
|
||||||
guard !authors.isEmpty else {
|
guard !authors.isEmpty else {
|
||||||
|
|||||||
@@ -111,14 +111,22 @@ class NostrEvent: Codable, Identifiable, CustomStringConvertible, Equatable, Has
|
|||||||
return parse_mentions(content: content, tags: self.tags)
|
return parse_mentions(content: content, tags: self.tags)
|
||||||
}
|
}
|
||||||
|
|
||||||
lazy var inner_event: NostrEvent? = {
|
private lazy var inner_event: NostrEvent? = {
|
||||||
// don't try to deserialize an inner event if we know there won't be one
|
return event_from_json(dat: self.content)
|
||||||
if self.known_kind == .boost {
|
|
||||||
return event_from_json(dat: self.content)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
func get_inner_event(cache: EventCache) -> NostrEvent? {
|
||||||
|
guard self.known_kind == .boost else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.content == "", let ref = self.referenced_ids.first {
|
||||||
|
return cache.lookup(ref.ref_id)
|
||||||
|
}
|
||||||
|
|
||||||
|
return self.inner_event
|
||||||
|
}
|
||||||
|
|
||||||
private var _event_refs: [EventRef]? = nil
|
private var _event_refs: [EventRef]? = nil
|
||||||
func event_refs(_ privkey: String?) -> [EventRef] {
|
func event_refs(_ privkey: String?) -> [EventRef] {
|
||||||
if let rs = _event_refs {
|
if let rs = _event_refs {
|
||||||
@@ -998,8 +1006,8 @@ func last_etag(tags: [[String]]) -> String? {
|
|||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
func inner_event_or_self(ev: NostrEvent) -> NostrEvent {
|
func inner_event_or_self(ev: NostrEvent, cache: EventCache) -> NostrEvent {
|
||||||
guard let inner_ev = ev.inner_event else {
|
guard let inner_ev = ev.get_inner_event(cache: cache) else {
|
||||||
return ev
|
return ev
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ struct EventView: View {
|
|||||||
var body: some View {
|
var body: some View {
|
||||||
VStack {
|
VStack {
|
||||||
if event.known_kind == .boost {
|
if event.known_kind == .boost {
|
||||||
if let inner_ev = event.inner_event {
|
if let inner_ev = event.get_inner_event(cache: damus.events) {
|
||||||
RepostedEvent(damus: damus, event: event, inner_ev: inner_ev, options: options)
|
RepostedEvent(damus: damus, event: event, inner_ev: inner_ev, options: options)
|
||||||
} else {
|
} else {
|
||||||
EmptyView()
|
EmptyView()
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ struct BuilderEventView: View {
|
|||||||
var body: some View {
|
var body: some View {
|
||||||
VStack {
|
VStack {
|
||||||
if let event {
|
if let event {
|
||||||
let ev = event.inner_event ?? event
|
let ev = event.get_inner_event(cache: damus.events) ?? event
|
||||||
let thread = ThreadModel(event: ev, damus_state: damus)
|
let thread = ThreadModel(event: ev, damus_state: damus)
|
||||||
let dest = ThreadView(state: damus, thread: thread)
|
let dest = ThreadView(state: damus, thread: thread)
|
||||||
NavigationLink(destination: dest) {
|
NavigationLink(destination: dest) {
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ struct InnerTimelineView: View {
|
|||||||
ForEach(events.filter(filter), id: \.id) { (ev: NostrEvent) in
|
ForEach(events.filter(filter), id: \.id) { (ev: NostrEvent) in
|
||||||
EventView(damus: damus, event: ev, options: event_options)
|
EventView(damus: damus, event: ev, options: event_options)
|
||||||
.onTapGesture {
|
.onTapGesture {
|
||||||
nav_target = ev.inner_event ?? ev
|
nav_target = ev.get_inner_event(cache: self.damus.events) ?? ev
|
||||||
navigating = true
|
navigating = true
|
||||||
}
|
}
|
||||||
.padding(.top, 7)
|
.padding(.top, 7)
|
||||||
|
|||||||
Reference in New Issue
Block a user