Skip to content

Commit

Permalink
切换用户时需要清理用户相关的组织缓存
Browse files Browse the repository at this point in the history
  • Loading branch information
heavyrian2012 committed Jan 2, 2023
1 parent 77c19c2 commit ac62324
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 3 deletions.
2 changes: 2 additions & 0 deletions wfchat/WildFireChat/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,8 @@ - (void)onConnectionStatusChanged:(ConnectionStatus)status {
[[AppService sharedAppService] clearAppServiceAuthInfos];
[[OrgService sharedOrgService] clearOrgServiceAuthInfos];
[[NSUserDefaults standardUserDefaults] synchronize];

self.firstConnected = NO;
} else if(status == kConnectionStatusConnected) {
if(!self.firstConnected) {
self.firstConnected = YES;
Expand Down
3 changes: 3 additions & 0 deletions wfchat/WildFireChat/OrgService/OrgService.m
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,9 @@ - (NSString *)getOrgServiceAuthToken {

- (void)clearOrgServiceAuthInfos {
[[NSUserDefaults standardUserDefaults] removeObjectForKey:WFC_ORGSERVER_AUTH_TOKEN];

//remove kit org cache
[[WFCUOrganizationCache sharedCache] clearCaches];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -731,12 +731,17 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
NSMutableArray *ids = [[NSMutableArray alloc] init];
while (index) {
[ids insertObject:@(index) atIndex:0];
__block BOOL has = NO;
[rs enumerateObjectsUsingBlock:^(WFCUOrgRelationship * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if(obj.organizationId == index) {
index = obj.parentOrganizationId;
*stop = YES;
has = YES;
}
}];
if(!has) {
break;
}
}
WFCUOrganizationViewController *orgVC = [[WFCUOrganizationViewController alloc] init];
orgVC.organizationIds = ids;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ - (void)viewDidLoad {
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
layout.minimumLineSpacing = 0;
layout.minimumInteritemSpacing = 0;
layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
layout.sectionInset = UIEdgeInsetsMake(0, 10, 0, 10);
self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 32) collectionViewLayout:layout];
self.collectionView.dataSource = self;
self.collectionView.delegate = self;
Expand Down
1 change: 1 addition & 0 deletions wfuikit/WFChatUIKit/Organization/WFCUOrganizationCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ extern NSString *kOrgRelationUpdated;
@property(nonatomic, strong)NSArray<NSNumber *> *bottomOrganizationIds;

- (void)loadMyOrganizationInfos;
- (void)clearCaches;

- (void)getRelationship:(NSString *)employeeId
refresh:(BOOL)refresh
Expand Down
10 changes: 8 additions & 2 deletions wfuikit/WFChatUIKit/Organization/WFCUOrganizationCache.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ + (WFCUOrganizationCache *)sharedCache {
sharedSingleton.organizationDict = [[NSMutableDictionary alloc] init];
sharedSingleton.organizationExDict = [[NSMutableDictionary alloc] init];
sharedSingleton.relationshipDict = [[NSMutableDictionary alloc] init];
[sharedSingleton restoreMyOrganizationInfos];
}
}
}
Expand Down Expand Up @@ -78,9 +79,14 @@ - (void)restoreMyOrganizationInfos {
}];
}

- (void)loadMyOrganizationInfos {
[self restoreMyOrganizationInfos];
- (void)clearCaches {
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"WFC_bottomOrganizationIds"];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"WFC_rootOrganizationIds"];
self.bottomOrganizationIds = nil;
self.rootOrganizationIds = nil;
}

- (void)loadMyOrganizationInfos {
[[WFCUConfigManager globalManager].orgServiceProvider getRelationship:[WFCCNetworkService sharedInstance].userId success:^(NSArray<WFCUOrgRelationship *> * _Nonnull relationships) {
self.relationshipDict[[WFCCNetworkService sharedInstance].userId] = relationships;
NSMutableArray<NSNumber *> *bottomIds = [[NSMutableArray alloc] init];
Expand Down

0 comments on commit ac62324

Please sign in to comment.