WIP DM timestamps
This commit is contained in:
@@ -12,24 +12,47 @@ struct DMChatView: View {
|
||||
let pubkey: String
|
||||
@EnvironmentObject var dms: DirectMessageModel
|
||||
@State var showPrivateKeyWarning: Bool = false
|
||||
@State var eventsInView = Set<NostrEvent>()
|
||||
@State var minDate: String = ""
|
||||
|
||||
var Messages: some View {
|
||||
ScrollViewReader { scroller in
|
||||
ScrollView {
|
||||
VStack(alignment: .leading) {
|
||||
ForEach(Array(zip(dms.events, dms.events.indices)), id: \.0.id) { (ev, ind) in
|
||||
DMView(event: dms.events[ind], damus_state: damus_state)
|
||||
.event_context_menu(ev, keypair: damus_state.keypair, target_pubkey: ev.pubkey)
|
||||
VStack {
|
||||
Text(minDate)
|
||||
.contentShape(RoundedRectangle(cornerRadius: 4.0))
|
||||
.foregroundColor(.primary)
|
||||
.padding(16)
|
||||
|
||||
ScrollViewReader { scroller in
|
||||
ScrollView {
|
||||
LazyVStack(alignment: .leading) {
|
||||
ForEach(Array(zip(dms.events, dms.events.indices)), id: \.0.id) { (ev, ind) in
|
||||
let date = Date.init(timeIntervalSince1970: Double(ev.created_at))
|
||||
DMView(event: ev, damus_state: damus_state)
|
||||
.event_context_menu(ev, keypair: damus_state.keypair, target_pubkey: ev.pubkey)
|
||||
.onAppear {
|
||||
eventsInView.insert(ev)
|
||||
}
|
||||
.onDisappear {
|
||||
eventsInView.remove(ev)
|
||||
}
|
||||
}
|
||||
EndBlock(height: 80)
|
||||
}
|
||||
EndBlock(height: 80)
|
||||
.padding(.horizontal)
|
||||
}
|
||||
.padding(.horizontal)
|
||||
}
|
||||
.onAppear {
|
||||
scroller.scrollTo("endblock")
|
||||
}.onChange(of: dms.events.count) { _ in
|
||||
withAnimation {
|
||||
.onAppear {
|
||||
scroller.scrollTo("endblock")
|
||||
}.onChange(of: dms.events.count) { _ in
|
||||
withAnimation {
|
||||
scroller.scrollTo("endblock")
|
||||
}
|
||||
}.onChange(of: eventsInView) { _ in
|
||||
print("eventsInView \(eventsInView.count)")
|
||||
let timestamps = eventsInView.map { $0.created_at }
|
||||
guard let minTimestamp = timestamps.min() else {
|
||||
return
|
||||
}
|
||||
minDate = Date.init(timeIntervalSince1970: Double(minTimestamp)).formatted(date: .abbreviated, time: .omitted)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,12 +23,20 @@ struct DMView: View {
|
||||
|
||||
let should_show_img = should_show_images(contacts: damus_state.contacts, ev: event, our_pubkey: damus_state.pubkey)
|
||||
|
||||
NoteContentView(damus_state: damus_state, event: event, show_images: should_show_img, size: .normal, artifacts: .just_content(event.get_content(damus_state.keypair.privkey)))
|
||||
.foregroundColor(is_ours ? Color.white : Color.primary)
|
||||
.padding(10)
|
||||
.background(is_ours ? Color.accentColor : Color.secondary.opacity(0.15))
|
||||
.cornerRadius(8.0)
|
||||
.tint(is_ours ? Color.white : Color.accentColor)
|
||||
VStack {
|
||||
NoteContentView(damus_state: damus_state, event: event, show_images: should_show_img, size: .normal, artifacts: .just_content(event.get_content(damus_state.keypair.privkey)))
|
||||
.foregroundColor(is_ours ? Color.white : Color.primary)
|
||||
.padding(10)
|
||||
.background(is_ours ? Color.accentColor : Color.secondary.opacity(0.15))
|
||||
.cornerRadius(8.0)
|
||||
.tint(is_ours ? Color.white : Color.accentColor)
|
||||
|
||||
Text(verbatim: Date.init(timeIntervalSince1970: Double(event.created_at)).formatted(date: .abbreviated, time: .shortened))
|
||||
.font(.footnote)
|
||||
.foregroundColor(.gray)
|
||||
.frame(maxWidth: .infinity, alignment: is_ours ? .trailing : .leading)
|
||||
}
|
||||
|
||||
if !is_ours {
|
||||
Spacer(minLength: UIScreen.main.bounds.width * 0.2)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user