送礼物可以发送自定义消息

This commit is contained in:
fengshuo
2021-11-16 19:56:37 +08:00
parent b4c50569dd
commit 1a4b6b537a
17 changed files with 403 additions and 17 deletions

View File

@@ -164,6 +164,9 @@
E8788960273BB14200BF1D57 /* XPGiftMicroUserModel.m in Sources */ = {isa = PBXBuildFile; fileRef = E878895F273BB14200BF1D57 /* XPGiftMicroUserModel.m */; };
E87A24F1272935920086A794 /* XPMessageRemoteExtModel.m in Sources */ = {isa = PBXBuildFile; fileRef = E87A24F0272935920086A794 /* XPMessageRemoteExtModel.m */; };
E884C36C2743951B00E1EBED /* GiftReceiveInfoModel.m in Sources */ = {isa = PBXBuildFile; fileRef = E884C36B2743951B00E1EBED /* GiftReceiveInfoModel.m */; };
E884C36F2743AAC800E1EBED /* AttachmentModel.m in Sources */ = {isa = PBXBuildFile; fileRef = E884C36E2743AAC800E1EBED /* AttachmentModel.m */; };
E884C3722743AEDE00E1EBED /* CustomAttachmentDecoder.m in Sources */ = {isa = PBXBuildFile; fileRef = E884C3712743AEDE00E1EBED /* CustomAttachmentDecoder.m */; };
E884C37B2743B6E900E1EBED /* IMMessageHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = E884C37A2743B6E900E1EBED /* IMMessageHelper.m */; };
E88B5CA526FB088600DA9178 /* XPMineTeenagerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E88B5CA426FB088600DA9178 /* XPMineTeenagerViewController.m */; };
E88B5CA826FB089C00DA9178 /* XPMineTeenagePwdViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E88B5CA726FB089C00DA9178 /* XPMineTeenagePwdViewController.m */; };
E88B5CAD26FB16A800DA9178 /* XPMineTeenagerDesView.m in Sources */ = {isa = PBXBuildFile; fileRef = E88B5CAC26FB16A800DA9178 /* XPMineTeenagerDesView.m */; };
@@ -566,6 +569,12 @@
E87A24F0272935920086A794 /* XPMessageRemoteExtModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPMessageRemoteExtModel.m; sourceTree = "<group>"; };
E884C36A2743951B00E1EBED /* GiftReceiveInfoModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GiftReceiveInfoModel.h; sourceTree = "<group>"; };
E884C36B2743951B00E1EBED /* GiftReceiveInfoModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GiftReceiveInfoModel.m; sourceTree = "<group>"; };
E884C36D2743AAC800E1EBED /* AttachmentModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AttachmentModel.h; sourceTree = "<group>"; };
E884C36E2743AAC800E1EBED /* AttachmentModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AttachmentModel.m; sourceTree = "<group>"; };
E884C3702743AEDE00E1EBED /* CustomAttachmentDecoder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CustomAttachmentDecoder.h; sourceTree = "<group>"; };
E884C3712743AEDE00E1EBED /* CustomAttachmentDecoder.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CustomAttachmentDecoder.m; sourceTree = "<group>"; };
E884C3792743B6E900E1EBED /* IMMessageHelper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IMMessageHelper.h; sourceTree = "<group>"; };
E884C37A2743B6E900E1EBED /* IMMessageHelper.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = IMMessageHelper.m; sourceTree = "<group>"; };
E88B5CA326FB088600DA9178 /* XPMineTeenagerViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPMineTeenagerViewController.h; sourceTree = "<group>"; };
E88B5CA426FB088600DA9178 /* XPMineTeenagerViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XPMineTeenagerViewController.m; sourceTree = "<group>"; };
E88B5CA626FB089C00DA9178 /* XPMineTeenagePwdViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XPMineTeenagePwdViewController.h; sourceTree = "<group>"; };
@@ -1036,6 +1045,7 @@
189DD56126DE45F800AB55B1 /* Main */ = {
isa = PBXGroup;
children = (
E884C3732743B66400E1EBED /* IM */,
18486210271EA9A5005FC5DC /* RTC */,
E8AEAED3271412D00017FCE0 /* Room */,
E8E70D6E26F2EB1200F03460 /* Mine */,
@@ -1587,6 +1597,35 @@
path = Cell;
sourceTree = "<group>";
};
E884C3732743B66400E1EBED /* IM */ = {
isa = PBXGroup;
children = (
E884C3782743B6AA00E1EBED /* Tool */,
E884C3772743B67E00E1EBED /* Model */,
);
path = IM;
sourceTree = "<group>";
};
E884C3772743B67E00E1EBED /* Model */ = {
isa = PBXGroup;
children = (
E884C36D2743AAC800E1EBED /* AttachmentModel.h */,
E884C36E2743AAC800E1EBED /* AttachmentModel.m */,
);
path = Model;
sourceTree = "<group>";
};
E884C3782743B6AA00E1EBED /* Tool */ = {
isa = PBXGroup;
children = (
E884C3702743AEDE00E1EBED /* CustomAttachmentDecoder.h */,
E884C3712743AEDE00E1EBED /* CustomAttachmentDecoder.m */,
E884C3792743B6E900E1EBED /* IMMessageHelper.h */,
E884C37A2743B6E900E1EBED /* IMMessageHelper.m */,
);
path = Tool;
sourceTree = "<group>";
};
E88B5CA926FB15B900DA9178 /* Teenager */ = {
isa = PBXGroup;
children = (
@@ -2214,6 +2253,7 @@
E8788950273A699900BF1D57 /* ThemeColor+SendGift.m in Sources */,
E81C279D26EEEC620031E639 /* XPConstant.m in Sources */,
187EEEFE26E8A82C002833B2 /* NSObject+AutoCoding.m in Sources */,
E884C36F2743AAC800E1EBED /* AttachmentModel.m in Sources */,
E8AC721926F46E0B007D6E91 /* XPMineSettingItemModel.m in Sources */,
189DD55A26DE39D200AB55B1 /* BaseMvpPresenter.m in Sources */,
180806D827293794001FD836 /* NSObject+MJExtension.m in Sources */,
@@ -2326,6 +2366,7 @@
187EEEDC26E89B32002833B2 /* BaseModel.m in Sources */,
E81366FC26F0D2980076364C /* UIButton+EnlargeTouchArea.m in Sources */,
E824546426F5FF1C00BE8163 /* XPMineResetPayPasswordPresenter.m in Sources */,
E884C3722743AEDE00E1EBED /* CustomAttachmentDecoder.m in Sources */,
E8B846BC26FD7C1200A777FE /* UploadImage.m in Sources */,
186A534D26FC6ED900D67B2C /* TTActionSheetView.m in Sources */,
E878893F273A54F500BF1D57 /* XPGiftPresenter.m in Sources */,
@@ -2333,6 +2374,7 @@
E88B5CC126FB407B00DA9178 /* XPMineUserInfoViewController.m in Sources */,
E824545926F5E65900BE8163 /* XPMineVerifIdentityView.m in Sources */,
189DD74026E21C3F00AB55B1 /* YYUtility+App.m in Sources */,
E884C37B2743B6E900E1EBED /* IMMessageHelper.m in Sources */,
189DD74526E21CCC00AB55B1 /* YYReachability.m in Sources */,
E82109AD26F1C8A000FC3319 /* CountDownHelper.m in Sources */,
E8E70D8F26F2F5DB00F03460 /* XPMineMenuTableViewCell.m in Sources */,

View File

@@ -11,6 +11,7 @@
#import <NIMSDK/NIMSDK.h>
///Tool
#import "XPConstant.h"
#import "CustomAttachmentDecoder.h"
@implementation AppDelegate (ThirdConfig)
@@ -37,6 +38,9 @@
NIMSDKOption *option = [NIMSDKOption optionWithAppKey:appKey];
option.apnsCername = KeyWithType(KeyType_APNSCer);
[[NIMSDK sharedSDK] registerWithOption:option];
// NIM SDK
[NIMCustomObject registerCustomDecoder:[[CustomAttachmentDecoder alloc] init]];
}
@end

View File

@@ -52,6 +52,26 @@ NS_ASSUME_NONNULL_BEGIN
@property(nonatomic, strong)NSString *avatar;
@end
@interface GiftLuckyUserInfo : NSObject
@property(nonatomic, copy) NSString *nick;
//基础信息
@property(nonatomic, assign) NSInteger uid;
@end
@interface GiftListsInfo : NSObject
@property (nonatomic, assign) NSInteger giftNum;
@property (nonatomic, assign) NSInteger prizeLevel;
@property (nonatomic, assign) NSInteger giftId;
@end
// 要多次发送消息 福袋相关的modle单独处理
@interface GiftLuckyBagGiftsInfo : NSObject
@property (nonatomic, strong) NSArray <GiftListsInfo *> *giftList;
@property (nonatomic, strong) GiftLuckyUserInfo *user;
@end
@interface GiftReceiveInfoModel : NSObject
@property (nonatomic, strong) NSArray *targetUids;
@@ -69,8 +89,16 @@ NS_ASSUME_NONNULL_BEGIN
@property (assign, nonatomic) NSInteger giftNum;
/** 非全麦 多人送礼时 */
@property (nonatomic, strong) NSArray<GiftReceiveUserInfoModel *> *targetUsers;
/** 福袋礼物需要展示的vg动画 */
@property (nonatomic, strong) NSArray<GiftInfoModel *> *displayGift;
///福袋随机获取的礼物
@property (nonatomic, strong) NSArray <GiftLuckyBagGiftsInfo *> *luckyBagGifts;
//多人接收到的具体福袋礼物 是对luckyBagGifts的分离 要多次发送消息使用
@property (nonatomic, strong) GiftLuckyBagGiftsInfo* luckyGiftList;
///礼物来源
@property (nonatomic,assign) GiftSourceType sourceType;
///房间送礼物的类型
@property (nonatomic,assign) RoomSendGiftType roomSendGiftType;
@end
NS_ASSUME_NONNULL_END

View File

@@ -10,12 +10,35 @@
@implementation GiftReceiveUserInfoModel
@end
@implementation GiftLuckyUserInfo
@end
@implementation GiftListsInfo
@end
@implementation GiftLuckyBagGiftsInfo
+ (NSDictionary *)objectClassInArray {
return @{@"giftList":GiftListsInfo.class
};
}
@end
@implementation GiftReceiveInfoModel
+ (NSDictionary *)objectClassInArray {
return @{@"targetUsers":GiftReceiveUserInfoModel.class};
return @{@"targetUsers":GiftReceiveUserInfoModel.class,
@"displayGift":GiftInfoModel.class,
@"luckyBagGifts":GiftLuckyBagGiftsInfo.class
};
}
@end

View File

@@ -91,9 +91,12 @@
roomUid = @"";
}
[Api requestSendGift:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
GiftReceiveInfoModel *receive = [GiftReceiveInfoModel modelWithJSON:data.data];
receive.sourceType = giftSource;
[self.getView sendGiftSuccess:receive];
if (code == 200 && data.data) {
GiftReceiveInfoModel *receive = [GiftReceiveInfoModel modelWithJSON:data.data];
receive.sourceType = giftSource;
receive.roomSendGiftType = roomSendType;
[self.getView sendGiftSuccess:receive originDic:data.data];
}
} targetUids:targetUids giftNum:giftNum sendType:giftSendTypeStr giftId:giftId giftSource:giftSourceStr giftType:giftTypeStr roomUid:roomUid msg:msg uid:uid];
}

