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;
},
timestamp: number
): Promise<boolean | number>;
): Promise<number>;
}
declare class LokiAppDotNetServerAPI implements LokiAppDotNetServerInterface {

@ -2355,7 +2355,7 @@ class LokiPublicChannelAPI {
}
// there's no retry on desktop
// 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>
try {
const result = await MessageSender.sendToOpenGroup(message);
// sendToOpenGroup returns false if failed or a number if succeeded
if (typeof result === 'boolean') {
// sendToOpenGroup returns -1 if failed or an id if succeeded
if (result < 0) {
this.events.emit('fail', message, error);
} else {
const messageEventData = {

@ -98,7 +98,7 @@ function wrapEnvelope(envelope: SignalService.Envelope): Uint8Array {
*/
export async function sendToOpenGroup(
message: OpenGroupMessage
): Promise<boolean | number> {
): Promise<number> {
/*
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.
@ -112,10 +112,10 @@ export async function sendToOpenGroup(
);
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(
{
quote,

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

Loading…
Cancel
Save