Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c964432
feat(messages): Store user that created group/chat
SamShanks1 Jun 5, 2022
767d0e6
fix(messages): createdBy errors
SamShanks1 Jun 5, 2022
7096ea5
feat(messages): remove group member
SamShanks1 Jun 6, 2022
dbae408
fix(messages): get createdBy from db
SamShanks1 Jun 6, 2022
c7b02e2
fix(files): delete accidental upload
SamShanks1 Jun 6, 2022
64dd1ce
feat(messages): leave group chats
SamShanks1 Jun 6, 2022
3168c0c
fix(messages): review changes
SamShanks1 Jun 10, 2022
7bed1b7
fix(messages): event typings
SamShanks1 Jun 10, 2022
ccf1274
fix(messages): nested if statement & error logging
SamShanks1 Jun 10, 2022
1cf33e3
fix(messages): created by defined on server
SamShanks1 Jun 10, 2022
a9748cf
fix(messages): removegroupmember endpoint validation
SamShanks1 Jun 10, 2022
692fafa
chore(messages): cleanup
SamShanks1 Jun 10, 2022
abd0155
chore(messages): cleanup
SamShanks1 Jun 10, 2022
876a3dd
feat(messages): system messages
SamShanks1 Jun 11, 2022
6873390
Merge branch 'master' into master
SamShanks1 Jun 11, 2022
ac580da
fix(messages): errors
SamShanks1 Jun 11, 2022
1f6f048
feat(messages): translations
SamShanks1 Jun 11, 2022
de9541e
feat(messages): use name for avatar
SamShanks1 Jun 11, 2022
3083315
refactor(messages): group chat rework
SamShanks1 Jul 2, 2022
e263c4f
refactor(messages): if owner leaves then set new owner
SamShanks1 Jul 2, 2022
f4126dc
feat: add participants
SamShanks1 Aug 14, 2022
831b92c
Merge branch 'master' into master
SamShanks1 Sep 26, 2022
aea51e1
fix(message): merge mistakes
SamShanks1 Sep 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions import.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,17 @@
# ALTER TABLE npwd_messages ADD COLUMN `is_embed` tinyint(4) NOT NULL DEFAULT 0;
# ALTER TABLE npwd_messages ADD COLUMN `embed` varchar(512) NOT NULL DEFAULT '';


# Group Chat Overhaul SQL Update
# ALTER TABLE npwd_messages ADD COLUMN `is_system` tinyint(4) NOT NULL DEFAULT 0;
# ALTER TABLE npwd_messages ADD COLUMN `system_type` varchar(48) NOT NULL DEFAULT '';
# ALTER TABLE npwd_messages ADD COLUMN `system_number` varchar(48) NOT NULL DEFAULT '';
# ALTER TABLE npwd_messages_conversations ADD COLUMN `owner` varchar(48) NOT NULL DEFAULT '';

#match voice messages update
# ALTER TABLE npwd_match_profiles ADD COLUMN `voiceMessage` varchar(512) DEFAULT NULL;


