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
@@ -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());
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user