diff --git a/src/Tweak.xm b/src/Tweak.xm index 6af2879..bc099de 100644 --- a/src/Tweak.xm +++ b/src/Tweak.xm @@ -135,13 +135,16 @@ BOOL (^isGroupInBlackList)() = ^BOOL() { return [[WBRedEnvelopConfig sharedConfig].blackList containsObject:wrap.m_nsFromUsr]; }; - + /** 是否领取私聊红包 */ + BOOL (^isReceivePrivateRedEnvelop)() = ^BOOL() { + return [WBRedEnvelopConfig sharedConfig].autoReceivePrivateEnable; + }; /** 是否自动抢红包 */ BOOL (^shouldReceiveRedEnvelop)() = ^BOOL() { if (![WBRedEnvelopConfig sharedConfig].autoReceiveEnable) { return NO; } if (isGroupInBlackList()) { return NO; } - return isGroupReceiver() || (isGroupSender() && isReceiveSelfRedEnvelop()); + return isGroupReceiver() || (isGroupSender() && isReceiveSelfRedEnvelop()) || (isReceivePrivateRedEnvelop() && !isSender() && !isGroupReceiver()); }; NSDictionary *(^parseNativeUrl)(NSString *nativeUrl) = ^(NSString *nativeUrl) { diff --git a/src/WBRedEnvelopConfig.h b/src/WBRedEnvelopConfig.h index 42879a6..3ed3188 100644 --- a/src/WBRedEnvelopConfig.h +++ b/src/WBRedEnvelopConfig.h @@ -15,6 +15,7 @@ @property (assign, nonatomic) BOOL autoReceiveEnable; @property (assign, nonatomic) NSInteger delaySeconds; +@property (assign, nonatomic) BOOL autoReceivePrivateEnable;//自动领取私聊红包 /** Pro */ @property (assign, nonatomic) BOOL receiveSelfRedEnvelop; diff --git a/src/WBRedEnvelopConfig.m b/src/WBRedEnvelopConfig.m index bca3f19..c070867 100644 --- a/src/WBRedEnvelopConfig.m +++ b/src/WBRedEnvelopConfig.m @@ -11,6 +11,7 @@ static NSString * const kDelaySecondsKey = @"XGDelaySecondsKey"; static NSString * const kAutoReceiveRedEnvelopKey = @"XGWeChatRedEnvelopSwitchKey"; +static NSString * const kAutoReceivePrivateRedEnvelopKey = @"kAutoReceivePrivateRedEnvelopKey"; static NSString * const kReceiveSelfRedEnvelopKey = @"WBReceiveSelfRedEnvelopKey"; static NSString * const kSerialReceiveKey = @"WBSerialReceiveKey"; static NSString * const kBlackListKey = @"WBBlackListKey"; @@ -35,6 +36,7 @@ - (instancetype)init { if (self = [super init]) { _delaySeconds = [[NSUserDefaults standardUserDefaults] integerForKey:kDelaySecondsKey]; _autoReceiveEnable = [[NSUserDefaults standardUserDefaults] boolForKey:kAutoReceiveRedEnvelopKey]; + _autoReceivePrivateEnable = [[NSUserDefaults standardUserDefaults] boolForKey:kAutoReceivePrivateRedEnvelopKey]; _serialReceive = [[NSUserDefaults standardUserDefaults] boolForKey:kSerialReceiveKey]; _blackList = [[NSUserDefaults standardUserDefaults] objectForKey:kBlackListKey]; _receiveSelfRedEnvelop = [[NSUserDefaults standardUserDefaults] boolForKey:kReceiveSelfRedEnvelopKey]; @@ -57,6 +59,13 @@ - (void)setAutoReceiveEnable:(BOOL)autoReceiveEnable { [[NSUserDefaults standardUserDefaults] synchronize]; } +- (void)setAutoReceivePrivateEnable:(BOOL)autoReceivePrivateEnable { + _autoReceivePrivateEnable = autoReceivePrivateEnable; + + [[NSUserDefaults standardUserDefaults] setBool:autoReceivePrivateEnable forKey:kAutoReceivePrivateRedEnvelopKey]; + [[NSUserDefaults standardUserDefaults] synchronize]; +} + - (void)setReceiveSelfRedEnvelop:(BOOL)receiveSelfRedEnvelop { _receiveSelfRedEnvelop = receiveSelfRedEnvelop; diff --git a/src/WBSettingViewController.m b/src/WBSettingViewController.m index 2648218..8c364d7 100644 --- a/src/WBSettingViewController.m +++ b/src/WBSettingViewController.m @@ -75,6 +75,7 @@ - (void)addBasicSettingSection { MMTableViewSectionInfo *sectionInfo = [objc_getClass("MMTableViewSectionInfo") sectionInfoDefaut]; [sectionInfo addCell:[self createAutoReceiveRedEnvelopCell]]; + [sectionInfo addCell:[self createAutoReceivePrivateRedEnvelopCell]]; [sectionInfo addCell:[self createDelaySettingCell]]; [self.tableViewInfo addSection:sectionInfo]; @@ -85,6 +86,10 @@ - (MMTableViewCellInfo *)createAutoReceiveRedEnvelopCell { return [objc_getClass("MMTableViewCellInfo") switchCellForSel:@selector(switchRedEnvelop:) target:self title:@"自动抢红包" on:[WBRedEnvelopConfig sharedConfig].autoReceiveEnable]; } +- (MMTableViewCellInfo *)createAutoReceivePrivateRedEnvelopCell { + return [objc_getClass("MMTableViewCellInfo") switchCellForSel:@selector(switchPrivateRedEnvelop:) target:self title:@"自动领取私聊红包" on:[WBRedEnvelopConfig sharedConfig].autoReceivePrivateEnable]; +} + - (MMTableViewCellInfo *)createDelaySettingCell { NSInteger delaySeconds = [WBRedEnvelopConfig sharedConfig].delaySeconds; NSString *delayString = delaySeconds == 0 ? @"不延迟" : [NSString stringWithFormat:@"%ld 秒", (long)delaySeconds]; @@ -98,6 +103,12 @@ - (MMTableViewCellInfo *)createDelaySettingCell { return cellInfo; } +- (void)switchPrivateRedEnvelop:(UISwitch *)privateRedEnvelop { + [WBRedEnvelopConfig sharedConfig].autoReceivePrivateEnable = privateRedEnvelop.on; + + [self reloadTableData]; +} + - (void)switchRedEnvelop:(UISwitch *)envelopSwitch { [WBRedEnvelopConfig sharedConfig].autoReceiveEnable = envelopSwitch.on;