diff --git a/Monal/Monal.xcodeproj/project.pbxproj b/Monal/Monal.xcodeproj/project.pbxproj index 518815a..435a6be 100644 --- a/Monal/Monal.xcodeproj/project.pbxproj +++ b/Monal/Monal.xcodeproj/project.pbxproj @@ -13,6 +13,7 @@ 1C8760F8FB99C27D0C3A6ED1 /* RegistrationScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82D4382FFF3D97C4E1D7727C /* RegistrationScreen.swift */; }; 1D3623260D0F684500981E51 /* MonalAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D3623250D0F684500981E51 /* MonalAppDelegate.m */; }; 1D60589B0D05DD56006BFB54 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; }; + 2075230B91C7DB319CCBA11D /* WrapperXMPP.swift in Sources */ = {isa = PBXBuildFile; fileRef = 998D2BEBAB8C1CA1AC471B4A /* WrapperXMPP.swift */; }; 20D3611C2C10E12500E46587 /* BoardingCards.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20D3611B2C10E12500E46587 /* BoardingCards.swift */; }; 20D8C65E2C3C37FE00E6BDA2 /* MediaGallery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20D8C65D2C3C37FE00E6BDA2 /* MediaGallery.swift */; }; 20ED55852BADDA5C0005783E /* GeneralSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20ED55842BADDA5C0005783E /* GeneralSettings.swift */; }; @@ -139,7 +140,6 @@ 7E1C0AC72CEF68C000B8FEC0 /* MainTabScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E1C0AC62CEF68C000B8FEC0 /* MainTabScreen.swift */; }; 7E1C0ACB2CEF6C7800B8FEC0 /* ContactsScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E1C0AC92CEF6C7800B8FEC0 /* ContactsScreen.swift */; }; 7E1C0ACC2CEF6C7800B8FEC0 /* AddContactOrChannelScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E1C0AC82CEF6C7800B8FEC0 /* AddContactOrChannelScreen.swift */; }; - 7E6AF38F2CEB9110004328B5 /* MonalXmppWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E6AF38E2CEB9110004328B5 /* MonalXmppWrapper.swift */; }; 7E6AF3902CEB982F004328B5 /* sworim.sqlite in Resources */ = {isa = PBXBuildFile; fileRef = 2601D9CA0FBF25EF004DB939 /* sworim.sqlite */; }; 7E71758D2CECC5C70059F30B /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 7E71758B2CECC5C70059F30B /* Localizable.strings */; }; 7E71758E2CECC5C70059F30B /* server_features.plist in Resources */ = {isa = PBXBuildFile; fileRef = 7E71758A2CECC5C70059F30B /* server_features.plist */; }; @@ -242,6 +242,7 @@ 84FC37552897521500634E3E /* snprintf.m in Sources */ = {isa = PBXBuildFile; fileRef = 84FC37542897521400634E3E /* snprintf.m */; }; 84FC37572897523500634E3E /* metamacros.h in Headers */ = {isa = PBXBuildFile; fileRef = 84FC37562897523500634E3E /* metamacros.h */; }; 84FC375928981A5600634E3E /* PasswordMigration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84FC375828981A5600634E3E /* PasswordMigration.swift */; }; + 90722912B34CD0DFD6ED291E /* WrapperChat.swift in Sources */ = {isa = PBXBuildFile; fileRef = 585781EBEDA697BA88FC803D /* WrapperChat.swift */; }; 952EBC802BAF72F300183DBF /* DebugView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 952EBC7F2BAF72F300183DBF /* DebugView.swift */; }; C10490492612ED2F0054AC9E /* MLEmoji.swift in Sources */ = {isa = PBXBuildFile; fileRef = C10490482612ED2F0054AC9E /* MLEmoji.swift */; }; C10490E32612F3D00054AC9E /* MLCrypto.swift in Sources */ = {isa = PBXBuildFile; fileRef = C10490E22612F3D00054AC9E /* MLCrypto.swift */; }; @@ -646,6 +647,7 @@ 54E594BC2523C34A00E4172B /* MLPubSub.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MLPubSub.m; sourceTree = ""; }; 54F0B81828231690003664BD /* WelcomeLogIn.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WelcomeLogIn.swift; sourceTree = ""; }; 54F0B81B282316F5003664BD /* RegisterAccount.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RegisterAccount.swift; sourceTree = ""; }; + 585781EBEDA697BA88FC803D /* WrapperChat.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = WrapperChat.swift; sourceTree = ""; }; 59F4A459FBC6040A0F8CCAF3 /* Pods-NotificaionService.alpha-catalyst.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NotificaionService.alpha-catalyst.xcconfig"; path = "Target Support Files/Pods-NotificaionService/Pods-NotificaionService.alpha-catalyst.xcconfig"; sourceTree = ""; }; 5B9C86E0A568734587FE9BA2 /* Pods_monalxmpp.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_monalxmpp.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 5BACDACCFE405FE0C903C897 /* Pods-MonalUITests.alpha.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MonalUITests.alpha.xcconfig"; path = "Target Support Files/Pods-MonalUITests/Pods-MonalUITests.alpha.xcconfig"; sourceTree = ""; }; @@ -664,7 +666,6 @@ 7E1C0AC62CEF68C000B8FEC0 /* MainTabScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainTabScreen.swift; sourceTree = ""; }; 7E1C0AC82CEF6C7800B8FEC0 /* AddContactOrChannelScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddContactOrChannelScreen.swift; sourceTree = ""; }; 7E1C0AC92CEF6C7800B8FEC0 /* ContactsScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContactsScreen.swift; sourceTree = ""; }; - 7E6AF38E2CEB9110004328B5 /* MonalXmppWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MonalXmppWrapper.swift; sourceTree = ""; }; 7E6E446D2CECB76500505D5C /* another.im.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = another.im.entitlements; sourceTree = ""; }; 7E7175892CECC5C70059F30B /* launchscreen.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = launchscreen.storyboard; sourceTree = ""; }; 7E71758A2CECC5C70059F30B /* server_features.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = server_features.plist; sourceTree = ""; }; @@ -775,6 +776,7 @@ 9705AFFB59AF72A9B79C1D7B /* Pods-MonalXMPPUnitTests.adhoc.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MonalXMPPUnitTests.adhoc.xcconfig"; path = "Target Support Files/Pods-MonalXMPPUnitTests/Pods-MonalXMPPUnitTests.adhoc.xcconfig"; sourceTree = ""; }; 9760CF4718351300C4256921 /* Pods-shareSheet.appstore-quicksy.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-shareSheet.appstore-quicksy.xcconfig"; path = "Target Support Files/Pods-shareSheet/Pods-shareSheet.appstore-quicksy.xcconfig"; sourceTree = ""; }; 9899D670570190DCBE9EEDDB /* Pods-monalxmpp.appstore-quicksy.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-monalxmpp.appstore-quicksy.xcconfig"; path = "Target Support Files/Pods-monalxmpp/Pods-monalxmpp.appstore-quicksy.xcconfig"; sourceTree = ""; }; + 998D2BEBAB8C1CA1AC471B4A /* WrapperXMPP.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = WrapperXMPP.swift; sourceTree = ""; }; A2ED40D3515305509E3E166C /* Pods-MonalUITests.alpha-catalyst.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MonalUITests.alpha-catalyst.xcconfig"; path = "Target Support Files/Pods-MonalUITests/Pods-MonalUITests.alpha-catalyst.xcconfig"; sourceTree = ""; }; A4C686567AC126CDDFB1BE44 /* Pods-NotificaionService.beta.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NotificaionService.beta.xcconfig"; path = "Target Support Files/Pods-NotificaionService/Pods-NotificaionService.beta.xcconfig"; sourceTree = ""; }; AA697C1F9B9637B86665DFF1 /* Pods-NotificationService.appstore-quicksy.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NotificationService.appstore-quicksy.xcconfig"; path = "Target Support Files/Pods-NotificationService/Pods-NotificationService.appstore-quicksy.xcconfig"; sourceTree = ""; }; @@ -1452,7 +1454,7 @@ name = tools; sourceTree = ""; }; - 29B97314FDCFA39411CA2CEA /* CustomTemplate */ = { + 29B97314FDCFA39411CA2CEA = { isa = PBXGroup; children = ( 8414ADF92A7ABAC900EFFCCC /* Packages */, @@ -1578,10 +1580,10 @@ 7E8D7AE52CECD05C009AD3DF /* XMPP */ = { isa = PBXGroup; children = ( - 7E6AF38E2CEB9110004328B5 /* MonalXmppWrapper.swift */, 404FB187FD6CB3DD41DAC820 /* AimErrors.swift */, E23C31EA05858AFC0AB43D06 /* Scenaries */, 8C5F2E42A69F9A7B93A20F78 /* Models */, + ABC8671064FCFD060C57E114 /* Wrappers */, ); path = XMPP; sourceTree = ""; @@ -1787,6 +1789,16 @@ path = Models; sourceTree = ""; }; + ABC8671064FCFD060C57E114 /* Wrappers */ = { + isa = PBXGroup; + children = ( + 998D2BEBAB8C1CA1AC471B4A /* WrapperXMPP.swift */, + 585781EBEDA697BA88FC803D /* WrapperChat.swift */, + ); + name = Wrappers; + path = Wrappers; + sourceTree = ""; + }; C1049187261301530054AC9E /* MonalXMPPUnitTests */ = { isa = PBXGroup; children = ( @@ -2174,7 +2186,7 @@ eu, "es-AR", ); - mainGroup = 29B97314FDCFA39411CA2CEA /* CustomTemplate */; + mainGroup = 29B97314FDCFA39411CA2CEA; packageReferences = ( C1F5C7AD2777638B0001F295 /* XCRemoteSwiftPackageReference "swift-collections" */, 841898A82957712000FEC77D /* XCRemoteSwiftPackageReference "ViewExtractor" */, @@ -2780,7 +2792,6 @@ 7E1C0ACC2CEF6C7800B8FEC0 /* AddContactOrChannelScreen.swift in Sources */, 7E8D7AFE2CECEDB3009AD3DF /* LoadingScreen.swift in Sources */, 7E995F252CEAC5D2005B30EE /* RootView.swift in Sources */, - 7E6AF38F2CEB9110004328B5 /* MonalXmppWrapper.swift in Sources */, 335B19D1B8E6A4D5FE71380C /* WelcomeScreen.swift in Sources */, C11E557980B75AA90738EC9C /* LoginScreen.swift in Sources */, 1C8760F8FB99C27D0C3A6ED1 /* RegistrationScreen.swift in Sources */, @@ -2790,6 +2801,8 @@ 07D2570A3091519439B47A6A /* Chat.swift in Sources */, DEDA22BC3DBA90E586F6B7CE /* Message.swift in Sources */, 5C2B6A5C14F38F315ECC3F5E /* ScenarioLogIn.swift in Sources */, + 2075230B91C7DB319CCBA11D /* WrapperXMPP.swift in Sources */, + 90722912B34CD0DFD6ED291E /* WrapperChat.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -3737,7 +3750,7 @@ CODE_SIGN_ENTITLEMENTS = another.im/Resources/another.im.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 3; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_TEAM = K78H7BT98L; @@ -3828,7 +3841,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 3; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_TEAM = K78H7BT98L; @@ -3925,7 +3938,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 3; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_TEAM = K78H7BT98L; @@ -4022,7 +4035,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 3; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_TEAM = K78H7BT98L; @@ -4119,7 +4132,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 3; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_TEAM = K78H7BT98L; @@ -4216,7 +4229,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 3; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_TEAM = K78H7BT98L; diff --git a/Monal/another.im/AnotherIMApp.swift b/Monal/another.im/AnotherIMApp.swift index 94bf33d..7979c25 100644 --- a/Monal/another.im/AnotherIMApp.swift +++ b/Monal/another.im/AnotherIMApp.swift @@ -4,7 +4,7 @@ import SwiftUI @main struct AnotherIMApp: App { @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate - @StateObject var wrapper = MonalXmppWrapper() + @StateObject var wrapper = WrapperXMPP() init() { DDLog.add(DDOSLogger.sharedInstance, with: .all) diff --git a/Monal/another.im/Views/Conversation/ConversationMessageRow.swift b/Monal/another.im/Views/Conversation/ConversationMessageRow.swift index 4422639..d1c7716 100644 --- a/Monal/another.im/Views/Conversation/ConversationMessageRow.swift +++ b/Monal/another.im/Views/Conversation/ConversationMessageRow.swift @@ -2,7 +2,7 @@ import Foundation import SwiftUI struct ConversationMessageRow: View { - @EnvironmentObject var chatWrapper: MonalChatWrapper + @EnvironmentObject var chatWrapper: WrapperXMPP let message: Message @State private var offset: CGSize = .zero diff --git a/Monal/another.im/Views/Conversation/ConversationScreen.swift b/Monal/another.im/Views/Conversation/ConversationScreen.swift index 3487ee2..4271e9e 100644 --- a/Monal/another.im/Views/Conversation/ConversationScreen.swift +++ b/Monal/another.im/Views/Conversation/ConversationScreen.swift @@ -4,7 +4,7 @@ import SwiftUI struct ConversationScreen: View { @Environment(\.router) var router - @EnvironmentObject var chatWrapper: MonalChatWrapper + @EnvironmentObject var chatWrapper: WrapperChat @State private var autoScroll = true @State private var firstIsVisible = true diff --git a/Monal/another.im/Views/Conversation/ConversationSettingsScreen.swift b/Monal/another.im/Views/Conversation/ConversationSettingsScreen.swift index 8c95591..678c92c 100644 --- a/Monal/another.im/Views/Conversation/ConversationSettingsScreen.swift +++ b/Monal/another.im/Views/Conversation/ConversationSettingsScreen.swift @@ -3,7 +3,7 @@ import Foundation import SwiftUI struct ConversationSettingsScreen: View { - @EnvironmentObject var chatWrapper: MonalChatWrapper + @EnvironmentObject var chatWrapper: WrapperChat @Environment(\.router) var router var body: some View { diff --git a/Monal/another.im/Views/Conversation/ConversationTextInput.swift b/Monal/another.im/Views/Conversation/ConversationTextInput.swift index 5b6dcef..86be111 100644 --- a/Monal/another.im/Views/Conversation/ConversationTextInput.swift +++ b/Monal/another.im/Views/Conversation/ConversationTextInput.swift @@ -3,7 +3,7 @@ import UIKit struct ConversationTextInput: View { @Environment(\.router) var router - @EnvironmentObject var chatWrapper: MonalChatWrapper + @EnvironmentObject var chatWrapper: WrapperChat @State private var messageStr = "" @FocusState private var isFocused: Bool diff --git a/Monal/another.im/Views/Enter/LoginScreen.swift b/Monal/another.im/Views/Enter/LoginScreen.swift index 33980c8..983b2e5 100644 --- a/Monal/another.im/Views/Enter/LoginScreen.swift +++ b/Monal/another.im/Views/Enter/LoginScreen.swift @@ -2,7 +2,7 @@ import Combine import SwiftUI struct LoginScreen: View { - @EnvironmentObject var wrapper: MonalXmppWrapper + @EnvironmentObject var wrapper: WrapperXMPP @Environment(\.router) var router enum Field { diff --git a/Monal/another.im/Views/Enter/WelcomeScreen.swift b/Monal/another.im/Views/Enter/WelcomeScreen.swift index d12d6a6..5ec99ec 100644 --- a/Monal/another.im/Views/Enter/WelcomeScreen.swift +++ b/Monal/another.im/Views/Enter/WelcomeScreen.swift @@ -1,7 +1,7 @@ import SwiftUI struct WelcomeScreen: View { - @EnvironmentObject var wrapper: MonalXmppWrapper + @EnvironmentObject var wrapper: WrapperXMPP @Environment(\.router) var router var body: some View { diff --git a/Monal/another.im/Views/Main/ChatList/ChatsListScreen.swift b/Monal/another.im/Views/Main/ChatList/ChatsListScreen.swift index 228e046..59d004d 100644 --- a/Monal/another.im/Views/Main/ChatList/ChatsListScreen.swift +++ b/Monal/another.im/Views/Main/ChatList/ChatsListScreen.swift @@ -1,7 +1,7 @@ import SwiftUI struct ChatsListScreen: View { - @EnvironmentObject var wrapper: MonalXmppWrapper + @EnvironmentObject var wrapper: WrapperXMPP @Environment(\.router) var router var body: some View { @@ -43,7 +43,7 @@ struct ChatsListScreen: View { } private struct ChatsRow: View { - @EnvironmentObject var wrapper: MonalXmppWrapper + @EnvironmentObject var wrapper: WrapperXMPP @Environment(\.router) var router var chat: Chat diff --git a/Monal/another.im/Views/Main/Contacts/AddContactOrChannelScreen.swift b/Monal/another.im/Views/Main/Contacts/AddContactOrChannelScreen.swift index 5985338..b1ed4d3 100644 --- a/Monal/another.im/Views/Main/Contacts/AddContactOrChannelScreen.swift +++ b/Monal/another.im/Views/Main/Contacts/AddContactOrChannelScreen.swift @@ -1,7 +1,7 @@ import SwiftUI struct AddContactOrChannelScreen: View { - @EnvironmentObject var wrapper: MonalXmppWrapper + @EnvironmentObject var wrapper: WrapperXMPP @Environment(\.router) var router enum Field { diff --git a/Monal/another.im/Views/Main/Contacts/ContactsScreen.swift b/Monal/another.im/Views/Main/Contacts/ContactsScreen.swift index 031d8e4..ed0f4b8 100644 --- a/Monal/another.im/Views/Main/Contacts/ContactsScreen.swift +++ b/Monal/another.im/Views/Main/Contacts/ContactsScreen.swift @@ -1,7 +1,7 @@ import SwiftUI struct ContactsScreen: View { - @EnvironmentObject var wrapper: MonalXmppWrapper + @EnvironmentObject var wrapper: WrapperXMPP @Environment(\.router) var router var body: some View { @@ -43,7 +43,7 @@ struct ContactsScreen: View { } private struct ContactsScreenRow: View { - @EnvironmentObject var wrapper: MonalXmppWrapper + @EnvironmentObject var wrapper: WrapperXMPP @Environment(\.router) var router var contact: Contact diff --git a/Monal/another.im/Views/Main/MainTabScreen.swift b/Monal/another.im/Views/Main/MainTabScreen.swift index d39f29e..54fbfd6 100644 --- a/Monal/another.im/Views/Main/MainTabScreen.swift +++ b/Monal/another.im/Views/Main/MainTabScreen.swift @@ -9,7 +9,7 @@ private enum Tab { } struct MainTabScreen: View { - @EnvironmentObject var wrapper: MonalXmppWrapper + @EnvironmentObject var wrapper: WrapperXMPP @State private var selectedTab: Tab = .chats diff --git a/Monal/another.im/Views/RootView.swift b/Monal/another.im/Views/RootView.swift index 636d7e8..f7269f9 100644 --- a/Monal/another.im/Views/RootView.swift +++ b/Monal/another.im/Views/RootView.swift @@ -2,7 +2,7 @@ import SwiftfulRouting import SwiftUI struct RootView: View { - @EnvironmentObject var wrapper: MonalXmppWrapper + @EnvironmentObject var wrapper: WrapperXMPP var body: some View { if wrapper.accountsAvailability == .someEnabled { diff --git a/Monal/another.im/XMPP/Wrappers/WrapperChat.swift b/Monal/another.im/XMPP/Wrappers/WrapperChat.swift new file mode 100644 index 0000000..9b4c6dc --- /dev/null +++ b/Monal/another.im/XMPP/Wrappers/WrapperChat.swift @@ -0,0 +1,111 @@ +import Foundation +import monalxmpp + +final class WrapperChat: ObservableObject { + @Published private(set) var messages: [Message] = [] + @Published var replyText: String = "" + @Published private(set) var mamRequestInProgress = false + @Published var isOmemoEnabled: Bool { + didSet { + toggleOmemo(isOmemoEnabled) + } + } + + let contact: Contact + + private let monalContact: MLContact + private let account: Account + private let xmpp: MLXMPPManager + private let db: DataLayer + private var notificationObservers: [AnyObject] = [] + + init(account: Account, contact: Contact, db: DataLayer, xmpp: MLXMPPManager) { + self.contact = contact + self.account = account + self.db = db + self.xmpp = xmpp + + // swiftlint:disable:next force_unwrapping + monalContact = db.contactList().first { $0.accountID.intValue == contact.ownerId && $0.contactJid == contact.contactJid }! + isOmemoEnabled = monalContact.isEncrypted + + subscribe() + NotificationCenter.default.post(name: Notification.Name(kMonalNewMessageNotice), object: nil) + + // + } + + deinit { + notificationObservers.forEach { NotificationCenter.default.removeObserver($0) } + } + + var chatTitle: String { + contact.name + } + + func sendText(_ text: String) { + let newMessageId = UUID().uuidString + _ = db.addMessageHistory( + to: contact.contactJid, + forAccount: monalContact.accountID, + withMessage: text, + actuallyFrom: account.jid, + withId: newMessageId, + encrypted: monalContact.isEncrypted, + messageType: kMessageTypeText, + mimeType: nil, + size: nil + ) + print(newMessageId) + xmpp.sendMessage(text, to: monalContact, isEncrypted: monalContact.isEncrypted, isUpload: false, messageId: newMessageId) + } + + func requestMAM() { + if mamRequestInProgress { return } + mamRequestInProgress = true + + guard let acc = xmpp.getEnabledAccount(forID: NSNumber(value: account.id)) else { return } + + let lastStanzaId = messages.last?.stanzaId // last here because list is reversed + ?? db.lastStanzaId(forAccount: NSNumber(value: account.id)) + + acc.setMAMQueryMostRecentFor(monalContact, before: lastStanzaId) { [weak self] msgs, _ in + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in + self?.mamRequestInProgress = false + if !(msgs ?? []).isEmpty { + self?.refreshMessages() + } + } + } + } +} + +private extension WrapperChat { + func subscribe() { + let newMsg = NotificationCenter.default.addObserver(forName: Notification.Name(kMonalNewMessageNotice), object: nil, queue: .main) { [weak self] _ in + self?.refreshMessages() + } + notificationObservers.append(newMsg) + + let sentMsg = NotificationCenter.default.addObserver(forName: Notification.Name(kMonalSentMessageNotice), object: nil, queue: .main) { [weak self] _ in + self?.refreshMessages() + } + notificationObservers.append(sentMsg) + } + + func refreshMessages() { + let messages = db.messages(forContact: contact.contactJid, forAccount: NSNumber(value: contact.ownerId)) + .compactMap { obj -> Message? in + guard let message = obj as? MLMessage else { return nil } + return Message(message) + } + .sorted { $0.timestamp > $1.timestamp } + self.messages = messages + } + + func toggleOmemo(_ new: Bool) { + if monalContact.isEncrypted != new { + monalContact.toggleEncryption(new) + } + } +} diff --git a/Monal/another.im/XMPP/MonalXmppWrapper.swift b/Monal/another.im/XMPP/Wrappers/WrapperXMPP.swift similarity index 53% rename from Monal/another.im/XMPP/MonalXmppWrapper.swift rename to Monal/another.im/XMPP/Wrappers/WrapperXMPP.swift index 8e8175c..cc011f0 100644 --- a/Monal/another.im/XMPP/MonalXmppWrapper.swift +++ b/Monal/another.im/XMPP/Wrappers/WrapperXMPP.swift @@ -7,7 +7,7 @@ enum AccountsAvailability { case someEnabled } -final class MonalXmppWrapper: ObservableObject { +final class WrapperXMPP: ObservableObject { @Published private(set) var accountsAvailability: AccountsAvailability = .noAccounts @Published private(set) var accounts: [Account] = [] @Published private(set) var contacts: [Contact] = [] @@ -19,8 +19,6 @@ final class MonalXmppWrapper: ObservableObject { private var notificationObservers: [AnyObject] = [] init() { - // here is some inits (just for now) - // init monalxmpp components xmpp = MLXMPPManager.sharedInstance() db = DataLayer.sharedInstance() @@ -29,10 +27,6 @@ final class MonalXmppWrapper: ObservableObject { subscribeToUpdates() xmpp.reconnectAll() NotificationCenter.default.post(name: Notification.Name(kMonalRefresh), object: nil) - - // reconnect - // xmpp.nowForegrounded() - // xmpp.connectIfNecessary() } deinit { @@ -41,7 +35,7 @@ final class MonalXmppWrapper: ObservableObject { } // MARK: - Public -extension MonalXmppWrapper { +extension WrapperXMPP { func tryLogin(_ login: String, _ password: String) async throws { let scenario = ScenarioLogIn() let result = await scenario.tryLogin(login, password) @@ -65,14 +59,14 @@ extension MonalXmppWrapper { } } - func chat(with: Contact) -> MonalChatWrapper { + func chat(with: Contact) -> WrapperChat { // swiftlint:disable:next force_unwrapping let account = accounts.first { $0.id == with.ownerId }! - let chatModel = MonalChatWrapper(account: account, contact: with, db: db, xmpp: xmpp) + let chatModel = WrapperChat(account: account, contact: with, db: db, xmpp: xmpp) return chatModel } - func chat(with: Chat) -> MonalChatWrapper? { + func chat(with: Chat) -> WrapperChat? { guard let account = accounts.first(where: { $0.id == with.accountId }) else { return nil } var contact = contacts.first(where: { $0.ownerId == with.accountId && $0.contactJid == with.participantJid }) @@ -89,13 +83,13 @@ extension MonalXmppWrapper { } guard let contact else { return nil } - let chatModel = MonalChatWrapper(account: account, contact: contact, db: db, xmpp: xmpp) + let chatModel = WrapperChat(account: account, contact: contact, db: db, xmpp: xmpp) return chatModel } } // MARK: - Handle notifications -private extension MonalXmppWrapper { +private extension WrapperXMPP { func subscribeToUpdates() { // General let generalRefresh = NotificationCenter.default.addObserver(forName: Notification.Name(kMonalRefresh), object: nil, queue: .main) { [weak self] _ in @@ -151,113 +145,3 @@ private extension MonalXmppWrapper { } } } - -// MARK: - Chat object -final class MonalChatWrapper: ObservableObject { - @Published private(set) var messages: [Message] = [] - @Published var replyText: String = "" - @Published private(set) var mamRequestInProgress = false - @Published var isOmemoEnabled: Bool { - didSet { - toggleOmemo(isOmemoEnabled) - } - } - - let contact: Contact - - private let monalContact: MLContact - private let account: Account - private let xmpp: MLXMPPManager - private let db: DataLayer - private var notificationObservers: [AnyObject] = [] - - init(account: Account, contact: Contact, db: DataLayer, xmpp: MLXMPPManager) { - self.contact = contact - self.account = account - self.db = db - self.xmpp = xmpp - - // swiftlint:disable:next force_unwrapping - monalContact = db.contactList().first { $0.accountID.intValue == contact.ownerId && $0.contactJid == contact.contactJid }! - isOmemoEnabled = monalContact.isEncrypted - - subscribe() - NotificationCenter.default.post(name: Notification.Name(kMonalNewMessageNotice), object: nil) - - // - } - - deinit { - notificationObservers.forEach { NotificationCenter.default.removeObserver($0) } - } - - var chatTitle: String { - contact.name - } - - func sendText(_ text: String) { - let newMessageId = UUID().uuidString - _ = db.addMessageHistory( - to: contact.contactJid, - forAccount: monalContact.accountID, - withMessage: text, - actuallyFrom: account.jid, - withId: newMessageId, - encrypted: monalContact.isEncrypted, - messageType: kMessageTypeText, - mimeType: nil, - size: nil - ) - print(newMessageId) - xmpp.sendMessage(text, to: monalContact, isEncrypted: monalContact.isEncrypted, isUpload: false, messageId: newMessageId) - } - - func requestMAM() { - if mamRequestInProgress { return } - mamRequestInProgress = true - - guard let acc = xmpp.getEnabledAccount(forID: NSNumber(value: account.id)) else { return } - - let lastStanzaId = messages.last?.stanzaId // last here because list is reversed - ?? db.lastStanzaId(forAccount: NSNumber(value: account.id)) - - acc.setMAMQueryMostRecentFor(monalContact, before: lastStanzaId) { [weak self] msgs, _ in - DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in - self?.mamRequestInProgress = false - if !(msgs ?? []).isEmpty { - self?.refreshMessages() - } - } - } - } -} - -private extension MonalChatWrapper { - func subscribe() { - let newMsg = NotificationCenter.default.addObserver(forName: Notification.Name(kMonalNewMessageNotice), object: nil, queue: .main) { [weak self] _ in - self?.refreshMessages() - } - notificationObservers.append(newMsg) - - let sentMsg = NotificationCenter.default.addObserver(forName: Notification.Name(kMonalSentMessageNotice), object: nil, queue: .main) { [weak self] _ in - self?.refreshMessages() - } - notificationObservers.append(sentMsg) - } - - func refreshMessages() { - let messages = db.messages(forContact: contact.contactJid, forAccount: NSNumber(value: contact.ownerId)) - .compactMap { obj -> Message? in - guard let message = obj as? MLMessage else { return nil } - return Message(message) - } - .sorted { $0.timestamp > $1.timestamp } - self.messages = messages - } - - func toggleOmemo(_ new: Bool) { - if monalContact.isEncrypted != new { - monalContact.toggleEncryption(new) - } - } -}