Suggestions

close search

Messages

Once authenticed, users can send or received messages such as: text, photo, vieo, audio, location, contact... To send a message contains media content (photo, video, audio, file...), you need to upload media content to your server first. Then you use Stringee SDK to send the uploaded url.

1. Create a message

Create a message in JSON format:

    var message = {
      type: 1,
      text: "react-native first message.",
      conversationId: this.state.convId
    };

In which:

2. Send a message

Send a Message by calling:

    this.refs.client.sendMessage(message, (status, code, message) => {
      console.log("status-" + status + " code-" + code + " message-" + message);
    });

3. Get Messages

Messages are stored on Stringee server and cached on Local Database as well. You can get messages as follows:

3.1. Get local messages

To get local messages of a conversation, you call:

    this.refs.client.getLocalMessages(this.state.convId, count, (status, code, message, messages) => {
      console.log("status-" + status + " code-" + code + " message-" + message);
      messages.map((message) => {
        console.log("Message's Id" + message.id + "==== " + message.text);
      });
    });

3.2. Get last messages

To get latest messages from Stringee server, you call:

    this.refs.client.getLastMessages(this.state.convId, count, (status, code, message, messages) => {
      console.log("status-" + status + " code-" + code + " message-" + message);
      messages.map((message) => {
        console.log("Message's Id" + message.id + "==== " + message.text);
      });
    });

3.3. Get messages after

To get a list of messages tied to a conversation from server which have sequence greater than seq, you call:

    this.refs.client.getMessagesAfter(this.state.convId, sequence, count, (status, code, message, messages) => {
      console.log("status-" + status + " code-" + code + " message-" + message);
      messages.map((message) => {
        console.log("Message's Id" + message.id + "==== " + message.text);
      });
    });

3.4. Get messages before

To get a list of messages tied to a conversation from server which have sequence smaller than seq, you call:

    this.refs.client.getMessagesBefore(this.state.convId, sequence, count, (status, code, message, messages) => {
      console.log("status-" + status + " code-" + code + " message-" + message);
      messages.map((message) => {
        console.log("Message's Id" + message.id + "==== " + message.text);
      });
    });

4. Message statuses

Stringee keeps track of the recipient status of each message. There are five possible statuses: INITIALIZE, SENDING, SENT, DELIVERED, READ. Stringee automatically updates the recipient status to sent, delivered. The only update your app can perform is to mark a conversation's messages as read:

    this.refs.client.markConversationAsRead(this.state.convId, (status, code, message) => {
      console.log("status-" + status + " code-" + code + " message-" + message);
    });

Stringee notify you the status update of a message via the onObjectChange event of StringeeClient.

5. Delete message

To delete a message, you call:

    this.refs.client.deleteMessage(conversationId, messageId, (status, code, message) => {
      console.log("status-" + status + " code-" + code + " message-" + message);
    });