Added showing pow icon.

pull/43/head
Mikunj 7 years ago
parent 3789e94342
commit ece266fffd

@ -562,6 +562,13 @@
appView.showFriendRequest(friendRequest); appView.showFriendRequest(friendRequest);
} }
}); });
Whisper.events.on('calculatingPoW', ({ pubKey, timestamp}) => {
try {
const conversation = ConversationController.get(pubKey);
conversation.onCalculatingPoW(pubKey, timestamp);
} catch (e) {}
});
} }
window.getSyncRequest = () => window.getSyncRequest = () =>

@ -198,6 +198,15 @@
await this.inProgressFetch; await this.inProgressFetch;
removeMessage(); removeMessage();
}, },
async onCalculatingPoW(pubKey, timestamp) {
if (this.id !== pubKey) return;
// Go through our messages and find the one that we need to update
const messages = this.messageCollection.models.filter(m => m.get('sent_at') === timestamp);
for (const message of messages) {
await message.setCalculatingPoW();
}
},
addSingleMessage(message, setToExpire = true) { addSingleMessage(message, setToExpire = true) {
const model = this.messageCollection.add(message, { merge: true }); const model = this.messageCollection.add(message, { merge: true });

@ -93,6 +93,7 @@
return { return {
timestamp: new Date().getTime(), timestamp: new Date().getTime(),
attachments: [], attachments: [],
pow: false,
}; };
}, },
validate(attributes) { validate(attributes) {
@ -439,6 +440,8 @@
if (sent || sentTo.length > 0) { if (sent || sentTo.length > 0) {
return 'sent'; return 'sent';
} }
const calculatingPoW = this.get('calculatingPoW');
if (calculatingPoW) return 'pow';
return 'sending'; return 'sending';
}, },
@ -930,7 +933,17 @@
return null; return null;
}, },
async setCalculatingPoW() {
if (this.calculatingPoW) return;
this.set({
calculatingPoW: true,
});
await window.Signal.Data.saveMessage(this.attributes, {
Message: Whisper.Message,
});
},
send(promise) { send(promise) {
this.trigger('pending'); this.trigger('pending');
return promise return promise

@ -46,7 +46,7 @@ class LokiServer {
}); });
} }
async sendMessage(pubKey, data, ttl) { async sendMessage(pubKey, data, messageTimeStamp, ttl) {
const data64 = dcodeIO.ByteBuffer.wrap(data).toString('base64'); const data64 = dcodeIO.ByteBuffer.wrap(data).toString('base64');
// Hardcoded to use a single node/server for now // Hardcoded to use a single node/server for now
const currentNode = this.nodes[0]; const currentNode = this.nodes[0];
@ -55,6 +55,10 @@ class LokiServer {
// Nonce is returned as a base64 string to include in header // Nonce is returned as a base64 string to include in header
let nonce; let nonce;
try { try {
window.Whisper.events.trigger('calculatingPoW', {
pubKey,
timestamp: messageTimeStamp,
});
nonce = await getPoWNonce(timestamp, ttl, pubKey, data64); nonce = await getPoWNonce(timestamp, ttl, pubKey, data64);
} catch (err) { } catch (err) {
// Something went horribly wrong // Something went horribly wrong

@ -177,7 +177,7 @@ OutgoingMessage.prototype = {
async transmitMessage(number, data, timestamp, ttl = 24 * 60 * 60) { async transmitMessage(number, data, timestamp, ttl = 24 * 60 * 60) {
const pubKey = number; const pubKey = number;
try { try {
const result = await this.lokiserver.sendMessage(pubKey, data, ttl); const result = await this.lokiserver.sendMessage(pubKey, data, timestamp, ttl);
return result; return result;
} catch (e) { } catch (e) {
if (e.name === 'HTTPError' && (e.code !== 409 && e.code !== 410)) { if (e.name === 'HTTPError' && (e.code !== 409 && e.code !== 410)) {

Loading…
Cancel
Save