* lib/db: Add ExpirePendingFolders(). Use-case is to drop any no-longer-pending folders for a specific device when parsing its ClusterConfig message where previously offered folders are not mentioned any more. The timestamp in ObservedFolder is stored with only second precision, so round to seconds here as well. This allows calling the function within the same second of adding or updating entries. * lib/model: Weed out pending folders when receiving ClusterConfig. Filter the entries by timestamp, which must be newer than or equal to the reception time of the ClusterConfig. For just mentioned ones, this assumption will hold as AddOrUpdatePendingFolder() updates the timestamp. * lib/model, gui: Notify when one or more pending folders expired. Introduce new event type FolderOfferCancelled and use it to trigger a complete refreshCluster() cycle. Listing individual entries would be much more code and probably just as much work to answer the API request. * lib/model: Add comment and rename ExpirePendingFolders(). * lib/events: Rename FolderOfferCancelled to ClusterPendingChanged. * lib/model: Reuse ClusterPendingChanged event for cleanPending() Changing the config does not necessarily mean that the /resut/cluster/pending endpoints need to be refreshed, but only if something was actually removed. Detect this and indicate it through the ClusterPendingChanged event, which is already hooked up to requery respective endpoints within the GUI. No more need for a separate refreshCluster() in reaction to ConfigSaved event or calling refreshConfig(). * lib/model: Gofmt. * lib/db: Warn instead of info log for failed removal. * gui: Fix pending notifications not loading on GUI start. * lib/db: Use short device ID in log message. * lib/db: Return list of expired folder IDs after deleting them. * lib/model: Refactor Pending...Changed events. * lib/model: Adjust format of removed pending folders enumeration. Use an array of objects with device / folder ID properties, matching the other places where it's used. * lib/db: Drop invalid entries in RemovePendingFoldersBeforeTime(). * lib/model: Gofmt. My local gofmt did not complain here, strangely... * gui: Handle PendingDevicesChanged event. Even though it currently only holds one device at a time, wrap the contents in an array under the "added" property name. * lib/model: Fix null values in PendingFoldersChanged removed member. * gui: Handle PendingFoldersChanged event. * lib/model: Simplify construction of expiredPendingList. * lib/model: Reduce code duplication in cleanPending(). Use goto and a label for the common parts of calling the DB removal function and building the event data part. * lib/events, gui: Mark ...Rejected events deprecated. Extend comments explaining the conditions when the replacement event types are emitted. * lib/model: Wrap removed devices in array of objects as well. * lib/db: Use iter.Value() instead of needless db.Get(iter.Key()) * lib/db: Add comment explaining RemovePendingFoldersBeforeTime(). * lib/model: Rename fields folderID and deviceID in event data. * lib/db: Only list actually expired IDs as removed. Skip entries where Delete() failed as well as invalid entries that got removed automatically. * lib/model: Gofmt
91 lines
5.1 KiB
JavaScript
91 lines
5.1 KiB
JavaScript
var debugEvents = !true;
|
|
|
|
angular.module('syncthing.core')
|
|
.service('Events', ['$http', '$rootScope', '$timeout', function ($http, $rootScope, $timeout) {
|
|
'use strict';
|
|
|
|
var lastID = 0;
|
|
var self = this;
|
|
|
|
function successFn(data) {
|
|
// When Syncthing restarts while the long polling connection is in
|
|
// progress the browser on some platforms returns a 200 (since the
|
|
// headers has been flushed with the return code 200), with no data.
|
|
// This basically means that the connection has been reset, and the call
|
|
// was not actually successful.
|
|
if (!data) {
|
|
errorFn(data);
|
|
return;
|
|
}
|
|
$rootScope.$broadcast(self.ONLINE);
|
|
|
|
if (lastID > 0) { // not emit events from first response
|
|
data.forEach(function (event) {
|
|
if (debugEvents) {
|
|
console.log("event", event.id, event.type, event.data);
|
|
}
|
|
$rootScope.$broadcast(event.type, event);
|
|
});
|
|
}
|
|
|
|
var lastEvent = data.pop();
|
|
if (lastEvent) {
|
|
lastID = lastEvent.id;
|
|
}
|
|
|
|
$http.get(urlbase + '/events?since=' + lastID)
|
|
.success(successFn)
|
|
.error(errorFn);
|
|
}
|
|
|
|
function errorFn(dummy) {
|
|
$rootScope.$broadcast(self.OFFLINE);
|
|
|
|
$timeout(function () {
|
|
$http.get(urlbase + '/events?limit=1')
|
|
.success(successFn)
|
|
.error(errorFn);
|
|
}, 1000, false);
|
|
}
|
|
|
|
angular.extend(self, {
|
|
// emitted by this
|
|
|
|
ONLINE: 'UIOnline',
|
|
OFFLINE: 'UIOffline',
|
|
|
|
// emitted by syncthing process
|
|
|
|
CONFIG_SAVED: 'ConfigSaved', // Emitted after the config has been saved by the user or by Syncthing itself
|
|
DEVICE_CONNECTED: 'DeviceConnected', // Generated each time a connection to a device has been established
|
|
DEVICE_DISCONNECTED: 'DeviceDisconnected', // Generated each time a connection to a device has been terminated
|
|
DEVICE_DISCOVERED: 'DeviceDiscovered', // Emitted when a new device is discovered using local discovery
|
|
DEVICE_REJECTED: 'DeviceRejected', // DEPRECATED: Emitted when there is a connection from a device we are not configured to talk to
|
|
PENDING_DEVICES_CHANGED: 'PendingDevicesChanged', // Emitted when pending devices were added / updated (connection from unknown ID) or removed (device is ignored or added)
|
|
DEVICE_PAUSED: 'DevicePaused', // Emitted when a device has been paused
|
|
DEVICE_RESUMED: 'DeviceResumed', // Emitted when a device has been resumed
|
|
DOWNLOAD_PROGRESS: 'DownloadProgress', // Emitted during file downloads for each folder for each file
|
|
FOLDER_COMPLETION: 'FolderCompletion', //Emitted when the local or remote contents for a folder changes
|
|
FOLDER_REJECTED: 'FolderRejected', // DEPRECATED: Emitted when a device sends index information for a folder we do not have, or have but do not share with the device in question
|
|
PENDING_FOLDERS_CHANGED: 'PendingFoldersChanged', // Emitted when pending folders were added / updated (offered by some device, but not shared to them) or removed (folder ignored or added or no longer offered from the remote device)
|
|
FOLDER_SUMMARY: 'FolderSummary', // Emitted when folder contents have changed locally
|
|
ITEM_FINISHED: 'ItemFinished', // Generated when Syncthing ends synchronizing a file to a newer version
|
|
ITEM_STARTED: 'ItemStarted', // Generated when Syncthing begins synchronizing a file to a newer version
|
|
LOCAL_INDEX_UPDATED: 'LocalIndexUpdated', // Generated when the local index information has changed, due to synchronizing one or more items from the cluster or discovering local changes during a scan
|
|
REMOTE_INDEX_UPDATED: 'RemoteIndexUpdated', // Generated each time new index information is received from a device
|
|
STARTING: 'Starting', // Emitted exactly once, when Syncthing starts, before parsing configuration etc
|
|
STARTUP_COMPLETED: 'StartupCompleted', // Emitted exactly once, when initialization is complete and Syncthing is ready to start exchanging data with other devices
|
|
STATE_CHANGED: 'StateChanged', // Emitted when a folder changes state
|
|
FOLDER_ERRORS: 'FolderErrors', // Emitted when a folder has errors preventing a full sync
|
|
FOLDER_SCAN_PROGRESS: 'FolderScanProgress', // Emitted every ScanProgressIntervalS seconds, indicating how far into the scan it is at.
|
|
FOLDER_PAUSED: 'FolderPaused', // Emitted when a folder is paused
|
|
FOLDER_RESUMED: 'FolderResumed', // Emitted when a folder is resumed
|
|
|
|
start: function () {
|
|
$http.get(urlbase + '/events?limit=1')
|
|
.success(successFn)
|
|
.error(errorFn);
|
|
}
|
|
});
|
|
}]);
|