mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-05 06:28:51 +00:00
tweak(server/messages): General cleanup changes and added missing docs
I personally don't like if else chains, so changed to if checks
This commit is contained in:
1 parent
adf9758d9f
commit
78961b788f
1 file changed
+16
-12
@@ -5,7 +5,6 @@ import { CreateMessageGroupResult, Message, MessageGroup } from '../../typings/m
|
|||||||
import { pool, withTransaction } from './db';
|
import { pool, withTransaction } from './db';
|
||||||
import { getIdentifier, getSource, getPlayerFromIdentifier } from './functions';
|
import { getIdentifier, getSource, getPlayerFromIdentifier } from './functions';
|
||||||
import { mainLogger } from './sv_logger';
|
import { mainLogger } from './sv_logger';
|
||||||
import { group } from 'console';
|
|
||||||
|
|
||||||
const messageLogger = mainLogger.child({ module: 'messages' });
|
const messageLogger = mainLogger.child({ module: 'messages' });
|
||||||
|
|
||||||
@@ -172,7 +171,7 @@ async function createMessageGroup(
|
|||||||
(user_identifier, group_id, participant_identifier)
|
(user_identifier, group_id, participant_identifier)
|
||||||
VALUES (?, ?, ?)
|
VALUES (?, ?, ?)
|
||||||
`;
|
`;
|
||||||
const [results] = await pool.query(query, [userIdentifier, groupId, participantIdentifier]);
|
await pool.query(query, [userIdentifier, groupId, participantIdentifier]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -379,7 +378,8 @@ function getIdentifiersFromParticipants(groupId: string) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the current message isRead to 0 for said player
|
* Sets the current message isRead to 0 for said player
|
||||||
* @param id
|
* @param groupId The unique group ID for the message
|
||||||
|
* @param identifier The identifier for the player
|
||||||
*/
|
*/
|
||||||
async function setMessageRead(groupId: string, identifier: string) {
|
async function setMessageRead(groupId: string, identifier: string) {
|
||||||
const query =
|
const query =
|
||||||
@@ -408,32 +408,37 @@ onNet(
|
|||||||
const result = await createMessageGroupsFromPhoneNumbers(_identifier, phoneNumbers, label);
|
const result = await createMessageGroupsFromPhoneNumbers(_identifier, phoneNumbers, label);
|
||||||
|
|
||||||
if (result.error && result.duplicate) {
|
if (result.error && result.duplicate) {
|
||||||
emitNet(events.MESSAGES_ACTION_RESULT, _source, {
|
return emitNet(events.MESSAGES_ACTION_RESULT, _source, {
|
||||||
message: 'MESSAGES_MESSAGE_GROUP_DUPLICATE',
|
message: 'MESSAGES_MESSAGE_GROUP_DUPLICATE',
|
||||||
type: 'error',
|
type: 'error',
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// if the phoneNumber is invalid
|
// if the phoneNumber is invalid
|
||||||
} else if (result.error && result.phoneNumber) {
|
if (result.error && result.phoneNumber) {
|
||||||
emitNet(events.MESSAGES_ACTION_RESULT, _source, {
|
return emitNet(events.MESSAGES_ACTION_RESULT, _source, {
|
||||||
message: 'MESSAGES_INVALID_PHONE_NUMBER',
|
message: 'MESSAGES_INVALID_PHONE_NUMBER',
|
||||||
type: 'error',
|
type: 'error',
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// if you are try to add yourself
|
// if you are try to add yourself
|
||||||
} else if (result.error && result.mine) {
|
if (result.error && result.mine) {
|
||||||
emitNet(events.MESSAGES_ACTION_RESULT, _source, {
|
return emitNet(events.MESSAGES_ACTION_RESULT, _source, {
|
||||||
message: 'MESSAGES_MESSAGE_GROUP_CREATE_MINE',
|
message: 'MESSAGES_MESSAGE_GROUP_CREATE_MINE',
|
||||||
type: 'error',
|
type: 'error',
|
||||||
});
|
});
|
||||||
} else if (result.error) {
|
}
|
||||||
|
|
||||||
// if it just fails, welp
|
// if it just fails, welp
|
||||||
|
if (result.error) {
|
||||||
emitNet(events.MESSAGES_CREATE_MESSAGE_GROUP_FAILED, _source, result);
|
emitNet(events.MESSAGES_CREATE_MESSAGE_GROUP_FAILED, _source, result);
|
||||||
emitNet(events.MESSAGES_ACTION_RESULT, _source, {
|
return emitNet(events.MESSAGES_ACTION_RESULT, _source, {
|
||||||
message: `MESSAGES_MESSAGE_GROUP_CREATE_FAILED:`,
|
message: `MESSAGES_MESSAGE_GROUP_CREATE_FAILED:`,
|
||||||
type: 'error',
|
type: 'error',
|
||||||
});
|
});
|
||||||
} else {
|
}
|
||||||
|
|
||||||
emitNet(events.MESSAGES_CREATE_MESSAGE_GROUP_SUCCESS, _source, result);
|
emitNet(events.MESSAGES_CREATE_MESSAGE_GROUP_SUCCESS, _source, result);
|
||||||
if (result.identifiers) {
|
if (result.identifiers) {
|
||||||
for (const participantId of result.identifiers) {
|
for (const participantId of result.identifiers) {
|
||||||
@@ -444,7 +449,6 @@ onNet(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emitNet(events.MESSAGES_CREATE_MESSAGE_GROUP_FAILED, _source);
|
emitNet(events.MESSAGES_CREATE_MESSAGE_GROUP_FAILED, _source);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user