Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Commit

Permalink
[relay] this may or may not solve problems here once and for all
Browse files Browse the repository at this point in the history
  • Loading branch information
kirb committed Feb 16, 2017
1 parent 54f2db6 commit b16aa63
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions relay/Conversation.x
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,32 @@
extern NSString *kFZDaemonPropertyEnableReadReceipts;

HBTSConversationPreferences *preferences;
BOOL hasValue = NO;
BOOL sendReceipt = NO;

%group Stuff
%hook MessageServiceSession

- (void)sendReadReceiptForMessage:(id)message toChatID:(NSString *)chatID identifier:(NSString *)identifier style:(unsigned char)style {
// indicate to the hook below if receipts are blocked or not
hasValue = YES;
sendReceipt = [preferences readReceiptsEnabledForHandle:identifier];
%orig;
hasValue = NO;
}

- (void)sendPlayedReceiptForMessage:(id)message toChatID:(NSString *)chatID identifier:(NSString *)identifier style:(unsigned char)style {
hasValue = YES;
sendReceipt = [preferences readReceiptsEnabledForHandle:identifier];
%orig;
hasValue = NO;
}

- (void)sendSavedReceiptForMessage:(id)message toChatID:(NSString *)chatID identifier:(NSString *)identifier style:(unsigned char)style {
hasValue = YES;
sendReceipt = [preferences readReceiptsEnabledForHandle:identifier];
%orig;
hasValue = NO;
}

%end
Expand All @@ -35,18 +42,16 @@ BOOL sendReceipt = NO;
return %orig(CFSTR("ReadReceiptsEnabled"), applicationID, keyExistsAndHasValidFormat);
}

// if we are enabled, and com.apple.madrid’s ReadReceiptsEnabled key is being queried, override
// it. otherwise, return the original value as per usual
if ([preferences.class shouldEnable] && [(__bridge NSString *)applicationID isEqualToString:@"com.apple.madrid"] && [(__bridge NSString *)key isEqualToString:@"ReadReceiptsEnabled"]) {
// if we are enabled, and com.apple.madrid’s ReadReceiptsEnabled key is being queried, and we
// have something to use, override it. otherwise, return the original value as per usual
if ([preferences.class shouldEnable] && [(__bridge NSString *)applicationID isEqualToString:@"com.apple.madrid"] && [(__bridge NSString *)key isEqualToString:@"ReadReceiptsEnabled"] && hasValue) {
// if the pointer arg is non-null, set it
if (keyExistsAndHasValidFormat != NULL) {
*keyExistsAndHasValidFormat = YES;
}

// override value and set our var back to NO for safety
BOOL result = sendReceipt;
sendReceipt = NO;
return result;
// return our overridden value
return sendReceipt;
}

return %orig;
Expand Down

0 comments on commit b16aa63

Please sign in to comment.