mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
refactor(server/source-handling): Altered how we handle source
These changes are made in case source is not guranteed to remain the same Due to how JS should operate, this shouldn't be an issue but this just ensures that
This commit is contained in:
1 parent
acb8e056c3
commit
1aa6a383ab
12 files changed
+222
-140
No files matched your search
@@ -7,7 +7,7 @@ import {
|
||||
CreateMessageGroupResult,
|
||||
} from '../../phone/src/common/typings/messages';
|
||||
import { pool, withTransaction } from './db';
|
||||
import { getSource, useIdentifier } from './functions';
|
||||
import { getSource, getIdentifier } from './functions';
|
||||
import { mainLogger } from './sv_logger';
|
||||
|
||||
const messageLogger = mainLogger.child({ module: 'messages' });
|
||||
@@ -376,16 +376,17 @@ async function createMessageGroupsFromPhoneNumbers(
|
||||
}
|
||||
|
||||
onNet(events.MESSAGES_FETCH_MESSAGE_GROUPS, async () => {
|
||||
const _source = getSource();
|
||||
try {
|
||||
const _identifier = await useIdentifier();
|
||||
const messageGroups = await getFormattedMessageGroups(_identifier);
|
||||
const identifier = getIdentifier(_source);
|
||||
const messageGroups = await getFormattedMessageGroups(identifier);
|
||||
emitNet(
|
||||
events.MESSAGES_FETCH_MESSAGE_GROUPS_SUCCESS,
|
||||
getSource(),
|
||||
messageGroups
|
||||
);
|
||||
} catch (e) {
|
||||
emitNet(events.MESSAGES_FETCH_MESSAGE_GROUPS_FAILED, getSource());
|
||||
emitNet(events.MESSAGES_FETCH_MESSAGE_GROUPS_FAILED, _source);
|
||||
messageLogger.error(`Failed to fetch messages groups, ${e.message}`);
|
||||
}
|
||||
});
|
||||
@@ -393,8 +394,9 @@ onNet(events.MESSAGES_FETCH_MESSAGE_GROUPS, async () => {
|
||||
onNet(
|
||||
events.MESSAGES_CREATE_MESSAGE_GROUP,
|
||||
async (phoneNumbers: string[], label: string = null) => {
|
||||
const _source = getSource();
|
||||
try {
|
||||
const _identifier = await useIdentifier();
|
||||
const _identifier = await getIdentifier(_source);
|
||||
const result = await createMessageGroupsFromPhoneNumbers(
|
||||
_identifier,
|
||||
phoneNumbers,
|
||||
@@ -416,32 +418,40 @@ onNet(
|
||||
}
|
||||
} catch (e) {
|
||||
emitNet(events.MESSAGES_CREATE_MESSAGE_GROUP_FAILED, getSource());
|
||||
messageLogger.error(`Failed to create message group, ${e.message}`);
|
||||
messageLogger.error(`Failed to create message group, ${e.message}`, {
|
||||
source: _source,
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
onNet(events.MESSAGES_FETCH_MESSAGES, async (groupId: string) => {
|
||||
const _source = getSource();
|
||||
try {
|
||||
const _identifier = await useIdentifier();
|
||||
const _identifier = await getIdentifier(_source);
|
||||
const messages = await getMessages(_identifier, groupId);
|
||||
emitNet(events.MESSAGES_FETCH_MESSAGES_SUCCESS, getSource(), messages);
|
||||
emitNet(events.MESSAGES_FETCH_MESSAGES_SUCCESS, _source, messages);
|
||||
} catch (e) {
|
||||
emitNet(events.MESSAGES_FETCH_MESSAGES_FAILED, getSource());
|
||||
messageLogger.error(`Failed to fetch messages, ${e.message}`);
|
||||
emitNet(events.MESSAGES_FETCH_MESSAGES_FAILED, _source);
|
||||
messageLogger.error(`Failed to fetch messages, ${e.message}`, {
|
||||
source: _source,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
onNet(
|
||||
events.MESSAGES_SEND_MESSAGE,
|
||||
async (groupId: string, message: string) => {
|
||||
const _source = getSource();
|
||||
try {
|
||||
const _identifier = await useIdentifier();
|
||||
const _identifier = getIdentifier(_source);
|
||||
await createMessage(_identifier, groupId, message);
|
||||
emitNet(events.MESSAGES_SEND_MESSAGE_SUCCESS, getSource(), groupId);
|
||||
emitNet(events.MESSAGES_SEND_MESSAGE_SUCCESS, _source, groupId);
|
||||
} catch (e) {
|
||||
emitNet(events.MESSAGES_SEND_MESSAGE_FAILED, getSource());
|
||||
messageLogger.error(`Failed to send message, ${e.message}`);
|
||||
emitNet(events.MESSAGES_SEND_MESSAGE_FAILED, _source);
|
||||
messageLogger.error(`Failed to send message, ${e.message}`, {
|
||||
source: _source,
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
Reference in new issue
Block a user