Skip to content

Commit

Permalink
Fix Big Sur-Ventura FindMy to listen for new locations actively
Browse files Browse the repository at this point in the history
  • Loading branch information
tneotia committed Jan 31, 2024
1 parent 93eaa82 commit bae95fd
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 15 deletions.
10 changes: 6 additions & 4 deletions Messages/MacOS-11+/BlueBubblesHelper.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
A69A83DE27D18092007BB936 /* IMDPersistentAttachmentController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IMDPersistentAttachmentController.h; sourceTree = "<group>"; };
A69A83DF27D18385007BB936 /* IMDPersistence.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IMDPersistence.framework; path = /System/Library/PrivateFrameworks/IMDPersistence.framework; sourceTree = "<group>"; };
A6DAE8E729CCD09F00C23C79 /* SKStatusSubscriptionServiceDelegate-Protocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "SKStatusSubscriptionServiceDelegate-Protocol.h"; sourceTree = "<group>"; };
A6E13E352B65C8F9002983AD /* FMFSessionDataManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FMFSessionDataManager.h; sourceTree = "<group>"; };
A6E1F4CF27166012000A0EF6 /* IMPinnedConversationsController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IMPinnedConversationsController.h; sourceTree = "<group>"; };
A6E7318229A3D37000AAED78 /* IMAggregateAttachmentMessagePartChatItem.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IMAggregateAttachmentMessagePartChatItem.h; sourceTree = "<group>"; };
A6E7318329A3D49600AAED78 /* IMAttachmentMessagePartChatItem.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IMAttachmentMessagePartChatItem.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -342,6 +343,7 @@
A69960F12B2005100081FB69 /* FMLSession.h */,
A69960F62B20E46B0081FB69 /* FMLLocation.h */,
A69960F72B20E4AD0081FB69 /* FMLHandle.h */,
A6E13E352B65C8F9002983AD /* FMFSessionDataManager.h */,
);
name = IMCore;
sourceTree = "<group>";
Expand Down Expand Up @@ -579,7 +581,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = "$(inherited)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 20;
CURRENT_PROJECT_VERSION = 21;
DEFINES_MODULE = YES;
DSTROOT = /;
DYLIB_COMPATIBILITY_VERSION = 1;
Expand All @@ -589,7 +591,7 @@
INSTALL_PATH = /Users/tanay/Desktop/test;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 0.0.18;
MARKETING_VERSION = 0.0.19;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand All @@ -614,7 +616,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = "$(inherited)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 20;
CURRENT_PROJECT_VERSION = 21;
DEFINES_MODULE = YES;
DSTROOT = /;
DYLIB_COMPATIBILITY_VERSION = 1;
Expand All @@ -624,7 +626,7 @@
INSTALL_PATH = /Users/tanay/Desktop/test;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 0.0.18;
MARKETING_VERSION = 0.0.19;
MTL_FAST_MATH = YES;
PRODUCT_NAME = BlueBubblesHelper;
SDKROOT = macosx;
Expand Down
Binary file not shown.
74 changes: 63 additions & 11 deletions Messages/MacOS-11+/BlueBubblesHelper/BlueBubblesHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#import "CTBlockDescription.h"
#import "FMLHandle.h"
#import "FMLLocation.h"
#import "FMFSessionDataManager.h"

@interface BlueBubblesHelper : NSObject
+ (instancetype)sharedInstance;
Expand Down Expand Up @@ -740,7 +741,7 @@ -(void) handleMessage: (NetworkController*)controller message:(NSString *)messa
}
}
// If the server tells us to get findmy friends locations
} else if ([event isEqualToString:@"findmy-friends"]) {
} else if ([event isEqualToString:@"refresh-findmy-friends"]) {
if ([[NSProcessInfo processInfo] operatingSystemVersion].majorVersion > 13) {
FindMyLocateSession *session = [[IMFMFSession sharedInstance] fmlSession];
DLog("BLUEBUBBLESHELPER: block 1: %@", [session locationUpdateCallback]);
Expand Down Expand Up @@ -776,26 +777,23 @@ -(void) handleMessage: (NetworkController*)controller message:(NSString *)messa
} else {
FMFSession *session = [[IMFMFSession sharedInstance] session];
NSArray* handles = [session getHandlesSharingLocationsWithMe];
DLog("BLUEBUBBLESHELPER: handles test: %@", handles);
NSMutableArray* locations = [[NSMutableArray alloc] initWithArray:@[]];
[self DumpObjcMethods:[FMFSession class]];

IMAccountController *controller = [IMAccountController sharedInstance];
IMAccount *account = [controller activeIMessageAccount];
[session refreshLocationForHandles:(handles) callerId:([FMFHandle handleWithId:[account strippedLogin]]) priority:(1000) completion:^(NSObject *test2, NSObject *test) {
DLog("BLUEBUBBLESHELPER: %@", test);
DLog("BLUEBUBBLESHELPER: %@", [test className]);
}];
DLog("BLUEBUBBLESHELPER: Found FMF Handles: %{public}@", handles);

// Send the current cached locations to the server just in case
NSMutableArray* locations = [[NSMutableArray alloc] initWithArray:@[]];
for (NSObject* handle in handles) {
FMFLocation* location = [[IMFMFSession sharedInstance] locationForFMFHandle:handle];
NSInteger* type = ([[NSProcessInfo processInfo] operatingSystemVersion].majorVersion < 13) ? 0 : [location locationType];
NSDictionary* locDetails = @{
@"handle": [[location handle] identifier] ?: [NSNull null],
@"coordinates": @[@([location coordinate].latitude), @([location coordinate].longitude)],
@"long_address": [location longAddress] ?: [NSNull null],
@"short_address": [location shortAddress] ?: [NSNull null],
@"subtitle": [location subtitle] ?: [NSNull null],
@"title": [location title] ?: [NSNull null],
@"last_updated": [NSNumber numberWithDouble:round([[location timestamp] timeIntervalSince1970])*1000],
@"is_locating_in_progress": [NSNumber numberWithBool:[location isLocatingInProgress]] ?: [NSNull null],
@"status": (type == 0) ? @"legacy" : (type == 2) ? @"live" : @"shallow"
};
[locations addObject:locDetails];
}
Expand All @@ -807,6 +805,10 @@ -(void) handleMessage: (NetworkController*)controller message:(NSString *)messa
};
[[NetworkController sharedInstance] sendMessage: data];
}

