TIMMessage.h 13.9 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693
//
//  TIMMessage.h
//  ImSDK
//
//  Created by bodeng on 28/1/15.
//  Copyright (c) 2015 tencent. All rights reserved.
//

#ifndef ImSDK_TIMMessage_h
#define ImSDK_TIMMessage_h


#import <Foundation/Foundation.h>

#import "TIMComm.h"
#import "TIMCallback.h"

@class TIMUserProfile;
@class TIMGroupMemberInfo;
@class TIMConversation;

/**
 *  消息Elem基类
 */
@interface TIMElem : NSObject
@end

/**
 *  文本消息Elem
 */
@interface TIMTextElem : TIMElem
/**
 *  消息文本
 */
@property(nonatomic,strong) NSString * text;
@end

#pragma mark - 普通消息类型

@interface TIMImage : NSObject
/**
 *  图片ID,内部标识,可用于外部缓存key
 */
@property(nonatomic,strong) NSString * uuid;
/**
 *  图片类型
 */
@property(nonatomic,assign) TIM_IMAGE_TYPE type;
/**
 *  图片大小
 */
@property(nonatomic,assign) int size;
/**
 *  图片宽度
 */
@property(nonatomic,assign) int width;
/**
 *  图片高度
 */
@property(nonatomic,assign) int height;
/**
 *  下载URL
 */
@property(nonatomic, strong) NSString * url;

/**
 *  获取图片
 *
 *  @param path 图片保存路径
 *  @param succ 成功回调,返回图片数据
 *  @param fail 失败回调,返回错误码和错误描述
 */
- (void)getImage:(NSString*)path succ:(TIMSucc)succ fail:(TIMFail)fail;
- (void)getImage:(NSString*)path progress:(TIMProgress)progress succ:(TIMSucc)succ fail:(TIMFail)fail;

@end


/**
 *  图片消息Elem
 */
@interface TIMImageElem : TIMElem

/**
 *  要发送的图片路径
 */
@property(nonatomic,strong) NSString * path;

/**
 *  所有类型图片,只读
 */
@property(nonatomic,strong) NSArray * imageList;

/**
 * 上传时任务Id,可用来查询上传进度
 */
@property(nonatomic,assign) uint32_t taskId;

/**
 *  图片压缩等级,详见 TIM_IMAGE_COMPRESS_TYPE(仅对jpg格式有效)
 */
@property(nonatomic,assign) TIM_IMAGE_COMPRESS_TYPE level;

/**
 *  图片格式,详见 TIM_IMAGE_FORMAT
 */
@property(nonatomic,assign) TIM_IMAGE_FORMAT format;

@end

/**
 *  文件消息Elem
 */
@interface TIMFileElem : TIMElem
/**
 *  上传时任务Id,可用来查询上传进度
 */
@property(nonatomic,assign) uint32_t taskId;
/**
 *  上传时,文件的路径(设置path时,优先上传文件)
 */
@property(nonatomic,strong) NSString * path;
/**
 *  文件内部ID
 */
@property(nonatomic,strong) NSString * uuid;
/**
 *  文件大小
 */
@property(nonatomic,assign) int fileSize;
/**
 *  文件显示名,发消息时设置
 */
@property(nonatomic,strong) NSString * filename;

/**
 *  获取文件数据到指定路径的文件中
 *
 *  @param path 文件保存路径
 *  @param succ 成功回调,返回数据
 *  @param fail 失败回调,返回错误码和错误描述
 */
- (void)getFile:(NSString*)path succ:(TIMSucc)succ fail:(TIMFail)fail;
- (void)getFile:(NSString*)path progress:(TIMProgress)progress succ:(TIMSucc)succ fail:(TIMFail)fail;

@end

/**
 *  语音消息Elem
 */
@interface TIMSoundElem : TIMElem
/**
 *  上传时任务Id,可用来查询上传进度
 */
@property(nonatomic,assign) uint32_t taskId;
/**
 *  上传时,语音文件的路径,接收时使用getSound获得数据
 */
@property(nonatomic,strong) NSString * path;
/**
 *  语音消息内部ID
 */
@property(nonatomic,strong) NSString * uuid;
/**
 *  语音数据大小
 */
@property(nonatomic,assign) int dataSize;
/**
 *  语音长度(秒),发送消息时设置
 */
@property(nonatomic,assign) int second;

