Skip to content
This repository was archived by the owner on Jul 19, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/Tweak.xm
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/WBRedEnvelopConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions src/WBRedEnvelopConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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];
Expand All @@ -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;

Expand Down
11 changes: 11 additions & 0 deletions src/WBSettingViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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];
Expand All @@ -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;

Expand Down