From 09d3a6e606af42f4088e4552d18a97c7538f70c4 Mon Sep 17 00:00:00 2001 From: fmodf Date: Wed, 11 Sep 2024 14:37:54 +0200 Subject: [PATCH] wip --- .../AppData/Model/Message+OMEMO.swift | 5 ++++- ConversationsClassic/AppData/Model/Message.swift | 5 ++++- .../AppData/Services/Database+Migrations.swift | 11 +++-------- .../AppData/Store/MessagesStore.swift | 1 + .../Conversation/ConversationMessageContainer.swift | 10 +++++++--- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/ConversationsClassic/AppData/Model/Message+OMEMO.swift b/ConversationsClassic/AppData/Model/Message+OMEMO.swift index b4e58c0..abf7199 100644 --- a/ConversationsClassic/AppData/Model/Message+OMEMO.swift +++ b/ConversationsClassic/AppData/Model/Message+OMEMO.swift @@ -33,6 +33,7 @@ extension Message { } // Try to recognize if message is omemo-encoded and decode it + var secure = false if let omemo = context?.module(.omemo) { let decodingResult = omemo.decode(message: martinMessage) switch decodingResult { @@ -46,6 +47,7 @@ extension Message { remotePath: oob )) } + secure = true case .successTransportKey: break @@ -76,7 +78,8 @@ extension Message { body: martinMessage.body, subject: martinMessage.subject, thread: martinMessage.thread, - oobUrl: martinMessage.oob + oobUrl: martinMessage.oob, + secure: secure ) return msg } diff --git a/ConversationsClassic/AppData/Model/Message.swift b/ConversationsClassic/AppData/Model/Message.swift index 4b51cab..411842f 100644 --- a/ConversationsClassic/AppData/Model/Message.swift +++ b/ConversationsClassic/AppData/Model/Message.swift @@ -68,6 +68,8 @@ struct Message: DBStorable, Equatable { var subject: String? var thread: String? var oobUrl: String? + + var secure: Bool } extension Message { @@ -97,7 +99,8 @@ extension Message { body: nil, subject: nil, thread: nil, - oobUrl: nil + oobUrl: nil, + secure: false ) } } diff --git a/ConversationsClassic/AppData/Services/Database+Migrations.swift b/ConversationsClassic/AppData/Services/Database+Migrations.swift index ad23119..c3a01b5 100644 --- a/ConversationsClassic/AppData/Services/Database+Migrations.swift +++ b/ConversationsClassic/AppData/Services/Database+Migrations.swift @@ -94,14 +94,9 @@ extension Database { table.primaryKey(["account", "id"], onConflict: .replace) } - // try db.alter(table: "chats") { table in - // table.add(column: "encryption", .text) - // } - // - // try db.alter(table: "messages") { table in - // table.add(column: "encryption", .integer) - // table.add(column: "fingerprint", .text) - // } + try db.alter(table: "messages") { table in + table.add(column: "secure", .boolean).notNull().defaults(to: false) + } } migrator.registerMigration("Add settings table") { db in diff --git a/ConversationsClassic/AppData/Store/MessagesStore.swift b/ConversationsClassic/AppData/Store/MessagesStore.swift index 37635a2..4e0cffa 100644 --- a/ConversationsClassic/AppData/Store/MessagesStore.swift +++ b/ConversationsClassic/AppData/Store/MessagesStore.swift @@ -29,6 +29,7 @@ extension MessagesStore { msg.from = roster.bareJid msg.to = roster.contactBareJid msg.body = message + msg.secure = true // store as pending on db, and send do { diff --git a/ConversationsClassic/View/Main/Conversation/ConversationMessageContainer.swift b/ConversationsClassic/View/Main/Conversation/ConversationMessageContainer.swift index ffb7915..5520eb6 100644 --- a/ConversationsClassic/View/Main/Conversation/ConversationMessageContainer.swift +++ b/ConversationsClassic/View/Main/Conversation/ConversationMessageContainer.swift @@ -41,6 +41,10 @@ struct MessageAttr: View { Image(systemName: "clock") .font(.body3) .foregroundColor(.Material.Shape.separator) + } else if message.secure { + Image(systemName: "lock") + .font(.body3) + .foregroundColor(.Material.Shape.separator) } } } @@ -186,13 +190,13 @@ private struct AttachmentView: View { switch type { case .image: return "photo" - + case .audio: return "music.note" - + case .video: return "film" - + case .file: return "doc" }