@ -30,6 +30,15 @@ public final class OpenGroupManagerV2 : NSObject {
// MARK: A d d i n g & R e m o v i n g
public func add ( room : String , server : String , publicKey : String , using transaction : Any ) -> Promise < Void > {
// I f w e a r e c u r r e n t l y p o l l i n g f o r t h i s s e r v e r a n d a l r e a d y h a v e a T S G r o u p T h r e a d f o r t h i s r o o m t h e d o n o t h i n g
let transaction = transaction as ! YapDatabaseReadWriteTransaction
let groupId : Data = LKGroupUtilities . getEncodedOpenGroupIDAsData ( " \( server ) . \( room ) " )
if OpenGroupManagerV2 . shared . pollers [ server ] != nil && TSGroupThread . fetch ( uniqueId : TSGroupThread . threadId ( fromGroupId : groupId ) , transaction : transaction ) != nil {
SNLog ( " Ignoring join open group attempt (already joined) " )
return Promise . value ( ( ) )
}
let storage = Storage . shared
// C l e a r a n y e x i s t i n g d a t a i f n e e d e d
storage . removeLastMessageServerID ( for : room , on : server , using : transaction )
@ -38,7 +47,7 @@ public final class OpenGroupManagerV2 : NSObject {
// S t o r e t h e p u b l i c k e y
storage . setOpenGroupPublicKey ( for : server , to : publicKey , using : transaction )
let ( promise , seal ) = Promise < Void > . pending ( )
let transaction = transaction as ! YapDatabaseReadWriteTransaction
transaction . addCompletionQueue ( DispatchQueue . global ( qos : . userInitiated ) ) {
// G e t t h e g r o u p i n f o
OpenGroupAPIV2 . getInfo ( for : room , on : server ) . done ( on : DispatchQueue . global ( qos : . userInitiated ) ) { info in