Save message id when sending/receiving to/from public server and lint

pull/390/head
Beaudan 6 years ago
parent 899bfc3b2b
commit c9f433fbba

@ -1945,10 +1945,13 @@ async function removeMessage(id) {
); );
} }
async function getMessageByServerId(id) { async function getMessageByServerId(serverId) {
const row = await db.get('SELECT * FROM messages WHERE ServerId = $ServerId;', { const row = await db.get(
$ServerId: ServerId, 'SELECT * FROM messages WHERE serverId = $serverId;',
}); {
$serverId: serverId,
}
);
if (!row) { if (!row) {
return null; return null;

@ -750,14 +750,17 @@
} }
}); });
Whisper.events.on('publicMessageSent', ({ pubKey, timestamp }) => { Whisper.events.on(
try { 'publicMessageSent',
const conversation = ConversationController.get(pubKey); ({ pubKey, timestamp, serverId }) => {
conversation.onPublicMessageSent(pubKey, timestamp); try {
} catch (e) { const conversation = ConversationController.get(pubKey);
window.log.error('Error setting public on message'); conversation.onPublicMessageSent(pubKey, timestamp, serverId);
} catch (e) {
window.log.error('Error setting public on message');
}
} }
}); );
Whisper.events.on('password-updated', () => { Whisper.events.on('password-updated', () => {
if (appView && appView.inboxView) { if (appView && appView.inboxView) {

@ -368,9 +368,14 @@
await Promise.all(messages.map(m => m.setIsP2p(true))); await Promise.all(messages.map(m => m.setIsP2p(true)));
}, },
async onPublicMessageSent(pubKey, timestamp) { async onPublicMessageSent(pubKey, timestamp, serverId) {
const messages = this._getMessagesWithTimestamp(pubKey, timestamp); const messages = this._getMessagesWithTimestamp(pubKey, timestamp);
await Promise.all(messages.map(m => m.setIsPublic(true))); await Promise.all(
messages.map(message => [
message.setIsPublic(true),
message.setServerId(serverId),
])
);
}, },
async onNewMessage(message) { async onNewMessage(message) {

@ -110,7 +110,7 @@ class LokiMessageAPI {
], ],
}; };
try { try {
await nodeFetch(publicEndpoint, { const result = await nodeFetch(publicEndpoint, {
method: 'post', method: 'post',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
@ -118,6 +118,8 @@ class LokiMessageAPI {
}, },
body: JSON.stringify(payload), body: JSON.stringify(payload),
}); });
const body = await result.json();
messageEventData.serverId = body.data.id;
window.Whisper.events.trigger('publicMessageSent', messageEventData); window.Whisper.events.trigger('publicMessageSent', messageEventData);
return; return;
} catch (e) { } catch (e) {

@ -167,6 +167,7 @@ class LokiPublicChannelAPI {
} }
const messageData = { const messageData = {
serverId: adnMessage.id,
friendRequest: false, friendRequest: false,
source, source,
sourceDevice: 1, sourceDevice: 1,

Loading…
Cancel
Save