You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-28 05:03:59 +03:00
Check unsigned.age for getAge() for v2. Don't spam SYNCING emissions.
This commit is contained in:
@@ -143,7 +143,10 @@ module.exports.MatrixEvent.prototype = {
|
||||
* @return {Number} The age of this event in milliseconds.
|
||||
*/
|
||||
getAge: function() {
|
||||
return this.event.age;
|
||||
if (this.event.unsigned && this.event.unsigned.age) {
|
||||
return this.event.unsigned.age; // v2
|
||||
}
|
||||
return this.event.age; // v1
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
10
lib/sync.js
10
lib/sync.js
@@ -15,6 +15,12 @@ var utils = require("./utils");
|
||||
var httpApi = require("./http-api");
|
||||
var Filter = require("./filter");
|
||||
|
||||
// /sync requests allow you to set a timeout= but the request may continue
|
||||
// beyond that and wedge forever, so we need to track how long we are willing
|
||||
// to keep open the connection. This constant is *ADDED* to the timeout= value
|
||||
// to determine the max time we're willing to wait.
|
||||
var BUFFER_PERIOD_MS = 90 * 1000;
|
||||
|
||||
function getFilterName(userId) {
|
||||
// scope this on the user ID because people may login on many accounts
|
||||
// and they all need to be stored!
|
||||
@@ -185,7 +191,7 @@ SyncApi.prototype._sync = function(syncOptions, attempt) {
|
||||
var timeoutObj = setTimeout(function() {
|
||||
discardResult = true;
|
||||
errHandler("Locally timed out waiting for a response");
|
||||
}, qps.timeout + (20 * 1000)); // 20s buffer
|
||||
}, qps.timeout + BUFFER_PERIOD_MS);
|
||||
|
||||
client._http.authedRequestWithPrefix(
|
||||
undefined, "GET", "/sync", qps, undefined, httpApi.PREFIX_V2_ALPHA
|
||||
@@ -324,7 +330,9 @@ SyncApi.prototype._sync = function(syncOptions, attempt) {
|
||||
updateSyncState(client, "PREPARED");
|
||||
syncOptions.hasSyncedBefore = true;
|
||||
}
|
||||
if (client._syncState !== "SYNCING") {
|
||||
updateSyncState(client, "SYNCING");
|
||||
}
|
||||
self._sync(syncOptions);
|
||||
}, errHandler);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user