User information
Chat UI does not maintain user, group, or group member information from your business side. The application layer must set the current logged-in user after establishing a connection and implement data sources for profile information to ensure proper display of nicknames, avatars, and group name cards in the channel list, chat page, group info page, and @mention selection page.
Current user
Set the current logged-in user through NCChatUI.shared().currentUserInfo in Swift or [NCChatUI shared].currentUserInfo in Objective-C. We recommend setting this after establishing a successful connection.
#import <NexconnChatSDK/NexconnChatSDK.h>
#import <NexconnChatUI/NexconnChatUI.h>
- (void)setupCurrentUser {
NCChatUIUserInfo *user = [[NCChatUIUserInfo alloc] init];
user.userId = @"user_001";
user.name = @"John";
user.avatarUrl = @"https://example.com/avatar/john.png";
[NCChatUI shared].currentUserInfo = user;
}
Data models
NCChatUIUserInfo contains the profile fields that Chat UI can display or cache:
| Property | Type | Description |
|---|---|---|
userId | NSString * | User ID. |
name | NSString * | Display name. |
avatarUrl | NSString * | Avatar URL. |
alias | NSString * | Alias or remark. |
extra | NSString * | Extra profile data. |
profile | NCUserProfile * | Managed user profile object. |
friendInfo | NCFriendInfo * | Managed friend info object. |
memberInfo | NCGroupMemberInfo * | Managed group member info object. |
NCChatUIGroup contains the group fields that Chat UI can display or cache:
| Property | Type | Description |
|---|---|---|
groupId | NSString * | Group ID. |
groupName | NSString * | Group display name. |
avatarUrl | NSString * | Group avatar URL. |
extra | NSString * | Extra group data. |
notice | NSString * | Group notice. |
groupInfo | NCGroupInfo * | Managed group info object. |
Profile caching strategies
Enable local persistent caching
[NCChatUI shared].enablePersistentUserInfoCache = YES;
Attach current user profile to message body
NCChatUIConfigCenter.message.enableMessageAttachUserInfo = YES;
Data source mode
currentDataSourceType defaults to NCDataSourceTypeInfoManagement, which uses the managed profile service. If your app provides user, group, and group member data through Chat UI data source protocols, set it to NCDataSourceTypeInfoProvider before profile data is loaded.
[NCChatUI shared].currentDataSourceType = NCDataSourceTypeInfoProvider;
Set up profile data sources
Chat UI currently exposes four profile-related protocols:
NCChatUIUserInfoDataSourceNCChatUIGroupInfoDataSourceNCChatUIGroupUserInfoDataSourceNCChatUIGroupMemberDataSource
@interface AppDelegate () <
NCChatUIUserInfoDataSource,
NCChatUIGroupInfoDataSource,
NCChatUIGroupUserInfoDataSource,
NCChatUIGroupMemberDataSource
>
@end
- (void)setupChatUIDataSources {
[NCChatUI shared].userInfoDataSource = self;
[NCChatUI shared].groupInfoDataSource = self;
[NCChatUI shared].groupUserInfoDataSource = self;
[NCChatUI shared].groupMemberDataSource = self;
}
User info provider
- (void)getUserInfoWithUserId:(NSString *)userId
completion:(void (^)(NCChatUIUserInfo * _Nullable userInfo))completion {
NCChatUIUserInfo *user = [[NCChatUIUserInfo alloc] init];
user.userId = userId;
user.name = [NSString stringWithFormat:@"User %@", userId];
user.avatarUrl = @"https://example.com/avatar/default.png";
completion(user);
}
Group info provider
- (void)getGroupInfoWithGroupId:(NSString *)groupId
completion:(void (^)(NCChatUIGroup * _Nullable groupInfo))completion {
NCChatUIGroup *group = [[NCChatUIGroup alloc] init];
group.groupId = groupId;
group.groupName = @"Product Group";
group.avatarUrl = @"https://example.com/group/default.png";
completion(group);
}
Group member profile provider
- (void)getUserInfoWithUserId:(NSString *)userId
inGroup:(NSString *)groupId
completion:(void (^)(NCChatUIUserInfo * _Nullable userInfo))completion {
NCChatUIUserInfo *user = [[NCChatUIUserInfo alloc] init];
user.userId = userId;
user.name = @"Group Nickname";
completion(user);
}
Group member list provider
- (void)getAllMembersOfGroup:(NSString *)groupId
result:(void (^)(NSArray<NSString *> * _Nullable userIdList))resultBlock {
resultBlock(@[@"user_001", @"user_002", @"user_003"]);
}
Active fetching, refreshing, and cache clearing
User information
NCChatUIUserInfo *cachedUser = [[NCChatUI shared] getUserInfoCache:@"user_001"];
[[NCChatUI shared] getUserInfo:@"user_001" complete:^(NCChatUIUserInfo *userInfo) {
}];
NCChatUIUserInfo *user = [[NCChatUIUserInfo alloc] init];
user.userId = @"user_001";
user.name = @"New Nickname";
[[NCChatUI shared] refreshUserInfoCache:user withUserId:user.userId];
[[NCChatUI shared] clearUserInfoCache];
Group information
NCChatUIGroup *group = [[NCChatUI shared] getGroupInfoCache:@"group_001"];
NCChatUIGroup *newGroup = [[NCChatUIGroup alloc] init];
newGroup.groupId = @"group_001";
newGroup.groupName = @"New Group Name";
[[NCChatUI shared] refreshGroupInfoCache:newGroup withGroupId:newGroup.groupId];
[[NCChatUI shared] clearGroupInfoCache];
Group member profile information
NCChatUIUserInfo *member = [[NCChatUI shared] getGroupUserInfoCache:@"user_001" withGroupId:@"group_001"];
NCChatUIUserInfo *updatedMember = [[NCChatUIUserInfo alloc] init];
updatedMember.userId = @"user_001";
updatedMember.name = @"New Group Nickname";
[[NCChatUI shared] refreshGroupUserInfoCache:updatedMember withUserId:updatedMember.userId withGroupId:@"group_001"];
[[NCChatUI shared] clearGroupUserInfoCache];