How to use the @cometchat-pro/chat.CometChat.addMessageListener function in @cometchat-pro/chat

To help you get started, we’ve selected a few @cometchat-pro/chat examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cometchat-pro-samples / javascript-reactjs-chat-app / src / components / cometchat / ChatBody.jsx View on Github external
componentDidMount() {
    //listener1
    var listenerID = LISTENER_NEW_MESSAGE;

    CometChat.addMessageListener(
      listenerID,
      new CometChat.MessageListener({
        onTextMessageReceived: textMessage => {
         
          let messageId;
          let senderID;
          if (
            textMessage.receiverType === CometChat.RECEIVER_TYPE.USER &&
            textMessage.sender.uid === this.props.activeConversation.uid
          ) {
            // Handle text message
            senderID = textMessage.sender.uid;
            messageId = textMessage.id;

            if (senderID !== this.props.subjectUID) {
              CometChat.markMessageAsRead(
github cometchat-pro-samples / javascript-reactjs-chat-app / src / js / components / message / CCMessageBox.js View on Github external
componentWillMount() {
    this.fetchfirstTimeMessage(this.props.activeUser.type,this.props.activeUser.id);
    CometChat.addMessageListener(
      "CHAT_BOX_LISTENER",
      new CometChat.MessageListener({
        onTextMessageReceived: message => {
          this.markAsRead(message);
        },
        onMediaMessageReceived: message => {
          this.markAsRead(message);
        }
      })
    );
  }
github cometchat-pro-samples / javascript-reactjs-chat-app / src / components / cometchat / ChatBody.jsx View on Github external
new CometChat.MessageListener({
        onMessageEdited: message => {
          let msghistory = this.state.msghistory;
          let messageKey = _.findIndex(msghistory, function(m) {
            return m.id === message.id;
          });
          msghistory[messageKey] = message;
          this.setState({ msghistory });

          this.props.handleOnRecentMessageSent(message.id);
        }
      })
    );

    var listenerID5 = LISTENER_RT_MSG_DELETE;
    CometChat.addMessageListener(
      listenerID5,
      new CometChat.MessageListener({
        onMessageDeleted: message => {
          let msghistory = this.state.msghistory;
          const messageKey = _.findIndex(msghistory, function(m) {
            return m.id === message.id;
          });
          msghistory[messageKey] = message;
          this.setState({ msghistory });
          this.props.handleOnRecentMessageSent(message.id);
        }
      })
    );

  }
github cometchat-pro-samples / javascript-reactjs-chat-app / src / js / lib / cometchat / ccManager.js View on Github external
static addMessageListener(dispatch) {
    CometChat.addMessageListener(
      this.LISTENER_KEY_MESSAGE,
      new CometChat.MessageListener({
        onTextMessageReceived: message => {
          this.handleMessage(message, dispatch);
        },
        onMediaMessageReceived: message => {
          this.handleMessage(message, dispatch);
        },
        onMessagesDelivered: (messageReceipt) => {
          this.handleMessageDelivered(messageReceipt, dispatch);
        },
        onMessagesRead: (messageReceipt) => {
          this.handleMessageRead(messageReceipt, dispatch);
        },
        onTypingStarted: (typingIndicator) => {
          this.handleStartTyping(typingIndicator,dispatch);
github cometchat-pro-samples / javascript-reactjs-chat-app / src / components / cometchat / ChatBody.jsx View on Github external
"id",
            messageReceipt.messageId
          ]);
         
          if (index_in_history !== undefined) {
            msghistory[index_in_history]["deliveredAt"] =
              messageReceipt.deliveredAt;
            this.setState({ msghistory });
          }
        }
      })
    );

    var listenerID4 = LISTENER_RT_MSG_EDIT;

    CometChat.addMessageListener(
      listenerID4,
      new CometChat.MessageListener({
        onMessageEdited: message => {
          let msghistory = this.state.msghistory;
          let messageKey = _.findIndex(msghistory, function(m) {
            return m.id === message.id;
          });
          msghistory[messageKey] = message;
          this.setState({ msghistory });

          this.props.handleOnRecentMessageSent(message.id);
        }
      })
    );

    var listenerID5 = LISTENER_RT_MSG_DELETE;