[session removeHandles:[session handles]];
[session addHandles:handles];
[session forceRefresh];
}
// If the event is something that hasn't been implemented, we simply ignore it and put this log
} else {
Expand Down Expand Up @@ -1156,6 +1158,56 @@ @implementation BBH_FindMyLocateSession

@end

// Handle FindMy data changes
ZKSwizzleInterface(BBH_FMFSessionDataManager, FMFSessionDataManager , NSObject)
@implementation BBH_FMFSessionDataManager

- (void)setLocations:(id)arg1 {
Class class = NSClassFromString(@"FMFSessionDataManager");
NSSet* locations = [[class sharedInstance] locations];
DLog("BLUEBUBBLESHELPER: Got new locations: %{public}@", locations);

for (FMFLocation* location in locations) {
NSInteger* type = ([[NSProcessInfo processInfo] operatingSystemVersion].majorVersion < 13) ? 0 : [location locationType];
NSMutableDictionary* locDetails = [[NSMutableDictionary alloc] initWithDictionary: @{
@"handle": [[location handle] identifier] ?: [NSNull null],
@"coordinates": @[@([location coordinate].latitude), @([location coordinate].longitude)],
@"long_address": [location longAddress] ?: [NSNull null],
@"short_address": [location shortAddress] ?: [NSNull null],
@"subtitle": [location subtitle] ?: [NSNull null],
@"title": [location title] ?: [NSNull null],
@"last_updated": [NSNumber numberWithDouble:round([[location timestamp] timeIntervalSince1970])*1000],
@"is_locating_in_progress": [NSNumber numberWithBool:[location isLocatingInProgress]] ?: [NSNull null],
@"status": (type == 0) ? @"legacy" : (type == 2) ? @"live" : @"shallow"
}];

if ([location coordinate].latitude == 0 && [location coordinate].longitude == 0 && [location longAddress] != nil) {
DLog("BLUEBUBBLESHELPER: Geocoding location for %{public}@", [[location handle] identifier]);
[[[CLGeocoder alloc] init] geocodeAddressString:[location longAddress] completionHandler:^(NSArray<CLPlacemark*>* placemarks, NSError* error) {
if (placemarks.count > 0) {
CLLocation* coords = [[placemarks firstObject] location];
[locDetails setValue:@[@([coords coordinate].latitude), @([coords coordinate].longitude)] forKey:@"coordinates"];
}

NSDictionary *data = @{
@"event": @"new-findmy-location",
@"data": @[locDetails],
};
[[NetworkController sharedInstance] sendMessage: data];
}];
} else {
NSDictionary *data = @{
@"event": @"new-findmy-location",
@"data": @[locDetails],
};
[[NetworkController sharedInstance] sendMessage: data];
}
}
return ZKOrig(void, arg1);
}

@end

ZKSwizzleInterface(BBH_IMAccount, IMAccount, NSObject)
@implementation BBH_IMAccount

Expand Down
36 changes: 36 additions & 0 deletions Messages/MacOS-11+/BlueBubblesHelper/FMFSessionDataManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Headers generated with ktool v1.4.0
// https://github.com/cxnder/ktool | pip3 install k2l
// Platform: IOS | Minimum OS: 16.0.0 | SDK: 16.0.0


#ifndef FMFSESSIONDATAMANAGER_H
#define FMFSESSIONDATAMANAGER_H

@class NSSet, NSMutableDictionary;

#import <Foundation/Foundation.h>


@interface FMFSessionDataManager : NSObject

@property (retain, nonatomic) NSSet *fences; // ivar: _fences
@property (retain, nonatomic) NSSet *followers; // ivar: _followers
@property (retain, nonatomic) NSSet *following; // ivar: _following
@property (retain, nonatomic) NSSet *locations; // ivar: _locations
@property (retain, nonatomic) NSMutableDictionary *locationsCache; // ivar: _locationsCache


+(id)sharedInstance;
-(id)favoritesOrdered;
-(id)followerForHandle:(id)arg0 ;
-(id)followingForHandle:(id)arg0 ;
-(id)locationForHandle:(id)arg0 ;
-(id)offerExpirationForHandle:(id)arg0 groupId:(id)arg1 ;
-(void)abDidChange;
-(void)abPreferencesDidChange;


@end


#endif

0 comments on commit bae95fd

Please sign in to comment.