backport fixes from vector
parent
aba4c1e9af
commit
6cca5f4c05
|
@ -23,6 +23,16 @@ var matrixClient = null;
|
||||||
|
|
||||||
var localStorage = window.localStorage;
|
var localStorage = window.localStorage;
|
||||||
|
|
||||||
|
function deviceId() {
|
||||||
|
var id = Math.floor(Math.random()*16777215).toString(16);
|
||||||
|
id = "W" + "000000".substring(id.length) + id;
|
||||||
|
if (localStorage) {
|
||||||
|
id = localStorage.getItem("mx_device_id") || id;
|
||||||
|
localStorage.setItem("mx_device_id", id);
|
||||||
|
}
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
function createClient(hs_url, is_url, user_id, access_token) {
|
function createClient(hs_url, is_url, user_id, access_token) {
|
||||||
var opts = {
|
var opts = {
|
||||||
baseUrl: hs_url,
|
baseUrl: hs_url,
|
||||||
|
@ -31,6 +41,11 @@ function createClient(hs_url, is_url, user_id, access_token) {
|
||||||
userId: user_id
|
userId: user_id
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (localStorage) {
|
||||||
|
opts.sessionStore = new Matrix.WebStorageSessionStore(localStorage);
|
||||||
|
opts.deviceId = deviceId();
|
||||||
|
}
|
||||||
|
|
||||||
matrixClient = Matrix.createClient(opts);
|
matrixClient = Matrix.createClient(opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,6 +64,10 @@ module.exports = {
|
||||||
return matrixClient;
|
return matrixClient;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
unset: function() {
|
||||||
|
matrixClient = null;
|
||||||
|
},
|
||||||
|
|
||||||
replaceUsingUrls: function(hs_url, is_url) {
|
replaceUsingUrls: function(hs_url, is_url) {
|
||||||
matrixClient = Matrix.createClient({
|
matrixClient = Matrix.createClient({
|
||||||
baseUrl: hs_url,
|
baseUrl: hs_url,
|
||||||
|
@ -57,10 +76,16 @@ module.exports = {
|
||||||
},
|
},
|
||||||
|
|
||||||
replaceUsingAccessToken: function(hs_url, is_url, user_id, access_token) {
|
replaceUsingAccessToken: function(hs_url, is_url, user_id, access_token) {
|
||||||
createClient(hs_url, is_url, user_id, access_token);
|
|
||||||
if (localStorage) {
|
if (localStorage) {
|
||||||
try {
|
try {
|
||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
|
} catch (e) {
|
||||||
|
console.warn("Error using local storage");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
createClient(hs_url, is_url, user_id, access_token);
|
||||||
|
if (localStorage) {
|
||||||
|
try {
|
||||||
localStorage.setItem("mx_hs_url", hs_url);
|
localStorage.setItem("mx_hs_url", hs_url);
|
||||||
localStorage.setItem("mx_is_url", is_url);
|
localStorage.setItem("mx_is_url", is_url);
|
||||||
localStorage.setItem("mx_user_id", user_id);
|
localStorage.setItem("mx_user_id", user_id);
|
||||||
|
|
|
@ -17,7 +17,12 @@ limitations under the License.
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
function tsOfNewestEvent(room) {
|
function tsOfNewestEvent(room) {
|
||||||
return room.timeline[room.timeline.length - 1].getTs();
|
if (room.timeline.length) {
|
||||||
|
return room.timeline[room.timeline.length - 1].getTs();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return Number.MAX_SAFE_INTEGER;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function mostRecentActivityFirst(roomList) {
|
function mostRecentActivityFirst(roomList) {
|
||||||
|
|
Loading…
Reference in New Issue