make sendMessage return -1 on fail rather than false

pull/1295/head
Audric Ackermann 5 years ago
parent 2637981fdb
commit 6d65c9cc0a
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -30,7 +30,7 @@ export interface LokiPublicChannelAPI {
body?: string; body?: string;
}, },
timestamp: number timestamp: number
): Promise<boolean | number>; ): Promise<number>;
} }
declare class LokiAppDotNetServerAPI implements LokiAppDotNetServerInterface { declare class LokiAppDotNetServerAPI implements LokiAppDotNetServerInterface {

@ -2355,7 +2355,7 @@ class LokiPublicChannelAPI {
} }
// there's no retry on desktop // there's no retry on desktop
// this is supposed to be after retries // this is supposed to be after retries
return false; return -1;
} }
} }

@ -61,8 +61,8 @@ export class MessageQueue implements MessageQueueInterface {
// This is absolutely yucky ... we need to make it not use Promise<boolean> // This is absolutely yucky ... we need to make it not use Promise<boolean>
try { try {
const result = await MessageSender.sendToOpenGroup(message); const result = await MessageSender.sendToOpenGroup(message);
// sendToOpenGroup returns false if failed or a number if succeeded // sendToOpenGroup returns -1 if failed or an id if succeeded
if (typeof result === 'boolean') { if (result < 0) {
this.events.emit('fail', message, error); this.events.emit('fail', message, error);
} else { } else {
const messageEventData = { const messageEventData = {

@ -98,7 +98,7 @@ function wrapEnvelope(envelope: SignalService.Envelope): Uint8Array {
*/ */
export async function sendToOpenGroup( export async function sendToOpenGroup(
message: OpenGroupMessage message: OpenGroupMessage
): Promise<boolean | number> { ): Promise<number> {
/* /*
Note: Retrying wasn't added to this but it can be added in the future if needed. Note: Retrying wasn't added to this but it can be added in the future if needed.
The only problem is that `channelAPI.sendMessage` returns true/false and doesn't throw any error so we can never be sure why sending failed. The only problem is that `channelAPI.sendMessage` returns true/false and doesn't throw any error so we can never be sure why sending failed.
@ -112,10 +112,10 @@ export async function sendToOpenGroup(
); );
if (!channelAPI) { if (!channelAPI) {
return false; return -1;
} }
// Don't think returning true/false on `sendMessage` is a good way // Returns -1 on fail or an id > 0 on success
return channelAPI.sendMessage( return channelAPI.sendMessage(
{ {
quote, quote,

@ -324,12 +324,12 @@ describe('MessageQueue', () => {
describe('open groups', async () => { describe('open groups', async () => {
let sendToOpenGroupStub: sinon.SinonStub< let sendToOpenGroupStub: sinon.SinonStub<
[OpenGroupMessage], [OpenGroupMessage],
Promise<boolean | number> Promise<number>
>; >;
beforeEach(() => { beforeEach(() => {
sendToOpenGroupStub = sandbox sendToOpenGroupStub = sandbox
.stub(MessageSender, 'sendToOpenGroup') .stub(MessageSender, 'sendToOpenGroup')
.resolves(true); .resolves(-1);
}); });
it('can send to open group', async () => { it('can send to open group', async () => {
@ -351,7 +351,7 @@ describe('MessageQueue', () => {
}); });
it('should emit a fail event if something went wrong', async () => { it('should emit a fail event if something went wrong', async () => {
sendToOpenGroupStub.resolves(false); sendToOpenGroupStub.resolves(-1);
const message = TestUtils.generateOpenGroupMessage(); const message = TestUtils.generateOpenGroupMessage();
const eventPromise = PromiseUtils.waitForTask(complete => { const eventPromise = PromiseUtils.waitForTask(complete => {
messageQueueStub.events.once('fail', complete); messageQueueStub.events.once('fail', complete);

Loading…
Cancel
Save