This commit is contained in:
Woit 2024-12-09 20:49:39 +01:00
parent 55b3469284
commit 413d4f1c72
2 changed files with 34 additions and 27 deletions

View file

@ -3749,7 +3749,7 @@
CODE_SIGN_ENTITLEMENTS = another.im/Resources/another.im.entitlements; CODE_SIGN_ENTITLEMENTS = another.im/Resources/another.im.entitlements;
CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 5; CURRENT_PROJECT_VERSION = 6;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = K78H7BT98L; DEVELOPMENT_TEAM = K78H7BT98L;
@ -3840,7 +3840,7 @@
CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
COPY_PHASE_STRIP = NO; COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 5; CURRENT_PROJECT_VERSION = 6;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = K78H7BT98L; DEVELOPMENT_TEAM = K78H7BT98L;
@ -3937,7 +3937,7 @@
CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
COPY_PHASE_STRIP = NO; COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 5; CURRENT_PROJECT_VERSION = 6;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = K78H7BT98L; DEVELOPMENT_TEAM = K78H7BT98L;
@ -4034,7 +4034,7 @@
CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
COPY_PHASE_STRIP = NO; COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 5; CURRENT_PROJECT_VERSION = 6;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = K78H7BT98L; DEVELOPMENT_TEAM = K78H7BT98L;
@ -4131,7 +4131,7 @@
CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
COPY_PHASE_STRIP = NO; COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 5; CURRENT_PROJECT_VERSION = 6;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = K78H7BT98L; DEVELOPMENT_TEAM = K78H7BT98L;
@ -4228,7 +4228,7 @@
CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
COPY_PHASE_STRIP = NO; COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 5; CURRENT_PROJECT_VERSION = 6;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = K78H7BT98L; DEVELOPMENT_TEAM = K78H7BT98L;

View file

@ -14,9 +14,9 @@ final class WrapperChat: ObservableObject {
let contact: Contact let contact: Contact
let account: Account let account: Account
private let xmpp: MLXMPPManager private var xmpp: MLXMPPManager?
private let db: DataLayer private var db: DataLayer?
private let monalContact: MLContact private var monalContact: MLContact?
private var notificationObservers: [AnyObject] = [] private var notificationObservers: [AnyObject] = []
init?(with: Contact, account: Account) { init?(with: Contact, account: Account) {
@ -26,7 +26,7 @@ final class WrapperChat: ObservableObject {
self.account = account self.account = account
guard guard
let monalContact = db.contactList() let monalContact = db?.contactList()
.first(where: { .first(where: {
$0.accountID.intValue == with.ownerId && $0.accountID.intValue == with.ownerId &&
$0.contactJid == with.contactJid $0.contactJid == with.contactJid
@ -45,7 +45,7 @@ final class WrapperChat: ObservableObject {
self.account = account self.account = account
guard guard
let monalContact = db.contactList() let monalContact = db?.contactList()
.first(where: { .first(where: {
$0.accountID.intValue == with.accountId && $0.accountID.intValue == with.accountId &&
$0.contactJid == with.participantJid $0.contactJid == with.participantJid
@ -63,7 +63,16 @@ final class WrapperChat: ObservableObject {
deinit { deinit {
notificationObservers.forEach { NotificationCenter.default.removeObserver($0) } notificationObservers.forEach { NotificationCenter.default.removeObserver($0) }
print("Chat wrapper deinit") // print("Chat wrapper deinit")
}
func deactivate() {
db = nil
xmpp = nil
monalContact = nil
messages = []
notificationObservers.forEach { NotificationCenter.default.removeObserver($0) }
// print("Chat wrapper deactivated")
} }
var chatTitle: String { var chatTitle: String {
@ -71,8 +80,9 @@ final class WrapperChat: ObservableObject {
} }
func sendText(_ text: String) { func sendText(_ text: String) {
guard let monalContact else { return }
let newMessageId = UUID().uuidString let newMessageId = UUID().uuidString
let histId = db.addMessageHistory( let histId = db?.addMessageHistory(
to: contact.contactJid, to: contact.contactJid,
forAccount: monalContact.accountID, forAccount: monalContact.accountID,
withMessage: text, withMessage: text,
@ -83,19 +93,20 @@ final class WrapperChat: ObservableObject {
mimeType: nil, mimeType: nil,
size: nil size: nil
) )
if let newMlMessage = db.message(forHistoryID: histId), let message = Message(newMlMessage) { if let newMlMessage = db?.message(forHistoryID: histId), let message = Message(newMlMessage) {
messages.insert(message, at: 0) messages.insert(message, at: 0)
} }
xmpp.sendMessage(text, to: monalContact, isEncrypted: monalContact.isEncrypted, isUpload: false, messageId: newMessageId) xmpp?.sendMessage(text, to: monalContact, isEncrypted: monalContact.isEncrypted, isUpload: false, messageId: newMessageId)
} }
func requestMAM() { func requestMAM() {
guard let monalContact else { return }
guard let acc = monalContact.account else { return } guard let acc = monalContact.account else { return }
if mamRequestInProgress { return } if mamRequestInProgress { return }
mamRequestInProgress = true mamRequestInProgress = true
let lastStanzaId = messages.last?.messageId // last here because list is reversed let lastStanzaId = messages.last?.stanzaId // last here because list is reversed
?? db.lastStanzaId(forAccount: NSNumber(value: contact.ownerId)) ?? db?.lastStanzaId(forAccount: NSNumber(value: contact.ownerId))
acc.setMAMQueryMostRecentFor(monalContact, before: lastStanzaId) { [weak self] msgs, _ in acc.setMAMQueryMostRecentFor(monalContact, before: lastStanzaId) { [weak self] msgs, _ in
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in
@ -107,12 +118,6 @@ final class WrapperChat: ObservableObject {
} }
} }
} }
func deactivate() {
messages = []
notificationObservers.forEach { NotificationCenter.default.removeObserver($0) }
print("Chat wrapper unsubscribed")
}
} }
private extension WrapperChat { private extension WrapperChat {
@ -157,18 +162,20 @@ private extension WrapperChat {
} }
func reloadMessages() { func reloadMessages() {
let messages = db.messages(forContact: contact.contactJid, forAccount: NSNumber(value: contact.ownerId)) let messages = db?.messages(forContact: contact.contactJid, forAccount: NSNumber(value: contact.ownerId))
.compactMap { obj -> Message? in .compactMap { obj -> Message? in
guard let message = obj as? MLMessage else { return nil } guard let message = obj as? MLMessage else { return nil }
return Message(message) return Message(message)
} }
.sorted { $0.timestamp > $1.timestamp } .sorted { $0.timestamp > $1.timestamp }
self.messages = messages self.messages = messages ?? []
} }
func toggleOmemo(_ new: Bool) { func toggleOmemo(_ new: Bool) {
if let monalContact {
if monalContact.isEncrypted != new { if monalContact.isEncrypted != new {
monalContact.toggleEncryption(new) monalContact.toggleEncryption(new)
} }
} }
} }
}