From 1879508ec3379d472aec0f4b20215a0997887c2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20Wo=CC=81jcik?= Date: Sat, 25 Jan 2020 13:31:24 +0100 Subject: [PATCH] Fixed "issues" reported by AppStore review team and version bump to 3.5b73 #beagleim-190 --- .xcodeproj/project.pbxproj | 4 +- BeagleIM/AppDelegate.swift | 86 ++++++-------------------- BeagleIM/chatslist/ChatCellView.swift | 11 ++-- BeagleIM/service/MucEventHandler.swift | 50 ++++++++------- BeagleIM/ui/ChatCellViewMessage.swift | 3 + 5 files changed, 58 insertions(+), 96 deletions(-) diff --git a/ .xcodeproj/project.pbxproj b/ .xcodeproj/project.pbxproj index 7e27af13..3ac712a6 100644 --- a/ .xcodeproj/project.pbxproj +++ b/ .xcodeproj/project.pbxproj @@ -1179,7 +1179,7 @@ CODE_SIGN_IDENTITY = "Mac Developer"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 72; + CURRENT_PROJECT_VERSION = 73; DEVELOPMENT_TEAM = YBEYW6E35C; ENABLE_HARDENED_RUNTIME = YES; FRAMEWORK_SEARCH_PATHS = ( @@ -1208,7 +1208,7 @@ CODE_SIGN_IDENTITY = "Mac Developer"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 72; + CURRENT_PROJECT_VERSION = 73; DEVELOPMENT_TEAM = YBEYW6E35C; ENABLE_HARDENED_RUNTIME = YES; FRAMEWORK_SEARCH_PATHS = ( diff --git a/BeagleIM/AppDelegate.swift b/BeagleIM/AppDelegate.swift index e15cca3a..9b46ad43 100644 --- a/BeagleIM/AppDelegate.swift +++ b/BeagleIM/AppDelegate.swift @@ -538,6 +538,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele return; } + // TODO: remove in the next version switch id { case "authentication-failure": guard let _ = BareJID(userInfo["account"] as? String) else { @@ -628,60 +629,33 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele return; } - let id = "authenticationError.\(accountName.stringValue)"; - - if #available(OSX 10.14, *) { - UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: [id]); - - let content = UNMutableNotificationContent(); - content.title = accountName.stringValue; - content.subtitle = "Authentication failure"; + DispatchQueue.main.async { + let alert = Alert(); + alert.messageText = "Authentication failure for \(accountName.stringValue)"; switch error { case .aborted, .temporary_auth_failure: - content.body = "Temporary authetnication failure, will retry.."; + // those are temporary errors and we will retry, so there is no point in notifying user... + return; case .invalid_mechanism: - content.body = "Required authentication mechanism not supported"; + alert.informativeText = "Required authentication mechanism not supported"; case .mechanism_too_weak: - content.body = "Authentication mechanism is too weak for authentication"; + alert.informativeText = "Authentication mechanism is too weak for authentication"; case .incorrect_encoding, .invalid_authzid, .not_authorized: - content.body = "Invalid password for account"; + alert.informativeText = "Invalid password for account"; case .server_not_trusted: - content.body = "It was not possible to verify that server is trusted"; - } - content.sound = UNNotificationSound.defaultCritical; - content.userInfo = ["account": accountName.stringValue, "id": "authentication-failure"]; - let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: nil); - UNUserNotificationCenter.current().add(request) { (error) in - print("could not show notification:", error as Any); - } - } else { - // invalidate old auth error notification if there is any - NSUserNotificationCenter.default.deliveredNotifications.filter { (n) -> Bool in - return n.identifier == id; - }.forEach { (n) in - NSUserNotificationCenter.default.removeDeliveredNotification(n); + alert.informativeText = "It was not possible to verify that server is trusted"; } - let notification = NSUserNotification(); - notification.identifier = UUID().uuidString; - notification.title = accountName.stringValue; - notification.subtitle = "Authentication failure"; - switch error { - case .aborted, .temporary_auth_failure: - notification.informativeText = "Temporary authetnication failure, will retry.."; - case .invalid_mechanism: - notification.informativeText = "Required authentication mechanism not supported"; - case .mechanism_too_weak: - notification.informativeText = "Authentication mechanism is too weak for authentication"; - case .incorrect_encoding, .invalid_authzid, .not_authorized: - notification.informativeText = "Invalid password for account"; - case .server_not_trusted: - notification.informativeText = "It was not possible to verify that server is trusted"; - } - notification.soundName = NSUserNotificationDefaultSoundName; - notification.userInfo = ["account": accountName.stringValue, "id": "authentication-failure"]; - NSUserNotificationCenter.default.deliver(notification); - } + alert.icon = NSImage(named: NSImage.cautionName); + alert.addButton(withTitle: "OK"); + alert.run(completionHandler: { response in + guard let windowController = (NSApplication.shared.delegate as? AppDelegate)?.preferencesWindowController else { + return; + } + (windowController.contentViewController as? NSTabViewController)?.selectedTabViewItemIndex = 1; + windowController.showWindow(self); + }) + } } @objc func chatUpdated(_ notification: Notification) { @@ -822,26 +796,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele return; } - if #available(OSX 10.14, *) { - let content = UNMutableNotificationContent(); - content.title = "Unknown SSL certificate"; - content.subtitle = "SSL certificate could not be verified."; - content.body = "Account \(accountName) was disabled."; - content.sound = UNNotificationSound.defaultCritical; - let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: nil); - UNUserNotificationCenter.current().add(request) { (error) in - print("could not show notification:", error as Any); - } - } else { - let notification = NSUserNotification(); - notification.identifier = UUID().uuidString; - notification.title = "Unknown SSL certificate"; - notification.subtitle = "SSL certificate could not be verified."; - notification.informativeText = "Account \(accountName) was disabled."; - notification.soundName = NSUserNotificationDefaultSoundName; - NSUserNotificationCenter.default.deliver(notification); - } - DispatchQueue.main.async { guard let windowController = NSStoryboard(name: "Main", bundle: nil).instantiateController(withIdentifier: "ServerCertificateErrorWindowController") as? NSWindowController else { return; diff --git a/BeagleIM/chatslist/ChatCellView.swift b/BeagleIM/chatslist/ChatCellView.swift index ad98cbbf..f9361a87 100644 --- a/BeagleIM/chatslist/ChatCellView.swift +++ b/BeagleIM/chatslist/ChatCellView.swift @@ -71,8 +71,10 @@ class ChatCellView: NSTableCellView { self.avatar?.name = name; } - func set(lastActivity: LastChatActivity?, ts: Date?) { + func set(lastActivity: LastChatActivity?, ts: Date?, chatState: ChatState) { + self.chatState = chatState; if chatState != .composing { + self.lastMessage?.stopAnimating(); if let activity = lastActivity { switch activity { case .message(let lastMessage): @@ -94,9 +96,11 @@ class ChatCellView: NSTableCellView { self.lastMessage?.maximumNumberOfLines = 3; } else { self.lastMessage?.stringValue = ""; + self.lastMessage?.startAnimating(); } //self.lastMessage?.preferredMaxLayoutWidth = self.lastMessage!.frame.width; self.lastMessageTs?.stringValue = ts != nil ? formatTimestamp(ts!) : ""; + self.lastMessage?.invalidateIntrinsicContentSize(); } func set(chatState: ChatState) { @@ -139,10 +143,7 @@ class ChatCellView: NSTableCellView { func update(from item: ChatItemProtocol) { self.set(name: item.name); self.set(unread: item.unread); - if let chat = item.chat as? DBChatStore.DBChat { - self.set(chatState: chat.remoteChatState ?? .active); - } - self.set(lastActivity: item.lastActivity, ts: item.lastMessageTs); + self.set(lastActivity: item.lastActivity, ts: item.lastMessageTs, chatState: (item.chat as? DBChatStore.DBChat)?.remoteChatState ?? .active); if item.chat is Chat { self.avatar.update(for: item.chat.jid.bareJid, on: item.chat.account); } else if let room = item.chat as? Room { diff --git a/BeagleIM/service/MucEventHandler.swift b/BeagleIM/service/MucEventHandler.swift index 2b00fc2d..088f1d15 100644 --- a/BeagleIM/service/MucEventHandler.swift +++ b/BeagleIM/service/MucEventHandler.swift @@ -128,29 +128,33 @@ class MucEventHandler: XmppServiceEventHandler { } print("received error from room:", e.room as Any, ", error:", error) - if #available(OSX 10.14, *) { - let content = UNMutableNotificationContent(); - content.title = "Room \(e.room.roomJid.stringValue)"; - content.body = "Could not join room. Reason:\n\(error.reason)"; - content.sound = UNNotificationSound.defaultCritical; - if error != .banned && error != .registrationRequired { - content.userInfo = ["account": e.sessionObject.userBareJid!.stringValue, "roomJid": e.room.roomJid.stringValue, "nickname": e.room.nickname, "id": "room-join-error"]; - } - let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: nil); - UNUserNotificationCenter.current().add(request) { (error) in - print("could not show notification:", error as Any); - } - } else { - let notification = NSUserNotification(); - notification.identifier = UUID().uuidString; - notification.title = "Room \(e.room.roomJid.stringValue)"; - notification.informativeText = "Could not join room. Reason:\n\(error.reason)"; - notification.soundName = NSUserNotificationDefaultSoundName; - notification.contentImage = NSImage(named: NSImage.userGroupName); - if error != .banned && error != .registrationRequired { - notification.userInfo = ["account": e.sessionObject.userBareJid!.stringValue, "roomJid": e.room.roomJid.stringValue, "nickname": e.room.nickname, "id": "room-join-error"]; - } - NSUserNotificationCenter.default.deliver(notification); + DispatchQueue.main.async { + let alert = Alert(); + alert.messageText = "Room \(e.room.roomJid.stringValue)"; + alert.informativeText = "Could not join room. Reason:\n\(error.reason)"; + alert.icon = NSImage(named: NSImage.userGroupName); + alert.addButton(withTitle: "OK"); + alert.run(completionHandler: { response in + if error != .banned && error != .registrationRequired { + let storyboard = NSStoryboard(name: "Main", bundle: nil); + guard let windowController = storyboard.instantiateController(withIdentifier: "OpenGroupchatController") as? NSWindowController else { + return; + } + guard let openRoomController = windowController.contentViewController as? OpenGroupchatController else { + return; + } + let roomJid = e.room.roomJid; + openRoomController.searchField.stringValue = roomJid.stringValue; + openRoomController.mucJids = [BareJID(roomJid.domain)]; + openRoomController.account = e.sessionObject.userBareJid!; + openRoomController.nicknameField.stringValue = e.room.nickname; + guard let window = (NSApplication.shared.delegate as? AppDelegate)?.mainWindowController?.window else { + return; + } + window.windowController?.showWindow(self); + window.beginSheet(windowController.window!, completionHandler: nil); + } + }) } guard let mucModule: MucModule = XmppService.instance.getClient(for: e.sessionObject.userBareJid!)?.modulesManager.getModule(MucModule.ID) else { diff --git a/BeagleIM/ui/ChatCellViewMessage.swift b/BeagleIM/ui/ChatCellViewMessage.swift index c26f6af7..dc603f86 100644 --- a/BeagleIM/ui/ChatCellViewMessage.swift +++ b/BeagleIM/ui/ChatCellViewMessage.swift @@ -112,6 +112,9 @@ class ChatCellViewMessage: NSTextField { } func stopAnimating() { + guard !dotLayers.isEmpty else { + return; + } dotLayers.forEach { (layer) in layer.removeAllAnimations(); }