rename MessageQueue event to be more easily searchable

success -> sendSuccess
fail -> sendFail
pull/1381/head
Audric Ackermann 4 years ago
parent 5c55a9411f
commit 80523a9a3e
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -226,11 +226,14 @@ export class SessionInboxView extends React.Component<Props, State> {
this.handleMessageSentSuccess = this.handleMessageSentSuccess.bind(this);
getMessageQueue().events.addListener(
'success',
'sendSuccess',
this.handleMessageSentSuccess
);
getMessageQueue().events.addListener('fail', this.handleMessageSentFailure);
getMessageQueue().events.addListener(
'sendFail',
this.handleMessageSentFailure
);
window.Whisper.events.on('messageExpired', messageExpired);
window.Whisper.events.on('messageChanged', messageChanged);

@ -65,7 +65,7 @@ export class MessageQueue implements MessageQueueInterface {
const result = await MessageSender.sendToOpenGroup(message);
// sendToOpenGroup returns -1 if failed or an id if succeeded
if (result.serverId < 0) {
this.events.emit('fail', message, error);
this.events.emit('sendFail', message, error);
} else {
const messageEventData = {
pubKey: message.group.groupId,
@ -73,7 +73,7 @@ export class MessageQueue implements MessageQueueInterface {
serverId: result.serverId,
serverTimestamp: result.serverTimestamp,
};
this.events.emit('success', message);
this.events.emit('sendSuccess', message);
window.Whisper.events.trigger('publicMessageSent', messageEventData);
}
@ -82,7 +82,7 @@ export class MessageQueue implements MessageQueueInterface {
`Failed to send message to open group: ${message.group.server}`,
e
);
this.events.emit('fail', message, error);
this.events.emit('sendFail', message, error);
}
return;
@ -164,9 +164,9 @@ export class MessageQueue implements MessageQueueInterface {
const job = async () => {
try {
const wrappedEnvelope = await MessageSender.send(message);
this.events.emit('success', message, wrappedEnvelope);
this.events.emit('sendSuccess', message, wrappedEnvelope);
} catch (e) {
this.events.emit('fail', message, e);
this.events.emit('sendFail', message, e);
} finally {
// Remove from the cache because retrying is done in the sender
void this.pendingMessageCache.remove(message);

@ -15,11 +15,11 @@ type GroupMessageType =
| MediumGroupMessage;
export interface MessageQueueInterfaceEvents {
success: (
sendSuccess: (
message: RawMessage | OpenGroupMessage,
wrappedEnvelope?: Uint8Array
) => void;
fail: (message: RawMessage | OpenGroupMessage, error: Error) => void;
sendFail: (message: RawMessage | OpenGroupMessage, error: Error) => void;
}
export interface MessageQueueInterface {

@ -113,7 +113,7 @@ describe('MessageQueue', () => {
await pendingMessageCache.add(device, TestUtils.generateChatMessage());
const successPromise = PromiseUtils.waitForTask(done => {
messageQueueStub.events.once('success', done);
messageQueueStub.events.once('sendSuccess', done);
});
await messageQueueStub.processPending(device);
await expect(successPromise).to.be.fulfilled;
@ -123,9 +123,9 @@ describe('MessageQueue', () => {
it('should remove message from cache', async () => {
hasSessionStub.resolves(true);
const events = ['success', 'fail'];
const events = ['sendSuccess', 'sendFail'];
for (const event of events) {
if (event === 'success') {
if (event === 'sendSuccess') {
sendStub.resolves();
} else {
sendStub.throws(new Error('fail'));
@ -157,7 +157,7 @@ describe('MessageQueue', () => {
const eventPromise = PromiseUtils.waitForTask<
RawMessage | OpenGroupMessage
>(complete => {
messageQueueStub.events.once('success', complete);
messageQueueStub.events.once('sendSuccess', complete);
});
await messageQueueStub.processPending(device);
@ -172,7 +172,7 @@ describe('MessageQueue', () => {
sendStub.throws(new Error('failure'));
const spy = sandbox.spy();
messageQueueStub.events.on('fail', spy);
messageQueueStub.events.on('sendFail', spy);
const device = TestUtils.generateFakePubKey();
const message = TestUtils.generateChatMessage();
@ -181,7 +181,7 @@ describe('MessageQueue', () => {
const eventPromise = PromiseUtils.waitForTask<
[RawMessage | OpenGroupMessage, Error]
>(complete => {
messageQueueStub.events.once('fail', (...args) => {
messageQueueStub.events.once('sendFail', (...args) => {
complete(args);
});
});
@ -341,7 +341,7 @@ describe('MessageQueue', () => {
const message = TestUtils.generateOpenGroupMessage();
const eventPromise = PromiseUtils.waitForTask(complete => {
messageQueueStub.events.once('success', complete);
messageQueueStub.events.once('sendSuccess', complete);
}, 2000);
await messageQueueStub.sendToGroup(message);
@ -352,7 +352,7 @@ describe('MessageQueue', () => {
sendToOpenGroupStub.resolves({ serverId: -1, serverTimestamp: -1 });
const message = TestUtils.generateOpenGroupMessage();
const eventPromise = PromiseUtils.waitForTask(complete => {
messageQueueStub.events.once('fail', complete);
messageQueueStub.events.once('sendFail', complete);
}, 2000);
await messageQueueStub.sendToGroup(message);

Loading…
Cancel
Save