Skip to content

Commit

Permalink
Fixed issue with creating MUC rooms on some servers #beagleim-483
Browse files Browse the repository at this point in the history
  • Loading branch information
hantu85 committed Mar 14, 2023
1 parent 3fe5663 commit 99ebed9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
37 changes: 30 additions & 7 deletions BeagleIM/channel/CreateChannelViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class CreateChannelViewController: BaseJoinChannelViewController, NSTextFieldDel
}
let avatar: NSImage? = self.avatarButton.image;

self.create(account: account, channelLocalPart: localPart, channelName: name, channelDescription: description, type: type, private: isPrivate, avatar: avatar, completionHander: { result, completionHandler in
self.create(account: account, channelLocalPart: localPart, channelName: name, channelDescription: description, type: type, private: isPrivate, avatar: avatar, completionHander: { result, wasCreated, completionHandler in
DispatchQueue.main.async {
switch result {
case .success(let channelJid):
Expand All @@ -117,6 +117,10 @@ class CreateChannelViewController: BaseJoinChannelViewController, NSTextFieldDel
controller.componentType = type;
controller.suggestedNickname = nil;
controller.password = nil;
controller.isCreation = !wasCreated;
if !wasCreated {
controller.info = DiscoveryModule.DiscoveryInfoResult(identities: [.init(category: "conference", type: "text", name: name)], features: [], form: nil);
}

let windowController = NSWindowController(window: NSWindow(contentViewController: controller));
window.beginSheet(windowController.window!, completionHandler: { result in
Expand All @@ -143,7 +147,7 @@ class CreateChannelViewController: BaseJoinChannelViewController, NSTextFieldDel
});
}

func create(account: BareJID, channelLocalPart: String?, channelName: String, channelDescription: String?, type: BaseJoinChannelViewController.ComponentType, private priv: Bool, avatar: NSImage?, completionHander: @escaping (Result<BareJID,XMPPError>, (()->Void)?)->Void) {
func create(account: BareJID, channelLocalPart: String?, channelName: String, channelDescription: String?, type: BaseJoinChannelViewController.ComponentType, private priv: Bool, avatar: NSImage?, completionHander: @escaping (Result<BareJID,XMPPError>,Bool, (()->Void)?)->Void) {
guard let client = XmppService.instance.getClient(for: account), let component = self.components.first(where: { $0.type == type }) else {
return;
}
Expand Down Expand Up @@ -177,9 +181,9 @@ class CreateChannelViewController: BaseJoinChannelViewController, NSTextFieldDel
self?.logger.debug("changed channel access policy: \(result)");
})
}
completionHander(.success(channelJid), nil);
completionHander(.success(channelJid), true, nil);
case .failure(let error):
completionHander(.failure(error), nil);
completionHander(.failure(error), false, nil);
}
DispatchQueue.main.async {
self?.operationFinished();
Expand Down Expand Up @@ -208,7 +212,7 @@ class CreateChannelViewController: BaseJoinChannelViewController, NSTextFieldDel
vcard.photos = [VCard.Photo(uri: nil, type: "image/jpeg", binval: binval, types: [.home])];
}
client.module(.vcardTemp).publishVCard(vcard, to: roomJid, completionHandler: nil);
completionHander(.success(roomJid), {
completionHander(.success(roomJid), true, {
if channelDescription != nil {
mucModule.setRoomSubject(roomJid: roomJid, newSubject: channelDescription);
}
Expand All @@ -217,8 +221,27 @@ class CreateChannelViewController: BaseJoinChannelViewController, NSTextFieldDel
self?.operationFinished();
}
case .failure(let error):
completionHander(.failure(error), nil);
}
guard error == .item_not_found else {
completionHander(.failure(error), false, nil);
DispatchQueue.main.async {
self?.operationFinished();
}
return;
}
// workaround for prosody sending item-not-found but allowing to create a room anyway..
let vcard = VCard();
if let binval = avatar?.scaled(maxWidthOrHeight: 512.0).jpegData(compressionQuality: 0.8)?.base64EncodedString(options: []) {
vcard.photos = [VCard.Photo(uri: nil, type: "image/jpeg", binval: binval, types: [.home])];
}
completionHander(.success(roomJid), false, {
client.module(.vcardTemp).publishVCard(vcard, to: roomJid, completionHandler: nil);
if channelDescription != nil {
mucModule.setRoomSubject(roomJid: roomJid, newSubject: channelDescription);
}
});
DispatchQueue.main.async {
self?.operationFinished();
} }
});
}

Expand Down
6 changes: 5 additions & 1 deletion BeagleIM/channel/EnterChannelViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class EnterChannelViewController: NSViewController, NSTextFieldDelegate {

var isPasswordVisible: Bool = true;
var isBookmarkVisible: Bool = true;
var isCreation: Bool = false;

override func viewWillAppear() {
super.viewWillAppear();
Expand All @@ -61,7 +62,7 @@ class EnterChannelViewController: NSViewController, NSTextFieldDelegate {
bookmarkAutojoinButton.isEnabled = isBookmarkVisible && bookmarkCreateButton.state == .on;
updateJoinButton();

if let client = XmppService.instance.getClient(for: account) {
if let client = XmppService.instance.getClient(for: account), !isCreation {
self.progressIndicator.startAnimation(self);
client.module(.disco).getInfo(for: JID(channelJid!), completionHandler: { [weak self] result in
DispatchQueue.main.async {
Expand Down Expand Up @@ -166,6 +167,9 @@ class EnterChannelViewController: NSViewController, NSTextFieldDelegate {
if createBookmark {
client.module(.pepBookmarks).addOrUpdate(bookmark: Bookmarks.Conference(name: channelName ?? room.localPart ?? room.stringValue, jid: JID(room), autojoin: autojoin, nick: nickname, password: password));
}
if let roomObj = client.module(.muc).roomManager.room(for: client, with: room) as? Room {
MucEventHandler.instance.updateRoomName(room: roomObj);
}
DispatchQueue.main.async {
self?.close(returnCode: .OK);
}
Expand Down

0 comments on commit 99ebed9

Please sign in to comment.