View File

@@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
///获取背包礼物列表
- (void)getPacketGiftListSuccess:(NSArray<GiftInfoModel *> *)giftList;
- (void)sendGiftSuccess:(GiftReceiveInfoModel *)receiveInfo;;
- (void)sendGiftSuccess:(GiftReceiveInfoModel *)receiveInfo originDic:(NSDictionary *)originDic;
@end
NS_ASSUME_NONNULL_END

View File

@@ -52,8 +52,7 @@
- (void)initSubViewConstraints {
[self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.top.mas_equalTo(self.contentView);
make.height.mas_equalTo(28);
make.width.mas_equalTo(28);
make.width.height.mas_equalTo(38);
}];
[self.positionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
@@ -92,7 +91,7 @@
if (!_avatarImageView) {
_avatarImageView = [[NetImageView alloc] init];
_avatarImageView.layer.masksToBounds = YES;
_avatarImageView.layer.cornerRadius = 28/2;
_avatarImageView.layer.cornerRadius = 38/2;
_avatarImageView.imageType = ImageTypeUserIcon;
_avatarImageView.image = [UIImageConstant defaultAvatarPlaceholder];
}
@@ -117,7 +116,7 @@
_coverView = [[UIView alloc] init];
_coverView.backgroundColor = [ThemeColor avatarCoverColor];
_coverView.layer.masksToBounds = YES;
_coverView.layer.cornerRadius = 35/2;
_coverView.layer.cornerRadius = 43/2;
}
return _coverView;
}

