Implement Group Messaging
Group messaging is an extended concept of 1-on-1 messaging. It also comes with features for inviting users, a typing indicator and an unread message count.
Three or more users are required in order to start a group messaging. The sample project provides these feature for it in a Messaging Tab.
You can select users you want to invite in Messaging Tab > Invite > Select Channel > Select User.
Invite Users
Open `MessagingInviteSelectUserViewController.m
in Xcode to implement invitation.
The callback block is required to get the messaging channel after inviting users. The messagingStartedBlock:
will be invoked after the invitation. You should insert the lines of code to open MessagingViewController
here.
- (void)viewDidLoad {
// ...
[SendBird loginWithUserId:[SendBird deviceUniqueID] andUserName:[MyUtils getUserName] andUserImageUrl:[MyUtils getUserProfileImage] andAccessToken:@""];
memberListQuery = [SendBird queryMemberListInChannel:[selectedChannel url]];
[memberListQuery nextWithResultBlock:^(NSMutableArray *queryResult) {
for (SendBirdMember *user in queryResult) {
[userArray addObject:user];
}
[self.messagingInviteSelectUserTableView reloadData];
} endBlock:^(NSError *error) {
}];
[SendBird setEventHandlerConnectBlock:^(SendBirdChannel *channel) {
} errorBlock:^(NSInteger code) {
} channelLeftBlock:^(SendBirdChannel *channel) {
} messageReceivedBlock:^(SendBirdMessage *message) {
} systemMessageReceivedBlock:^(SendBirdSystemMessage *message) {
} broadcastMessageReceivedBlock:^(SendBirdBroadcastMessage *message) {
} fileReceivedBlock:^(SendBirdFileLink *fileLink) {
} messagingStartedBlock:^(SendBirdMessagingChannel *channel) {
UIStoryboard *storyboard = [self storyboard];
MessagingViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"MessagingViewController"];
[vc setMessagingChannel:channel];
[vc setDelegate:self];
[self presentViewController:vc animated:YES completion:nil];
} messagingUpdatedBlock:^(SendBirdMessagingChannel *channel) {
} messagingEndedBlock:^(SendBirdMessagingChannel *channel) {
} allMessagingEndedBlock:^{
} messagingHiddenBlock:^(SendBirdMessagingChannel *channel) {
} allMessagingHiddenBlock:^{
} readReceivedBlock:^(SendBirdReadStatus *status) {
} typeStartReceivedBlock:^(SendBirdTypeStatus *status) {
} typeEndReceivedBlock:^(SendBirdTypeStatus *status) {
} allDataReceivedBlock:^(NSUInteger sendBirdDataType, int count) {
} messageDeliveryBlock:^(BOOL send, NSString *message, NSString *data, NSString *messageId) {
}];
}
You have to modify inviteUsers:
method in order to invite multiple users.
- (IBAction)inviteUsers:(id)sender {
NSArray * indexPaths = [self.messagingInviteSelectUserTableView indexPathsForSelectedRows];
NSMutableArray<NSString *> *userIds = [[NSMutableArray alloc] init];
for (NSIndexPath *indexPath in indexPaths) {
[userIds addObject:[[userArray objectAtIndex:indexPath.row] guestId]];
}
if ([userIds count] > 0) {
[SendBird startMessagingWithUserIds:userIds];
}
}
Other features are equivalent to those for 1-on-1 messaging.