WIP
This commit is contained in:
parent
b8d9334d19
commit
f364ee3907
|
@ -13,13 +13,14 @@ extension AppDelegate {
|
|||
let job = MessageSendJob(message: configurationMessage, destination: destination)
|
||||
JobQueue.shared.add(job, using: transaction)
|
||||
}
|
||||
userDefaults[.lastConfigurationSync] = Date()
|
||||
}
|
||||
|
||||
func forceSyncConfigurationNowIfNeeded() -> Promise<Void> {
|
||||
let configurationMessage = ConfigurationMessage.getCurrent()
|
||||
let destination = Message.Destination.contact(publicKey: getUserHexEncodedPublicKey())
|
||||
let (promise, seal) = Promise<Void>.pending()
|
||||
Storage.write { transaction in
|
||||
Storage.writeSync { transaction in
|
||||
MessageSender.send(configurationMessage, to: destination, using: transaction).done {
|
||||
seal.fulfill(())
|
||||
}.catch { _ in
|
||||
|
|
|
@ -132,11 +132,9 @@ final class JoinPublicChatVC : BaseVC, UIPageViewControllerDataSource, UIPageVie
|
|||
}
|
||||
isJoining = true
|
||||
ModalActivityIndicatorViewController.present(fromViewController: navigationController!, canCancel: false) { [weak self] _ in
|
||||
Storage.shared.write { transaction in
|
||||
Storage.shared.write(with: { transaction in
|
||||
OpenGroupManager.shared.addOpenGroup(with: urlAsString, using: transaction)
|
||||
.done(on: DispatchQueue.main) { [weak self] _ in
|
||||
let appDelegate = UIApplication.shared.delegate as! AppDelegate
|
||||
appDelegate.forceSyncConfigurationNowIfNeeded().retainUntilComplete() // FIXME: It's probably cleaner to do this inside addOpenGroup(...)
|
||||
self?.presentingViewController!.dismiss(animated: true, completion: nil)
|
||||
}
|
||||
.catch(on: DispatchQueue.main) { [weak self] error in
|
||||
|
@ -150,7 +148,10 @@ final class JoinPublicChatVC : BaseVC, UIPageViewControllerDataSource, UIPageVie
|
|||
self?.isJoining = false
|
||||
self?.showError(title: title, message: message)
|
||||
}
|
||||
}
|
||||
}, completion: {
|
||||
let appDelegate = UIApplication.shared.delegate as! AppDelegate
|
||||
appDelegate.forceSyncConfigurationNowIfNeeded().retainUntilComplete() // FIXME: It's probably cleaner to do this inside addOpenGroup(...)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ public final class OpenGroupManager : OpenGroupManagerProtocol {
|
|||
let transaction = transaction as! YapDatabaseReadWriteTransaction
|
||||
transaction.removeObject(forKey: "\(urlAsString).\(channelID)", inCollection: Storage.lastMessageServerIDCollection)
|
||||
transaction.removeObject(forKey: "\(urlAsString).\(channelID)", inCollection: Storage.lastDeletionServerIDCollection)
|
||||
return PublicChatManager.shared.addChat(server: urlAsString, channel: channelID).done(on: DispatchQueue.main) { _ in
|
||||
return PublicChatManager.shared.addChat(server: urlAsString, channel: channelID, using: transaction).done(on: DispatchQueue.main) { _ in
|
||||
let _ = OpenGroupAPI.setDisplayName(to: displayName, on: urlAsString)
|
||||
let _ = OpenGroupAPI.setProfilePictureURL(to: profilePictureURL, using: profileKey, on: urlAsString)
|
||||
let _ = OpenGroupAPI.join(channelID, on: urlAsString)
|
||||
|
|
|
@ -48,43 +48,43 @@ public final class PublicChatManager : NSObject {
|
|||
isPolling = false
|
||||
}
|
||||
|
||||
public func addChat(server: String, channel: UInt64) -> Promise<OpenGroup> {
|
||||
public func addChat(server: String, channel: UInt64, using transaction: YapDatabaseReadWriteTransaction) -> Promise<OpenGroup> {
|
||||
if let existingChat = getChat(server: server, channel: channel) {
|
||||
if let newChat = self.addChat(server: server, channel: channel, name: existingChat.displayName) {
|
||||
if let newChat = self.addChat(server: server, channel: channel, name: existingChat.displayName, using: transaction) {
|
||||
return Promise.value(newChat)
|
||||
} else {
|
||||
return Promise(error: Error.chatCreationFailed)
|
||||
}
|
||||
}
|
||||
return OpenGroupAPI.getInfo(for: channel, on: server).map2 { channelInfo -> OpenGroup in
|
||||
guard let chat = self.addChat(server: server, channel: channel, name: channelInfo.displayName) else { throw Error.chatCreationFailed }
|
||||
guard let chat = self.addChat(server: server, channel: channel, name: channelInfo.displayName, using: transaction) else { throw Error.chatCreationFailed }
|
||||
return chat
|
||||
}
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
@objc(addChatWithServer:channel:name:)
|
||||
public func addChat(server: String, channel: UInt64, name: String) -> OpenGroup? {
|
||||
@objc(addChatWithServer:channel:name:using:)
|
||||
public func addChat(server: String, channel: UInt64, name: String, using transaction: YapDatabaseReadWriteTransaction) -> OpenGroup? {
|
||||
guard let chat = OpenGroup(channel: channel, server: server, displayName: name, isDeletable: true) else { return nil }
|
||||
let model = TSGroupModel(title: chat.displayName, memberIds: [userHexEncodedPublicKey!, chat.server], image: nil, groupId: LKGroupUtilities.getEncodedOpenGroupIDAsData(chat.id), groupType: .openGroup, adminIds: [])
|
||||
|
||||
// Store the group chat mapping
|
||||
Storage.writeSync { transaction in
|
||||
let thread = TSGroupThread.getOrCreateThread(with: model, transaction: transaction)
|
||||
|
||||
// Save the group chat
|
||||
Storage.shared.setOpenGroup(chat, for: thread.uniqueId!, using: transaction)
|
||||
}
|
||||
|
||||
let thread = TSGroupThread.getOrCreateThread(with: model, transaction: transaction)
|
||||
|
||||
// Save the group chat
|
||||
Storage.shared.setOpenGroup(chat, for: thread.uniqueId!, using: transaction)
|
||||
|
||||
// Update chats and pollers
|
||||
self.refreshChatsAndPollers()
|
||||
transaction.addCompletionQueue(DispatchQueue.main) {
|
||||
self.refreshChatsAndPollers()
|
||||
}
|
||||
|
||||
return chat
|
||||
}
|
||||
|
||||
@objc(addChatWithServer:channel:)
|
||||
public func objc_addChat(server: String, channel: UInt64) -> AnyPromise {
|
||||
return AnyPromise.from(addChat(server: server, channel: channel))
|
||||
@objc(addChatWithServer:channel:using:)
|
||||
public func objc_addChat(server: String, channel: UInt64, using transaction: YapDatabaseReadWriteTransaction) -> AnyPromise {
|
||||
return AnyPromise.from(addChat(server: server, channel: channel, using: transaction))
|
||||
}
|
||||
|
||||
@objc func refreshChatsAndPollers() {
|
||||
|
|
Loading…
Reference in New Issue