123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- //
- // NIMKit.m
- // NIMKit
- //
- // Created by amao on 8/14/15.
- // Copyright (c) 2015 NetEase. All rights reserved.
- //
- #import "NIMKit.h"
- #import "NIMKitTimerHolder.h"
- #import "NIMKitNotificationFirer.h"
- #import "NIMKitDataProviderImpl.h"
- #import "NIMCellLayoutConfig.h"
- #import "NIMKitInfoFetchOption.h"
- extern NSString *const NIMKitUserInfoHasUpdatedNotification;
- extern NSString *const NIMKitTeamInfoHasUpdatedNotification;
- @interface NIMKit(){
- NSRegularExpression *_urlRegex;
- }
- @property (nonatomic,strong) NIMKitNotificationFirer *firer;
- @property (nonatomic,strong) id<NIMCellLayoutConfig> layoutConfig;
- @end
- @implementation NIMKit
- - (instancetype)init
- {
- if (self = [super init]) {
- _resourceBundleName = @"NIMKitResource.bundle";
- _emoticonBundleName = @"NIMKitEmoticon.bundle";
-
- _firer = [[NIMKitNotificationFirer alloc] init];
- _provider = [[NIMKitDataProviderImpl alloc] init]; //默认使用 NIMKit 的实现
-
- _layoutConfig = [[NIMCellLayoutConfig alloc] init];
- _robotTemplateParser = [[NIMKitRobotDefaultTemplateParser alloc] init];
- }
- return self;
- }
- + (instancetype)sharedKit
- {
- static NIMKit *instance = nil;
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- instance = [[NIMKit alloc] init];
- });
- return instance;
- }
- - (void)registerLayoutConfig:(NIMCellLayoutConfig *)layoutConfig
- {
- if ([layoutConfig isKindOfClass:[NIMCellLayoutConfig class]])
- {
- self.layoutConfig = layoutConfig;
- }
- else
- {
- NSAssert(0, @"class should be subclass of NIMLayoutConfig");
- }
- }
- - (id<NIMCellLayoutConfig>)layoutConfig
- {
- return _layoutConfig;
- }
- - (NIMKitConfig *)config
- {
- //不要放在 NIMKit 初始化里面,因为 UIConfig 初始化会使用 NIMKit, 防止死循环
- if (!_config)
- {
- _config = [[NIMKitConfig alloc] init];
- }
- return _config;
- }
- - (void)notfiyUserInfoChanged:(NSArray *)userIds{
- if (!userIds.count) {
- return;
- }
- for (NSString *userId in userIds) {
- NIMSession *session = [NIMSession session:userId type:NIMSessionTypeP2P];
- NIMKitFirerInfo *info = [[NIMKitFirerInfo alloc] init];
- info.session = session;
- info.notificationName = NIMKitUserInfoHasUpdatedNotification;
- [self.firer addFireInfo:info];
- }
- }
- - (void)notifyTeamInfoChanged:(NSArray *)teamIds{
- if (teamIds.count)
- {
- for (NSString *teamId in teamIds)
- {
- [self notifyTeam:teamId];
- }
- }
- else
- {
- [self notifyTeam:nil];
- }
- }
- - (void)notifyTeamMemebersChanged:(NSArray *)teamIds
- {
- if (teamIds.count)
- {
- for (NSString *teamId in teamIds)
- {
- [self notifyTeamMemebers:teamId];
- }
- }
- else
- {
- [self notifyTeamMemebers:nil];
- }
- }
- - (void)notifyTeam:(NSString *)teamId
- {
- NIMKitFirerInfo *info = [[NIMKitFirerInfo alloc] init];
- if (teamId.length) {
- NIMSession *session = [NIMSession session:teamId type:NIMSessionTypeTeam];
- info.session = session;
- }
- info.notificationName = NIMKitTeamInfoHasUpdatedNotification;
- [self.firer addFireInfo:info];
- }
- - (void)notifyTeamMemebers:(NSString *)teamId
- {
- NIMKitFirerInfo *info = [[NIMKitFirerInfo alloc] init];
- if (teamId.length) {
- NIMSession *session = [NIMSession session:teamId type:NIMSessionTypeTeam];
- info.session = session;
- }
- extern NSString *NIMKitTeamMembersHasUpdatedNotification;
- info.notificationName = NIMKitTeamMembersHasUpdatedNotification;
- [self.firer addFireInfo:info];
- }
- - (NIMKitInfo *)infoByUser:(NSString *)userId option:(NIMKitInfoFetchOption *)option
- {
- NIMKitInfo *info = nil;
- if (self.provider && [self.provider respondsToSelector:@selector(infoByUser:option:)]) {
- info = [self.provider infoByUser:userId option:option];
- }
- return info;
- }
- - (NIMKitInfo *)infoByTeam:(NSString *)teamId option:(NIMKitInfoFetchOption *)option
- {
- NIMKitInfo *info = nil;
- if (self.provider && [self.provider respondsToSelector:@selector(infoByTeam:option:)]) {
- info = [self.provider infoByTeam:teamId option:option];
- }
- return info;
- }
- @end
|