Milan
Milan

Reputation: 152

Sendbird messaging service duplicate new messages in each group channel

When am sending new message it goes to all the distinct group channel, and it shouldn't be like this by default. Any suggestion appreciated.

For messaging part I have to array to store previous and new messages and load it when it is need.

The language is used is react.js and it is for simple web-app.

sendMessage(message) {
const data = '';
const customType = '';
this.state.currentChannel.sendUserMessage(message, data, customType, (mess, error) => {
  if (error) {
    console.error(`error sending message: ${error}`);
    return;
  }
  console.log(`message sent!! ${mess}`);
  console.log(mess);
  const messagesState = this.state.messages;
  messagesState.push(mess);
  this.setState({
    messages: messagesState,
  });
});

}

Is there anything wrong in this part ?!

Upvotes: 2

Views: 533

Answers (2)

Radoslav Naidenov
Radoslav Naidenov

Reputation: 807

Just add an empty array before each channel handler.

message = [];
channelHandler = currentChannel;

Upvotes: 1

terryk
terryk

Reputation: 116

Your Channel Handler receives all incoming messages. You have to check if the message's channel corresponds to the one you're currently entered in.

So, in onMessageReceived,

if (channel.url == myChannelUrl) {
    // Add the message to myChannel's message list.
}

Upvotes: 1

Related Questions