timestamping chat viewed timestamp when closing the header team chat

This commit is contained in:
Carter 2025-10-29 10:50:41 -06:00
parent 61ea77846c
commit 49e8160ccf
3 changed files with 25 additions and 2 deletions

View file

@ -8,6 +8,8 @@ import { pond } from "protobuf-ts/pond";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { getSignatureAccentColour } from "services/whiteLabel"; import { getSignatureAccentColour } from "services/whiteLabel";
import NotificationDrawer from "./NotificationDrawer"; import NotificationDrawer from "./NotificationDrawer";
import { useTeamAPI } from "providers";
import { cloneDeep } from "lodash";
const useStyles = makeStyles((theme: Theme) => ({ const useStyles = makeStyles((theme: Theme) => ({
@ -55,7 +57,9 @@ export default function HeaderButtons(props: Props) {
const [hasNewNotifications, setHasNewNotifications] = useState(false); const [hasNewNotifications, setHasNewNotifications] = useState(false);
const [chatDrawerOpen, setChatDrawerOpen] = useState(false); const [chatDrawerOpen, setChatDrawerOpen] = useState(false);
const [notificationDrawerOpen, setNotificationDrawerOpen] = useState<boolean>(false); const [notificationDrawerOpen, setNotificationDrawerOpen] = useState<boolean>(false);
const classes = useStyles(); const classes = useStyles();
const teamAPI = useTeamAPI();
useEffect(() => { useEffect(() => {
if (!team) return; if (!team) return;
@ -66,6 +70,8 @@ export default function HeaderButtons(props: Props) {
setHasNewChats(true); setHasNewChats(true);
return; return;
} }
console.log(team.preferences.chatViewedTimestamp)
console.log(team.settings.lastChatTimestamp)
let viewMoment = moment(team.preferences.chatViewedTimestamp); let viewMoment = moment(team.preferences.chatViewedTimestamp);
let chatMoment = moment(team.settings.lastChatTimestamp); let chatMoment = moment(team.settings.lastChatTimestamp);
if (viewMoment.diff(chatMoment) < 0) { if (viewMoment.diff(chatMoment) < 0) {
@ -154,13 +160,29 @@ export default function HeaderButtons(props: Props) {
) )
} }
const onChatClose = () => {
setChatDrawerOpen(false)
let newTeamPrefs = cloneDeep(team.preferences)
newTeamPrefs.chatViewedTimestamp = new Date().toISOString();
teamAPI
.updatePreferences(
team.key(),
newTeamPrefs,
// getContextKeys(),
// getContextTypes()
)
.then(() => {
// setTeamPrefs(newTeamPrefs);
});
}
return ( return (
<> <>
{chatButton()} {chatButton()}
{team && team.settings && team.settings.key && ( {team && team.settings && team.settings.key && (
<ChatDrawer <ChatDrawer
open={chatDrawerOpen} open={chatDrawerOpen}
onClose={() => setChatDrawerOpen(false)} onClose={onChatClose}
team={team} team={team}
/> />
)} )}

View file

@ -72,6 +72,7 @@ export default function UserWrapper(props: Props) {
if (hasFetched.current) return; if (hasFetched.current) return;
setLoading(true) setLoading(true)
userAPI.getUserWithTeam(user_id).then(resp => { userAPI.getUserWithTeam(user_id).then(resp => {
console.log(resp.data.team)
setGlobal({ setGlobal({
user: resp.data.user ? User.create(resp.data.user) : User.create(), user: resp.data.user ? User.create(resp.data.user) : User.create(),
team: resp.data.team ? Team.create(resp.data.team) : Team.create(), team: resp.data.team ? Team.create(resp.data.team) : Team.create(),

View file

@ -75,7 +75,7 @@ export default function ChatMessage(props: Props) {
return mappedPerm; // Return null for invalid keys return mappedPerm; // Return null for invalid keys
}).filter(Boolean); // Optionally filter out any null values }).filter(Boolean); // Optionally filter out any null values
} else { } else {
console.error("data.permissions is not an array or does not exist"); // console.error("data.permissions is not an array or does not exist");
perms = []; perms = [];
} }
return perms return perms