WIP DM timestamps
This commit is contained in:
@@ -12,24 +12,47 @@ struct DMChatView: View {
|
|||||||
let pubkey: String
|
let pubkey: String
|
||||||
@EnvironmentObject var dms: DirectMessageModel
|
@EnvironmentObject var dms: DirectMessageModel
|
||||||
@State var showPrivateKeyWarning: Bool = false
|
@State var showPrivateKeyWarning: Bool = false
|
||||||
|
@State var eventsInView = Set<NostrEvent>()
|
||||||
|
@State var minDate: String = ""
|
||||||
|
|
||||||
var Messages: some View {
|
var Messages: some View {
|
||||||
ScrollViewReader { scroller in
|
VStack {
|
||||||
ScrollView {
|
Text(minDate)
|
||||||
VStack(alignment: .leading) {
|
.contentShape(RoundedRectangle(cornerRadius: 4.0))
|
||||||
ForEach(Array(zip(dms.events, dms.events.indices)), id: \.0.id) { (ev, ind) in
|
.foregroundColor(.primary)
|
||||||
DMView(event: dms.events[ind], damus_state: damus_state)
|
.padding(16)
|
||||||
.event_context_menu(ev, keypair: damus_state.keypair, target_pubkey: ev.pubkey)
|
|
||||||
|
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 {
|
||||||
}
|
|
||||||
.onAppear {
|
|
||||||
scroller.scrollTo("endblock")
|
|
||||||
}.onChange(of: dms.events.count) { _ in
|
|
||||||
withAnimation {
|
|
||||||
scroller.scrollTo("endblock")
|
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)
|
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)))
|
VStack {
|
||||||
.foregroundColor(is_ours ? Color.white : Color.primary)
|
NoteContentView(damus_state: damus_state, event: event, show_images: should_show_img, size: .normal, artifacts: .just_content(event.get_content(damus_state.keypair.privkey)))
|
||||||
.padding(10)
|
.foregroundColor(is_ours ? Color.white : Color.primary)
|
||||||
.background(is_ours ? Color.accentColor : Color.secondary.opacity(0.15))
|
.padding(10)
|
||||||
.cornerRadius(8.0)
|
.background(is_ours ? Color.accentColor : Color.secondary.opacity(0.15))
|
||||||
.tint(is_ours ? Color.white : Color.accentColor)
|
.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 {
|
if !is_ours {
|
||||||
Spacer(minLength: UIScreen.main.bounds.width * 0.2)
|
Spacer(minLength: UIScreen.main.bounds.width * 0.2)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user