Added showing pow icon.

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

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

@ -198,6 +198,15 @@
await this.inProgressFetch;
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) {
const model = this.messageCollection.add(message, { merge: true });

@ -93,6 +93,7 @@
return {
timestamp: new Date().getTime(),
attachments: [],
pow: false,
};
},
validate(attributes) {
@ -439,6 +440,8 @@
if (sent || sentTo.length > 0) {
return 'sent';
}
const calculatingPoW = this.get('calculatingPoW');
if (calculatingPoW) return 'pow';
return 'sending';
},
@ -930,7 +933,17 @@
return null;
},
async setCalculatingPoW() {
if (this.calculatingPoW) return;
this.set({
calculatingPoW: true,
});
await window.Signal.Data.saveMessage(this.attributes, {
Message: Whisper.Message,
});
},
send(promise) {
this.trigger('pending');
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');
// Hardcoded to use a single node/server for now
const currentNode = this.nodes[0];
@ -55,6 +55,10 @@ class LokiServer {
// Nonce is returned as a base64 string to include in header
let nonce;
try {
window.Whisper.events.trigger('calculatingPoW', {
pubKey,
timestamp: messageTimeStamp,
});
nonce = await getPoWNonce(timestamp, ttl, pubKey, data64);
} catch (err) {
// Something went horribly wrong

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

Loading…
Cancel
Save