diff --git a/Monal/Classes/MLConstants.h b/Monal/Classes/MLConstants.h index bbd61fe..3277c0a 100644 --- a/Monal/Classes/MLConstants.h +++ b/Monal/Classes/MLConstants.h @@ -41,7 +41,7 @@ static const DDLogLevel ddLogLevel = LOG_LEVEL_STDOUT; #else // fmodf: 19.11.24 - changed to actual another.im group // #define kAppGroup @"group.monal" - #define kAppGroup @"group.another.im.test" + #define kAppGroup @"group.im.narayana.anotherim" #define kMonalOpenURL [NSURL URLWithString:@"monalOpen://"] #define kBackgroundProcessingTask @"im.monal.process" #define kBackgroundRefreshingTask @"im.monal.refresh" diff --git a/Monal/Monal.xcodeproj/project.pbxproj b/Monal/Monal.xcodeproj/project.pbxproj index 75322ba..beea7e3 100644 --- a/Monal/Monal.xcodeproj/project.pbxproj +++ b/Monal/Monal.xcodeproj/project.pbxproj @@ -3706,7 +3706,7 @@ CURRENT_PROJECT_VERSION = 1; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_ASSET_PATHS = ""; - DEVELOPMENT_TEAM = U6CKGHL5VR; + DEVELOPMENT_TEAM = K78H7BT98L; ENABLE_PREVIEWS = YES; ENABLE_USER_SCRIPT_SANDBOXING = NO; GCC_C_LANGUAGE_STANDARD = gnu17; @@ -3736,7 +3736,7 @@ MARKETING_VERSION = 1.0.0; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; - PRODUCT_BUNDLE_IDENTIFIER = com.mitrofanovegor.anotherim; + PRODUCT_BUNDLE_IDENTIFIER = im.narayana.anotherim.ios; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; @@ -3792,7 +3792,7 @@ CURRENT_PROJECT_VERSION = 1; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_ASSET_PATHS = ""; - DEVELOPMENT_TEAM = U6CKGHL5VR; + DEVELOPMENT_TEAM = K78H7BT98L; ENABLE_NS_ASSERTIONS = NO; ENABLE_PREVIEWS = YES; ENABLE_STRICT_OBJC_MSGSEND = YES; @@ -3826,7 +3826,7 @@ MARKETING_VERSION = 1.0.0; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; - PRODUCT_BUNDLE_IDENTIFIER = com.mitrofanovegor.anotherim; + PRODUCT_BUNDLE_IDENTIFIER = im.narayana.anotherim.ios; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; SDKROOT = iphoneos; @@ -3884,7 +3884,7 @@ CURRENT_PROJECT_VERSION = 1; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_ASSET_PATHS = ""; - DEVELOPMENT_TEAM = U6CKGHL5VR; + DEVELOPMENT_TEAM = K78H7BT98L; ENABLE_NS_ASSERTIONS = NO; ENABLE_PREVIEWS = YES; ENABLE_STRICT_OBJC_MSGSEND = YES; @@ -3918,7 +3918,7 @@ MARKETING_VERSION = 1.0.0; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; - PRODUCT_BUNDLE_IDENTIFIER = com.mitrofanovegor.anotherim; + PRODUCT_BUNDLE_IDENTIFIER = im.narayana.anotherim.ios; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; SDKROOT = iphoneos; @@ -3976,7 +3976,7 @@ CURRENT_PROJECT_VERSION = 1; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_ASSET_PATHS = ""; - DEVELOPMENT_TEAM = U6CKGHL5VR; + DEVELOPMENT_TEAM = K78H7BT98L; ENABLE_NS_ASSERTIONS = NO; ENABLE_PREVIEWS = YES; ENABLE_STRICT_OBJC_MSGSEND = YES; @@ -4010,7 +4010,7 @@ MARKETING_VERSION = 1.0.0; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; - PRODUCT_BUNDLE_IDENTIFIER = com.mitrofanovegor.anotherim; + PRODUCT_BUNDLE_IDENTIFIER = im.narayana.anotherim.ios; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; SDKROOT = iphoneos; @@ -4068,7 +4068,7 @@ CURRENT_PROJECT_VERSION = 1; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_ASSET_PATHS = ""; - DEVELOPMENT_TEAM = U6CKGHL5VR; + DEVELOPMENT_TEAM = K78H7BT98L; ENABLE_NS_ASSERTIONS = NO; ENABLE_PREVIEWS = YES; ENABLE_STRICT_OBJC_MSGSEND = YES; @@ -4102,7 +4102,7 @@ MARKETING_VERSION = 1.0.0; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; - PRODUCT_BUNDLE_IDENTIFIER = com.mitrofanovegor.anotherim; + PRODUCT_BUNDLE_IDENTIFIER = im.narayana.anotherim.ios; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; SDKROOT = iphoneos; @@ -4160,7 +4160,7 @@ CURRENT_PROJECT_VERSION = 1; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_ASSET_PATHS = ""; - DEVELOPMENT_TEAM = U6CKGHL5VR; + DEVELOPMENT_TEAM = K78H7BT98L; ENABLE_NS_ASSERTIONS = NO; ENABLE_PREVIEWS = YES; ENABLE_STRICT_OBJC_MSGSEND = YES; @@ -4194,7 +4194,7 @@ MARKETING_VERSION = 1.0.0; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; - PRODUCT_BUNDLE_IDENTIFIER = com.mitrofanovegor.anotherim; + PRODUCT_BUNDLE_IDENTIFIER = im.narayana.anotherim.ios; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; SDKROOT = iphoneos; diff --git a/Monal/another.im/Resources/another.im.entitlements b/Monal/another.im/Resources/another.im.entitlements index 3163c75..524b466 100644 --- a/Monal/another.im/Resources/another.im.entitlements +++ b/Monal/another.im/Resources/another.im.entitlements @@ -4,7 +4,7 @@ com.apple.security.application-groups - group.another.im.test + group.im.narayana.anotherim diff --git a/Monal/another.im/Views/Conversation/ConversationMessageRow.swift b/Monal/another.im/Views/Conversation/ConversationMessageRow.swift index a229fa3..0d12b6e 100644 --- a/Monal/another.im/Views/Conversation/ConversationMessageRow.swift +++ b/Monal/another.im/Views/Conversation/ConversationMessageRow.swift @@ -3,7 +3,7 @@ import SwiftUI struct ConversationMessageRow: View { // @EnvironmentObject var messages: MessagesStore - // let message: Message + let message: Message @State private var offset: CGSize = .zero var body: some View { diff --git a/Monal/another.im/Views/Conversation/ConversationScreen.swift b/Monal/another.im/Views/Conversation/ConversationScreen.swift index ee40b30..0e63020 100644 --- a/Monal/another.im/Views/Conversation/ConversationScreen.swift +++ b/Monal/another.im/Views/Conversation/ConversationScreen.swift @@ -4,10 +4,7 @@ import SwiftUI struct ConversationScreen: View { @Environment(\.router) var router - @EnvironmentObject var chatModel: ChatModel - // @StateObject var messagesStore: MessagesStore - // @StateObject var attachments: AttachmentsStore - // @StateObject var settings: ChatSettingsStore + @EnvironmentObject var chatWrapper: MonalChatWrapper @State private var autoScroll = true @State private var firstIsVisible = true @@ -29,58 +26,58 @@ struct ConversationScreen: View { } ), centerText: .init(text: centerText()), - rightButton: .init( - image: Image(systemName: "gear"), - action: { - router.showScreen(.push) { _ in - ConversationSettingsScreen() - // .environmentObject(settings) - .navigationBarHidden(true) - } - } - ) + rightButton: nil + // rightButton: .init( + // image: Image(systemName: "gear"), + // action: { + // router.showScreen(.push) { _ in + // ConversationSettingsScreen() + // // .environmentObject(settings) + // .navigationBarHidden(true) + // } + // } + // ) ) // Msg list - // let messages = messagesStore.messages - // if !messages.isEmpty { - // ScrollViewReader { proxy in - // ScrollView { - // LazyVStack(spacing: 0) { - // ForEach(messages) { message in - // ConversationMessageRow(message: message) - // .id(message.id) - // .flip() - // .onAppear { - // if message.id == messages.first?.id { - // firstIsVisible = true - // autoScroll = true - // } - // messagesStore.scrolledMessage(message.id) - // } - // .onDisappear { - // if message.id == messages.first?.id { - // firstIsVisible = false - // autoScroll = false - // } - // } - // } - // } - // } - // .flip() - // .scrollDismissesKeyboard(.immediately) - // .onChange(of: autoScroll) { new in - // if new, !firstIsVisible { - // withAnimation { - // proxy.scrollTo(messages.first?.id, anchor: .top) - // } - // } - // } - // } - // } else { - // Spacer() - // } - Spacer() + if !chatWrapper.messages.isEmpty { + ScrollViewReader { proxy in + ScrollView { + LazyVStack(spacing: 0) { + ForEach(chatWrapper.messages) { message in + ConversationMessageRow(message: message) + .id(message.id) + .flip() + .onAppear { + if message.id == chatWrapper.messages.first?.id { + firstIsVisible = true + autoScroll = true + } + // messagesStore.scrolledMessage(message.id) + } + .onDisappear { + if message.id == chatWrapper.messages.first?.id { + firstIsVisible = false + autoScroll = false + } + } + } + } + } + .flip() + .scrollDismissesKeyboard(.immediately) + .onChange(of: autoScroll) { new in + print(proxy) + if new, !firstIsVisible { + withAnimation { + proxy.scrollTo(chatWrapper.messages.first?.id, anchor: .top) + } + } + } + } + } else { + Spacer() + } } .onTapGesture { UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil) @@ -121,6 +118,6 @@ struct ConversationScreen: View { } private func centerText() -> String { - chatModel.contact.name ?? chatModel.contact.contactJid + chatWrapper.contact.name ?? chatWrapper.contact.contactJid } } diff --git a/Monal/another.im/Views/Main/Contacts/ContactsScreen.swift b/Monal/another.im/Views/Main/Contacts/ContactsScreen.swift index af3d877..564b01e 100644 --- a/Monal/another.im/Views/Main/Contacts/ContactsScreen.swift +++ b/Monal/another.im/Views/Main/Contacts/ContactsScreen.swift @@ -127,29 +127,11 @@ private struct ContactsScreenRow: View { } private func startChat() { - Task { - router.showModal { - LoadingScreen() - } - defer { - router.dismissModal() - } - - do { - // let (messages, attachments, settings) = try await clientsStore.conversationStores(for: roster) - // router.showScreen(.push) { _ in - // ConversationScreen(messagesStore: messages, attachments: attachments, settings: settings) - // .navigationBarHidden(true) - // } - } catch { - router.showAlert( - .alert, - title: L10n.Global.Error.title, - subtitle: L10n.Conversation.startError - ) { - Button(L10n.Global.ok, role: .cancel) {} - } - } + let model = wrapper.chat(with: contact) + router.showScreen(.push) { _ in + ConversationScreen() + .navigationBarHidden(true) + .environmentObject(model) } } } diff --git a/Monal/another.im/XMPP/MonalWrapperModels.swift b/Monal/another.im/XMPP/MonalWrapperModels.swift index cb32c36..eaeb0ed 100644 --- a/Monal/another.im/XMPP/MonalWrapperModels.swift +++ b/Monal/another.im/XMPP/MonalWrapperModels.swift @@ -80,3 +80,25 @@ struct Chat: Identifiable { participantName = obj.nickName } } + +// MARK: Message +struct Message: Identifiable { + let accountId: Int + let participantJid: String + let dbId: Int + let timestamp: Date + let body: String + + var id: String { + "\(accountId)|\(dbId)" + } + + init?(_ obj: MLMessage) { + guard let accId = obj.accountID as? Int, let dbId = obj.messageDBId as? Int else { return nil } + accountId = accId + participantJid = obj.participantJid + self.dbId = dbId + timestamp = obj.timestamp + body = obj.messageText + } +} diff --git a/Monal/another.im/XMPP/MonalXmppWrapper.swift b/Monal/another.im/XMPP/MonalXmppWrapper.swift index b8968a6..d74d5c1 100644 --- a/Monal/another.im/XMPP/MonalXmppWrapper.swift +++ b/Monal/another.im/XMPP/MonalXmppWrapper.swift @@ -55,8 +55,8 @@ extension MonalXmppWrapper { } } - func chat(with: Contact) -> ChatModel { - let chatModel = ChatModel(contact: with) + func chat(with: Contact) -> MonalChatWrapper { + let chatModel = MonalChatWrapper(contact: with, db: db, xmpp: xmpp) return chatModel } } @@ -167,10 +167,24 @@ private extension MonalXmppWrapper { } // MARK: - Chat object -final class ChatModel: ObservableObject { - let contact: Contact +final class MonalChatWrapper: ObservableObject { + @Published private(set) var messages: [Message] = [] - init(contact: Contact) { + let contact: Contact + private let xmpp: MLXMPPManager + private let db: DataLayer + + init(contact: Contact, db: DataLayer, xmpp: MLXMPPManager) { self.contact = contact + self.db = db + self.xmpp = xmpp + } + + private func refreshMessages() { + messages = db.messages(forContact: contact.contactJid, forAccount: NSNumber(value: contact.ownerId)) + .compactMap { + guard let message = $0 as? MLMessage else { return nil } + return Message(message) + } } }