mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
feat/messages additions (in memory of Leonard Nimoy) (#118)
* feat(resouces/messages): broadcast messagse to participants * feat(phone/messages): notifications for messages * remove weird empty onNet * reformat? * last reformat! This pr will be squashed * tweak(phone/messages): send groupName to notification alert * fix identifer * fixing notification groupName * resbasee...i think * feat(messages): check for unread messages * send nui event is count > 0 * remove usless test * import.sql update * Refactor NotificationsProvider and fix messages notifications * Send groupId on message broadcast * Update phone/src/apps/messages/components/modal/Conversation.tsx * Update phone/src/apps/messages/hooks/useMessageNotifications.ts * Update phone/src/os/notifications/providers/NotificationsProvider.tsx * Update phone/src/common/typings/messages.ts * Update phone/src/apps/messages/hooks/useMessageNotifications.ts * clean sql file * Update resources/server/sv_messages.ts * Fetch message groups when other person created for you * fix sql * Select unreadCount from messageGroups * whatever husky again * Add members menu and add contact in messages * Add from group bubbles * Fix messages scroll with new msg * Message image menu flicker + justify bottom messages * Improve debugging * Add container to Slider * Improve logger * Fix create message * add creator identifier to group hash * Fix dafuq i broke * group_id bigger varchar in column * group_id bigger varchar in column * Phone visibility default browser * Add debugging Co-authored-by: J Francisco Rader <[email protected]> Co-authored-by: J Francisco Rader <[email protected]>
This commit is contained in:
38 files changed
+634
-328
No files matched your search
@@ -1,76 +1,92 @@
|
||||
import React, { useEffect, useRef, useState } from 'react';
|
||||
import { Slide, Paper, Typography, Button } from '@material-ui/core';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import {
|
||||
Slide,
|
||||
Paper,
|
||||
Typography,
|
||||
Button,
|
||||
Box,
|
||||
List,
|
||||
ListItem,
|
||||
ListItemText,
|
||||
ListItemSecondaryAction,
|
||||
} from '@material-ui/core';
|
||||
import ArrowBackIcon from '@material-ui/icons/ArrowBack';
|
||||
|
||||
import MoreVertIcon from '@material-ui/icons/MoreVert';
|
||||
import PersonAddIcon from '@material-ui/icons/PersonAdd';
|
||||
import useStyles from './modal.styles';
|
||||
import useMessages from '../../hooks/useMessages';
|
||||
import Conversation, { CONVERSATION_ELEMENT_ID } from './Conversation';
|
||||
import MessageSkeletonList from './MessageSkeletonList';
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import { useQueryParams } from '../../../../common/hooks/useQueryParams';
|
||||
import { MessageGroup } from '../../../../common/typings/messages';
|
||||
import { useHistory, useParams } from 'react-router-dom';
|
||||
import { useHistory, useLocation, useParams } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import Modal from '../../../../ui/components/Modal';
|
||||
import { useContacts } from '../../../contacts/hooks/useContacts';
|
||||
import { useSimcard } from '../../../../os/simcard/hooks/useSimcard';
|
||||
|
||||
const LARGE_HEADER_CHARS = 30;
|
||||
const MAX_HEADER_CHARS = 80;
|
||||
const MINIMUM_LOAD_TIME = 750;
|
||||
const MESSAGES_REFRESH_RATE = 5000;
|
||||
|
||||
const memberDisplay = (display, number, myNumber, t) => {
|
||||
if (myNumber === number) {
|
||||
return (
|
||||
<span>
|
||||
{t('APPS_MESSAGES_ME')} ({number})
|
||||
</span>
|
||||
);
|
||||
}
|
||||
if (display !== number) {
|
||||
return (
|
||||
<span>
|
||||
{display} ({number})
|
||||
</span>
|
||||
);
|
||||
}
|
||||
return <span>{number}</span>;
|
||||
};
|
||||
|
||||
export const MessageModal = () => {
|
||||
const classes = useStyles();
|
||||
const history = useHistory();
|
||||
const activeMessageGroup = useQueryParams<MessageGroup>();
|
||||
const { number: myNumber } = useSimcard();
|
||||
const { pathname } = useLocation();
|
||||
const { t } = useTranslation();
|
||||
const { groupId } = useParams<{ groupId: string }>();
|
||||
const { messages, setMessages } = useMessages();
|
||||
const { messages, setMessages, activeMessageGroup, setActiveMessageGroup } = useMessages();
|
||||
const { getContactByNumber, getDisplayByNumber } = useContacts();
|
||||
|
||||
const [minimumLoadPassed, setMimimumLoadPassed] = useState(false);
|
||||
|
||||
const minLoadTimeoutRef = useRef(null);
|
||||
const fetchInterval = useRef(null);
|
||||
const [groupActionsOpen, setGroupActionsOpen] = useState(false);
|
||||
|
||||
const closeModal = () => {
|
||||
history.push('/messages');
|
||||
setMessages(null);
|
||||
setMimimumLoadPassed(false);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!groupId) return;
|
||||
|
||||
minLoadTimeoutRef.current = setTimeout(() => {
|
||||
setMimimumLoadPassed(true);
|
||||
}, MINIMUM_LOAD_TIME);
|
||||
|
||||
fetchInterval.current = setInterval(() => {
|
||||
if (!groupId) return;
|
||||
Nui.send('phone:fetchMessages', {
|
||||
groupId,
|
||||
});
|
||||
}, MESSAGES_REFRESH_RATE);
|
||||
|
||||
return () => {
|
||||
clearInterval(fetchInterval.current);
|
||||
fetchInterval.current = null;
|
||||
clearTimeout(minLoadTimeoutRef.current);
|
||||
minLoadTimeoutRef.current = null;
|
||||
};
|
||||
}, [groupId]);
|
||||
setActiveMessageGroup(groupId);
|
||||
}, [groupId, setActiveMessageGroup]);
|
||||
|
||||
useEffect(() => {
|
||||
// when we get a new message group we should scroll to the
|
||||
// bottom to show the latest messages
|
||||
if (activeMessageGroup) {
|
||||
if (messages) {
|
||||
const element = document.getElementById(CONVERSATION_ELEMENT_ID);
|
||||
if (element) {
|
||||
element.scrollTop = element.scrollHeight;
|
||||
}
|
||||
}
|
||||
}, [activeMessageGroup, minimumLoadPassed]);
|
||||
}, [messages]);
|
||||
|
||||
// we add a minimum (but short) load time here so that
|
||||
// there isn't a quick flash of loading and immediately
|
||||
// another flash to the tweets screen.
|
||||
const hasLoaded = messages && minimumLoadPassed;
|
||||
// sends all unread messages
|
||||
useEffect(() => {
|
||||
if (activeMessageGroup?.groupId && activeMessageGroup.unreadCount > 0) {
|
||||
Nui.send('phone:setReadMessages', {
|
||||
groupId: activeMessageGroup.groupId,
|
||||
});
|
||||
}
|
||||
}, [activeMessageGroup]);
|
||||
|
||||
const hasLoaded = !!(messages && activeMessageGroup);
|
||||
|
||||
// don't allow too many characters, it takes too much room
|
||||
let header = activeMessageGroup ? activeMessageGroup.groupDisplay : '';
|
||||
@@ -80,23 +96,73 @@ export const MessageModal = () => {
|
||||
const headerClass =
|
||||
header.length > LARGE_HEADER_CHARS ? classes.largeGroupDisplay : classes.groupdisplay;
|
||||
|
||||
const handleAddContact = (number) => {
|
||||
const exists = getContactByNumber(number);
|
||||
if (exists) {
|
||||
return history.push(`/contacts/${exists.id}/?referal=${pathname}`);
|
||||
}
|
||||
return history.push(`/contacts/-1/?addNumber=${number}&referal=${pathname}`);
|
||||
};
|
||||
|
||||
const phoneNumbers = activeMessageGroup?.phoneNumbers || [];
|
||||
|
||||
return (
|
||||
<Slide direction="left" in={!!activeMessageGroup}>
|
||||
<Paper className={classes.modalRoot}>
|
||||
<Paper className={classes.topContainer}>
|
||||
<Button onClick={closeModal}>
|
||||
<ArrowBackIcon fontSize="large" />
|
||||
</Button>
|
||||
<Typography variant="h5" className={headerClass}>
|
||||
{header}
|
||||
</Typography>
|
||||
<div>
|
||||
<Modal visible={groupActionsOpen} handleClose={() => setGroupActionsOpen(false)}>
|
||||
<Typography variant="h6">{t('APPS_MESSAGES_MEMBERS_TITLE')}</Typography>
|
||||
<List>
|
||||
{phoneNumbers.map((number) => {
|
||||
const display = getDisplayByNumber(number);
|
||||
return (
|
||||
<ListItem divider>
|
||||
<ListItemText>{memberDisplay(display, number, myNumber, t)}</ListItemText>
|
||||
{!getContactByNumber(number) && myNumber !== number && (
|
||||
<ListItemSecondaryAction>
|
||||
<Button onClick={() => handleAddContact(number)}>
|
||||
<PersonAddIcon />
|
||||
</Button>
|
||||
</ListItemSecondaryAction>
|
||||
)}
|
||||
</ListItem>
|
||||
);
|
||||
})}
|
||||
</List>
|
||||
</Modal>
|
||||
<Slide direction="left" in={!!activeMessageGroup}>
|
||||
<Paper className={classes.modalRoot}>
|
||||
<Paper>
|
||||
<Box display="flex" justifyContent="space-between">
|
||||
<Button onClick={closeModal}>
|
||||
<ArrowBackIcon fontSize="large" />
|
||||
</Button>
|
||||
<Typography variant="h5" className={headerClass}>
|
||||
{header}
|
||||
</Typography>
|
||||
{activeMessageGroup?.isGroupChat ? (
|
||||
<Button>
|
||||
<MoreVertIcon onClick={() => setGroupActionsOpen(true)} fontSize="large" />
|
||||
</Button>
|
||||
) : (
|
||||
<Button>
|
||||
<PersonAddIcon
|
||||
onClick={() => handleAddContact(phoneNumbers.find((n) => myNumber !== n))}
|
||||
fontSize="large"
|
||||
/>
|
||||
</Button>
|
||||
)}
|
||||
</Box>
|
||||
</Paper>
|
||||
{hasLoaded ? (
|
||||
<Conversation
|
||||
onClickDisplay={handleAddContact}
|
||||
messages={messages}
|
||||
activeMessageGroup={activeMessageGroup}
|
||||
/>
|
||||
) : (
|
||||
<MessageSkeletonList />
|
||||
)}
|
||||
</Paper>
|
||||
{hasLoaded ? (
|
||||
<Conversation messages={messages} activeMessageGroup={activeMessageGroup} />
|
||||
) : (
|
||||
<MessageSkeletonList />
|
||||
)}
|
||||
</Paper>
|
||||
</Slide>
|
||||
</Slide>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
Reference in new issue
Block a user