Batch vue data updates, and sort the users list.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3719 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
62e9dfea90
commit
f7974d2cef
@ -1 +1 @@
|
|||||||
{"type":"tildefriends-app","files":{"app.js":"&LPDR4ZoE/qdPy9djmNFUfblXk7W1znMbwuAXp3/zWPI=.sha256","index.html":"&LGgeVc7llvfOU2gbnQZ60PGYCgcNjtEdHd1vjnJXLaU=.sha256","vue-material.js":"&K5cdLqXYCENPak/TCINHQhyJhpS4G9DlZHGwoh/LF2g=.sha256","tf-user.js":"&uD6N8xUmrjXwIr95nkH/YjuZST6W1Q2MuJ8u6Vcmo6Q=.sha256","tf-message.js":"&KjVh7zASx0TZtZTsS6lJ7T70K9tyXcf+ink4vK7gSWI=.sha256","tf.js":"&r3w4aWGpCJ6J/x/K8hKAx6nohTuXHwVGvTDohJdnhiE=.sha256","commonmark.min.js":"&5x6ek3tFrKTZX6hXNNyFsjmhvrjmWpUkwuuaiyVV1Us=.sha256","vue.js":"&g1wvA+yHl1sVC+eufTsg9If7ZeVyMTBU+h0tks7ZNzE=.sha256","vue-material-theme-default-dark.css":"&RP2nr+2CR18BpHHw5ST9a5GJUCOG9n0G2kuGkcQioWE=.sha256","vue-material.min.css":"&kGbUM2QgFSyHZRzqQb0b+0S3EVIlZ0AXpdiAVjIhou8=.sha256","roboto.css":"&jJv43Om673mQO5JK0jj7714s5E+5Yrf82H6LcDx7wUs=.sha256","material-icons.css":"&a28PdcVvgq/DxyIvJAx/e+ZOEtOuHnr3kjLWKyzH11M=.sha256"}}
|
{"type":"tildefriends-app","files":{"app.js":"&LPDR4ZoE/qdPy9djmNFUfblXk7W1znMbwuAXp3/zWPI=.sha256","index.html":"&zwiRwroNQ1SnCsq97zB8dRiGwY4H+ii4ZtuKR385zdI=.sha256","vue-material.js":"&K5cdLqXYCENPak/TCINHQhyJhpS4G9DlZHGwoh/LF2g=.sha256","tf-user.js":"&uD6N8xUmrjXwIr95nkH/YjuZST6W1Q2MuJ8u6Vcmo6Q=.sha256","tf-message.js":"&KjVh7zASx0TZtZTsS6lJ7T70K9tyXcf+ink4vK7gSWI=.sha256","tf.js":"&Kf578HPfGnoog7LmW2Nof8dQldS04Opl26CE5+nsFLA=.sha256","commonmark.min.js":"&5x6ek3tFrKTZX6hXNNyFsjmhvrjmWpUkwuuaiyVV1Us=.sha256","vue.js":"&g1wvA+yHl1sVC+eufTsg9If7ZeVyMTBU+h0tks7ZNzE=.sha256","vue-material-theme-default-dark.css":"&RP2nr+2CR18BpHHw5ST9a5GJUCOG9n0G2kuGkcQioWE=.sha256","vue-material.min.css":"&kGbUM2QgFSyHZRzqQb0b+0S3EVIlZ0AXpdiAVjIhou8=.sha256","roboto.css":"&jJv43Om673mQO5JK0jj7714s5E+5Yrf82H6LcDx7wUs=.sha256","material-icons.css":"&a28PdcVvgq/DxyIvJAx/e+ZOEtOuHnr3kjLWKyzH11M=.sha256"}}
|
@ -39,7 +39,7 @@
|
|||||||
<md-list-item v-for="connection in connections" v-bind:key="'connection-' + JSON.stringify(connection)"><tf-user :id="connection"></tf-user></md-list-item>
|
<md-list-item v-for="connection in connections" v-bind:key="'connection-' + JSON.stringify(connection)"><tf-user :id="connection"></tf-user></md-list-item>
|
||||||
<md-list-item @click="show_connect_dialog = true">Connect</md-list-item>
|
<md-list-item @click="show_connect_dialog = true">Connect</md-list-item>
|
||||||
<md-subheader>Users</md-subheader>
|
<md-subheader>Users</md-subheader>
|
||||||
<md-list-item v-for="user in Object.keys(users)" v-bind:key="'user-' + user"><tf-user v-bind:id="user"/></md-list-item>
|
<md-list-item v-for="user in Object.keys(users).sort((x, y) => (users[x].name || x).localeCompare(users[y].name || y))" v-bind:key="'user-' + user"><tf-user v-bind:id="user"/></md-list-item>
|
||||||
</md-list>
|
</md-list>
|
||||||
</md-app-drawer>
|
</md-app-drawer>
|
||||||
<md-app-toolbar class="md-secondary" v-show="unread > 0">
|
<md-app-toolbar class="md-secondary" v-show="unread > 0">
|
||||||
|
@ -16,22 +16,25 @@ var g_data = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var g_data_initial = JSON.parse(JSON.stringify(g_data));
|
var g_data_initial = JSON.parse(JSON.stringify(g_data));
|
||||||
window.addEventListener('message', function(event) {
|
var g_message_queue = [];
|
||||||
var key = Object.keys(event.data)[0];
|
var g_process_pending = false;
|
||||||
if (key == 'message') {
|
|
||||||
event.data[key].children = [];
|
function processMessages() {
|
||||||
var found = false;
|
for (let event of g_message_queue) {
|
||||||
var root = JSON.parse(event.data[key].content).root;
|
var key = Object.keys(event.data)[0];
|
||||||
if (root) {
|
if (key == 'message') {
|
||||||
for (let message of g_data.messages) {
|
event.data[key].children = [];
|
||||||
if (root == message.id) {
|
var found = false;
|
||||||
message.children.push(event.data[key]);
|
var root = JSON.parse(event.data[key].content).root;
|
||||||
message.children.sort((x, y) => y.timestamp - x.timestamp);
|
if (root) {
|
||||||
found = true;
|
for (let message of g_data.messages) {
|
||||||
|
if (root == message.id) {
|
||||||
|
message.children.push(event.data[key]);
|
||||||
|
message.children.sort((x, y) => y.timestamp - x.timestamp);
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (!found) {
|
|
||||||
for (let message of g_data.messages) {
|
for (let message of g_data.messages) {
|
||||||
if (JSON.parse(message.content).root == event.data[key].id) {
|
if (JSON.parse(message.content).root == event.data[key].id) {
|
||||||
event.data[key].children.push(message);
|
event.data[key].children.push(message);
|
||||||
@ -40,51 +43,61 @@ window.addEventListener('message', function(event) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if (!found) {
|
||||||
if (!found) {
|
g_data.messages.push(event.data[key]);
|
||||||
g_data.messages.push(event.data[key]);
|
g_data.messages.sort((x, y) => y.timestamp - x.timestamp);
|
||||||
g_data.messages.sort((x, y) => y.timestamp - x.timestamp);
|
|
||||||
}
|
|
||||||
} else if (key + 's' in g_data && Array.isArray(g_data[key + 's'])) {
|
|
||||||
g_data[key + 's'].push(event.data[key]);
|
|
||||||
} else if (key == 'user') {
|
|
||||||
Vue.set(g_data.users, event.data.user.user, Object.assign({}, g_data.users[event.data.user.user] || {}, event.data.user.about));
|
|
||||||
} else if (key == 'followers') {
|
|
||||||
if (!g_data.users[event.data.followers.id]) {
|
|
||||||
Vue.set(g_data.users, event.data.followers.id, {});
|
|
||||||
}
|
|
||||||
Vue.set(g_data.users[event.data.followers.id], 'followers', event.data.followers.users);
|
|
||||||
} else if (key == 'following') {
|
|
||||||
if (!g_data.users[event.data.following.id]) {
|
|
||||||
Vue.set(g_data.users, event.data.following.id, {});
|
|
||||||
}
|
|
||||||
Vue.set(g_data.users[event.data.following.id], 'following', event.data.following.users);
|
|
||||||
} else if (key == 'broadcasts') {
|
|
||||||
g_data.broadcasts = event.data.broadcasts;
|
|
||||||
} else if (key == 'pubs') {
|
|
||||||
g_data.pubs = event.data.pubs;
|
|
||||||
} else if (key == 'apps') {
|
|
||||||
g_data.apps = event.data.apps;
|
|
||||||
} else if (key == 'votes') {
|
|
||||||
event.data.votes.forEach(function(vote) {
|
|
||||||
var content = JSON.parse(vote.content);
|
|
||||||
var link = content.vote.link;
|
|
||||||
if (!g_data.votes[link]) {
|
|
||||||
Vue.set(g_data.votes, link, {});
|
|
||||||
}
|
}
|
||||||
if (!g_data.votes[link][content.vote.expression]) {
|
} else if (key + 's' in g_data && Array.isArray(g_data[key + 's'])) {
|
||||||
Vue.set(g_data.votes[link], content.vote.expression, []);
|
g_data[key + 's'].push(event.data[key]);
|
||||||
|
} else if (key == 'user') {
|
||||||
|
Vue.set(g_data.users, event.data.user.user, Object.assign({}, g_data.users[event.data.user.user] || {}, event.data.user.about));
|
||||||
|
} else if (key == 'followers') {
|
||||||
|
if (!g_data.users[event.data.followers.id]) {
|
||||||
|
Vue.set(g_data.users, event.data.followers.id, {});
|
||||||
}
|
}
|
||||||
g_data.votes[link][content.vote.expression].push({author: vote.author, value: content.vote.value});
|
Vue.set(g_data.users[event.data.followers.id], 'followers', event.data.followers.users);
|
||||||
});
|
} else if (key == 'following') {
|
||||||
} else if (key == 'clear') {
|
if (!g_data.users[event.data.following.id]) {
|
||||||
Object.keys(g_data_initial).forEach(function(key) {
|
Vue.set(g_data.users, event.data.following.id, {});
|
||||||
Vue.set(g_data, key, JSON.parse(JSON.stringify(g_data_initial[key])));
|
}
|
||||||
});
|
Vue.set(g_data.users[event.data.following.id], 'following', event.data.following.users);
|
||||||
} else if (key == 'unread') {
|
} else if (key == 'broadcasts') {
|
||||||
g_data.unread += event.data.unread;
|
g_data.broadcasts = event.data.broadcasts;
|
||||||
} else {
|
} else if (key == 'pubs') {
|
||||||
g_data[key] = event.data[key];
|
g_data.pubs = event.data.pubs;
|
||||||
|
} else if (key == 'apps') {
|
||||||
|
g_data.apps = event.data.apps;
|
||||||
|
} else if (key == 'votes') {
|
||||||
|
event.data.votes.forEach(function(vote) {
|
||||||
|
var content = JSON.parse(vote.content);
|
||||||
|
var link = content.vote.link;
|
||||||
|
if (!g_data.votes[link]) {
|
||||||
|
Vue.set(g_data.votes, link, {});
|
||||||
|
}
|
||||||
|
if (!g_data.votes[link][content.vote.expression]) {
|
||||||
|
Vue.set(g_data.votes[link], content.vote.expression, []);
|
||||||
|
}
|
||||||
|
g_data.votes[link][content.vote.expression].push({author: vote.author, value: content.vote.value});
|
||||||
|
});
|
||||||
|
} else if (key == 'clear') {
|
||||||
|
Object.keys(g_data_initial).forEach(function(key) {
|
||||||
|
Vue.set(g_data, key, JSON.parse(JSON.stringify(g_data_initial[key])));
|
||||||
|
});
|
||||||
|
} else if (key == 'unread') {
|
||||||
|
g_data.unread += event.data.unread;
|
||||||
|
} else {
|
||||||
|
g_data[key] = event.data[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
g_message_queue = [];
|
||||||
|
g_process_pending = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener('message', function(event) {
|
||||||
|
g_message_queue.push(event);
|
||||||
|
if (!g_process_pending) {
|
||||||
|
g_process_pending = true;
|
||||||
|
setTimeout(processMessages, 250);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
window.addEventListener('load', function() {
|
window.addEventListener('load', function() {
|
||||||
|
Loading…
Reference in New Issue
Block a user