mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-03 22:16:54 +00:00
working sending messages
This commit is contained in:
1 parent
79857fd52a
commit
ccbc2d3b87
8 files changed
+74
-15
No files matched your search
@@ -2,10 +2,6 @@ import events from '../utils/events';
|
||||
import { Message } from '../../phone/src/common/interfaces/messages';
|
||||
import { sendMessageEvent } from '../utils/messages';
|
||||
|
||||
RegisterNuiCallbackType(events.MESSAGES_SEND_MESSAGE);
|
||||
on(`__cfx_nui:${events.MESSAGES_SEND_MESSAGE}`, (data: any) => {
|
||||
emitNet(events.MESSAGES_SEND_MESSAGE, data);
|
||||
})
|
||||
|
||||
/**
|
||||
* Twitter fetch messages
|
||||
@@ -23,4 +19,24 @@ onNet(events.MESSAGES_FETCH_MESSAGES_FAILED, () => {
|
||||
sendMessageEvent(events.MESSAGES_FETCH_MESSAGES_FAILED);
|
||||
});
|
||||
|
||||
emitNet(events.MESSAGES_FETCH_MESSAGES);
|
||||
// fetch messages on client launch
|
||||
emitNet(events.MESSAGES_FETCH_MESSAGES);
|
||||
|
||||
|
||||
/**
|
||||
* Messages send message
|
||||
*/
|
||||
RegisterNuiCallbackType(events.MESSAGES_SEND_MESSAGE);
|
||||
on(`__cfx_nui:${events.MESSAGES_SEND_MESSAGE}`, (data: any) => {
|
||||
emitNet(events.MESSAGES_SEND_MESSAGE, data.groupId, data.message);
|
||||
});
|
||||
|
||||
onNet(events.MESSAGES_SEND_MESSAGE_SUCCESS, (result: any) => {
|
||||
console.log(result);
|
||||
sendMessageEvent(events.MESSAGES_SEND_MESSAGE_SUCCESS, result);
|
||||
emitNet(events.MESSAGES_FETCH_MESSAGES);
|
||||
});
|
||||
|
||||
onNet(events.MESSAGES_SEND_MESSAGE_FAILED, () => {
|
||||
sendMessageEvent(events.MESSAGES_SEND_MESSAGE_FAILED);
|
||||
});
|
||||
@@ -18,6 +18,20 @@ interface GroupMessages {
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
async function createMessage(userIdentifier: string, groupId: string, message: string): Promise<any> {
|
||||
const query = `
|
||||
INSERT INTO npwd_messages
|
||||
(user_identifier, message, group_id)
|
||||
VALUES (?, ?, ?)
|
||||
`;
|
||||
const [results] = await pool.query(query, [
|
||||
userIdentifier,
|
||||
message,
|
||||
groupId,
|
||||
]);
|
||||
return results;
|
||||
}
|
||||
|
||||
async function getMessages(userIdentifier: string): Promise<Message[]> {
|
||||
const query = `
|
||||
SELECT
|
||||
@@ -96,3 +110,13 @@ onNet(events.MESSAGES_FETCH_MESSAGES, async () => {
|
||||
emitNet(events.MESSAGES_FETCH_MESSAGES_FAILED, getSource());
|
||||
}
|
||||
});
|
||||
|
||||
onNet(events.MESSAGES_SEND_MESSAGE, async (groupId: string, message: string) => {
|
||||
try {
|
||||
const _identifier = await useIdentifier();
|
||||
const result = await createMessage(_identifier, groupId, message)
|
||||
emitNet(events.MESSAGES_SEND_MESSAGE_SUCCESS, getSource(), result);
|
||||
} catch (e) {
|
||||
emitNet(events.MESSAGES_SEND_MESSAGE_FAILED, getSource());
|
||||
}
|
||||
});
|
||||
@@ -55,6 +55,8 @@ export default {
|
||||
|
||||
//messages
|
||||
MESSAGES_SEND_MESSAGE: 'phone:sendMessage',
|
||||
MESSAGES_SEND_MESSAGE_SUCCESS: 'phone:sendMessageSuccess',
|
||||
MESSAGES_SEND_MESSAGE_FAILED: 'phone:sendMessageFailed',
|
||||
MESSAGES_FETCH_MESSAGES: 'phone:fetchMessages',
|
||||
MESSAGES_FETCH_MESSAGES_SUCCESS: 'phone:fetchMessagesSuccess',
|
||||
MESSAGES_FETCH_MESSAGES_FAILED: 'phone:fetchMessagesFailed',
|
||||
|
||||
Reference in new issue
Block a user