mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Merge pull request #1219 from RCGV1/MessageTimeStamp
Timestamps above messages in between distinct conversations
This commit is contained in:
commit
e2fbb2a26c
3 changed files with 23 additions and 3 deletions
|
|
@ -31,4 +31,11 @@ extension MessageEntity {
|
|||
|
||||
return (try? context.fetch(fetchRequest)) ?? [MessageEntity]()
|
||||
}
|
||||
|
||||
func displayTimestamp(aboveMessage: MessageEntity?) -> Bool {
|
||||
if let aboveMessage = aboveMessage {
|
||||
return aboveMessage.timestamp.addingTimeInterval(900) < timestamp // 15 minutes
|
||||
}
|
||||
return false // First message will have no timestamp
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,8 +33,15 @@ struct ChannelMessageList: View {
|
|||
ZStack(alignment: .bottomTrailing) {
|
||||
ScrollView {
|
||||
LazyVStack {
|
||||
ForEach(channel.allPrivateMessages) { (message: MessageEntity) in
|
||||
ForEach(Array(channel.allPrivateMessages.enumerated()), id: \.element.id) { index, message in
|
||||
// Get the previous message, if it exists
|
||||
let previousMessage = index > 0 ? channel.allPrivateMessages[index - 1] : nil
|
||||
let currentUser: Bool = (Int64(preferredPeripheralNum) == message.fromUser?.num ? true : false)
|
||||
if message.displayTimestamp(aboveMessage: previousMessage) {
|
||||
Text(message.timestamp.formatted(date: .abbreviated, time: .shortened))
|
||||
.font(.caption)
|
||||
.foregroundColor(.gray)
|
||||
}
|
||||
if message.replyID > 0 {
|
||||
let messageReply = channel.allPrivateMessages.first(where: { $0.messageId == message.replyID })
|
||||
HStack {
|
||||
|
|
@ -44,7 +51,6 @@ struct ChannelMessageList: View {
|
|||
messageToHighlight = messageNum
|
||||
}
|
||||
scrollView.scrollTo(messageNum, anchor: .center)
|
||||
|
||||
// Reset highlight after delay
|
||||
Task {
|
||||
try? await Task.sleep(nanoseconds: 1_000_000_000) // 1 second
|
||||
|
|
|
|||
|
|
@ -33,7 +33,14 @@ struct UserMessageList: View {
|
|||
ZStack(alignment: .bottomTrailing) {
|
||||
ScrollView {
|
||||
LazyVStack {
|
||||
ForEach( user.messageList ) { (message: MessageEntity) in
|
||||
ForEach( Array(user.messageList.enumerated()) , id: \.element.id) { index, message in
|
||||
// Get the previous message, if it exists
|
||||
let previousMessage = index > 0 ? user.messageList[index - 1] : nil
|
||||
if message.displayTimestamp(aboveMessage: previousMessage) {
|
||||
Text(message.timestamp.formatted(date: .abbreviated, time: .shortened))
|
||||
.font(.caption)
|
||||
.foregroundColor(.gray)
|
||||
}
|
||||
if user.num != bleManager.connectedPeripheral?.num ?? -1 {
|
||||
let currentUser: Bool = (Int64(UserDefaults.preferredPeripheralNum) == message.fromUser?.num ?? -1 ? true : false)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue