Commit 830f33f96f5c7c152eb9021e6e503d9e165977f4
1 parent
63303376
0.1.3 版本 处理会话列表转余额显示逻辑
Showing
9 changed files
with
282 additions
and
6 deletions
CNLiveNewIMAManagerKit.podspec
| @@ -8,7 +8,7 @@ | @@ -8,7 +8,7 @@ | ||
| 8 | 8 | ||
| 9 | Pod::Spec.new do |s| | 9 | Pod::Spec.new do |s| |
| 10 | s.name = 'CNLiveNewIMAManagerKit' | 10 | s.name = 'CNLiveNewIMAManagerKit' |
| 11 | - s.version = '0.1.2' | 11 | + s.version = '0.1.3' |
| 12 | s.summary = 'A short description of CNLiveNewIMAManagerKit.' | 12 | s.summary = 'A short description of CNLiveNewIMAManagerKit.' |
| 13 | 13 | ||
| 14 | # This description is used to generate tags and improve search results. | 14 | # This description is used to generate tags and improve search results. |
CNLiveNewIMAManagerKit/Classes/Playform/IMAConversationManager.m
| @@ -1002,6 +1002,15 @@ | @@ -1002,6 +1002,15 @@ | ||
| 1002 | [[NSNotificationCenter defaultCenter] postNotificationName:kIMAMSG_ReceivingGiftsNotification object:nil userInfo:dic]; | 1002 | [[NSNotificationCenter defaultCenter] postNotificationName:kIMAMSG_ReceivingGiftsNotification object:nil userInfo:dic]; |
| 1003 | } | 1003 | } |
| 1004 | } | 1004 | } |
| 1005 | + else if ([dic[@"type"] integerValue] == CustomMsgTypeTransferExpired) | ||
| 1006 | + { | ||
| 1007 | + NSDictionary *transferBalanceExpiredData = [dic objectForKey:@"transferBalanceExpiredData"]; | ||
| 1008 | + | ||
| 1009 | + [[NSNotificationCenter defaultCenter] postNotificationName:@"CNTransferBalanceExpiredSuccessNotification" object:nil userInfo:transferBalanceExpiredData]; | ||
| 1010 | + [[CNTransferBalanceUnreceivedCache cache] removeOneElement:@{@"sourceId" : transferBalanceExpiredData[@"sourceId"]} forKey:[NSString stringWithFormat:@"key_%@_%@",CNUserShareModel.uid,[conv getReceiver]]]; | ||
| 1011 | + isBreak = YES; | ||
| 1012 | + | ||
| 1013 | + } | ||
| 1005 | return isBreak; | 1014 | return isBreak; |
| 1006 | } | 1015 | } |
| 1007 | 1016 |
CNLiveNewIMAManagerKit/Classes/TIMFMDBManager/CNTransferBalanceUnreceivedCache.h
0 → 100644
| 1 | +// | ||
| 2 | +// CNTransferBalanceUnreceivedCache.h | ||
| 3 | +// CNLiveNewIMAManagerKit | ||
| 4 | +// | ||
| 5 | +// Created by daojian on 2021/6/11. | ||
| 6 | +// | ||
| 7 | + | ||
| 8 | +#import <Foundation/Foundation.h> | ||
| 9 | + | ||
| 10 | +NS_ASSUME_NONNULL_BEGIN | ||
| 11 | + | ||
| 12 | +/// 缓存未领取的转账数据 | ||
| 13 | +@interface CNTransferBalanceUnreceivedCache : NSObject | ||
| 14 | + | ||
| 15 | +/// 获取缓存对象 | ||
| 16 | ++ (CNTransferBalanceUnreceivedCache *)cache; | ||
| 17 | + | ||
| 18 | +/// 往key对应的数组中添加一个未领取的转账消息数据 | ||
| 19 | +/// @param element 转账消息数据 | ||
| 20 | +/// @param key key 由会话id和用户id拼接而成,例如:key_userId_conversationId | ||
| 21 | +- (void)addOneElement:(NSDictionary *)element forKey:(NSString *)key; | ||
| 22 | + | ||
| 23 | +/// 取出key对应的数据,数据是个数组,数组里存放了具体待领取的转账数据 | ||
| 24 | +/// @param key key 由会话id和用户id拼接而成,例如:key_userId_conversationId | ||
| 25 | +- (NSArray <NSDictionary *> *)objectForKey:(NSString *)key; | ||
| 26 | + | ||
| 27 | +/// 从key对应的数据中移除一个元素,key保存的数据是个数组,数组里放每个具体元素 | ||
| 28 | +/// @param element 需要删除的某个元素 | ||
| 29 | +/// @param key key 由会话id和用户id拼接而成,例如:key_userId_conversationId | ||
| 30 | +- (void)removeOneElement:(NSDictionary *)element forKey:(NSString *)key; | ||
| 31 | + | ||
| 32 | +/// 移除key对应的数据 | ||
| 33 | +/// @param key key 由会话id和用户id拼接而成,例如:key_userId_conversationId | ||
| 34 | +- (void)removeObject:(NSString *)key; | ||
| 35 | + | ||
| 36 | +/// 是否存在 Key对应的数据 | ||
| 37 | +/// @param key key 由会话id和用户id拼接而成,例如:key_userId_conversationId | ||
| 38 | +- (BOOL)isExistKey:(NSString *)key; | ||
| 39 | + | ||
| 40 | +@end | ||
| 41 | + | ||
| 42 | +NS_ASSUME_NONNULL_END |
CNLiveNewIMAManagerKit/Classes/TIMFMDBManager/CNTransferBalanceUnreceivedCache.m
0 → 100644
| 1 | +// | ||
| 2 | +// CNTransferBalanceUnreceivedCache.m | ||
| 3 | +// CNLiveNewIMAManagerKit | ||
| 4 | +// | ||
| 5 | +// Created by daojian on 2021/6/11. | ||
| 6 | +// | ||
| 7 | + | ||
| 8 | +#import "CNTransferBalanceUnreceivedCache.h" | ||
| 9 | + | ||
| 10 | +@interface CNTransferBalanceUnreceivedCache() | ||
| 11 | + | ||
| 12 | +@property (nonatomic, strong)YYCache *cache; | ||
| 13 | + | ||
| 14 | +@end | ||
| 15 | + | ||
| 16 | +@implementation CNTransferBalanceUnreceivedCache | ||
| 17 | + | ||
| 18 | +static CNTransferBalanceUnreceivedCache *cache = nil; | ||
| 19 | + | ||
| 20 | +/// 获取缓存对象 | ||
| 21 | ++ (CNTransferBalanceUnreceivedCache *)cache | ||
| 22 | +{ | ||
| 23 | + static dispatch_once_t onceToken; | ||
| 24 | + dispatch_once(&onceToken, ^{ | ||
| 25 | + cache = [[CNTransferBalanceUnreceivedCache alloc] init]; | ||
| 26 | + NSString *filePath = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/%@/TransferBalanceUnreceivedData", CNUserShareModel.uid]]; | ||
| 27 | + cache.cache = [YYCache cacheWithPath:filePath]; | ||
| 28 | + }); | ||
| 29 | + return cache; | ||
| 30 | +} | ||
| 31 | + | ||
| 32 | +/// 往key对应的数组中添加一个未领取的转账消息数据 | ||
| 33 | +/// @param element 转账消息数据 | ||
| 34 | +/// @param key key 由会话id和用户id拼接而成,例如:key_userId_conversationId | ||
| 35 | +- (void)addOneElement:(NSDictionary *)element forKey:(NSString *)key | ||
| 36 | +{ | ||
| 37 | + if (element == nil) { | ||
| 38 | + return; | ||
| 39 | + } | ||
| 40 | + /**先取出Key对应的数据*/ | ||
| 41 | + NSArray *allArray = [self objectForKey:key]; | ||
| 42 | + if (allArray) { | ||
| 43 | + for (NSDictionary *dic in allArray) { | ||
| 44 | + if ([dic[@"sourceId"] isEqualToString:element[@"sourceId"]]) | ||
| 45 | + { | ||
| 46 | + //存在直接返回 | ||
| 47 | + return; | ||
| 48 | + } | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + } | ||
| 52 | + NSMutableArray *newArry = [NSMutableArray arrayWithArray:allArray]; | ||
| 53 | + [newArry addObject:element]; | ||
| 54 | + [self.cache setObject:newArry.copy forKey:key]; | ||
| 55 | + | ||
| 56 | +} | ||
| 57 | + | ||
| 58 | +/// 取出key对应的数据,数据是个数组,数组里存放了具体待领取的转账数据 | ||
| 59 | +/// @param key key 由会话id和用户id拼接而成,例如:key_userId_conversationId | ||
| 60 | +- (NSArray <NSDictionary *> *)objectForKey:(NSString *)key | ||
| 61 | +{ | ||
| 62 | + return [self.cache objectForKey:key]; | ||
| 63 | +} | ||
| 64 | + | ||
| 65 | +/// 从key对应的数据中移除一个元素,key保存的数据是个数组,数组里放每个具体元素 | ||
| 66 | +/// @param element 需要删除的某个元素 | ||
| 67 | +/// @param key key 由会话id和用户id拼接而成,例如:key_userId_conversationId | ||
| 68 | +- (void)removeOneElement:(NSDictionary *)element forKey:(NSString *)key | ||
| 69 | +{ | ||
| 70 | + if (element == nil) { | ||
| 71 | + return; | ||
| 72 | + } | ||
| 73 | + /**先取出Key对应的数据*/ | ||
| 74 | + NSArray *allArray = [self objectForKey:key]; | ||
| 75 | + if (!allArray || allArray.count == 0) { | ||
| 76 | + return; | ||
| 77 | + } | ||
| 78 | + NSMutableArray *newArry = [[NSMutableArray alloc] init]; | ||
| 79 | + for (NSDictionary *dic in allArray) { | ||
| 80 | + if (![dic[@"sourceId"] isEqualToString:element[@"sourceId"]]) { | ||
| 81 | + [newArry addObject:dic]; | ||
| 82 | + } | ||
| 83 | + } | ||
| 84 | + if (newArry.count == 0) { | ||
| 85 | + /**数组元素为空,直接把key对应的缓存数据清空*/ | ||
| 86 | + [self removeObject:key]; | ||
| 87 | + } | ||
| 88 | + else | ||
| 89 | + { | ||
| 90 | + /**重新缓存key对应的新数据*/ | ||
| 91 | + [self.cache setObject:newArry.copy forKey:key]; | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | +} | ||
| 95 | + | ||
| 96 | +/// 移除key对应的数据 | ||
| 97 | +/// @param key key 由会话id和用户id拼接而成,例如:key_userId_conversationId | ||
| 98 | +- (void)removeObject:(NSString *)key | ||
| 99 | +{ | ||
| 100 | + [self.cache removeObjectForKey:key]; | ||
| 101 | +} | ||
| 102 | + | ||
| 103 | +/// 是否存在 Key对应的数据 | ||
| 104 | +/// @param key key 由会话id和用户id拼接而成,例如:key_userId_conversationId | ||
| 105 | +- (BOOL)isExistKey:(NSString *)key | ||
| 106 | +{ | ||
| 107 | + return [self.cache containsObjectForKey:key]; | ||
| 108 | +} | ||
| 109 | + | ||
| 110 | +@end |
CNLiveNewIMAManagerKit/Classes/TIMFMDBManager/TIMFMDBManager.h
| @@ -15,5 +15,6 @@ | @@ -15,5 +15,6 @@ | ||
| 15 | #import "CNGroupIDFMDBManager.h" | 15 | #import "CNGroupIDFMDBManager.h" |
| 16 | #import "CNGroupListInfoModel.h" | 16 | #import "CNGroupListInfoModel.h" |
| 17 | #import "CNLiveGroupAvatorManager.h" | 17 | #import "CNLiveGroupAvatorManager.h" |
| 18 | +#import "CNTransferBalanceUnreceivedCache.h" | ||
| 18 | 19 | ||
| 19 | #endif /* TIMFMDBManager_h */ | 20 | #endif /* TIMFMDBManager_h */ |
CNLiveNewIMAManagerKit/Classes/TIMModel/MSG/IMAMsg.h
| @@ -132,11 +132,12 @@ typedef NS_ENUM(NSUInteger, CustomMsgType) { | @@ -132,11 +132,12 @@ typedef NS_ENUM(NSUInteger, CustomMsgType) { | ||
| 132 | 132 | ||
| 133 | CustomMsgTypeWithdrawMessage = 1009, //撤回消息 | 133 | CustomMsgTypeWithdrawMessage = 1009, //撤回消息 |
| 134 | 134 | ||
| 135 | - CustomMsgTypeSendCard = 1011, //发送名片 | 135 | + CustomMsgTypeSendCard = 1011, //发送普通好友名片 |
| 136 | 136 | ||
| 137 | CustomMsgTypeTransferBalance = 1013, //转余额 | 137 | CustomMsgTypeTransferBalance = 1013, //转余额 |
| 138 | CustomMsgTypeTransferExpired = 1014, //转余额过期,无人领取 | 138 | CustomMsgTypeTransferExpired = 1014, //转余额过期,无人领取 |
| 139 | - | 139 | + CustomMsgTypeSendDarenCard = 1015, //发送达人名片 |
| 140 | + | ||
| 140 | CustomMsgTypeReceiveE_BusinessOrder = 1021, //接收到电商订单消息(弃用) | 141 | CustomMsgTypeReceiveE_BusinessOrder = 1021, //接收到电商订单消息(弃用) |
| 141 | CustomMsgTypeE_BusinessOrderPaySuceess = 1022, //电商订单支付成功消息提醒 | 142 | CustomMsgTypeE_BusinessOrderPaySuceess = 1022, //电商订单支付成功消息提醒 |
| 142 | 143 |
CNLiveNewIMAManagerKit/Classes/TIMModel/MSG/IMAMsg.m
| @@ -531,7 +531,7 @@ | @@ -531,7 +531,7 @@ | ||
| 531 | // { | 531 | // { |
| 532 | // type = EIMAMSG_SharelocationEndTip; | 532 | // type = EIMAMSG_SharelocationEndTip; |
| 533 | // } | 533 | // } |
| 534 | - else if ([dic[@"type"] integerValue] == CustomMsgTypeSendCard) | 534 | + else if ([dic[@"type"] integerValue] == CustomMsgTypeSendCard || [dic[@"type"] integerValue] == CustomMsgTypeSendDarenCard) |
| 535 | { | 535 | { |
| 536 | type = EIMAMSG_SendCard; | 536 | type = EIMAMSG_SendCard; |
| 537 | 537 | ||
| @@ -1140,6 +1140,7 @@ | @@ -1140,6 +1140,7 @@ | ||
| 1140 | } | 1140 | } |
| 1141 | } | 1141 | } |
| 1142 | } | 1142 | } |
| 1143 | + | ||
| 1143 | return unReadMsgNumAtt; | 1144 | return unReadMsgNumAtt; |
| 1144 | } | 1145 | } |
| 1145 | 1146 | ||
| @@ -1204,6 +1205,18 @@ | @@ -1204,6 +1205,18 @@ | ||
| 1204 | [tipAtt addAttribute:NSForegroundColorAttributeName value:[UIColor qmui_colorWithHexString:@"#FC1541"] range:NSMakeRange(0, redTipStr.length)]; | 1205 | [tipAtt addAttribute:NSForegroundColorAttributeName value:[UIColor qmui_colorWithHexString:@"#FC1541"] range:NSMakeRange(0, redTipStr.length)]; |
| 1205 | 1206 | ||
| 1206 | } | 1207 | } |
| 1208 | + | ||
| 1209 | + TIMConversation *conv = [_msg getConversation]; | ||
| 1210 | + TIMConversationType type = [conv getType]; | ||
| 1211 | + if (type == TIM_C2C) { | ||
| 1212 | + /**未领取的转账数据*/ | ||
| 1213 | + NSArray *unreceivedTransferBalanceArray = [[CNTransferBalanceUnreceivedCache cache] objectForKey:[NSString stringWithFormat:@"key_%@_%@",CNUserShareModel.uid,[conv getReceiver]]]; | ||
| 1214 | + if (unreceivedTransferBalanceArray && unreceivedTransferBalanceArray.count > 0) { | ||
| 1215 | + NSString *redTipStr = @"[转余额]"; | ||
| 1216 | + [tipAtt appendString:redTipStr]; | ||
| 1217 | + [tipAtt addAttribute:NSForegroundColorAttributeName value:[UIColor qmui_colorWithHexString:@"#FC1541"] range:NSMakeRange(0, redTipStr.length)]; | ||
| 1218 | + } | ||
| 1219 | + } | ||
| 1207 | return tipAtt; | 1220 | return tipAtt; |
| 1208 | } | 1221 | } |
| 1209 | - (void)remove | 1222 | - (void)remove |
CNLiveNewIMAManagerKit/Classes/TIMShow/TIMElem+ShowDescription.m
| @@ -773,6 +773,80 @@ static NSString *const kGroupTypeKey = @"kGroupTypeKey"; | @@ -773,6 +773,80 @@ static NSString *const kGroupTypeKey = @"kGroupTypeKey"; | ||
| 773 | } | 773 | } |
| 774 | return des; | 774 | return des; |
| 775 | } | 775 | } |
| 776 | + else if(msg.type == EIMAMSG_TransferBalance) | ||
| 777 | + { | ||
| 778 | + NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:self.data options:NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves error:nil]; | ||
| 779 | + NSDictionary *transferBalanceData = dic[@"transferBalanceData"]; | ||
| 780 | + NSString *type = [NSString stringWithFormat:@"%@",transferBalanceData[@"type"]]; | ||
| 781 | + NSString *fromId = transferBalanceData[@"fromId"]; | ||
| 782 | + if ([fromId isEqualToString:CNUserShareModel.uid]) { | ||
| 783 | + //是打款方 | ||
| 784 | + switch ([type intValue]) { | ||
| 785 | + case 1: | ||
| 786 | + { | ||
| 787 | + //可能是未领取或者已过期 | ||
| 788 | + if ([msg.msg customInt] == 44) { | ||
| 789 | + //已过期 | ||
| 790 | + return @"[转余额]已过期"; | ||
| 791 | + } | ||
| 792 | + else | ||
| 793 | + { | ||
| 794 | + //未领取 | ||
| 795 | + return @"[转余额]你发起了一笔转余额"; | ||
| 796 | + } | ||
| 797 | + } | ||
| 798 | + break; | ||
| 799 | + case 2: | ||
| 800 | + { | ||
| 801 | + //已收款 | ||
| 802 | + return @"[转余额]对方已收款"; | ||
| 803 | + } | ||
| 804 | + break; | ||
| 805 | + case 3: | ||
| 806 | + { | ||
| 807 | + //已退还 | ||
| 808 | + return @"[转余额]对方已退还"; | ||
| 809 | + } | ||
| 810 | + break; | ||
| 811 | + default: | ||
| 812 | + break; | ||
| 813 | + } | ||
| 814 | + } | ||
| 815 | + else | ||
| 816 | + { | ||
| 817 | + //是收款方 | ||
| 818 | + switch ([type intValue]) { | ||
| 819 | + case 1: | ||
| 820 | + { | ||
| 821 | + //可能是未领取或者已过期 | ||
| 822 | + if ([msg.msg customInt] == 44) { | ||
| 823 | + //已过期 | ||
| 824 | + return @"[转余额]已过期"; | ||
| 825 | + } | ||
| 826 | + else | ||
| 827 | + { | ||
| 828 | + //未领取 | ||
| 829 | + return @"[转余额]待你领取"; | ||
| 830 | + } | ||
| 831 | + } | ||
| 832 | + break; | ||
| 833 | + case 2: | ||
| 834 | + { | ||
| 835 | + //已收款 | ||
| 836 | + return @"[转余额]已收款"; | ||
| 837 | + } | ||
| 838 | + break; | ||
| 839 | + case 3: | ||
| 840 | + { | ||
| 841 | + //已退还 | ||
| 842 | + return @"[转余额]已退还"; | ||
| 843 | + } | ||
| 844 | + break; | ||
| 845 | + default: | ||
| 846 | + break; | ||
| 847 | + } | ||
| 848 | + } | ||
| 849 | + } | ||
| 776 | else { | 850 | else { |
| 777 | NSString *des = [NSString stringWithFormat:@"%@", self.desc]; | 851 | NSString *des = [NSString stringWithFormat:@"%@", self.desc]; |
| 778 | return des; | 852 | return des; |
Example/CNLiveNewIMAManagerKit/CNLIVEViewController.m
| @@ -7,7 +7,7 @@ | @@ -7,7 +7,7 @@ | ||
| 7 | // | 7 | // |
| 8 | 8 | ||
| 9 | #import "CNLIVEViewController.h" | 9 | #import "CNLIVEViewController.h" |
| 10 | - | 10 | +#import <CNLiveNewIMAManagerKit/CNLiveNewIMAManagerKit.h> |
| 11 | @interface CNLIVEViewController () | 11 | @interface CNLIVEViewController () |
| 12 | 12 | ||
| 13 | @end | 13 | @end |
| @@ -18,6 +18,21 @@ | @@ -18,6 +18,21 @@ | ||
| 18 | { | 18 | { |
| 19 | [super viewDidLoad]; | 19 | [super viewDidLoad]; |
| 20 | // Do any additional setup after loading the view, typically from a nib. | 20 | // Do any additional setup after loading the view, typically from a nib. |
| 21 | + | ||
| 22 | + UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; | ||
| 23 | + btn.frame = CGRectMake(0, 50, 100, 50); | ||
| 24 | + [btn setTitle:@"存数据" forState:UIControlStateNormal]; | ||
| 25 | + btn.backgroundColor = [UIColor redColor]; | ||
| 26 | + [self.view addSubview:btn]; | ||
| 27 | + [btn addTarget:self action:@selector(setAction) forControlEvents:UIControlEventTouchUpInside]; | ||
| 28 | + | ||
| 29 | + | ||
| 30 | + UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom]; | ||
| 31 | + btn1.frame = CGRectMake(0, 150, 100, 50); | ||
| 32 | + [btn1 setTitle:@"取数据" forState:UIControlStateNormal]; | ||
| 33 | + btn1.backgroundColor = [UIColor redColor]; | ||
| 34 | + [self.view addSubview:btn1]; | ||
| 35 | + [btn1 addTarget:self action:@selector(getAction) forControlEvents:UIControlEventTouchUpInside]; | ||
| 21 | } | 36 | } |
| 22 | 37 | ||
| 23 | - (void)didReceiveMemoryWarning | 38 | - (void)didReceiveMemoryWarning |
| @@ -25,5 +40,16 @@ | @@ -25,5 +40,16 @@ | ||
| 25 | [super didReceiveMemoryWarning]; | 40 | [super didReceiveMemoryWarning]; |
| 26 | // Dispose of any resources that can be recreated. | 41 | // Dispose of any resources that can be recreated. |
| 27 | } | 42 | } |
| 28 | - | 43 | +- (void)setAction |
| 44 | +{ | ||
| 45 | + [[CNTransferBalanceUnreceivedCache cache] addOneElement:@{@"sourceId": @"1222", | ||
| 46 | + @"fromId" : @"1111", | ||
| 47 | + @"type" : @"1", | ||
| 48 | + } forKey:@"key1"]; | ||
| 49 | +} | ||
| 50 | +- (void)getAction | ||
| 51 | +{ | ||
| 52 | + NSArray *array = [[CNTransferBalanceUnreceivedCache cache] objectForKey:@"key1"]; | ||
| 53 | + NSLog(@"array = %@",array); | ||
| 54 | +} | ||
| 29 | @end | 55 | @end |