Combu  2.1.14
Unity API Documentation
Managing Messages

Table of Contents

In this section you will learn how to manage the in-game inbox of the local user.

Loading Messages

To retrieve the list of messages of a user you need to call the Message.Load:

// Load the received messages from the page 1 with 3 results per page
Mail.Load(eMailList.Received, 1, 3, (Mail[] messages, int count, int pagesCount, string error) => {
if (string.IsNullOrEmpty(error))
Debug.Log("Success: " + messages.Length);
else
Debug.Log("Failed: " + error);
});

Sending Messages

To send a new message to a user you need to call one of the overloads of Mail.Send:

// Send a private message to a user by Id
Mail.Send(123, "Subject", "Message body", false, (bool success, string error) => {
if (success)
Debug.Log("Success");
else
Debug.Log("Failed: " + error);
});
// Send a private message to a user by Username
Mail.Send("user1", "Subject", "Message body", false, (bool success, string error) => {
if (success)
Debug.Log("Success");
else
Debug.Log("Failed: " + error);
});
// Send a private message to multiple users by Id
Mail.Send( new long[] { 123, 456 }, "Subject", "Message body", false, (bool success, string error) => {
if (success)
Debug.Log("Success");
else
Debug.Log("Failed: " + error);
});
// Send a private message to multiple users by Username
Mail.Send( new string[] { "user1", "user2" }, "Subject", "Message body", false, (bool success, string error) => {
if (success)
Debug.Log("Success");
else
Debug.Log("Failed: " + error);
});

Sending to UserGroup

If you want to send a message to a UserGroup then you need to call Mail.SendMailToGroup:

// Send a message to the UserGroup ID '123'
Mail.SendMailToGroup(123, "Subject", "Message body", false, (bool success, string error) => {
if (success)
Debug.Log("Success");
else
Debug.Log("Failed: " + error);
});

Marking Messages as Read

To mark a message as Read you need to call Mail.Read, or call the method Read on a Mail instance:

// Mark as Read by Mail ID
Mail.Read( new long[] { 123, 456 }, new long[0], (bool success, string error) => {
if (success)
Debug.Log("Success");
else
Debug.Log("Failed: " + error);
});
// Mark as Read by Group ID
Mail.Read( new long[0], new long[] { 123, 456 }, (bool success, string error) => {
if (success)
Debug.Log("Success");
else
Debug.Log("Failed: " + error);
});
// Mark as Read by Mail object
myMail.Read( (bool success, string error) => {
if (success)
Debug.Log("Success");
else
Debug.Log("Failed: " + error);
});

Marking Messages as Unread

To mark a message as Unread you need to call Mail.Unread, or call the method Unread on a Mail instance:

// Mark as Unread by Mail ID
Mail.Unread( 123, (bool success, string error) => {
if (success)
Debug.Log("Success");
else
Debug.Log("Failed: " + error);
});
// Mark as Unread by Mail object
myMail.Unread( (bool success, string error) => {
if (success)
Debug.Log("Success");
else
Debug.Log("Failed: " + error);
});

Removing Items

To delete a message you need to call Message.Delete, or call the method Delete on a Mail instance:

// Remove by Message ID '123'
Mail.Delete(123, (bool success, string error) => {
if (success)
Debug.Log("Success");
else
Debug.Log("Failed: " + error);
});
// Remove by Mail object
myMail.Delete( (bool success, string error) => {
if (success)
Debug.Log("Success");
else
Debug.Log("Failed: " + error);
});

Loading Conversations

To load the list of discussions of the local user with others you can call Mail.LoadConversations, it will fill an ArrayList with objects of type User or UserGroup (based on the idGroup associated to the Mail object):

Mail.LoadConversations( (ArrayList conversations, int count, string error) => {
if (string.IsNullOrEmpty(error))
Debug.Log("Success: " + conversations.Count);
else
Debug.Log("Failed: " + error);
});

Counting Messages

To count the messages in the inbox of the local user you can call Mail.Count:

// Count the messages sent from users ID
Mail.Count( new long[] { 123, 456 }, new long[0], (MailCount[] counts, string error) => {
if (string.IsNullOrEmpty(error))
Debug.Log("Success: " + counts.Length);
else
Debug.Log("Failed: " + error);
});
// Count the messages sent from groups ID
Mail.Count( new long[0], new long[] { 123, 456 }, (MailCount[] counts, string error) => {
if (string.IsNullOrEmpty(error))
Debug.Log("Success: " + counts.Length);
else
Debug.Log("Failed: " + error);
});