Skip to main content

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.

Objective C
#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:

PropertyTypeDescription
userIdNSString *User ID.
nameNSString *Display name.
avatarUrlNSString *Avatar URL.
aliasNSString *Alias or remark.
extraNSString *Extra profile data.
profileNCUserProfile *Managed user profile object.
friendInfoNCFriendInfo *Managed friend info object.
memberInfoNCGroupMemberInfo *Managed group member info object.

NCChatUIGroup contains the group fields that Chat UI can display or cache:

PropertyTypeDescription
groupIdNSString *Group ID.
groupNameNSString *Group display name.
avatarUrlNSString *Group avatar URL.
extraNSString *Extra group data.
noticeNSString *Group notice.
groupInfoNCGroupInfo *Managed group info object.

Profile caching strategies

Enable local persistent caching

Objective C
[NCChatUI shared].enablePersistentUserInfoCache = YES;

Attach current user profile to message body

Objective C
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.

Objective C
[NCChatUI shared].currentDataSourceType = NCDataSourceTypeInfoProvider;

Set up profile data sources

Chat UI currently exposes four profile-related protocols:

  • NCChatUIUserInfoDataSource
  • NCChatUIGroupInfoDataSource
  • NCChatUIGroupUserInfoDataSource
  • NCChatUIGroupMemberDataSource
Objective C
@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

Objective C
- (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

Objective C
- (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

Objective C
- (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

Objective C
- (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

Objective C
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

Objective C
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

Objective C
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];