mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-20 20:59:16 +00:00
Fix websocket notificating multiple users on msg
This commit is contained in:
@@ -113,7 +113,6 @@ const MessagesInput = ({ searchParam }) => {
|
|||||||
const [inputMessage, setInputMessage] = useState("");
|
const [inputMessage, setInputMessage] = useState("");
|
||||||
const [showEmoji, setShowEmoji] = useState(false);
|
const [showEmoji, setShowEmoji] = useState(false);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
const [recording, setRecording] = useState(false);
|
const [recording, setRecording] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -276,7 +275,7 @@ const MessagesInput = ({ searchParam }) => {
|
|||||||
<IconButton
|
<IconButton
|
||||||
aria-label="emojiPicker"
|
aria-label="emojiPicker"
|
||||||
component="span"
|
component="span"
|
||||||
disabled={loading}
|
disabled={loading || recording}
|
||||||
onClick={e => setShowEmoji(prevState => !prevState)}
|
onClick={e => setShowEmoji(prevState => !prevState)}
|
||||||
>
|
>
|
||||||
<MoodIcon className={classes.sendMessageIcons} />
|
<MoodIcon className={classes.sendMessageIcons} />
|
||||||
@@ -295,11 +294,16 @@ const MessagesInput = ({ searchParam }) => {
|
|||||||
<input
|
<input
|
||||||
type="file"
|
type="file"
|
||||||
id="upload-button"
|
id="upload-button"
|
||||||
|
disabled={loading || recording}
|
||||||
className={classes.uploadInput}
|
className={classes.uploadInput}
|
||||||
onChange={handleChangeMedia}
|
onChange={handleChangeMedia}
|
||||||
/>
|
/>
|
||||||
<label htmlFor="upload-button">
|
<label htmlFor="upload-button">
|
||||||
<IconButton aria-label="upload" component="span" disabled={loading}>
|
<IconButton
|
||||||
|
aria-label="upload"
|
||||||
|
component="span"
|
||||||
|
disabled={loading || recording}
|
||||||
|
>
|
||||||
<AttachFileIcon className={classes.sendMessageIcons} />
|
<AttachFileIcon className={classes.sendMessageIcons} />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</label>
|
</label>
|
||||||
@@ -312,7 +316,7 @@ const MessagesInput = ({ searchParam }) => {
|
|||||||
rowsMax={5}
|
rowsMax={5}
|
||||||
value={inputMessage}
|
value={inputMessage}
|
||||||
onChange={handleChangeInput}
|
onChange={handleChangeInput}
|
||||||
disabled={recording}
|
disabled={recording || loading}
|
||||||
onPaste={handleInputPaste}
|
onPaste={handleInputPaste}
|
||||||
onKeyPress={e => {
|
onKeyPress={e => {
|
||||||
if (loading) return;
|
if (loading) return;
|
||||||
@@ -363,6 +367,7 @@ const MessagesInput = ({ searchParam }) => {
|
|||||||
<IconButton
|
<IconButton
|
||||||
aria-label="showRecorder"
|
aria-label="showRecorder"
|
||||||
component="span"
|
component="span"
|
||||||
|
disabled={loading}
|
||||||
onClick={handleStartRecording}
|
onClick={handleStartRecording}
|
||||||
>
|
>
|
||||||
<MicIcon className={classes.sendMessageIcons} />
|
<MicIcon className={classes.sendMessageIcons} />
|
||||||
|
|||||||
@@ -19,6 +19,26 @@ const TicketSkeleton = () => {
|
|||||||
/>
|
/>
|
||||||
</ListItem>
|
</ListItem>
|
||||||
<Divider />
|
<Divider />
|
||||||
|
<ListItem dense>
|
||||||
|
<ListItemAvatar>
|
||||||
|
<Skeleton animation="wave" variant="circle" width={40} height={40} />
|
||||||
|
</ListItemAvatar>
|
||||||
|
<ListItemText
|
||||||
|
primary={<Skeleton animation="wave" height={20} width={70} />}
|
||||||
|
secondary={<Skeleton animation="wave" height={20} width={120} />}
|
||||||
|
/>
|
||||||
|
</ListItem>
|
||||||
|
<Divider />
|
||||||
|
<ListItem dense>
|
||||||
|
<ListItemAvatar>
|
||||||
|
<Skeleton animation="wave" variant="circle" width={40} height={40} />
|
||||||
|
</ListItemAvatar>
|
||||||
|
<ListItemText
|
||||||
|
primary={<Skeleton animation="wave" height={20} width={60} />}
|
||||||
|
secondary={<Skeleton animation="wave" height={20} width={90} />}
|
||||||
|
/>
|
||||||
|
</ListItem>
|
||||||
|
<Divider />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,11 +5,8 @@ import openSocket from "socket.io-client";
|
|||||||
|
|
||||||
import { parseISO, format } from "date-fns";
|
import { parseISO, format } from "date-fns";
|
||||||
|
|
||||||
import profileDefaultPic from "../../../../Images/profile_default.png";
|
|
||||||
|
|
||||||
import { makeStyles } from "@material-ui/core/styles";
|
import { makeStyles } from "@material-ui/core/styles";
|
||||||
import { green } from "@material-ui/core/colors";
|
import { green } from "@material-ui/core/colors";
|
||||||
import CircularProgress from "@material-ui/core/CircularProgress";
|
|
||||||
import Paper from "@material-ui/core/Paper";
|
import Paper from "@material-ui/core/Paper";
|
||||||
import List from "@material-ui/core/List";
|
import List from "@material-ui/core/List";
|
||||||
import ListItem from "@material-ui/core/ListItem";
|
import ListItem from "@material-ui/core/ListItem";
|
||||||
@@ -46,6 +43,7 @@ const useStyles = makeStyles(theme => ({
|
|||||||
|
|
||||||
tabsHeader: {
|
tabsHeader: {
|
||||||
// display: "flex",
|
// display: "flex",
|
||||||
|
flex: "none",
|
||||||
backgroundColor: "#eee",
|
backgroundColor: "#eee",
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -86,7 +84,7 @@ const useStyles = makeStyles(theme => ({
|
|||||||
// flexShrink: 0,
|
// flexShrink: 0,
|
||||||
// -webkitBoxAlign: "center",
|
// -webkitBoxAlign: "center",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
fontWeight: 500,
|
fontWeight: 600,
|
||||||
fontSize: "16px",
|
fontSize: "16px",
|
||||||
height: "56px",
|
height: "56px",
|
||||||
// backgroundColor: "#eee",
|
// backgroundColor: "#eee",
|
||||||
@@ -114,6 +112,29 @@ const useStyles = makeStyles(theme => ({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
noTicketsDiv: {
|
||||||
|
display: "flex",
|
||||||
|
height: "100px",
|
||||||
|
margin: 40,
|
||||||
|
flexDirection: "column",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "center",
|
||||||
|
},
|
||||||
|
|
||||||
|
noTicketsText: {
|
||||||
|
textAlign: "center",
|
||||||
|
color: "rgb(104, 121, 146)",
|
||||||
|
fontSize: "14px",
|
||||||
|
lineHeight: "1.4",
|
||||||
|
},
|
||||||
|
|
||||||
|
noTicketsTitle: {
|
||||||
|
textAlign: "center",
|
||||||
|
fontSize: "16px",
|
||||||
|
fontWeight: "600",
|
||||||
|
margin: "0px",
|
||||||
|
},
|
||||||
|
|
||||||
contactsSearchBox: {
|
contactsSearchBox: {
|
||||||
position: "relative",
|
position: "relative",
|
||||||
background: "#fafafa",
|
background: "#fafafa",
|
||||||
@@ -230,12 +251,14 @@ const TicketsList = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.on("appMessage", data => {
|
socket.on("appMessage", data => {
|
||||||
|
console.log(data);
|
||||||
if (data.action === "create") {
|
if (data.action === "create") {
|
||||||
updateUnreadMessagesCount(data);
|
updateUnreadMessagesCount(data);
|
||||||
if (
|
if (
|
||||||
ticketId &&
|
(ticketId &&
|
||||||
data.message.ticketId === +ticketId &&
|
data.message.ticketId === +ticketId &&
|
||||||
document.visibilityState === "visible"
|
document.visibilityState === "visible") ||
|
||||||
|
(data.ticket.userId !== userId && data.ticket.userId)
|
||||||
)
|
)
|
||||||
return;
|
return;
|
||||||
showDesktopNotification(data);
|
showDesktopNotification(data);
|
||||||
@@ -245,7 +268,7 @@ const TicketsList = () => {
|
|||||||
return () => {
|
return () => {
|
||||||
socket.disconnect();
|
socket.disconnect();
|
||||||
};
|
};
|
||||||
}, [ticketId]);
|
}, [ticketId, userId]);
|
||||||
|
|
||||||
const updateUnreadMessagesCount = data => {
|
const updateUnreadMessagesCount = data => {
|
||||||
setTickets(prevState => {
|
setTickets(prevState => {
|
||||||
@@ -282,7 +305,6 @@ const TicketsList = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const showDesktopNotification = data => {
|
const showDesktopNotification = data => {
|
||||||
console.log("data", data);
|
|
||||||
const options = {
|
const options = {
|
||||||
body: `${data.message.body} - ${format(new Date(), "HH:mm")}`,
|
body: `${data.message.body} - ${format(new Date(), "HH:mm")}`,
|
||||||
icon: data.contact.profilePicUrl,
|
icon: data.contact.profilePicUrl,
|
||||||
@@ -330,17 +352,22 @@ const TicketsList = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const countTickets = status => {
|
const countTickets = (status, userId) => {
|
||||||
const ticketsFound = tickets.filter(t => t.status === status).length;
|
const ticketsFound = tickets.filter(
|
||||||
|
t => t.status === status && t.userId === userId
|
||||||
|
).length;
|
||||||
|
|
||||||
if (ticketsFound === 0) return "";
|
if (ticketsFound === 0) return "";
|
||||||
return ticketsFound;
|
return ticketsFound;
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderTickets = (status, userId) => {
|
const renderTickets = (status, userId) => {
|
||||||
const viewTickets = tickets.map(
|
const viewTickets = tickets.map(ticket => {
|
||||||
(ticket, index) =>
|
if (
|
||||||
ticket.status === status && (
|
(ticket.status === status && ticket.userId === userId) ||
|
||||||
|
ticket.status === "closed"
|
||||||
|
)
|
||||||
|
return (
|
||||||
<React.Fragment key={ticket.id}>
|
<React.Fragment key={ticket.id}>
|
||||||
<ListItem
|
<ListItem
|
||||||
dense
|
dense
|
||||||
@@ -355,9 +382,7 @@ const TicketsList = () => {
|
|||||||
<ListItemAvatar>
|
<ListItemAvatar>
|
||||||
<Avatar
|
<Avatar
|
||||||
src={
|
src={
|
||||||
ticket.Contact.profilePicUrl
|
ticket.Contact.profilePicUrl && ticket.Contact.profilePicUrl
|
||||||
? ticket.Contact.profilePicUrl
|
|
||||||
: profileDefaultPic
|
|
||||||
}
|
}
|
||||||
></Avatar>
|
></Avatar>
|
||||||
</ListItemAvatar>
|
</ListItemAvatar>
|
||||||
@@ -419,17 +444,22 @@ const TicketsList = () => {
|
|||||||
</ListItem>
|
</ListItem>
|
||||||
<Divider variant="inset" component="li" />
|
<Divider variant="inset" component="li" />
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
else return null;
|
||||||
|
});
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return <>{Array(2).fill(<TicketSkeleton />)}</>;
|
return <TicketSkeleton />;
|
||||||
} else if (viewTickets.length === 0) {
|
} else if (countTickets(status, userId) === "" && status !== "closed") {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div className={classes.noTicketsDiv}>
|
||||||
<span className={classes.noTicketsTitle}>All caught up</span>
|
<span className={classes.noTicketsTitle}>
|
||||||
|
{status === "pending" ? "Tudo resolvido" : "Pronto pra mais?"}
|
||||||
|
</span>
|
||||||
<p className={classes.noTicketsText}>
|
<p className={classes.noTicketsText}>
|
||||||
No tickets to look into for now. Take a breather!
|
{status === "pending"
|
||||||
|
? "Nenhum ticket pendente por enquanto. Hora do café!"
|
||||||
|
: "Aceite um ticket da fila para começar."}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -479,10 +509,10 @@ const TicketsList = () => {
|
|||||||
<div className={classes.ticketsListHeader}>
|
<div className={classes.ticketsListHeader}>
|
||||||
Meus tickets
|
Meus tickets
|
||||||
<span className={classes.ticketsCount}>
|
<span className={classes.ticketsCount}>
|
||||||
{countTickets("open")}
|
{countTickets("open", userId)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
{renderTickets("open")}
|
{renderTickets("open", userId)}
|
||||||
</List>
|
</List>
|
||||||
</Paper>
|
</Paper>
|
||||||
<Paper square elevation={0} className={classes.openTicketsList}>
|
<Paper square elevation={0} className={classes.openTicketsList}>
|
||||||
@@ -490,16 +520,16 @@ const TicketsList = () => {
|
|||||||
<div className={classes.ticketsListHeader}>
|
<div className={classes.ticketsListHeader}>
|
||||||
Aguardando
|
Aguardando
|
||||||
<span className={classes.ticketsCount}>
|
<span className={classes.ticketsCount}>
|
||||||
{countTickets("pending")}
|
{countTickets("pending", null)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
{renderTickets("pending")}
|
{renderTickets("pending", null)}
|
||||||
</List>
|
</List>
|
||||||
</Paper>
|
</Paper>
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<Paper square elevation={0} className={classes.closedTicketsList}>
|
<Paper square elevation={0} className={classes.closedTicketsList}>
|
||||||
<List>{renderTickets("closed")}</List>
|
<List>{renderTickets("closed", userId)}</List>
|
||||||
</Paper>
|
</Paper>
|
||||||
)}
|
)}
|
||||||
<audio id="sound" preload="auto">
|
<audio id="sound" preload="auto">
|
||||||
|
|||||||
Reference in New Issue
Block a user