View File

@@ -295,7 +295,7 @@
_rechargeStackView.axis = UILayoutConstraintAxisHorizontal;
_rechargeStackView.distribution = UIStackViewDistributionFill;
_rechargeStackView.alignment = UIStackViewAlignmentCenter;
_rechargeStackView.spacing = 5;
_rechargeStackView.spacing = 1;
}
return _rechargeStackView;
}

View File

@@ -15,7 +15,7 @@ NS_ASSUME_NONNULL_BEGIN
///选中的人 送给谁礼物
@property (nonatomic,strong, readonly) NSMutableArray<NSString *> *selectUserArray;
///是不是选择了全部麦上的人
@property (nonatomic,assign) BOOL isSelectAll;
@property (nonatomic,assign, readonly) BOOL isSelectAll;
///麦序变化 赋值使用
- (void)microQueueUpdate:(NSArray<MicroQueueModel *> *)queue;
@end

View File

@@ -29,6 +29,8 @@
@property (nonatomic,strong) NSArray<XPGiftMicroUserModel *> *userArray;
///
@property (nonatomic,strong) NSMutableArray<NSString *> *selectUserArray;
///
@property (nonatomic,assign) BOOL isSelectAll;
@end
@implementation XPGiftUsersView
@@ -44,7 +46,15 @@
- (void)allMicroButtonAction:(UIButton *)sender {
sender.selected = !sender.selected;
[self.userArray enumerateObjectsUsingBlock:^(XPGiftMicroUserModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
obj.isSelect = YES;
obj.isSelect = sender.selected;
NSString * selectUid = [NSString stringWithFormat:@"%ld", obj.microQueue.userInfo.uid];
if (obj.isSelect) {
[self.selectUserArray addObject:selectUid];
} else {
if ([self.selectUserArray containsObject:selectUid]) {
[self.selectUserArray removeObject:selectUid];
}
}
}];
self.isSelectAll = sender.selected;
[self.collectionView reloadData];
@@ -63,7 +73,7 @@
- (void)initSubViewConstraints {
[self mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(28 + 15 * 2);
make.height.mas_equalTo(43 + 15 * 2);
}];
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
@@ -72,7 +82,7 @@
}];
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(35);
make.height.mas_equalTo(43);
}];
}
@@ -115,6 +125,11 @@
XPGiftUserCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XPGiftUserCollectionViewCell class]) forIndexPath:indexPath];
XPGiftMicroUserModel * queue = [self.userArray objectAtIndex:indexPath.row];
cell.microModel = queue;
if (indexPath.row == 0) {
cell.backgroundColor = [UIColor redColor];
} else {
cell.backgroundColor = [UIColor yellowColor];
}
return cell;
}
@@ -133,8 +148,10 @@
}
if (self.selectUserArray.count == self.userArray.count) {
self.allMicroButton.selected = YES;
self.isSelectAll = YES;
} else {
self.allMicroButton.selected = NO;
self.isSelectAll = NO;
}
}
#pragma mark - Getters And Setters
@@ -162,8 +179,8 @@
- (UICollectionView *)collectionView{
if (!_collectionView) {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.itemSize = CGSizeMake(35, 35);
layout.minimumLineSpacing = 6;
layout.itemSize = CGSizeMake(43, 43);
layout.minimumLineSpacing = 1;
layout.sectionInset = UIEdgeInsetsMake(0, 0, 0,0);
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
_collectionView.dataSource = self;

View File

@@ -8,16 +8,20 @@
#import "XPSendGiftView.h"
///Third
#import <Masonry/Masonry.h>
#import <NIMSDK/NIMSDK.h>
///Tool
#import "XPMacro.h"
#import "XPGiftPresenter.h"
#import "TTPopup.h"
#import "ThemeColor+SendGift.h"
#import "XCHUDTool.h"
#import "IMMessageHelper.h"
///Model
#import "GiftInfoModel.h"
#import "XPGiftCountModel.h"
#import "GiftReceiveInfoModel.h"
#import "AttachmentModel.h"
#import "RoomInfoModel.h"
///View
#import "XPGiftUsersView.h"
#import "XPGiftInfoView.h"
@@ -91,6 +95,98 @@
[self.giftPresenter getPackGiftList];
}
#pragma mark - Send Custom Message
- (void)sendCustomMessage:(GiftReceiveInfoModel *)receiveModel oringinDic:(NSDictionary *)originDic {
AttachmentModel *attachement = [[AttachmentModel alloc] init];
NSDictionary * dict = originDic;
NSString *sessionID = [NSString stringWithFormat:@"%ld", [self.delegate getRoomInfo].roomId];
if (receiveModel.roomSendGiftType == RoomSendGiftType_AllMic) { //
NSMutableDictionary *data = [NSMutableDictionary dictionary];
[data addEntriesFromDictionary:dict];
if (receiveModel.gift.giftType == GiftType_Lucky) { //
attachement.first = CustomMessageType_ALLMicroSend;
attachement.second = Custom_Message_Sub_AllMicroLuckySend;
NSArray *luckyBagGifts = (NSArray *)[data objectForKey:@"luckyBagGifts"];
if (luckyBagGifts.count >0) {
[luckyBagGifts enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
[data setObject:idx == 0 ? @(YES):@(NO) forKey:@"isShowAnimation"];
[data setObject:obj forKey:@"luckyGiftList"];
[data setObject:receiveModel.gift.giftName forKey:@"giftName"];
[data setObject:[obj valueForKeyPath:@"user.uid"] forKey:@"targetUid"];
[data setObject:[dict valueForKeyPath:@"targetUsers.uid"] forKey:@"targetUids"];
[data removeObjectForKey:@"luckyBagGifts"];
[data removeObjectForKey:@"targetUsers"];
attachement.data = data;
[IMMessageHelper sendCustomMessage:attachement sessionId:sessionID type:NIMSessionTypeChatroom];
}];
}
}else { //
attachement.first = CustomMessageType_ALLMicroSend;
attachement.second = Custom_Message_Sub_AllMicroSend;
[data setObject:[dict valueForKeyPath:@"targetUsers.uid"] forKey:@"targetUids"];
attachement.data = data;
[IMMessageHelper sendCustomMessage:attachement sessionId:sessionID type:NIMSessionTypeChatroom];
}
} else if (receiveModel.roomSendGiftType == RoomSendGiftType_MutableOnMic) { //
NSMutableDictionary *data = [NSMutableDictionary dictionary];
[data addEntriesFromDictionary:dict];
if (receiveModel.gift.giftType == GiftType_Lucky) { //
attachement.first = CustomMessageType_ALLMicroSend;
attachement.second = Custom_Message_Sub_AllBatchMicroLuckySend;
NSArray *luckyBagGifts = (NSArray *)[data objectForKey:@"luckyBagGifts"];
if (luckyBagGifts.count >0) {
//
[luckyBagGifts enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
[data setObject:idx == 0 ? @(YES):@(NO) forKey:@"isShowAnimation"];
[data setObject:obj forKey:@"luckyGiftList"];
[data setObject:receiveModel.gift.giftName forKey:@"giftName"];
[data setObject:[obj valueForKeyPath:@"user.uid"] forKey:@"targetUid"];
[data setObject:[dict valueForKeyPath:@"targetUsers.uid"] forKey:@"targetUids"];
[data removeObjectForKey:@"luckyBagGifts"];
[data removeObjectForKey:@"targetUsers"];
attachement.data = data;
[IMMessageHelper sendCustomMessage:attachement sessionId:sessionID type:NIMSessionTypeChatroom];
}];
}
}else { //
attachement.first = CustomMessageType_ALLMicroSend;
attachement.second = Custom_Message_Sub_AllBatchSend;
attachement.data = data;
[IMMessageHelper sendCustomMessage:attachement sessionId:sessionID type:NIMSessionTypeChatroom];
}
} else if (receiveModel.roomSendGiftType == RoomSendGiftType_ToOne) { //
NSMutableDictionary *data = [NSMutableDictionary dictionary];
[data addEntriesFromDictionary:dict];
if (receiveModel.gift.giftType == GiftType_Lucky) { //
attachement.first = CustomMessageType_Gift;
attachement.second = Custom_Message_Sub_Gift_LuckySend;
NSArray *luckyBagGifts = (NSArray *)[data objectForKey:@"luckyBagGifts"];
[luckyBagGifts enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
[data setObject:idx == 0 ? @(YES):@(NO) forKey:@"isShowAnimation"];
[data setObject:obj forKey:@"luckyGiftList"];
[data setObject:receiveModel.gift.giftName forKey:@"giftName"];
[data setObject:[obj valueForKeyPath:@"user.uid"] forKey:@"targetUid"];
[data setObject:[obj valueForKeyPath:@"user.nick"] forKey:@"targetNick"];
[data setObject:[dict valueForKeyPath:@"targetUsers.uid"] forKey:@"targetUids"];
[data removeObjectForKey:@"luckyBagGifts"];
[data removeObjectForKey:@"targetUsers"];
attachement.data = data;
[IMMessageHelper sendCustomMessage:attachement sessionId:sessionID type:NIMSessionTypeChatroom];
}];
}else { //
attachement.first = CustomMessageType_Gift;
attachement.second = Custom_Message_Sub_Gift_Send;
NSDictionary *targetUsers = ((NSArray *)[data objectForKey:@"targetUsers"]).firstObject;
[data setObject:[targetUsers valueForKeyPath:@"uid"] forKey:@"targetUid"];
[data setObject:[targetUsers valueForKeyPath:@"nick"] forKey:@"targetNick"];
[data setObject:[targetUsers valueForKeyPath:@"avatar"] forKey:@"targetAvatar"];
attachement.data = data;
[IMMessageHelper sendCustomMessage:attachement sessionId:sessionID type:NIMSessionTypeChatroom];
}
}
}
#pragma mark - Deal Send Gift Data
- (NSString *)dealSendGiftCount:(XPGiftCountModel *)model gift:(GiftInfoModel *)gift {
NSString * count = @"1";
@@ -207,13 +303,14 @@
self.giftInfoView.normalOriginArray = giftList;
}
- (void)sendGiftSuccess:(GiftReceiveInfoModel *)receiveInfo {
- (void)sendGiftSuccess:(GiftReceiveInfoModel *)receiveInfo originDic:(NSDictionary *)originDic {
if (receiveInfo.sourceType == GiftSourceType_Pack) {
///
[self.giftInfoView updatePackSource:receiveInfo];
} else {
[self.giftPresenter getUserWallInfo];
}
[self sendCustomMessage:receiveInfo oringinDic:originDic];
}
#pragma mark - Getters And Setters

View File

@@ -0,0 +1,38 @@
//
// AttachmentModel.h
// xplan-ios
//
// Created by 冯硕 on 2021/11/16.
//
#import <Foundation/Foundation.h>
#import <NIMSDK/NIMSDK.h>
NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(NSUInteger, CustomMessageType) {
CustomMessageType_Gift = 3,///送礼物的接口
CustomMessageType_ALLMicroSend = 12, //全麦送
};
typedef NS_ENUM(NSUInteger, CustomMessageSubGift) {
Custom_Message_Sub_Gift_Send = 31,//发送礼物
Custom_Message_Sub_Gift_ChannelNotify = 32,//全服发送礼物
Custom_Message_Sub_Gift_LuckySend = 34,//发送 福袋 礼物
};
typedef NS_ENUM(NSUInteger, CustomMessageSubAllMicroSend) {
Custom_Message_Sub_AllMicroSend = 121, //全麦送礼物
Custom_Message_Sub_AllMicroLuckySend = 125, //全麦送 福袋 礼物 122老版本占用了
Custom_Message_Sub_AllBatchSend = 123, // 非全麦 多人送礼
Custom_Message_Sub_AllBatchMicroLuckySend = 124, // 非全麦 多人送福袋礼物
};
@interface AttachmentModel : NSObject<NIMCustomAttachment>
@property (nonatomic,assign) int first;
@property (nonatomic,assign) int second;
@property (nonatomic, strong) id data;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,16 @@
//
// AttachmentModel.m
// xplan-ios
//
// Created by on 2021/11/16.
//
#import "AttachmentModel.h"
#import "NSObject+MJExtension.h"
@implementation AttachmentModel
- (NSString *)encodeAttachment {
return [self toJSONString];
}
@end

View File

@@ -0,0 +1,16 @@
//
// CustomAttachmentDecoder.h
// xplan-ios
//
// Created by 冯硕 on 2021/11/16.
//
#import <Foundation/Foundation.h>
#import <NIMSDK/NIMSDK.h>
NS_ASSUME_NONNULL_BEGIN
@interface CustomAttachmentDecoder : NSObject<NIMCustomAttachmentCoding>
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,39 @@
//
// CustomAttachmentDecoder.m
// xplan-ios
//
// Created by on 2021/11/16.
//
#import "CustomAttachmentDecoder.h"
#import "NSObject+MJExtension.h"
#import "AttachmentModel.h"
@implementation CustomAttachmentDecoder
- (id<NIMCustomAttachment>)decodeAttachment:(NSString *)content{
id<NIMCustomAttachment> attachment;
NSData *data = [content dataUsingEncoding:NSUTF8StringEncoding];
if (data) {
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
if ([dict isKindOfClass:[NSDictionary class]]) {
int first = [dict[@"first"] intValue];
int second = [dict[@"second"] intValue];
NSDictionary *data = dict[@"data"];
if ([data isKindOfClass:[NSString class]]) {
data = [(NSString *)data model2dictionary];
}
if ([data isKindOfClass:[NSDictionary class]]) {
AttachmentModel *attachment = [[AttachmentModel alloc]init];
attachment.first = (short)first;
attachment.second = (short)second;
attachment.data = data;
return attachment;
}
}
}
return attachment;
}
@end

View File

@@ -0,0 +1,28 @@
//
// IMMessageHelper.h
// xplan-ios
//
// Created by 冯硕 on 2021/11/16.
//
#import <Foundation/Foundation.h>
#import <NIMSDK/NIMSDK.h>
#import "AttachmentModel.h"
NS_ASSUME_NONNULL_BEGIN
///发送消息的工具类
@interface IMMessageHelper : NSObject
/// 发送自定义消息
/// @param attachment 自定消息的内容
/// @param sessionId 回话ID
/// @param type 回话的类型
+ (void)sendCustomMessage:(AttachmentModel *)attachment
sessionId:(NSString *)sessionId
type:(NIMSessionType)type;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,36 @@
//
// IMMessageHelper.m
// xplan-ios
//
// Created by on 2021/11/16.
//
#import "IMMessageHelper.h"
@implementation IMMessageHelper
///
/// @param attachment
/// @param sessionId ID
/// @param type
+ (void)sendCustomMessage:(AttachmentModel *)attachment
sessionId:(NSString *)sessionId
type:(NIMSessionType)type {
NIMMessage *message = [[NIMMessage alloc]init];
NIMCustomObject *object = [[NIMCustomObject alloc] init];
object.attachment = attachment;
message.messageObject = object;
//yidun
NIMAntiSpamOption *option = [NIMAntiSpamOption new];
option.yidunEnabled =NO;
message.antiSpamOption = option;
NIMMessageSetting *setting = [[NIMMessageSetting alloc]init];
setting.apnsEnabled = NO;
message.setting = setting;
//
NIMSession *session = [NIMSession session:sessionId type:type];
[[NIMSDK sharedSDK].chatManager sendMessage:message toSession:session error:nil];
}
@end