// // NIMMessageMaker.m // YUMI // // Created by zu on 2021/11/28. // #import "NIMMessageMaker.h" #import "YUMIConstant.h" @implementation NIMMessageMaker + (NIMMessage*)msgWithText:(NSString*)text { NIMMessage *textMessage = [[NIMMessage alloc] init]; textMessage.text = text; [self setupMessage:textMessage]; return textMessage; } + (NIMMessage*)msgWithAudio:(NSString*)filePath { NIMAudioObject *audioObject = [[NIMAudioObject alloc] initWithSourcePath:filePath scene:NIMNOSSceneTypeMessage]; NIMMessage *message = [[NIMMessage alloc] init]; message.messageObject = audioObject; message.text = YMLocalizedString(@"NIMMessageMaker0"); [self setupMessage:message]; return message; } + (NIMMessage*)msgWithVideo:(NSString*)filePath { NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"]; NSString *dateString = [dateFormatter stringFromDate:[NSDate date]]; NIMVideoObject *videoObject = [[NIMVideoObject alloc] initWithSourcePath:filePath scene:NIMNOSSceneTypeMessage]; videoObject.displayName = [NSString stringWithFormat:@"%@%@", YMLocalizedString(@"NIMMessageMaker1"),dateString]; NIMMessage *message = [[NIMMessage alloc] init]; message.messageObject = videoObject; message.apnsContent = YMLocalizedString(@"NIMMessageMaker2"); [self setupMessage:message]; return message; } + (NIMMessage*)msgWithImage:(UIImage*)image { NIMImageObject *imageObject = [[NIMImageObject alloc] initWithImage:image scene:NIMNOSSceneTypeMessage]; NIMImageOption *option = [[NIMImageOption alloc] init]; option.compressQuality = 0.7; imageObject.option = option; return [NIMMessageMaker generateImageMessage:imageObject]; } + (NIMMessage *)msgWithImagePath:(NSString*)path { NIMImageObject * imageObject = [[NIMImageObject alloc] initWithFilepath:path scene:NIMNOSSceneTypeMessage]; return [NIMMessageMaker generateImageMessage:imageObject]; } + (NIMMessage *)msgWithImageData:(NSData *)data extension:(NSString *)extension { NIMImageObject *imageObject = [[NIMImageObject alloc] initWithData:data extension:extension]; return [NIMMessageMaker generateImageMessage:imageObject]; } + (NIMMessage *)generateImageMessage:(NIMImageObject *)imageObject { NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"]; NSString *dateString = [dateFormatter stringFromDate:[NSDate date]]; imageObject.displayName = [NSString stringWithFormat:@"%@%@",YMLocalizedString(@"NIMMessageMaker3"), dateString]; NIMMessage *message = [[NIMMessage alloc] init]; message.messageObject = imageObject; message.apnsContent = YMLocalizedString(@"NIMMessageMaker4"); [self setupMessage:message]; return message; } + (void)setupMessage:(NIMMessage *)message { message.apnsPayload = @{ @"apns-collapse-id": message.messageId, }; NIMMessageSetting *setting = [[NIMMessageSetting alloc] init]; setting.scene = NIMNOSSceneTypeMessage; setting.apnsEnabled = YES; message.setting = setting; NIMAntiSpamOption *option = [NIMAntiSpamOption new]; option.yidunEnabled = YES; option.businessId = KeyWithType(keyType_YiDunBussinessId); message.antiSpamOption = option; } @end @implementation NIMCommentMaker + (NIMQuickComment *)commentWithType:(int64_t)type content:(NSString *)content ext:(NSString *)ext { NIMQuickComment *comment = [[NIMQuickComment alloc] init]; comment.ext = ext; NIMQuickCommentSetting *setting = [[NIMQuickCommentSetting alloc] init]; setting.needPush = YES; setting.needBadge = YES; setting.pushTitle = YMLocalizedString(@"NIMMessageMaker5"); setting.pushContent = content; setting.pushPayload = @{ @"key" : @"value" }; comment.setting = setting; comment.replyType = type; return comment; } @end