How to use @cometchat-pro/react-native-chat - 10 common examples

To help you get started, we’ve selected a few @cometchat-pro/react-native-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 / react-native-chat-app / chatApp / src / HomeScreen.js View on Github external
addUserListner(){
        let  listenerID = "CONTACT_USER_LISTNER";
        let that=this;
        CometChat.addUserListener(
            listenerID,
            new CometChat.UserListener({
                onUserOnline: onlineUser => {
                    /* when someuser/friend comes online, user will be received here */
                    console.log("On User Online:", { onlineUser });
                    that.state.users.map(user=>{
                        if (user.uid == onlineUser.uid){
                            user.status="online"
                            that.setState({users:[...that.state.users]})
                        }
                    })
                },
                onUserOffline: offlineUser => {
                    /* when someuser/friend went offline, user will be received here */
                    console.log("On User Offline:", { offlineUser });
                    that.state.users.map(user=>{
                        if (user.uid == offlineUser.uid){
                            user.status="offline"
github cometchat-pro-samples / react-native-chat-app / chatApp / src / ChatScreen.js View on Github external
addUserListner(){
        var listenerID = "CHAT_SCREEN_USER_LISTNER";

        CometChat.addUserListener(
            listenerID,
            new CometChat.UserListener({
                onUserOnline: onlineUser => {
                    /* when someuser/friend comes online, user will be received here */
                    console.log("On User Online:", { onlineUser });

                    if(onlineUser.uid == uid){
                        status = "Online"
                        this.changeTypingText(status)
                    }
                },
                onUserOffline: offlineUser => {
                    /* when someuser/friend went offline, user will be received here */
                    console.log("On User Offline:", { offlineUser });
                    if(offlineUser.uid == uid){
                        status = "Offline"
                        this.changeTypingText(status)
                    }
github cometchat-pro-samples / react-native-chat-app / chatApp / src / HomeScreen.js View on Github external
addUserListner(){
        let  listenerID = "CONTACT_USER_LISTNER";
        let that=this;
        CometChat.addUserListener(
            listenerID,
            new CometChat.UserListener({
                onUserOnline: onlineUser => {
                    /* when someuser/friend comes online, user will be received here */
                    console.log("On User Online:", { onlineUser });
                    that.state.users.map(user=>{
                        if (user.uid == onlineUser.uid){
                            user.status="online"
                            that.setState({users:[...that.state.users]})
                        }
                    })
                },
                onUserOffline: offlineUser => {
                    /* when someuser/friend went offline, user will be received here */
                    console.log("On User Offline:", { offlineUser });
                    that.state.users.map(user=>{
github cometchat-pro-samples / react-native-chat-app / chatApp / src / ChatScreen.js View on Github external
addUserListner(){
        var listenerID = "CHAT_SCREEN_USER_LISTNER";

        CometChat.addUserListener(
            listenerID,
            new CometChat.UserListener({
                onUserOnline: onlineUser => {
                    /* when someuser/friend comes online, user will be received here */
                    console.log("On User Online:", { onlineUser });

                    if(onlineUser.uid == uid){
                        status = "Online"
                        this.changeTypingText(status)
                    }
                },
                onUserOffline: offlineUser => {
                    /* when someuser/friend went offline, user will be received here */
                    console.log("On User Offline:", { offlineUser });
                    if(offlineUser.uid == uid){
                        status = "Offline"
github cometchat-pro-samples / react-native-chat-app / chatApp / src / ChatScreen.js View on Github external
sendMediaMessage(){
        var messageType;
        if(this.state.mediaMsg.type.split('/')[0] == 'image'){
            messageType = CometChat.MESSAGE_TYPE.IMAGE;
        }else if(this.state.mediaMsg.type.split('/')[0] == 'video'){
            messageType = CometChat.MESSAGE_TYPE.VIDEO;
        }else{
            messageType = CometChat.MESSAGE_TYPE.FILE;
        }
        var receiverType = CometChat.RECEIVER_TYPE.USER;
        var mediaMessage = new CometChat.MediaMessage(uid, this.state.mediaMsg, messageType, receiverType);
        this.setState({
            mediaMsg: ''
        });
        console.log("mediaMessage: ", mediaMessage); 
        
        CometChat.sendMediaMessage(mediaMessage)
        .then(message => {
            console.log('cometchat send media message', message);
            this.setState((state) => {
                return state.messages.push(message)
            })
        },
        error => {
            console.log("Media message sending failed with error", error);
        }
        );
github cometchat-pro-samples / react-native-chat-app / chatApp / src / GroupChatScreen.js View on Github external
sendMediaMessage(){
        var messageType;
        if(this.state.mediaMsg.type.split('/')[0] == 'image'){
            messageType = CometChat.MESSAGE_TYPE.IMAGE;
        }else if(this.state.mediaMsg.type.split('/')[0] == 'video'){
            messageType = CometChat.MESSAGE_TYPE.VIDEO;
        }else{
            messageType = CometChat.MESSAGE_TYPE.FILE;
        }
        var receiverType = CometChat.RECEIVER_TYPE.GROUP;
        var mediaMessage = new CometChat.MediaMessage(guid, this.state.mediaMsg, messageType, receiverType);
        this.setState({
            mediaMsg: ''
        });
        console.log("mediaMessage", mediaMessage); 
        
        CometChat.sendMediaMessage(mediaMessage)
        .then(message => {
            console.log('cometchat send media message', message);
            this.setState((state) => {
                return state.messages.push(message)
            })
        },
        error => {
            console.log("Media message sending failed with error", error);
        }
        );
github cometchat-pro-samples / react-native-chat-app / chatApp / src / ChatScreen.js View on Github external
var messageType;
        if(this.state.mediaMsg.type.split('/')[0] == 'image'){
            messageType = CometChat.MESSAGE_TYPE.IMAGE;
        }else if(this.state.mediaMsg.type.split('/')[0] == 'video'){
            messageType = CometChat.MESSAGE_TYPE.VIDEO;
        }else{
            messageType = CometChat.MESSAGE_TYPE.FILE;
        }
        var receiverType = CometChat.RECEIVER_TYPE.USER;
        var mediaMessage = new CometChat.MediaMessage(uid, this.state.mediaMsg, messageType, receiverType);
        this.setState({
            mediaMsg: ''
        });
        console.log("mediaMessage: ", mediaMessage); 
        
        CometChat.sendMediaMessage(mediaMessage)
        .then(message => {
            console.log('cometchat send media message', message);
            this.setState((state) => {
                return state.messages.push(message)
            })
        },
        error => {
            console.log("Media message sending failed with error", error);
        }
        );
    }
github cometchat-pro-samples / react-native-chat-app / chatApp / src / GroupChatScreen.js View on Github external
var messageType;
        if(this.state.mediaMsg.type.split('/')[0] == 'image'){
            messageType = CometChat.MESSAGE_TYPE.IMAGE;
        }else if(this.state.mediaMsg.type.split('/')[0] == 'video'){
            messageType = CometChat.MESSAGE_TYPE.VIDEO;
        }else{
            messageType = CometChat.MESSAGE_TYPE.FILE;
        }
        var receiverType = CometChat.RECEIVER_TYPE.GROUP;
        var mediaMessage = new CometChat.MediaMessage(guid, this.state.mediaMsg, messageType, receiverType);
        this.setState({
            mediaMsg: ''
        });
        console.log("mediaMessage", mediaMessage); 
        
        CometChat.sendMediaMessage(mediaMessage)
        .then(message => {
            console.log('cometchat send media message', message);
            this.setState((state) => {
                return state.messages.push(message)
            })
        },
        error => {
            console.log("Media message sending failed with error", error);
        }
        );
    }
github cometchat-pro-samples / react-native-chat-app / chatApp / src / BlockedUsers.js View on Github external
getBlockedUsers(){
        var limit = 30;
        var blockedUsersRequest = new CometChat.BlockedUsersRequestBuilder().setLimit(limit).build();
        blockedUsersRequest.fetchNext().then(
            userList => {        
                console.log("Blocked user list received:", userList);   
                this.setState({blockedUsers: userList});     
            },
            error => {
                console.log("Blocked user list fetching failed with error:", error);
            }
        );
    }
github cometchat-pro-samples / react-native-chat-app / chatApp / src / HomeScreen.js View on Github external
fetchUser() {
        console.log('Fetch user called.....')
        var limit = 30;
        var usersRequest = new CometChat.UsersRequestBuilder().setLimit(limit).build();
        usersRequest.fetchNext().then(
            userList => {
                if(userList.length >0){
                    CometChat.getUnreadMessageCountForAllUsers().then(array=>{
                        var unread = Object.keys(array);
                        if(unread.length > 0){
                            unread.map(uid =>{
                                var index = userList.findIndex(user=> user.uid == uid);
                                if(index != -1){
                                    userList[index].unreadCount = array[uid];
                                }
                            });
                        } 
                        this.setState({
                            users: userList,
                        });