Add channel id to message table and provide helper functions

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

@ -118,6 +118,7 @@ module.exports = {
removeMessage,
getUnreadByConversation,
getMessageBySender,
getMessageByServerId,
getMessageById,
getAllMessages,
getAllMessageIds,
@ -801,6 +802,11 @@ async function updateToLokiSchemaVersion1(currentVersion, instance) {
const { id, type, name, friendRequestStatus } = publicChatData;
await instance.run(
`ALTER TABLE messages
ADD COLUMN serverId STRING;`
);
await instance.run(
`INSERT INTO conversations (
id,
@ -1718,6 +1724,7 @@ async function saveMessage(data, { forceSave } = {}) {
hasFileAttachments,
hasVisualMediaAttachments,
id,
serverId,
// eslint-disable-next-line camelcase
received_at,
schemaVersion,
@ -1736,6 +1743,7 @@ async function saveMessage(data, { forceSave } = {}) {
$id: id,
$json: objectToJSON(data),
$serverId: serverId,
$body: body,
$conversationId: conversationId,
$expirationStartTimestamp: expirationStartTimestamp,
@ -1758,6 +1766,7 @@ async function saveMessage(data, { forceSave } = {}) {
await db.run(
`UPDATE messages SET
json = $json,
serverId = $serverId,
body = $body,
conversationId = $conversationId,
expirationStartTimestamp = $expirationStartTimestamp,
@ -1792,6 +1801,7 @@ async function saveMessage(data, { forceSave } = {}) {
id,
json,
serverId,
body,
conversationId,
expirationStartTimestamp,
@ -1812,6 +1822,7 @@ async function saveMessage(data, { forceSave } = {}) {
$id,
$json,
$serverId,
$body,
$conversationId,
$expirationStartTimestamp,
@ -1934,6 +1945,18 @@ async function removeMessage(id) {
);
}
async function getMessageByServerId(id) {
const row = await db.get('SELECT * FROM messages WHERE ServerId = $ServerId;', {
$ServerId: ServerId,
});
if (!row) {
return null;
}
return jsonToObject(row.json);
}
async function getMessageById(id) {
const row = await db.get('SELECT * FROM messages WHERE id = $id;', {
$id: id,

@ -1242,6 +1242,17 @@
Message: Whisper.Message,
});
},
async setServerId(serverId) {
if (_.isEqual(this.get('serverId'), serverId)) return;
this.set({
serverId,
});
await window.Signal.Data.saveMessage(this.attributes, {
Message: Whisper.Message,
});
},
async setIsPublic(isPublic) {
if (_.isEqual(this.get('isPublic'), isPublic)) return;

@ -141,6 +141,7 @@ module.exports = {
removeAllMessagesInConversation,
getMessageBySender,
getMessageByServerId,
getMessageById,
getAllMessages,
getAllUnsentMessages,
@ -875,6 +876,15 @@ async function _removeMessages(ids) {
await channels.removeMessage(ids);
}
async function getMessageByServerId(id, { Message }) {
const message = await channels.getMessageByServerId(id);
if (!message) {
return null;
}
return new Message(message);
}
async function getMessageById(id, { Message }) {
const message = await channels.getMessageById(id);
if (!message) {

Loading…
Cancel
Save