A public forum is a common way to share information with other users. Forums are often organized around a particular subject. The following use case describes how to create public forum functionality in your app and illustrates use of the APIs by creating a channel for the SF Giants.
In Magnet Message, our channel object is how messages are sent to and received by a group. To create a channel (sf_giants
):
NOTE: The creator of the channel is automatically subscribed to the channel.
Next, discover channels that you can subscribe to
To discover all public channels that have been created in the application, use the code below.
NOTE: The limit and offset allow you to implement pagination with the results.
sf_giants
):After getting a channel, check if the current user is subscribed to the channel:
To subscribe to a channel and send and receive messages (sfGiants
):
To unsubscribe from a channel (in this case, the sfSeals
):
After subscribing, you can see other subscribers to the channel (sfGiants
):
You can also get all messages published on the channel. Let's retrieve the messages sent from an hour ago until now (limited to up to 10 at a time).
To publish a message to the channel:
Next, register for incoming message notifications to receive messages from the channels that you are subscribed to:
NOTE: We include the start
method to do the necessary initialization before your app starts so you can receive incoming messages.
Once incoming message notification has been enabled, you can continue to implement your notification code as shown below:
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 named with this format: “.NO_NAME.SDK_GENERATED_UUID”
See how to create a Private Discussion Group in your app.