/**
 *  获取语音数据到指定路径的文件中
 *
 *  @param path 语音保存路径
 *  @param succ 成功回调
 *  @param fail 失败回调,返回错误码和错误描述
 */
- (void)getSound:(NSString*)path succ:(TIMSucc)succ fail:(TIMFail)fail;
- (void)getSound:(NSString*)path progress:(TIMProgress)progress succ:(TIMSucc)succ fail:(TIMFail)fail;

@end

/**
 *  地理位置Elem
 */
@interface TIMLocationElem : TIMElem
/**
 *  地理位置描述信息,发送消息时设置
 */
@property(nonatomic,strong) NSString * desc;
/**
 *  纬度,发送消息时设置
 */
@property(nonatomic,assign) double latitude;
/**
 *  经度,发送消息时设置
 */
@property(nonatomic,assign) double longitude;
@end


/**
 *  自定义消息类型
 */
@interface TIMCustomElem : TIMElem

/**
 *  自定义消息二进制数据
 */
@property(nonatomic,strong) NSData * data;
/**
 *  自定义消息描述信息,做离线Push时文本展示(已废弃,请使用TIMMessage中offlinePushInfo进行配置)
 */
@property(nonatomic,strong) NSString * desc DEPRECATED_ATTRIBUTE;
/**
 *  离线Push时扩展字段信息(已废弃,请使用TIMMessage中offlinePushInfo进行配置)
 */
@property(nonatomic,strong) NSString * ext DEPRECATED_ATTRIBUTE;
/**
 *  离线Push时声音字段信息(已废弃,请使用TIMMessage中offlinePushInfo进行配置)
 */
@property(nonatomic,strong) NSString * sound DEPRECATED_ATTRIBUTE;
@end

/**
 *  表情消息类型
 */
@interface TIMFaceElem : TIMElem

/**
 *  表情索引,用户自定义
 */
@property(nonatomic, assign) int index;
/**
 *  额外数据,用户自定义
 */
@property(nonatomic,strong) NSData * data;

@end

@interface TIMVideo : NSObject
/**
 *  视频ID,不用设置
 */
@property(nonatomic,strong) NSString * uuid;
/**
 *  视频文件类型,发送消息时设置
 */
@property(nonatomic,strong) NSString * type;
/**
 *  视频大小,不用设置
 */
@property(nonatomic,assign) int size;
/**
 *  视频时长,发送消息时设置
 */
@property(nonatomic,assign) int duration;

/**
 *  获取视频
 *
 *  @param path 视频保存路径
 *  @param succ 成功回调
 *  @param fail 失败回调,返回错误码和错误描述
 */
- (void)getVideo:(NSString*)path succ:(TIMSucc)succ fail:(TIMFail)fail;
- (void)getVideo:(NSString*)path progress:(TIMProgress)progress succ:(TIMSucc)succ fail:(TIMFail)fail;
@end


@interface TIMSnapshot : NSObject
/**
 *  图片ID,不用设置
 */
@property(nonatomic,strong) NSString * uuid;
/**
 *  截图文件类型,发送消息时设置
 */
@property(nonatomic,strong) NSString * type;
/**
 *  图片大小,不用设置
 */
@property(nonatomic,assign) int size;
/**
 *  图片宽度,发送消息时设置
 */
@property(nonatomic,assign) int width;
/**
 *  图片高度,发送消息时设置
 */
@property(nonatomic,assign) int height;

/**
 *  获取图片
 *
 *  @param path 图片保存路径
 *  @param succ 成功回调,返回图片数据
 *  @param fail 失败回调,返回错误码和错误描述
 */
- (void)getImage:(NSString*)path succ:(TIMSucc)succ fail:(TIMFail)fail;
- (void)getImage:(NSString*)path progress:(TIMProgress)progress succ:(TIMSucc)succ fail:(TIMFail)fail;

@end

/**
 *  微视频消息
 */
@interface TIMVideoElem : TIMElem

/**
 *  上传时任务Id,可用来查询上传进度
 */
@property(nonatomic,assign) uint32_t taskId;

/**
 *  视频文件路径,发送消息时设置
 */
@property(nonatomic,strong) NSString * videoPath;

/**
 *  视频信息,发送消息时设置
 */
@property(nonatomic,strong) TIMVideo * video;

/**
 *  截图文件路径,发送消息时设置
 */
@property(nonatomic,strong) NSString * snapshotPath;

/**
 *  视频截图,发送消息时设置
 */
