Creating a Private Discussion Group
A private discussion group allows you to create an "invite-only" discussion group so that people can discuss a topic privately. The following use case describes how to create and interact with a Company Policies private discussion group.
Create Channel
Start by creating a channel object:
NSString *channelName = @"CompanyPolicies";
NSString *channelSummary = @"Stay up to date with the company policies";
[MMXChannel createWithName:channelName
summary:channelSummary
isPublic:NO
publishPermissions:MMXPublishPermissionsSubscribers
success:^(MMXChannel *channel) {
// do something
} failure:^(NSError *error) {
// do something
}];
Discover Private Channels
To discover all the private channels you own:
[MMXChannel allPrivateChannelsWithLimit:10
offset:0
success:^(int totalCount, NSArray *channels) {
//Success
} failure:^(NSError *) {
//Failure
}];
To discover the private channel you own by name (APrivateChannel
):
[MMXChannel channelForName:@"APrivateChannel"
isPublic:NO
success:^(MMXChannel *channel) {
//Success
}
failure:^(NSError *error) {
//Failure
}];
Invite Users to Channel
Invite users to join a channel:
MMUser *janeDoe = ...;
[mmxChannel inviteUser:janeDoe
comments:@"Subscribe to the Company Policies channel"
success:^(MMXInvite *invite) {
janeDoeInvite.timestamp; // returns the time the invite was sent
janeDoeInvite.comments; // returns @"Subscribe to the Company Policies channel"
janeDoeInvite.sender; // returns inviter
} failure:^(NSError *error) {
// do something
}];
Use Notifications for Invites
Notifications are leveraged to listen for incoming invites:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didReceiveChannelInvite:)
name:MMXDidReceiveChannelInviteNotification
object:nil];
}
- (void)didReceiveChannelInvite:(NSNotification *)notification {
// Do something with the invite
MMXInvite *invite = notification.userInfo[MMXInviteKey];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:(BOOL)animated];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
To display channel information from the invite like name, summary and owner:
MMXInvite *janeDoeInvite = ...;
janeDoeInvite.timestamp; // returns the time the invite was sent
janeDoeInvite.comments; // returns @"Subscribe to the Company Policies channel"
janeDoeInvite.sender; // returns inviter
MMXChannel *mmxChannel = janeDoeInvite.channel;
mmxChannel.ownerUserID; // returns the userID for the owner of the channel
mmxChannel.name; // returns @"CompanyPolicies"
mmxChannel.summary; // returns @"Stay upto date with the company policies"
Accept Invites
To accept an invite:
// Comments are optional, can be nil
[janeDoeInvite acceptWithComments:@"Thanks"
success:^{
// do something
} failure:^(NSError *error) {
// do something
}];
Decline Invites
To decline an invite:
// Comments are optional, can be nil
[janeDoeInvite declineWithComments:@"Thanks, but I'm transferring to the Berlin office!" success:^{
//do something
}
failure:^(NSError *error) {
// do something
}];
Receive Invitation Responses
To receive invitation responses:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didReceiveChannelInviteResponse:)
name:MMXDidReceiveChannelInviteResponseNotification
object:nil];
}
- (void)didReceiveChannelInviteResponse:(NSNotification *)notification {
MMXInviteResponse *inviteResponse = notification.userInfo[MMXInviteResponseKey];
NSString *message;
if (inviteResponse.accepted) {
message = @"accepted";
} else {
message = @"declined";
}
NSLog(@"%@ %@ invite to join %@", inviteResponse.sender.username, message, inviteResponse.channel.name);
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:(BOOL)animated];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
Publish to Channel
Publish to a channel using the code below:
MMXChannel *sfGiantsChannel = ...;
NSDictionary *messageContent = @{@"message":@"Go Giants!"};
[sfGiantsChannel publish:messageContent
success:^(MMXMessage *message) {
NSLog(@"Successfully published to channel %@",sfGiantsChannel.name);
} failure:^(NSError *error) {
NSLog(@"Error publishing to channel %@nError = %@",sfGiantsChannel.name,error);
}];
Register for Incoming Message Notification
To register for a notification to receive incoming messages from the channel:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// Indicate that you are ready to receive messages now!
[MMX start];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didReceiveMessage:)
name:MMXDidReceiveMessageNotification
object:nil];
}
Once the incoming messages has been enabled, you can continue to implement your notification code as shown below:
- (void)didReceiveMessage:(NSNotification *)notification {
MMXMessage *message = notification.userInfo[MMXMessageKey];
// Do something with the message
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:(BOOL)animated];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
Rename Channel
Additionally, a channel can be renamed. To rename a channel, call the rename
method on the channel object.
NOTE: Passing in a null name to the channel causes it to be automatically be named with this format:
“.NO_NAME.SDK_GENERATED_UUID”
MMXChannel *channel;
[channel rename:@"new_name"
success: ^(MMXChannel *channel){
//Channel renaming succeeded!
} failure: ^(NSError *error) {
//Channel renaming failed
}];
Useful Links