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) {
const row = await db.get('SELECT * FROM messages WHERE ServerId = $ServerId;', {
$ServerId: ServerId,
});
async function getMessageByServerId(serverId) {
const row = await db.get(
'SELECT * FROM messages WHERE serverId = $serverId;',
{
$serverId: serverId,
}
);
if (!row) {
return null;

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

@ -368,9 +368,14 @@
await Promise.all(messages.map(m => m.setIsP2p(true)));
},
async onPublicMessageSent(pubKey, timestamp) {
async onPublicMessageSent(pubKey, timestamp, serverId) {
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) {

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

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

Loading…
Cancel
Save