Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
markAsRead(msg) {
if (msg.receiverType == "user") {
if ((msg !== undefined && msg.readAt == undefined) && (msg.sender.uid == this.props.activeUser.id)) {
CometChat.markAsRead(msg.id, msg.sender.uid, msg.receiverType);
}
} else {
if ((msg !== undefined && msg.readByMeAt == undefined && msg.sender.uid !== this.props.loggedUid) && (msg.receiver == this.props.activeUser.id)) {
CometChat.markAsRead(msg.id, msg.receiver, msg.receiverType);
}
}
}
markAsRead(msg) {
if (msg.receiverType == "user") {
if ((msg !== undefined && msg.readAt == undefined) && (msg.sender.uid == this.props.activeUser.id)) {
CometChat.markAsRead(msg.id, msg.sender.uid, msg.receiverType);
}
} else {
if ((msg !== undefined && msg.readByMeAt == undefined && msg.sender.uid !== this.props.loggedUid) && (msg.receiver == this.props.activeUser.id)) {
CometChat.markAsRead(msg.id, msg.receiver, msg.receiverType);
}
}
}
const copyPSMessageState = Object.assign({}, state.messages[index]);
copyPSMessageState.message.push(action.message);
const PSMessageState = update(state, {messages: { index: { $set: [copyPSMessageState] } }});
return PSMessageState;
}
break;
case "updateMessageList":
if(action.tags == "user"){
var array = action.messages;
var incomingMessages = array.filter(function(msg) {
return msg.sender.uid == action.uid;
});
var lastMessage = incomingMessages[incomingMessages.length - 1];
if (lastMessage !== undefined && lastMessage.readAt == undefined) {
CometChat.markAsRead(lastMessage.id,lastMessage.sender.uid,lastMessage.receiverType);
}
}else{
var array = action.messages;
var incomingMessages = array.filter(function(msg) {
return msg.sender.uid != action.loggedInUser;
});
var lastMessage = incomingMessages[incomingMessages.length - 1];
if (lastMessage !== undefined && lastMessage.readByMeAt == undefined) {
CometChat.markAsRead(lastMessage.id,lastMessage.receiver,lastMessage.receiverType);
}
}
let index1 = newState.messages.findIndex(
userMessage => userMessage.muid === action.uid
);
var array = action.messages;
var incomingMessages = array.filter(function(msg) {
return msg.sender.uid == action.uid;
});
var lastMessage = incomingMessages[incomingMessages.length - 1];
if (lastMessage !== undefined && lastMessage.readAt == undefined) {
CometChat.markAsRead(lastMessage.id,lastMessage.sender.uid,lastMessage.receiverType);
}
}else{
var array = action.messages;
var incomingMessages = array.filter(function(msg) {
return msg.sender.uid != action.loggedInUser;
});
var lastMessage = incomingMessages[incomingMessages.length - 1];
if (lastMessage !== undefined && lastMessage.readByMeAt == undefined) {
CometChat.markAsRead(lastMessage.id,lastMessage.receiver,lastMessage.receiverType);
}
}
let index1 = newState.messages.findIndex(
userMessage => userMessage.muid === action.uid
);
if(index1 != -1){
const copyMessageState = Object.assign({}, state.messages[index1]);
action.messages.map(msg => {copyMessageState.message.push(msg);});
const copyMessagesState = Object.assign({}, state.messages);
const NPLMessageState = update(state, {messages: { index: { $set: [copyMessageState] } }});
return NPLMessageState;
}else{
var tempObj = {
muid: action.uid,