mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Pseudo working read messages and order by most recently received message contacts
This commit is contained in:
parent
2ef289e6aa
commit
4f7af1a4e8
6 changed files with 10 additions and 7 deletions
|
|
@ -705,6 +705,9 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate
|
|||
newMessage.receivedACK = false
|
||||
if toUserNum > 0 {
|
||||
newMessage.toUser = fetchedUsers.first(where: { $0.num == toUserNum })
|
||||
newMessage.toUser?.lastMessage = Date()
|
||||
newMessage.read = true
|
||||
newMessage.toUser?.objectWillChange.send()
|
||||
}
|
||||
newMessage.fromUser = fetchedUsers.first(where: { $0.num == fromUserNum })
|
||||
newMessage.isEmoji = isEmoji
|
||||
|
|
|
|||
|
|
@ -746,6 +746,7 @@ func textMessageAppPacket(packet: MeshPacket, connectedNode: Int64, context: NSM
|
|||
}
|
||||
newMessage.messagePayload = messageText
|
||||
newMessage.messagePayloadMarkdown = generateMessageMarkdown(message: messageText)
|
||||
newMessage.fromUser?.lastMessage = Date()
|
||||
|
||||
newMessage.fromUser?.objectWillChange.send()
|
||||
newMessage.toUser?.objectWillChange.send()
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="21754" systemVersion="22F82" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
|
||||
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="21754" systemVersion="22G90" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
|
||||
<entity name="BluetoothConfigEntity" representedClassName="BluetoothConfigEntity" syncable="YES" codeGenerationType="class">
|
||||
<attribute name="enabled" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
|
||||
<attribute name="fixedPin" optional="YES" attributeType="Integer 32" defaultValueString="123456" usesScalarValueType="YES"/>
|
||||
|
|
@ -328,7 +328,7 @@
|
|||
<entity name="UserEntity" representedClassName="UserEntity" syncable="YES" codeGenerationType="class">
|
||||
<attribute name="hwModel" attributeType="String"/>
|
||||
<attribute name="isLicensed" optional="YES" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
|
||||
<attribute name="lastMessage" optional="YES" attributeType="Date" usesScalarValueType="YES"/>
|
||||
<attribute name="lastMessage" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
|
||||
<attribute name="longName" attributeType="String"/>
|
||||
<attribute name="mute" optional="YES" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
|
||||
<attribute name="num" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
|
||||
|
|
|
|||
|
|
@ -23,4 +23,3 @@ extension UserEntity {
|
|||
return unreadMessages.count
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ struct Contacts: View {
|
|||
@EnvironmentObject var bleManager: BLEManager
|
||||
|
||||
@FetchRequest(
|
||||
sortDescriptors: [NSSortDescriptor(key: "lastMessage", ascending: true)],
|
||||
sortDescriptors: [NSSortDescriptor(key: "lastMessage", ascending: false)],
|
||||
animation: .default)
|
||||
|
||||
private var users: FetchedResults<UserEntity>
|
||||
|
|
@ -151,6 +151,7 @@ struct Contacts: View {
|
|||
}
|
||||
}
|
||||
Section(header: Text("direct.messages")) {
|
||||
|
||||
ForEach(users) { (user: UserEntity) in
|
||||
|
||||
let mostRecent = user.messageList.last
|
||||
|
|
@ -169,7 +170,6 @@ struct Contacts: View {
|
|||
}
|
||||
|
||||
CircleText(text: user.shortName ?? "???", color: Color(UIColor(hex: UInt32(user.num))), circleSize: 45, fontSize: (user.shortName ?? "???").isEmoji() ? 32 : (user.shortName?.count ?? 0 == 4 ? 14 : (user.shortName?.count ?? 0 == 3 ? 18 : 22)), brightness: 0.0, textColor: UIColor(hex: UInt32(user.num)).isLight() ? .black : .white)
|
||||
.brightness(0.2)
|
||||
|
||||
VStack(alignment: .leading){
|
||||
HStack{
|
||||
|
|
|
|||
|
|
@ -218,11 +218,11 @@ struct UserMessageList: View {
|
|||
}
|
||||
.onAppear {
|
||||
if !message.read {
|
||||
print("\(message.messageId) read")
|
||||
message.read = true
|
||||
message.toUser?.objectWillChange.send()
|
||||
do {
|
||||
try context.save()
|
||||
deleteMessageId = 0
|
||||
print("Read message \(message.messageId) ")
|
||||
} catch {
|
||||
print("Failed to read message \(message.messageId)")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue