@@ -441,8 +441,8 @@ -(void) handleMessage: (NetworkController*)controller message:(NSString *)messa
441441 } else if ([event isEqualToString: @" send-multipart" ]) {
442442 NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc ] initWithString: @" " ];
443443 NSMutableArray <NSString *> *transfers = [[NSMutableArray alloc ] init ];
444- NSUInteger index = 0 ;
445444 for (NSDictionary *dict in data[@" parts" ]) {
445+ NSUInteger index = [dict[@" partIndex" ] integerValue ];
446446 if (dict[@" filePath" ] != [NSNull null ] && [dict[@" filePath" ] length ] != 0 ) {
447447 NSString *filePath = dict[@" filePath" ];
448448 NSURL * fileUrl = [NSURL fileURLWithPath: filePath];
@@ -458,33 +458,13 @@ -(void) handleMessage: (NetworkController*)controller message:(NSString *)messa
458458 [attributedString appendAttributedString: attachmentStr];
459459 } else {
460460 if (dict[@" mention" ] != [NSNull null ] && [dict[@" mention" ] length ] != 0 ) {
461- NSMutableAttributedString *beforeStr = [[NSMutableAttributedString alloc ] initWithString: [(NSString *) dict[@" text" ] substringWithRange: NSMakeRange (0 , [[dict[@" range" ] firstObject ] integerValue ])]];
462- [beforeStr addAttributes: @{
463- @" __kIMBaseWritingDirectionAttributeName" : @" -1" ,
464- @" __kIMMessagePartAttributeName" : [NSNumber numberWithInt: index],
465- } range: NSMakeRange (0 , [[beforeStr string ] length ])];
466- NSMutableAttributedString *mentionStr = [[NSMutableAttributedString alloc ] initWithString: [(NSString *) dict[@" text" ] substringWithRange: NSMakeRange ([[dict[@" range" ] firstObject ] integerValue ], [[dict[@" range" ] lastObject ] integerValue ])]];
461+ NSMutableAttributedString *mentionStr = [[NSMutableAttributedString alloc ] initWithString: dict[@" text" ]];
467462 [mentionStr addAttributes: @{
468463 @" __kIMBaseWritingDirectionAttributeName" : @" -1" ,
469464 @" __kIMMentionConfirmedMention" : dict[@" mention" ],
470465 @" __kIMMessagePartAttributeName" : [NSNumber numberWithInt: index],
471466 } range: NSMakeRange (0 , [[mentionStr string ] length ])];
472- NSUInteger begin = [[dict[@" range" ] firstObject ] integerValue ] + [[dict[@" range" ] lastObject ] integerValue ];
473- NSUInteger end = [dict[@" text" ] length ] - begin;
474- NSMutableAttributedString *afterStr = [[NSMutableAttributedString alloc ] initWithString: [(NSString *) dict[@" text" ] substringWithRange: NSMakeRange (begin, end)]];
475- [afterStr addAttributes: @{
476- @" __kIMBaseWritingDirectionAttributeName" : @" -1" ,
477- @" __kIMMessagePartAttributeName" : [NSNumber numberWithInt: index],
478- } range: NSMakeRange (0 , [[afterStr string ] length ])];
479- if ([[beforeStr string ] length ] != 0 ) {
480- [attributedString appendAttributedString: beforeStr];
481- }
482- if ([[mentionStr string ] length ] != 0 ) {
483- [attributedString appendAttributedString: mentionStr];
484- }
485- if ([[afterStr string ] length ] != 0 ) {
486- [attributedString appendAttributedString: afterStr];
487- }
467+ [attributedString appendAttributedString: mentionStr];
488468 } else {
489469 NSMutableAttributedString *messageStr = [[NSMutableAttributedString alloc ] initWithString: dict[@" text" ]];
490470 [messageStr addAttributes: @{
@@ -494,7 +474,6 @@ -(void) handleMessage: (NetworkController*)controller message:(NSString *)messa
494474 [attributedString appendAttributedString: messageStr];
495475 }
496476 }
497- index++;
498477 }
499478 [BlueBubblesHelper sendMessage: (data) transfers: [transfers copy ] attributedString: attributedString transaction: (transaction)];
500479 // If the server tells us to get the vetted aliases
@@ -603,19 +582,25 @@ -(void) handleMessage: (NetworkController*)controller message:(NSString *)messa
603582 // Use reference to class since it doesn't exist on Big Sur
604583 Class cls = NSClassFromString (@" IMHandleAvailabilityManager" );
605584 if ([handles firstObject ] != nil && cls != nil ) {
606- [[cls sharedInstance ] _fetchUpdatedStatusForHandle: ([handles firstObject ]) completion: ^() {
607- // delay for 1 second to ensure we have latest status
608- NSTimeInterval delayInSeconds = 1.0 ;
609- dispatch_time_t popTime = dispatch_time (DISPATCH_TIME_NOW, (int64_t )(delayInSeconds * NSEC_PER_SEC));
610- dispatch_after (popTime, dispatch_get_main_queue (), ^(void ){
611- NSInteger *status = [[cls sharedInstance ] availabilityForHandle: ([handles firstObject ])];
612- DLog (" BLUEBUBBLESHELPER: Found status %{public}ld for %{public}@" , (long )status, data[@" address" ]);
613- if (transaction != nil ) {
614- BOOL silenced = status == 2 ;
615- [[NetworkController sharedInstance ] sendMessage: @{@" transactionId" : transaction, @" silenced" : [NSNumber numberWithBool: silenced]}];
616- }
617- });
618- }];
585+ if ([cls respondsToSelector: NSSelectorFromString (@" _fetchUpdatedStatusForHandle" )]) {
586+ [[cls sharedInstance ] _fetchUpdatedStatusForHandle: ([handles firstObject ]) completion: ^() {
587+ // delay for 1 second to ensure we have latest status
588+ NSTimeInterval delayInSeconds = 1.0 ;
589+ dispatch_time_t popTime = dispatch_time (DISPATCH_TIME_NOW, (int64_t )(delayInSeconds * NSEC_PER_SEC));
590+ dispatch_after (popTime, dispatch_get_main_queue (), ^(void ){
591+ NSInteger *status = [[cls sharedInstance ] availabilityForHandle: ([handles firstObject ])];
592+ DLog (" BLUEBUBBLESHELPER: Found status %{public}ld for %{public}@" , (long )status, data[@" address" ]);
593+ if (transaction != nil ) {
594+ BOOL silenced = status == 2 ;
595+ [[NetworkController sharedInstance ] sendMessage: @{@" transactionId" : transaction, @" silenced" : [NSNumber numberWithBool: silenced]}];
596+ }
597+ });
598+ }];
599+ } else {
600+ if (transaction != nil ) {
601+ [[NetworkController sharedInstance ] sendMessage: @{@" transactionId" : transaction, @" error" : @" Selector not found!" }];
602+ }
603+ }
619604 }
620605 } else if ([event isEqualToString: @" notify-anyways" ]) {
621606 IMChat *chat = [BlueBubblesHelper getChat: data[@" chatGuid" ] :transaction];
0 commit comments