From f03a84475e15796428013efef3b3197b51460c57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20Wo=CC=81jcik?= Date: Wed, 19 Jul 2023 17:33:35 +0200 Subject: [PATCH] Fixed issue with sending PMs to MUC rooms with PMs disabled (if `muc#roomconfig_allowpm` was not reported in room disco#info) #132 --- BeagleIM/channel/EnterChannelViewController.swift | 14 +++++++++++--- BeagleIM/database/model/conversations/Chat.swift | 2 +- BeagleIM/service/MucEventHandler.swift | 14 +++++++++++++- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/BeagleIM/channel/EnterChannelViewController.swift b/BeagleIM/channel/EnterChannelViewController.swift index 1598508..9f72936 100644 --- a/BeagleIM/channel/EnterChannelViewController.swift +++ b/BeagleIM/channel/EnterChannelViewController.swift @@ -158,10 +158,18 @@ class EnterChannelViewController: NSViewController, NSTextFieldDelegate { switch roomResult { case .created(let room), .joined(let room): (room as! Room).roomFeatures = Set(features.compactMap({ Room.Feature(rawValue: $0) })); - if let formElement = formElement, let config = RoomConfig(element: formElement) { - (room as! Room).allowedPM = config.allowPM ?? .anyone; + if let formElement = formElement, let config = RoomConfig(element: formElement), let allowPM = config.allowPM { + (room as! Room).allowedPM = allowPM; } else { - (room as! Room).allowedPM = .anyone; + (room as! Room).allowedPM = .none; + client.module(.muc).roomConfiguration(roomJid: JID(room.jid), completionHandler: { result in + switch result { + case .success(let config): + (room as! Room).allowedPM = config.allowPM ?? .none; + case .failure(let err): + (room as! Room).allowedPM = .none; + } + }) } } if createBookmark { diff --git a/BeagleIM/database/model/conversations/Chat.swift b/BeagleIM/database/model/conversations/Chat.swift index f88973b..f7e7e4e 100644 --- a/BeagleIM/database/model/conversations/Chat.swift +++ b/BeagleIM/database/model/conversations/Chat.swift @@ -138,7 +138,7 @@ public class Chat: ConversationBaseWithOptions, ChatProtocol, Conve } public func prepareAttachment(url originalURL: URL, completionHandler: @escaping (Result<(URL, Bool, ((URL) -> URL)?), ShareError>) -> Void) { - let encryption = self.options.encryption ?? .none; + let encryption = self.options.encryption ?? Settings.messageEncryption; switch encryption { case .none: completionHandler(.success((originalURL, false, nil))); diff --git a/BeagleIM/service/MucEventHandler.swift b/BeagleIM/service/MucEventHandler.swift index 37e2a47..9896c96 100644 --- a/BeagleIM/service/MucEventHandler.swift +++ b/BeagleIM/service/MucEventHandler.swift @@ -43,7 +43,19 @@ class MucEventHandler: XmppServiceExtension { mamVersions = info.features.compactMap({ MessageArchiveManagementModule.Version(rawValue: $0) }); (room as! Room).roomFeatures = Set(info.features.compactMap({ Room.Feature(rawValue: $0) })); let config = RoomConfig(form: info.form); - (room as! Room).allowedPM = config.allowPM ?? .anyone; + if let allowPM = config.allowPM { + (room as! Room).allowedPM = allowPM; + } else { + (room as! Room).allowedPM = .none; + client.module(.muc).roomConfiguration(roomJid: JID(room.jid), completionHandler: { result in + switch result { + case .success(let config): + (room as! Room).allowedPM = config.allowPM ?? .none; + case .failure(let err): + (room as! Room).allowedPM = .none; + } + }) + } default: break; }