renamed "messagingService" to "ws"

This commit is contained in:
zadam 2019-08-26 20:21:43 +02:00
parent d039a5f24e
commit 36c87b7fa0
21 changed files with 52 additions and 52 deletions

View File

@ -2,7 +2,7 @@ import cloning from './services/cloning.js';
import contextMenu from './services/tree_context_menu.js';
import dragAndDropSetup from './services/drag_and_drop.js';
import link from './services/link.js';
import messagingService from './services/messaging.js';
import ws from './services/ws.js';
import noteDetailService from './services/note_detail.js';
import noteType from './services/note_type.js';
import protectedSessionService from './services/protected_session.js';
@ -71,7 +71,7 @@ window.onerror = function (msg, url, lineNo, columnNo, error) {
].join(' - ');
}
messagingService.logError(message);
ws.logError(message);
return false;
};

View File

@ -1,6 +1,6 @@
import treeUtils from "../services/tree_utils.js";
import utils from "../services/utils.js";
import messagingService from "../services/messaging.js";
import ws from "../services/ws.js";
import infoService from "../services/info.js";
const $dialog = $("#export-dialog");
@ -112,7 +112,7 @@ $('input[name=export-subtree-format]').change(function () {
}
});
messagingService.subscribeToMessages(async message => {
ws.subscribeToMessages(async message => {
if (message.type === 'export-error') {
infoService.showError(message.message);
$dialog.modal('hide');

View File

@ -3,7 +3,7 @@ import utils from '../services/utils.js';
import treeUtils from "../services/tree_utils.js";
import server from "../services/server.js";
import infoService from "../services/info.js";
import messagingService from "../services/messaging.js";
import ws from "../services/ws.js";
const $dialog = $("#import-dialog");
const $form = $("#import-form");
@ -117,7 +117,7 @@ function boolToString($el) {
return $el.is(":checked") ? "true" : "false";
}
messagingService.subscribeToMessages(async message => {
ws.subscribeToMessages(async message => {
if (message.type === 'import-error') {
infoService.showError(message.message);
$dialog.modal('hide');

View File

@ -1,6 +1,6 @@
import server from "./server.js";
import utils from "./utils.js";
import messagingService from "./messaging.js";
import ws from "./ws.js";
import treeUtils from "./tree_utils.js";
import noteAutocompleteService from "./note_autocomplete.js";
import linkService from "./link.js";
@ -179,7 +179,7 @@ class Attributes {
.append($openButton));
}
else {
messagingService.logError("Unknown labelType=" + definitionAttr.labelType);
ws.logError("Unknown labelType=" + definitionAttr.labelType);
}
}
else if (valueAttr.type === 'relation') {
@ -197,7 +197,7 @@ class Attributes {
$input.setSelectedPath(valueAttr.value);
}
else {
messagingService.logError("Unknown attribute type=" + valueAttr.type);
ws.logError("Unknown attribute type=" + valueAttr.type);
return;
}

View File

@ -1,4 +1,4 @@
import messagingService from "./messaging.js";
import ws from "./ws.js";
import utils from "./utils.js";
function showMessage(message) {
@ -13,7 +13,7 @@ function showMessage(message) {
function showAndLogError(message, delay = 10000) {
showError(message, delay);
messagingService.logError(message);
ws.logError(message);
}
function showError(message, delay = 10000) {
@ -44,7 +44,7 @@ function getNotifySettings(type, delay) {
}
function throwError(message) {
messagingService.logError(message);
ws.logError(message);
throw new Error(message);
}

View File

@ -1,7 +1,7 @@
import treeService from './tree.js';
import TabContext from './tab_context.js';
import server from './server.js';
import messagingService from "./messaging.js";
import ws from "./ws.js";
import treeCache from "./tree_cache.js";
import NoteFull from "../entities/note_full.js";
import bundleService from "./bundle.js";
@ -353,7 +353,7 @@ function fireDetailLoaded() {
detailLoadedListeners = [];
}
messagingService.subscribeToOutsideSyncMessages(syncData => {
ws.subscribeToOutsideSyncMessages(syncData => {
const noteIdsToRefresh = new Set();
syncData
@ -370,7 +370,7 @@ messagingService.subscribeToOutsideSyncMessages(syncData => {
}
});
messagingService.subscribeToAllSyncMessages(syncData => {
ws.subscribeToAllSyncMessages(syncData => {
for (const tc of tabContexts) {
tc.syncDataReceived(syncData);
}

View File

@ -1,5 +1,5 @@
import bundleService from "./bundle.js";
import messagingService from "./messaging.js";
import ws from "./ws.js";
import optionsService from "./options.js";
class Sidebar {
@ -83,7 +83,7 @@ class Sidebar {
}
}
catch (e) {
messagingService.logError(`Error while creating widget ${widgetClass.name}: ${e.message}`);
ws.logError(`Error while creating widget ${widgetClass.name}: ${e.message}`);
}
}
@ -95,7 +95,7 @@ class Sidebar {
this.$widgetContainer.append($el);
}
catch (e) {
messagingService.logError(`Error while loading widget ${widget.widgetName}: ${e.message}`);
ws.logError(`Error while loading widget ${widget.widgetName}: ${e.message}`);
}
}
}

View File

@ -1,6 +1,6 @@
import contextMenuWidget from './context_menu.js';
import dragAndDropSetup from './drag_and_drop.js';
import messagingService from './messaging.js';
import ws from './ws.js';
import noteDetailService from './note_detail.js';
import protectedSessionHolder from './protected_session_holder.js';
import treeUtils from './tree_utils.js';
@ -126,7 +126,7 @@ async function getNodeFromPath(notePath, expand = false, expandOpts = {}) {
foundChildNode = findChildNode(parentNode, childNoteId);
if (!foundChildNode) {
messagingService.logError(`Can't find node for child node of noteId=${childNoteId} for parent of noteId=${parentNode.data.noteId} and hoistedNoteId=${hoistedNoteId}, requested path is ${notePath}`);
ws.logError(`Can't find node for child node of noteId=${childNoteId} for parent of noteId=${parentNode.data.noteId} and hoistedNoteId=${hoistedNoteId}, requested path is ${notePath}`);
return;
}
}
@ -233,7 +233,7 @@ async function getRunPath(notePath) {
const parents = await child.getParentNotes();
if (!parents) {
messagingService.logError("No parents found for " + childNoteId);
ws.logError("No parents found for " + childNoteId);
return;
}
@ -258,7 +258,7 @@ async function getRunPath(notePath) {
break;
}
else {
messagingService.logError("No parents, can't activate node.");
ws.logError("No parents, can't activate node.");
return;
}
}
@ -738,7 +738,7 @@ async function showTree() {
initFancyTree(tree);
}
messagingService.subscribeToMessages(message => {
ws.subscribeToMessages(message => {
if (message.type === 'refresh-tree') {
reload();
}
@ -753,7 +753,7 @@ messagingService.subscribeToMessages(message => {
}
});
messagingService.subscribeToOutsideSyncMessages(syncData => {
ws.subscribeToOutsideSyncMessages(syncData => {
if (syncData.some(sync => sync.entityName === 'branches')
|| syncData.some(sync => sync.entityName === 'notes')) {

View File

@ -3,7 +3,7 @@ import utils from "./utils.js";
import Branch from "../entities/branch.js";
import server from "./server.js";
import treeCache from "./tree_cache.js";
import messagingService from "./messaging.js";
import ws from "./ws.js";
import hoistedNoteService from "./hoisted_note.js";
async function prepareTree() {
@ -100,7 +100,7 @@ async function prepareRealBranch(parentNote) {
const childBranches = await parentNote.getChildBranches();
if (!childBranches) {
messagingService.logError(`No children for ${parentNote}. This shouldn't happen.`);
ws.logError(`No children for ${parentNote}. This shouldn't happen.`);
return;
}

View File

@ -2,7 +2,7 @@ import utils from "./utils.js";
import Branch from "../entities/branch.js";
import NoteShort from "../entities/note_short.js";
import infoService from "./info.js";
import messagingService from "./messaging.js";
import ws from "./ws.js";
import server from "./server.js";
/**
@ -107,7 +107,7 @@ class TreeCache {
return noteIds.map(noteId => {
if (!this.notes[noteId] && !silentNotFoundError) {
messagingService.logError(`Can't find note "${noteId}"`);
ws.logError(`Can't find note "${noteId}"`);
return null;
}

View File

@ -1,5 +1,5 @@
import treeService from './tree.js';
import messagingService from './messaging.js';
import ws from './ws.js';
import protectedSessionService from './protected_session.js';
import treeChangesService from './branches.js';
import treeUtils from './tree_utils.js';
@ -153,7 +153,7 @@ class TreeContextMenu {
hoistedNoteService.unhoist();
}
else {
messagingService.logError("Unknown command: " + cmd);
ws.logError("Unknown command: " + cmd);
}
}
}

View File

@ -1,6 +1,6 @@
import utils from "../services/utils.js";
import linkService from "../services/link.js";
import messagingService from "../services/messaging.js";
import ws from "../services/ws.js";
import StandardWidget from "./standard_widget.js";
class AttributesWidget extends StandardWidget {
@ -71,12 +71,12 @@ class AttributesWidget extends StandardWidget {
$container.append(await linkService.createNoteLink(attribute.value));
$container.append(" ");
} else {
messagingService.logError(`Relation ${attribute.attributeId} has empty target`);
ws.logError(`Relation ${attribute.attributeId} has empty target`);
}
} else if (attribute.type === 'label-definition' || attribute.type === 'relation-definition') {
$container.append(attribute.name + " definition ");
} else {
messagingService.logError("Unknown attr type: " + attribute.type);
ws.logError("Unknown attr type: " + attribute.type);
}
}
}

View File

@ -5,7 +5,7 @@ const dateNoteService = require('../../services/date_notes');
const dateUtils = require('../../services/date_utils');
const imageService = require('../../services/image');
const appInfo = require('../../services/app_info');
const messagingService = require('../../services/messaging');
const ws = require('../../services/ws.js');
const log = require('../../services/log');
const utils = require('../../services/utils');
const path = require('path');
@ -102,7 +102,7 @@ async function addImagesToNote(images, note, content) {
async function openNote(req) {
if (utils.isElectron()) {
messagingService.sendMessageToAllClients({
ws.sendMessageToAllClients({
type: 'open-note',
noteId: req.params.noteId
});

View File

@ -4,7 +4,7 @@ const tarExportService = require('../../services/export/tar');
const singleExportService = require('../../services/export/single');
const opmlExportService = require('../../services/export/opml');
const repository = require("../../services/repository");
const messagingService = require("../../services/messaging");
const ws = require("../../services/ws.js");
const log = require("../../services/log");
class ExportContext {
@ -23,7 +23,7 @@ class ExportContext {
if (Date.now() - this.lastSentCountTs >= 500) {
this.lastSentCountTs = Date.now();
await messagingService.sendMessageToAllClients({
await ws.sendMessageToAllClients({
exportId: this.exportId,
type: 'export-progress-count',
progressCount: this.progressCount
@ -32,7 +32,7 @@ class ExportContext {
}
async exportFinished() {
await messagingService.sendMessageToAllClients({
await ws.sendMessageToAllClients({
exportId: this.exportId,
type: 'export-finished'
});
@ -40,7 +40,7 @@ class ExportContext {
// must remaing non-static
async reportError(message) {
await messagingService.sendMessageToAllClients({
await ws.sendMessageToAllClients({
type: 'export-error',
message: message
});

View File

@ -10,7 +10,7 @@ const repository = require('./repository');
const axios = require('axios');
const dayjs = require('dayjs');
const cloningService = require('./cloning');
const messagingService = require('./messaging');
const ws = require('./ws.js');
const appInfo = require('./app_info');
const searchService = require('./search');
@ -211,7 +211,7 @@ function BackendScriptApi(currentNote, apiParams) {
this.createNoteAndRefresh = async function(parentNoteId, title, content, extraOptions) {
await noteService.createNote(parentNoteId, title, content, extraOptions);
messagingService.refreshTree();
ws.refreshTree();
};
/**
@ -307,7 +307,7 @@ function BackendScriptApi(currentNote, apiParams) {
*
* @returns {Promise<void>}
*/
this.refreshTree = messagingService.refreshTree;
this.refreshTree = ws.refreshTree;
/**
* @return {{syncVersion, appVersion, buildRevision, dbVersion, dataDirectory, buildDate}|*} - object representing basic info about running Trilium version

View File

@ -3,7 +3,7 @@
const sql = require('./sql');
const sqlInit = require('./sql_init');
const log = require('./log');
const messagingService = require('./messaging');
const ws = require('./ws.js');
const syncMutexService = require('./sync_mutex');
const repository = require('./repository');
const cls = require('./cls');
@ -381,13 +381,13 @@ async function runChecks() {
});
if (fixedIssues) {
messagingService.refreshTree();
ws.refreshTree();
}
if (unrecoverableConsistencyErrors) {
log.info(`Consistency checks failed (took ${elapsedTimeMs}ms)`);
messagingService.sendMessageToAllClients({type: 'consistency-checks-failed'});
ws.sendMessageToAllClients({type: 'consistency-checks-failed'});
}
else {
log.info(`All consistency checks passed (took ${elapsedTimeMs}ms)`);

View File

@ -4,7 +4,7 @@ const sql = require('./sql');
const utils = require('./utils');
const log = require('./log');
const eventLogService = require('./event_log');
const messagingService = require('./messaging');
const ws = require('./ws.js');
const ApiToken = require('../entities/api_token');
const Branch = require('../entities/branch');
const Note = require('../entities/note');
@ -60,7 +60,7 @@ async function checkContentHashes(otherHashes) {
if (key !== 'recent_notes') {
// let's not get alarmed about recent notes which get updated often and can cause failures in race conditions
await messagingService.sendMessageToAllClients({type: 'sync-hash-check-failed'});
await ws.sendMessageToAllClients({type: 'sync-hash-check-failed'});
}
}
}

View File

@ -1,6 +1,6 @@
"use strict";
const messagingService = require('./messaging');
const ws = require('./ws.js');
// importId => ImportContext
const importContexts = {};
@ -36,7 +36,7 @@ class ImportContext {
if (Date.now() - this.lastSentCountTs >= 500) {
this.lastSentCountTs = Date.now();
await messagingService.sendMessageToAllClients({
await ws.sendMessageToAllClients({
importId: this.importId,
type: 'import-progress-count',
progressCount: this.progressCount
@ -46,7 +46,7 @@ class ImportContext {
// must remaing non-static
async reportError(message) {
await messagingService.sendMessageToAllClients({
await ws.sendMessageToAllClients({
type: 'import-error',
message: message
});

View File

@ -21,7 +21,7 @@ const https = require('https');
const config = require('./services/config');
const log = require('./services/log');
const appInfo = require('./services/app_info');
const messagingService = require('./services/messaging');
const ws = require('./services/ws.js');
const utils = require('./services/utils');
const sqlInit = require('./services/sql_init');
const port = require('./services/port');
@ -77,7 +77,7 @@ async function startTrilium() {
httpServer.on('error', onError);
httpServer.on('listening', () => debug('Listening on port' + httpServer.address().port));
sqlInit.dbReady.then(() => messagingService.init(httpServer, sessionParser));
sqlInit.dbReady.then(() => ws.init(httpServer, sessionParser));
if (utils.isElectron()) {
const electronRouting = require('./routes/electron');