do inscremental updates instead of full updates
This commit is contained in:
+17
-8
@@ -2,23 +2,24 @@
|
|||||||
|
|
||||||
// Make shortcut icon appear with a green dot + show unread count in title.
|
// Make shortcut icon appear with a green dot + show unread count in title.
|
||||||
export function updateFavicon(count) {
|
export function updateFavicon(count) {
|
||||||
var oldIcon = document.getElementById('shortcut-icon');
|
const oldIcon = document.getElementById('shortcut-icon');
|
||||||
if (oldIcon) {
|
const head = document.head || document.getElementsByTagName('head')[0];
|
||||||
var head = document.head || document.getElementsByTagName('head')[0];
|
const newIcon = document.createElement('link');
|
||||||
var newIcon = document.createElement('link');
|
|
||||||
newIcon.type = 'image/png';
|
newIcon.type = 'image/png';
|
||||||
newIcon.id = 'shortcut-icon';
|
newIcon.id = 'shortcut-icon';
|
||||||
newIcon.rel = 'shortcut icon';
|
newIcon.rel = 'shortcut icon';
|
||||||
newIcon.href = 'img/logo32x32' + (count > 0 ? 'a' : '') + '.png';
|
newIcon.href = 'img/logo32x32' + (count > 0 ? 'a' : '') + '.png';
|
||||||
|
if (oldIcon) {
|
||||||
head.removeChild(oldIcon);
|
head.removeChild(oldIcon);
|
||||||
head.appendChild(newIcon);
|
|
||||||
}
|
}
|
||||||
|
head.appendChild(newIcon);
|
||||||
|
|
||||||
document.title = (count > 0 ? '('+count+') ' : '') + 'Tinode';
|
document.title = (count > 0 ? '('+count+') ' : '') + 'Tinode';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create VCard which represents topic 'public' info
|
// Create VCard which represents topic 'public' info
|
||||||
export function vcard(fn, imageDataUrl) {
|
export function vcard(fn, imageDataUrl) {
|
||||||
var card = null;
|
const card = null;
|
||||||
|
|
||||||
if ((fn && fn.trim()) || imageDataUrl) {
|
if ((fn && fn.trim()) || imageDataUrl) {
|
||||||
card = {};
|
card = {};
|
||||||
@@ -26,7 +27,7 @@ export function vcard(fn, imageDataUrl) {
|
|||||||
card.fn = fn.trim();
|
card.fn = fn.trim();
|
||||||
}
|
}
|
||||||
if (imageDataUrl) {
|
if (imageDataUrl) {
|
||||||
var dataStart = imageDataUrl.indexOf(',');
|
const dataStart = imageDataUrl.indexOf(',');
|
||||||
card.photo = {
|
card.photo = {
|
||||||
data: imageDataUrl.substring(dataStart+1),
|
data: imageDataUrl.substring(dataStart+1),
|
||||||
type: 'jpg'
|
type: 'jpg'
|
||||||
@@ -38,6 +39,14 @@ export function vcard(fn, imageDataUrl) {
|
|||||||
|
|
||||||
// Deep-shallow compare two arrays: shallow compare each element.
|
// Deep-shallow compare two arrays: shallow compare each element.
|
||||||
export function arrayEqual(a, b) {
|
export function arrayEqual(a, b) {
|
||||||
|
if (a === b) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Array.isArray(a) || !Array.isArray(b)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Compare lengths first.
|
// Compare lengths first.
|
||||||
if (a.length != b.length) {
|
if (a.length != b.length) {
|
||||||
return false;
|
return false;
|
||||||
@@ -45,7 +54,7 @@ export function arrayEqual(a, b) {
|
|||||||
// Order of elements is ignored.
|
// Order of elements is ignored.
|
||||||
a.sort();
|
a.sort();
|
||||||
b.sort();
|
b.sort();
|
||||||
for (var i = 0, l = a.length; i < l; i++) {
|
for (let i = 0, l = a.length; i < l; i++) {
|
||||||
if (a[i] !== b[i]) {
|
if (a[i] !== b[i]) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ export default class EditAccountView extends React.Component {
|
|||||||
|
|
||||||
handleFullNameUpdate(fn) {
|
handleFullNameUpdate(fn) {
|
||||||
this.setState({fullName: fn});
|
this.setState({fullName: fn});
|
||||||
this.props.onUpdateAccount(undefined, vcard(fn, this.state.avatar));
|
this.props.onUpdateAccount(undefined, vcard(fn, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
handlePasswordUpdate(pwd) {
|
handlePasswordUpdate(pwd) {
|
||||||
@@ -70,7 +70,7 @@ export default class EditAccountView extends React.Component {
|
|||||||
|
|
||||||
handleImageChanged(img) {
|
handleImageChanged(img) {
|
||||||
this.setState({avatar: img});
|
this.setState({avatar: img});
|
||||||
this.props.onUpdateAccount(undefined, vcard(this.state.fullName, img));
|
this.props.onUpdateAccount(undefined, vcard(null, img));
|
||||||
}
|
}
|
||||||
|
|
||||||
handleCheckboxClick(what, checked) {
|
handleCheckboxClick(what, checked) {
|
||||||
|
|||||||
@@ -220,26 +220,20 @@ class InfoView extends React.Component {
|
|||||||
fn = fn.trim();
|
fn = fn.trim();
|
||||||
if (this.state.fullName !== fn) {
|
if (this.state.fullName !== fn) {
|
||||||
this.setState({fullName: fn});
|
this.setState({fullName: fn});
|
||||||
this.props.onTopicDescUpdate(this.props.topic,
|
this.props.onTopicDescUpdate(this.props.topic, vcard(fn, null), null);
|
||||||
vcard(fn, this.state.avatar),
|
|
||||||
null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handlePrivateUpdate(priv) {
|
handlePrivateUpdate(priv) {
|
||||||
if (this.state.priv !== priv) {
|
if (this.state.priv !== priv) {
|
||||||
this.setState({private: priv});
|
this.setState({private: priv});
|
||||||
this.props.onTopicDescUpdate(this.props.topic,
|
this.props.onTopicDescUpdate(this.props.topic, null, priv || Tinode.DEL_CHAR);
|
||||||
null,
|
|
||||||
priv || Tinode.DEL_CHAR);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleImageChanged(img) {
|
handleImageChanged(img) {
|
||||||
this.setState({avatar: img});
|
this.setState({avatar: img});
|
||||||
this.props.onTopicDescUpdate(this.props.topic,
|
this.props.onTopicDescUpdate(this.props.topic, vcard(null, img), null);
|
||||||
vcard(this.state.fullName, img),
|
|
||||||
null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleMuted(ignored, checked) {
|
handleMuted(ignored, checked) {
|
||||||
|
|||||||
Reference in New Issue
Block a user