@property(nonatomic,strong) TIMSnapshot * snapshot;

@end

#pragma mark - 群系统消息和tip消息

/**
 *  群tips,成员变更信息
 */
@interface TIMGroupTipsElemMemberInfo : NSObject

/**
 *  变更用户
 */
@property(nonatomic,strong) NSString * identifier;
/**
 *  禁言时间(秒,表示还剩多少秒可以发言)
 */
@property(nonatomic,assign) uint32_t shutupTime;

@end

/**
 *  群tips,群变更信息
 */
@interface TIMGroupTipsElemGroupInfo : NSObject

/**
 *  变更类型
 */
@property(nonatomic, assign) TIM_GROUP_INFO_CHANGE_TYPE type;

/**
 *  根据变更类型表示不同含义
 */
@property(nonatomic,strong) NSString * value;
@end

/**
 *  群Tips
 */
@interface TIMGroupTipsElem : TIMElem

/**
 *  群组Id
 */
@property(nonatomic,strong) NSString * group;

/**
 *  群Tips类型
 */
@property(nonatomic,assign) TIM_GROUP_TIPS_TYPE type;

/**
 *  操作人用户名
 */
@property(nonatomic,strong) NSString * opUser;

/**
 *  被操作人列表 NSString* 数组
 */
@property(nonatomic,strong) NSArray * userList;

/**
 *  在群名变更时表示变更后的群名,否则为 nil
 */
@property(nonatomic,strong) NSString * groupName;

/**
 *  群信息变更: TIM_GROUP_TIPS_TYPE_INFO_CHANGE 时有效,为 TIMGroupTipsElemGroupInfo 结构体列表
 */
@property(nonatomic,strong) NSArray * groupChangeList;

/**
 *  成员变更: TIM_GROUP_TIPS_TYPE_MEMBER_INFO_CHANGE 时有效,为 TIMGroupTipsElemMemberInfo 结构体列表
 */
@property(nonatomic,strong) NSArray * memberChangeList;

/**
 *  操作者用户资料
 */
@property(nonatomic,strong) TIMUserProfile * opUserInfo;
/**
 *  操作者群成员资料
 */
@property(nonatomic,strong) TIMGroupMemberInfo * opGroupMemberInfo;
/**
 *  变更成员资料
 */
@property(nonatomic,strong) NSDictionary * changedUserInfo;
/**
 *  变更成员群内资料
 */
@property(nonatomic,strong) NSDictionary * changedGroupMemberInfo;

/**
 *  当前群人数: TIM_GROUP_TIPS_TYPE_INVITE、TIM_GROUP_TIPS_TYPE_QUIT_GRP、
 *             TIM_GROUP_TIPS_TYPE_KICKED时有效
 */
@property(nonatomic,assign) uint32_t memberNum;


/**
 *  操作方平台信息
 *  取值: iOS Android Windows Mac Web RESTAPI Unknown
 */
@property(nonatomic,strong) NSString * platform;

@end


/**
 *  群系统消息
 */
@interface TIMGroupSystemElem : TIMElem

/**
 * 操作类型
 */
@property(nonatomic,assign) TIM_GROUP_SYSTEM_TYPE type;

/**
 * 群组Id
 */
@property(nonatomic,strong) NSString * group;

/**
 * 操作人
 */
@property(nonatomic,strong) NSString * user;

/**
 * 操作理由
 */
@property(nonatomic,strong) NSString * msg;


/**
 *  消息标识,客户端无需关心
 */
@property(nonatomic,assign) uint64_t msgKey;

/**
 *  消息标识,客户端无需关心
 */
@property(nonatomic,strong) NSData * authKey;

/**
 *  用户自定义透传消息体(type=TIM_GROUP_SYSTEM_CUSTOM_INFO时有效)
 */
@property(nonatomic,strong) NSData * userData;

/**
 *  操作人资料
 */
@property(nonatomic,strong) TIMUserProfile * opUserInfo;

/**
 *  操作人群成员资料
 */
@property(nonatomic,strong) TIMGroupMemberInfo * opGroupMemberInfo;

/**
 *  操作方平台信息
 *  取值: iOS Android Windows Mac Web RESTAPI Unknown
 */
@property(nonatomic,strong) NSString * platform;

@end

#pragma mark - 消息体TIMMessage

/**
 填入sound字段表示接收时不会播放声音
 */
extern NSString * const kIOSOfflinePushNoSound;