CREATE TABLE IF NOT EXISTS `npwd_twitter_profiles`
(
`id` int NOT NULL AUTO_INCREMENT,
Expand Down Expand Up @@ -148,6 +156,9 @@ CREATE TABLE IF NOT EXISTS `npwd_messages`
`author` varchar(255) NOT NULL,
`is_embed` tinyint(4) NOT NULL default 0,
`embed` varchar(512) NOT NULL DEFAULT '',
`is_system` tinyint(4) NOT NULL default 0,
`system_type` varchar(48) NOT NULL default '',
`system_number` varchar(48) NOT NULL default '',
PRIMARY KEY (id),
INDEX `user_identifier` (`user_identifier`)
);
Expand All @@ -160,6 +171,7 @@ CREATE TABLE `npwd_messages_conversations`
`createdAt` TIMESTAMP NOT NULL DEFAULT current_timestamp(),
`updatedAt` TIMESTAMP NOT NULL DEFAULT current_timestamp(),
`last_message_id` INT(11) NULL DEFAULT NULL,
`owner` varchar(48) NOT NULL DEFAULT '',
`is_group_chat` TINYINT(4) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`) USING BTREE
);
Expand Down
16 changes: 14 additions & 2 deletions phone/src/apps/messages/components/list/MessageGroupItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,21 @@ const MessageGroupItem = ({
invisible={messageConversation.unreadCount <= 0}
>
{messageConversation.isGroupChat ? (
<MuiAvatar alt={messageConversation.label} />
<>
{messageConversation.avatar ? (
<MuiAvatar alt={messageConversation.label} src={messageConversation.avatar} />
) : (
<MuiAvatar alt={messageConversation.label} />
)}
</>
) : (
<MuiAvatar alt={getContact()?.display ?? ''} src={getContact()?.avatar} />
<>
{getContact()?.avatar ? (
<MuiAvatar alt={getContact()?.display ?? ''} src={getContact()?.avatar} />
) : (
<MuiAvatar>{getContact().display.charAt(0)}</MuiAvatar>
)}
</>
)}
</Badge>
</ListItemAvatar>
Expand Down
109 changes: 109 additions & 0 deletions phone/src/apps/messages/components/modal/AddParticipantModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import React, { useEffect, useState } from 'react';
import Modal from '../../../../ui/components/Modal';
import { Box, Popper, Autocomplete, Button } from '@mui/material';
import { TextField } from '@ui/components/Input';
import { PreDBContact, Contact } from '@typings/contact';
import { useContactsValue } from '../../../contacts/hooks/state';
import { useTranslation } from 'react-i18next';

const AddParticipantModal = ({
open,
onClose,
participants,
myPhoneNumber,
handleAddGroupMembers,
}: {
open: boolean;
onClose: () => void;
participants: string[];
myPhoneNumber: string;
handleAddGroupMembers: (members: string[]) => void;
}) => {
const [newParticipants, setNewParticipants] = useState<PreDBContact[]>([]);
const [allowedContact, setAllowedContact] = useState<Contact[]>([]);
const contacts = useContactsValue();
const [t] = useTranslation();

useEffect(() => {
setAllowedContact(contacts.filter((contact) => !participants.includes(contact.number)));
}, [participants, contacts]);

const handleSubmit = () => {
const selectedParticipants = newParticipants.map((participant) => participant.number);
handleAddGroupMembers(selectedParticipants);
setNewParticipants([]);
onClose();
};

const handleCLose = () => {
setNewParticipants([]);
onClose();
};

const onAutocompleteChange = (_e, value: any) => {
const lastIdx = value.length - 1;

// If we have a string, it means that we don't have the number as a contact.
if (typeof value[lastIdx] === 'string') {
value.splice(lastIdx, 1, { number: value[lastIdx] });
setNewParticipants(value);
return;
}
// If we have the contact
setNewParticipants(value as any[]);
};

const renderAutocompleteInput = (params) => (
<TextField
{...params}
fullWidth
label={t('MESSAGES.INPUT_NAME_OR_NUMBER')}
inputProps={{
...params.inputProps,
onKeyPress: (e) => {
if (e.key === 'Enter' && e.currentTarget.value) {
e.preventDefault();
onAutocompleteChange(e, [...newParticipants, e.currentTarget.value]);
}
},
autoFocus: true,
}}
/>
);

const isYourself = newParticipants.find((p) => p.number === myPhoneNumber);
const disableSubmit = !newParticipants?.length || !!isYourself;

return (
<Modal visible={open} handleClose={handleCLose}>
<Box px={2} py={3}>
<Autocomplete
value={newParticipants}
freeSolo
disablePortal
PopperComponent={(props) => <Popper placement="bottom-start" {...props} />}
multiple
autoHighlight
options={allowedContact || []}
ListboxProps={{ style: { marginLeft: 10 } }}
getOptionLabel={(contact) => contact.display || contact.number}
onChange={onAutocompleteChange}
renderInput={renderAutocompleteInput}
/>
</Box>
<Button
onClick={handleSubmit}
disabled={disableSubmit}
variant="contained"
fullWidth
sx={{ mb: 1 }}
color="primary"
type="submit"
>
{t('GENERIC.ADD')}
</Button>
</Modal>
);
};

export default AddParticipantModal;
Loading