You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-29 16:43:09 +03:00
Merge pull request #228 from pik/bug-invalid-filter
Fix sync breaking when an invalid filterId is in localStorage
This commit is contained in:
@@ -2395,7 +2395,26 @@ MatrixClient.prototype.getOrCreateFilter = function(filterName, filter) {
|
|||||||
}
|
}
|
||||||
// debuglog("Existing filter ID %s: %s; new filter: %s",
|
// debuglog("Existing filter ID %s: %s; new filter: %s",
|
||||||
// filterId, JSON.stringify(oldDef), JSON.stringify(newDef));
|
// filterId, JSON.stringify(oldDef), JSON.stringify(newDef));
|
||||||
return;
|
self.store.setFilterIdByName(filterName, undefined);
|
||||||
|
return undefined;
|
||||||
|
}, function(error) {
|
||||||
|
// Synapse currently returns the following when the filter cannot be found:
|
||||||
|
// {
|
||||||
|
// errcode: "M_UNKNOWN",
|
||||||
|
// name: "M_UNKNOWN",
|
||||||
|
// message: "No row found",
|
||||||
|
// data: Object, httpStatus: 404
|
||||||
|
// }
|
||||||
|
if (error.httpStatus === 404 &&
|
||||||
|
(error.errcode === "M_UNKNOWN" || error.errcode === "M_NOT_FOUND")) {
|
||||||
|
// Clear existing filterId from localStorage
|
||||||
|
// if it no longer exists on the server
|
||||||
|
self.store.setFilterIdByName(filterName, undefined);
|
||||||
|
// Return a undefined value for existingId further down the promise chain
|
||||||
|
return undefined;
|
||||||
|
} else {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ describe("MatrixClient", function() {
|
|||||||
if (next.error) {
|
if (next.error) {
|
||||||
return q.reject({
|
return q.reject({
|
||||||
errcode: next.error.errcode,
|
errcode: next.error.errcode,
|
||||||
|
httpStatus: next.error.httpStatus,
|
||||||
name: next.error.errcode,
|
name: next.error.errcode,
|
||||||
message: "Expected testing error",
|
message: "Expected testing error",
|
||||||
data: next.error
|
data: next.error
|
||||||
@@ -204,6 +205,44 @@ describe("MatrixClient", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("getOrCreateFilter", function() {
|
||||||
|
it("should POST createFilter if no id is present in localStorage", function() {
|
||||||
|
});
|
||||||
|
it("should use an existing filter if id is present in localStorage", function() {
|
||||||
|
});
|
||||||
|
it("should handle localStorage filterId missing from the server", function(done) {
|
||||||
|
function getFilterName(userId, suffix) {
|
||||||
|
// scope this on the user ID because people may login on many accounts
|
||||||
|
// and they all need to be stored!
|
||||||
|
return "FILTER_SYNC_" + userId + (suffix ? "_" + suffix : "");
|
||||||
|
}
|
||||||
|
var invalidFilterId = 'invalidF1lt3r';
|
||||||
|
httpLookups = [];
|
||||||
|
httpLookups.push({
|
||||||
|
method: "GET",
|
||||||
|
path: FILTER_PATH + '/' + invalidFilterId,
|
||||||
|
error: {
|
||||||
|
errcode: "M_UNKNOWN",
|
||||||
|
name: "M_UNKNOWN",
|
||||||
|
message: "No row found",
|
||||||
|
data: { errcode: "M_UNKNOWN", error: "No row found" },
|
||||||
|
httpStatus: 404
|
||||||
|
}
|
||||||
|
});
|
||||||
|
httpLookups.push(FILTER_RESPONSE);
|
||||||
|
store.getFilterIdByName.andReturn(invalidFilterId);
|
||||||
|
|
||||||
|
var filterName = getFilterName(client.credentials.userId);
|
||||||
|
client.store.setFilterIdByName(filterName, invalidFilterId);
|
||||||
|
var filter = new sdk.Filter(client.credentials.userId);
|
||||||
|
|
||||||
|
client.getOrCreateFilter(filterName, filter).then(function(filterId) {
|
||||||
|
expect(filterId).toEqual(FILTER_RESPONSE.data.filter_id);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("retryImmediately", function() {
|
describe("retryImmediately", function() {
|
||||||
it("should return false if there is no request waiting", function() {
|
it("should return false if there is no request waiting", function() {
|
||||||
client.startClient();
|
client.startClient();
|
||||||
|
|||||||
Reference in New Issue
Block a user