@interface TIMOfflinePushInfo : NSObject
/**
 *  自定义消息描述信息,做离线Push时文本展示
 */
@property(nonatomic,strong) NSString * desc;
/**
 *  离线Push时扩展字段信息
 */
@property(nonatomic,strong) NSString * ext;
/**
 *  推送规则标志
 */
@property(nonatomic,assign) TIMOfflinePushFlag pushFlag;
/**
 *  iOS离线推送配置
 */
@property(nonatomic,strong) TIMIOSOfflinePushConfig * iosConfig;
/**
 *  Android离线推送配置
 */
@property(nonatomic,strong) TIMAndroidOfflinePushConfig * androidConfig;
@end


/**
 *  消息
 */
@interface TIMMessage : NSObject

/**
 *  增加Elem
 *
 *  @param elem elem结构
 *
 *  @return 0       表示成功
 *          1       禁止添加Elem(文件或语音多于两个Elem)
 *          2       未知Elem
 */
- (int)addElem:(TIMElem*)elem;

/**
 *  获取对应索引的Elem
 *
 *  @param index 对应索引
 *
 *  @return 返回对应Elem
 */
- (TIMElem*)getElem:(int)index;

/**
 *  获取Elem数量
 *
 *  @return elem数量
 */
- (int)elemCount;

/**
 *  设置离线推送配置信息
 *
 *  @param info 配置信息
 *
 *  @return 0 成功
 */
- (int)setOfflinePushInfo:(TIMOfflinePushInfo*)info;

/**
 *  获得本消息离线推送配置信息
 *
 *  @return 配置信息,没设置返回nil
 */
- (TIMOfflinePushInfo*)getOfflinePushInfo;

/**
 *  设置业务命令字
 *
 *  @param buzCmds 业务命令字列表
 *                 @"im_open_busi_cmd.msg_robot" 表示发送给IM机器人
 *                 @"im_open_busi_cmd.msg_nodb" 表示不存离线
 *                 @"im_open_busi_cmd.msg_noramble" 表示不存漫游
 *                 @"im_open_busi_cmd.msg_nopush" 表示不实时下发给用户
 *
 *  @return 0 成功
 */
-(int) setBusinessCmd:(NSArray*)buzCmds;

/**
 *  获取会话
 *
 *  @return 该消息所对应会话
 */
- (TIMConversation*)getConversation;

/**
 *  消息状态
 *
 *  @return TIMMessageStatus 消息状态
 */
- (TIMMessageStatus)status;

/**
 *  是否发送方
 *
 *  @return TRUE 表示是发送消息    FALSE 表示是接收消息
 */
- (BOOL)isSelf;

/**
 *  获取发送方
 *
 *  @return 发送方标识
 */
- (NSString*)sender;

/**
 *  消息Id
 */
- (NSString*)msgId;

/**
 *  获取消息uniqueId
 *
 *  @return uniqueId
 */
- (uint64_t)uniqueId;

/**
 *  当前消息的时间戳
 *
 *  @return 时间戳
 */
- (NSDate*)timestamp;


/**
 *  获取发送者资料(发送者为自己时可能为空)
 *
 *  @return 发送者资料,nil 表示没有获取资料,目前只有字段:identifier、nickname、faceURL、customInfo
 */
- (TIMUserProfile*)getSenderProfile;

/**
 *  获取发送者群内资料(发送者为自己时可能为空)
 *
 *  @return 发送者群内资料,nil 表示没有获取资料或者不是群消息,目前只有字段:member、nameCard、role、customInfo
 */
- (TIMGroupMemberInfo*)getSenderGroupMemberProfile;

/**
 *  设置消息的优先级
 *
 *  @param priority 优先级
 *
 *  @return TRUE 设置成功
 */
- (BOOL)setPriority:(TIMMessagePriority)priority;

/**
 *  获取消息的优先级
 *
 *  @return 优先级
 */
- (TIMMessagePriority)getPriority;

/**
 *  获取消息所属会话的接收消息选项(仅对群组消息有效)
 *
 *  @return 接收消息选项
 */
- (TIMGroupReceiveMessageOpt)getRecvOpt;

/**
 *  拷贝消息中的属性(ELem、priority、online、offlinePushInfo)
 *
 *  @param srcMsg 源消息
 *
 *  @return 0 成功
 */
- (int)copyFrom:(TIMMessage*)srcMsg;

@end

#endif