|
|
|
@ -110,7 +110,6 @@ module.exports = {
|
|
|
|
|
getPublicConversationsByServer,
|
|
|
|
|
getPubkeysInPublicConversation,
|
|
|
|
|
getAllConversationIds,
|
|
|
|
|
getAllPrivateConversations,
|
|
|
|
|
getAllGroupsInvolvingId,
|
|
|
|
|
removeAllConversations,
|
|
|
|
|
removeAllPrivateConversations,
|
|
|
|
@ -130,6 +129,7 @@ module.exports = {
|
|
|
|
|
removeMessage,
|
|
|
|
|
getUnreadByConversation,
|
|
|
|
|
getMessageBySender,
|
|
|
|
|
getMessagesBySender,
|
|
|
|
|
getMessageIdsFromServerIds,
|
|
|
|
|
getMessageById,
|
|
|
|
|
getAllMessages,
|
|
|
|
@ -811,6 +811,7 @@ const LOKI_SCHEMA_VERSIONS = [
|
|
|
|
|
updateToLokiSchemaVersion5,
|
|
|
|
|
updateToLokiSchemaVersion6,
|
|
|
|
|
updateToLokiSchemaVersion7,
|
|
|
|
|
updateToLokiSchemaVersion8,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
async function updateToLokiSchemaVersion1(currentVersion, instance) {
|
|
|
|
@ -824,7 +825,6 @@ async function updateToLokiSchemaVersion1(currentVersion, instance) {
|
|
|
|
|
`ALTER TABLE messages
|
|
|
|
|
ADD COLUMN serverId INTEGER;`
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
await instance.run(
|
|
|
|
|
`CREATE TABLE servers(
|
|
|
|
|
serverUrl STRING PRIMARY KEY ASC,
|
|
|
|
@ -1052,6 +1052,29 @@ async function updateToLokiSchemaVersion7(currentVersion, instance) {
|
|
|
|
|
console.log('updateToLokiSchemaVersion7: success!');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function updateToLokiSchemaVersion8(currentVersion, instance) {
|
|
|
|
|
if (currentVersion >= 8) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
console.log('updateToLokiSchemaVersion8: starting...');
|
|
|
|
|
await instance.run('BEGIN TRANSACTION;');
|
|
|
|
|
|
|
|
|
|
await instance.run(
|
|
|
|
|
`ALTER TABLE messages
|
|
|
|
|
ADD COLUMN serverTimestamp INTEGER;`
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
await instance.run(
|
|
|
|
|
`INSERT INTO loki_schema (
|
|
|
|
|
version
|
|
|
|
|
) values (
|
|
|
|
|
8
|
|
|
|
|
);`
|
|
|
|
|
);
|
|
|
|
|
await instance.run('COMMIT TRANSACTION;');
|
|
|
|
|
console.log('updateToLokiSchemaVersion8: success!');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function updateLokiSchema(instance) {
|
|
|
|
|
const result = await instance.get(
|
|
|
|
|
"SELECT name FROM sqlite_master WHERE type = 'table' AND name='loki_schema';"
|
|
|
|
@ -1948,16 +1971,6 @@ async function getAllConversationIds() {
|
|
|
|
|
return map(rows, row => row.id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function getAllPrivateConversations() {
|
|
|
|
|
const rows = await db.all(
|
|
|
|
|
`SELECT json FROM ${CONVERSATIONS_TABLE} WHERE
|
|
|
|
|
type = 'private'
|
|
|
|
|
ORDER BY id ASC;`
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return map(rows, row => jsonToObject(row.json));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function getAllPublicConversations() {
|
|
|
|
|
const rows = await db.all(
|
|
|
|
|
`SELECT json FROM conversations WHERE
|
|
|
|
@ -2103,6 +2116,7 @@ async function saveMessage(data, { forceSave } = {}) {
|
|
|
|
|
hasVisualMediaAttachments,
|
|
|
|
|
id,
|
|
|
|
|
serverId,
|
|
|
|
|
serverTimestamp,
|
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
|
received_at,
|
|
|
|
|
schemaVersion,
|
|
|
|
@ -2122,6 +2136,7 @@ async function saveMessage(data, { forceSave } = {}) {
|
|
|
|
|
$json: objectToJSON(data),
|
|
|
|
|
|
|
|
|
|
$serverId: serverId,
|
|
|
|
|
$serverTimestamp: serverTimestamp,
|
|
|
|
|
$body: body,
|
|
|
|
|
$conversationId: conversationId,
|
|
|
|
|
$expirationStartTimestamp: expirationStartTimestamp,
|
|
|
|
@ -2145,6 +2160,7 @@ async function saveMessage(data, { forceSave } = {}) {
|
|
|
|
|
`UPDATE messages SET
|
|
|
|
|
json = $json,
|
|
|
|
|
serverId = $serverId,
|
|
|
|
|
serverTimestamp = $serverTimestamp,
|
|
|
|
|
body = $body,
|
|
|
|
|
conversationId = $conversationId,
|
|
|
|
|
expirationStartTimestamp = $expirationStartTimestamp,
|
|
|
|
@ -2180,6 +2196,7 @@ async function saveMessage(data, { forceSave } = {}) {
|
|
|
|
|
json,
|
|
|
|
|
|
|
|
|
|
serverId,
|
|
|
|
|
serverTimestamp,
|
|
|
|
|
body,
|
|
|
|
|
conversationId,
|
|
|
|
|
expirationStartTimestamp,
|
|
|
|
@ -2201,6 +2218,7 @@ async function saveMessage(data, { forceSave } = {}) {
|
|
|
|
|
$json,
|
|
|
|
|
|
|
|
|
|
$serverId,
|
|
|
|
|
$serverTimestamp,
|
|
|
|
|
$body,
|
|
|
|
|
$conversationId,
|
|
|
|
|
$expirationStartTimestamp,
|
|
|
|
@ -2394,6 +2412,20 @@ async function getMessageBySender({ source, sourceDevice, sent_at }) {
|
|
|
|
|
return map(rows, row => jsonToObject(row.json));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function getMessagesBySender({ source, sourceDevice }) {
|
|
|
|
|
const rows = await db.all(
|
|
|
|
|
`SELECT json FROM messages WHERE
|
|
|
|
|
source = $source AND
|
|
|
|
|
sourceDevice = $sourceDevice`,
|
|
|
|
|
{
|
|
|
|
|
$source: source,
|
|
|
|
|
$sourceDevice: sourceDevice,
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return map(rows, row => jsonToObject(row.json));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function getAllUnsentMessages() {
|
|
|
|
|
const rows = await db.all(`
|
|
|
|
|
SELECT json FROM messages WHERE
|
|
|
|
@ -2430,7 +2462,7 @@ async function getMessagesByConversation(
|
|
|
|
|
conversationId = $conversationId AND
|
|
|
|
|
received_at < $received_at AND
|
|
|
|
|
type LIKE $type
|
|
|
|
|
ORDER BY sent_at DESC
|
|
|
|
|
ORDER BY serverTimestamp DESC, serverId DESC, sent_at DESC
|
|
|
|
|
LIMIT $limit;
|
|
|
|
|
`,
|
|
|
|
|
{
|
|
|
|
|