Merge pull request #1295 from Bilb/fix-delete-open-group

pull/1296/head
Audric Ackermann 5 years ago committed by GitHub
commit 8e333b1d67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -30,7 +30,7 @@ export interface LokiPublicChannelAPI {
body?: string;
},
timestamp: number
): Promise<boolean>;
): 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,10 +61,18 @@ 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);
if (result) {
this.events.emit('success', message);
} else {
// sendToOpenGroup returns -1 if failed or an id if succeeded
if (result < 0) {
this.events.emit('fail', message, error);
} else {
const messageEventData = {
pubKey: message.group.groupId,
timestamp: message.timestamp,
serverId: result,
};
this.events.emit('success', message);
window.Whisper.events.trigger('publicMessageSent', messageEventData);
}
} catch (e) {
console.warn(

@ -98,7 +98,7 @@ function wrapEnvelope(envelope: SignalService.Envelope): Uint8Array {
*/
export async function sendToOpenGroup(
message: OpenGroupMessage
): Promise<boolean> {
): 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,
@ -125,18 +125,4 @@ export async function sendToOpenGroup(
},
timestamp
);
// TODO: The below should be handled in whichever class calls this
/*
const res = await sendToOpenGroup(message);
if (!res) {
throw new textsecure.PublicChatError('Failed to send public chat message');
}
const messageEventData = {
pubKey,
timestamp: messageTimeStamp,
};
messageEventData.serverId = res;
window.Whisper.events.trigger('publicMessageSent', messageEventData);
*/
}

@ -324,12 +324,12 @@ describe('MessageQueue', () => {
describe('open groups', async () => {
let sendToOpenGroupStub: sinon.SinonStub<
[OpenGroupMessage],
Promise<boolean>
Promise<number>
>;
beforeEach(() => {
sendToOpenGroupStub = sandbox
.stub(MessageSender, 'sendToOpenGroup')
.resolves(true);
.resolves(-1);
});
it('can send to open group', async () => {
@ -339,6 +339,8 @@ describe('MessageQueue', () => {
});
it('should emit a success event when send was successful', async () => {
sendToOpenGroupStub.resolves(123456);
const message = TestUtils.generateOpenGroupMessage();
const eventPromise = PromiseUtils.waitForTask(complete => {
messageQueueStub.events.once('success', complete);
@ -349,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