This commit is contained in:
Woit 2024-11-24 19:42:46 +01:00
parent 9d6f610b63
commit ea333acb1a
8 changed files with 112 additions and 97 deletions

View file

@ -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"

View file

@ -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;

View file

@ -4,7 +4,7 @@
<dict>
<key>com.apple.security.application-groups</key>
<array>
<string>group.another.im.test</string>
<string>group.im.narayana.anotherim</string>
</array>
</dict>
</plist>

View file

@ -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 {

View file

@ -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
}
}

View file

@ -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)
}
}
}

View file

@ -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
}
}

View file

@ -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)
}
}
}