ui: add quoted reposts view to threads

This adds quote reposts as an additional detail view on threads. It will
list quoted reposts that have the `q` tag. Not all clients have updated
to this yet (like primal), but hopefully they will soon.

Changelog-Added: Show list of quoted reposts in threads
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2024-03-16 12:20:59 +00:00
parent 3f1f257df2
commit c521998158
7 changed files with 74 additions and 15 deletions

View File

@@ -7,7 +7,6 @@
import Foundation
class EventsModel: ObservableObject {
let state: DamusState
let target: NoteId

View File

@@ -56,6 +56,7 @@ class ThreadModel: ObservableObject {
func subscribe() {
var meta_events = NostrFilter()
var quote_events = NostrFilter()
var event_filter = NostrFilter()
var ref_events = NostrFilter()
@@ -74,11 +75,14 @@ class ThreadModel: ObservableObject {
kinds.append(.like)
}
meta_events.kinds = kinds
meta_events.limit = 1000
quote_events.kinds = [.text]
quote_events.quotes = [event.id]
quote_events.limit = 1000
let base_filters = [event_filter, ref_events]
let meta_filters = [meta_events]
let meta_filters = [meta_events, quote_events]
print("subscribing to thread \(event.id) with sub_id \(base_subid)")
damus_state.pool.subscribe(sub_id: base_subid, filters: base_filters, handler: handle_event)
@@ -90,7 +94,7 @@ class ThreadModel: ObservableObject {
return
}
let the_ev = damus_state.events.upsert(ev)
damus_state.events.upsert(ev)
damus_state.replies.count_replies(ev, keypair: keypair)
damus_state.events.add_replies(ev: ev, keypair: keypair)
@@ -111,7 +115,13 @@ class ThreadModel: ObservableObject {
}
} else if ev.is_textlike {
self.add_event(ev, keypair: damus_state.keypair)
// handle thread quote reposts, we just count them instead of
// adding them to the thread
if let target = ev.is_quote_repost, target == self.event.id {
//let _ = self.damus_state.quote_reposts.add_event(ev, target: target)
} else {
self.add_event(ev, keypair: damus_state.keypair)
}
}
}

View File

@@ -41,7 +41,7 @@ struct QuoteId: IdType, TagKey, TagConvertible {
self.id = data
}
/// Refer to this QuoteId as a NoteId
/// The note id being quoted
var note_id: NoteId {
NoteId(self.id)
}

View File

@@ -32,6 +32,7 @@ enum Route: Hashable {
case DeveloperSettings(settings: UserSettingsStore)
case Thread(thread: ThreadModel)
case Reposts(reposts: EventsModel)
case QuoteReposts(quotes: EventsModel)
case Reactions(reactions: EventsModel)
case Zaps(target: ZapTarget)
case Search(search: SearchModel)
@@ -92,6 +93,8 @@ enum Route: Hashable {
ThreadView(state: damusState, thread: thread)
case .Reposts(let reposts):
RepostsView(damus_state: damusState, model: reposts)
case .QuoteReposts(let quote_reposts):
QuoteRepostsView(damus_state: damusState, model: quote_reposts)
case .Reactions(let reactions):
ReactionsView(damus_state: damusState, model: reactions)
case .Zaps(let target):
@@ -178,6 +181,9 @@ enum Route: Hashable {
case .Reposts(let reposts):
hasher.combine("reposts")
hasher.combine(reposts.target)
case .QuoteReposts(let evs_model):
hasher.combine("quote_reposts")
hasher.combine(evs_model.events.events.count)
case .Zaps(let target):
hasher.combine("zaps")
hasher.combine(target.id)

View File

@@ -33,6 +33,15 @@ struct EventDetailBar: View {
.buttonStyle(PlainButtonStyle())
}
if bar.quote_reposts > 0 {
NavigationLink(value: Route.QuoteReposts(quotes: .quotes(state: state, target: target))) {
let nounString = pluralizedString(key: "quoted_reposts_count", count: bar.quote_reposts)
let noun = Text(nounString).foregroundColor(.gray)
Text("\(Text(verbatim: bar.quote_reposts.formatted()).font(.body.bold())) \(noun)", comment: "Sentence composed of 2 variables to describe how many quoted reposts. In source English, the first variable is the number of reposts, and the second variable is 'Repost' or 'Reposts'.")
}
.buttonStyle(PlainButtonStyle())
}
if bar.likes > 0 && !state.settings.onlyzaps_mode {
NavigationLink(value: Route.Reactions(reactions: .likes(state: state, target: target))) {
let nounString = pluralizedString(key: "reactions_count", count: bar.likes)

View File

@@ -0,0 +1,31 @@
//
// QuoteRepostsView.swift
// damus
//
// Created by William Casarin on 2024-03-16.
//
import SwiftUI
struct QuoteRepostsView: View {
let damus_state: DamusState
@ObservedObject var model: EventsModel
var body: some View {
TimelineView<AnyView>(events: model.events, loading: $model.loading, damus: damus_state, show_friend_icon: true, filter: ContentFilters.default_filters(damus_state: damus_state).filter(ev:))
.navigationBarTitle(NSLocalizedString("Quotes", comment: "Navigation bar title for Quote Reposts view."))
.onAppear {
model.subscribe()
}
.onDisappear {
model.unsubscribe()
}
}
}
struct QuoteRepostsView_Previews: PreviewProvider {
static var previews: some View {
let state = test_damus_state
QuoteRepostsView(damus_state: state, model: .reposts(state: state, target: test_note.id))
}
}