merged from serial id to uuid for accounts and conversations ids
This commit is contained in:
@@ -13,7 +13,7 @@ export async function getContactsList(): Promise<ContactsProps[]> {
|
||||
}
|
||||
}
|
||||
|
||||
export async function setContactStatus(conversation_id: number, read: boolean) {
|
||||
export async function setContactStatus(conversation_id: string, read: boolean) {
|
||||
try {
|
||||
const response = await axiosClient.put(
|
||||
`/api/chat/contacts/${conversation_id}`,
|
||||
@@ -40,7 +40,7 @@ export async function sendContact(contact: string) {
|
||||
}
|
||||
|
||||
export async function getMessages(
|
||||
contact: number | null,
|
||||
contact: string | null,
|
||||
cursor: number | null = 0,
|
||||
limit: number = 50,
|
||||
): Promise<{ messages: ChatMessages[] }> {
|
||||
|
||||
@@ -48,8 +48,8 @@ function ContactsList({
|
||||
'added to group',
|
||||
(msg: {
|
||||
username: string;
|
||||
user_id: number;
|
||||
group_id: number;
|
||||
user_id: string;
|
||||
group_id: string;
|
||||
isadmin: false;
|
||||
}) => {
|
||||
console.log('added to group, fetching contacts');
|
||||
@@ -57,10 +57,6 @@ function ContactsList({
|
||||
fetchContacts();
|
||||
},
|
||||
);
|
||||
|
||||
return () => {
|
||||
socket?.off('added to group');
|
||||
};
|
||||
}, []);
|
||||
|
||||
const fetchContacts = async () => {
|
||||
@@ -70,7 +66,7 @@ function ContactsList({
|
||||
setContactsList(contacts);
|
||||
};
|
||||
|
||||
async function removeContact(contactId: number, conversation_id: number) {
|
||||
async function removeContact(contactId: number, conversation_id: string) {
|
||||
try {
|
||||
console.log('delete contact, conversation_id: ', conversation_id);
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ type MessagesAreaProps = {
|
||||
updateContactStatus: (contact: ContactsProps, read: boolean) => void;
|
||||
messageHandler: (msg: ChatMessages) => void;
|
||||
setContactsList: React.Dispatch<React.SetStateAction<ContactsProps[]>>;
|
||||
fetchPreviousMessages: (contact: number | null) => Promise<void>;
|
||||
fetchPreviousMessages: (contact: string | null) => Promise<void>;
|
||||
errorMessage: string | null;
|
||||
contactsList: ContactsProps[];
|
||||
};
|
||||
@@ -194,7 +194,7 @@ function MessagesArea({
|
||||
|
||||
socket.on(
|
||||
'delete message',
|
||||
(msg: { conversation_id: number; message_id: number }) => {
|
||||
(msg: { conversation_id: string; message_id: number }) => {
|
||||
console.log('deleted message from state');
|
||||
setMessages((prevMessages) =>
|
||||
prevMessages.filter(
|
||||
|
||||
@@ -14,7 +14,7 @@ import { useOutletContext } from 'react-router-dom';
|
||||
import LoadingWheel from '@/components/chat/LoadingWheel.tsx';
|
||||
|
||||
type ParticipantsProps = {
|
||||
user_id: number;
|
||||
user_id: string;
|
||||
username: string;
|
||||
isadmin: boolean;
|
||||
};
|
||||
@@ -75,8 +75,8 @@ function ParticipantsBar({
|
||||
'added to group',
|
||||
(msg: {
|
||||
username: string;
|
||||
user_id: number;
|
||||
group_id: number;
|
||||
user_id: string;
|
||||
group_id: string;
|
||||
isadmin: false;
|
||||
}) => {
|
||||
const { group_id } = msg;
|
||||
@@ -112,7 +112,7 @@ function ParticipantsBar({
|
||||
},
|
||||
);
|
||||
|
||||
socket.on('left group', (msg: { user_id: number; group_id: number }) => {
|
||||
socket.on('left group', (msg: { user_id: string; group_id: string }) => {
|
||||
console.log(`(socket on "left group")`, msg);
|
||||
// Initialize contact again to clear messages and participants list
|
||||
if (
|
||||
@@ -128,10 +128,11 @@ function ParticipantsBar({
|
||||
|
||||
return () => {
|
||||
socket?.off('left group');
|
||||
socket?.off('added to group');
|
||||
};
|
||||
}, [contact, participants]);
|
||||
|
||||
const handleRemoveUser = async (userId: number) => {
|
||||
const handleRemoveUser = async (userId: string) => {
|
||||
try {
|
||||
setIsLoading(true);
|
||||
socket?.emit(
|
||||
|
||||
@@ -24,9 +24,7 @@ function UserProfile() {
|
||||
</div>
|
||||
|
||||
<div className="text-gray-200">
|
||||
<p>
|
||||
{user?.user_id} {user.username}
|
||||
</p>
|
||||
<p>{user.username}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -14,22 +14,22 @@ import ParticipantsBar from '@/components/chat/ParticipantsBar.tsx';
|
||||
export type ChatMessages = {
|
||||
sender: string;
|
||||
message: string;
|
||||
recipient: number; // conversation_id
|
||||
recipient: string; // conversation_id
|
||||
message_id: number;
|
||||
pending: boolean;
|
||||
attachment_urls: string[] | null;
|
||||
sender_id: number;
|
||||
conversation_id: number;
|
||||
sender_id: string;
|
||||
conversation_id: string;
|
||||
sent_at: Date;
|
||||
};
|
||||
|
||||
export type ContactsProps = {
|
||||
read: boolean;
|
||||
username: string;
|
||||
user_id: number;
|
||||
user_id: string;
|
||||
id: number;
|
||||
type: 'direct' | 'group';
|
||||
conversation_id: number;
|
||||
conversation_id: string;
|
||||
last_active: string;
|
||||
};
|
||||
|
||||
@@ -92,7 +92,7 @@ function Chat() {
|
||||
}
|
||||
}
|
||||
|
||||
const fetchMessages = async (conversation_id: number) => {
|
||||
const fetchMessages = async (conversation_id: string) => {
|
||||
console.log('Fetching messages for: ', conversation_id);
|
||||
try {
|
||||
const messages = await getMessages(conversation_id);
|
||||
@@ -115,7 +115,7 @@ function Chat() {
|
||||
}
|
||||
};
|
||||
|
||||
const fetchPreviousMessages = async (contact: number | null) => {
|
||||
const fetchPreviousMessages = async (contact: string | null) => {
|
||||
if (!hasMoreMessages) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ function initializeSocket(token: string): Socket | null {
|
||||
}
|
||||
|
||||
async function joinRoom(
|
||||
conversation_id: number,
|
||||
conversation_id: string,
|
||||
): Promise<{ success: boolean; message: string }> {
|
||||
console.log('Attempting to join room:', conversation_id);
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import { axiosClient } from '../App.tsx';
|
||||
|
||||
export type UsernameType = {
|
||||
username: string | null;
|
||||
user_id: number | null;
|
||||
user_id: string | null;
|
||||
};
|
||||
|
||||
function ProtectedRoutes() {
|
||||
|
||||
Reference in New Issue
Block a user