Skip to content

Instantly share code, notes, and snippets.

@Sunilkumarr
Last active May 18, 2021 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sunilkumarr/347ba5b7676433660785cc71fd0ae046 to your computer and use it in GitHub Desktop.
Save Sunilkumarr/347ba5b7676433660785cc71fd0ae046 to your computer and use it in GitHub Desktop.
Recent chat message or latest message details for group or one to one
ALChannelService * channelService = [[ALChannelService alloc] init
];
ALContactDBService * contactDBService = [[ALContactDBService alloc] init];
[applozicClient getLatestMessages:NO withCompletionHandler:^(NSMutableArray *messageList, NSError *error) {
if(!error){
for (ALMessage *message in messageList) {
/// Message text
NSLog(@"Recent message text %@", message.message);
/// Group chat then will go in if else its an one to one chat message then will go in else part
if (message.groupId != nil) {
//Its a channel/group chat message
/// Get the channel
ALChannel *channel = [channelService getChannelByKey:message.groupId];
// Unread count of channel you can get from channel as channel.unreadCount
NSLog(@"Unread count of channel is: %@",channel.unreadCount);
// User count in channel or group
NSLog(@"User or member count in a channel is: %@",channel.userCount);
// Group id of channel
NSLog(@"User or member count in a channel is: %@",message.groupId);
// Group profile icon
NSLog(@"Channel image url is: %@",channel.channelImageURL);
// Group name
NSLog(@"Channel name is: %@",channel.name);
} else {
// one to one chat
// message.to;
ALContact *alContact = [contactDBService loadContactByKey:@"userId" value: message.to];
// User name
NSLog(@"User name in one to one chat %@",[alContact getDisplayName]);
// User profile image icon link
NSLog(@"user image url is: %@", alContact.contactImageUrl);
}
}
}
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment