...
 
Commits (2)
......@@ -82,8 +82,32 @@ function format_text(text)
});
}
let load_guild = fetch_json_object_promise('guild');
let load_users = fetch_json_object_promise('users');
let load_stor_info = ctx.storage.getItem('info').catch(() => null);
let load_xhr_info = new APIRequest('GET', 'data/info.json', null)
.setResponseType('json')
.send()
.then((req) => req.response)
.catch(() => null);
let load_info = Promise.all([load_stor_info, load_xhr_info])
.then((values) => {
let data_stor = values[0];
let data_xhr = values[1];
if (data_xhr === null)
return;
if (data_stor === null
|| data_stor.uid !== data_xhr.uid
|| data_stor.guild_id != data_xhr.guild_id)
{
ctx.storage.clear();
ctx.storage.setItem('info', data_xhr);
}
});
let load_guild = load_info.then(() => fetch_json_object_promise('guild'));
let load_users = load_info.then(() => fetch_json_object_promise('users'));
load_guild.then((guild) => {
let elem_channels = document.getElementById('channels');
......@@ -422,17 +446,17 @@ function create_msg_chunk_elem(guild, users, messages, first_msg_idx, last_msg_i
const next_msg = !is_last_msg ? messages[msg_idx - 1] : null;
if (is_first_msg
|| msg.author_id !== prev_msg.author_id)
|| msg.author.id !== prev_msg.author.id)
msg_html += '<div class="message_group">';
msg_html += '<div class="message_container">'
+ '<span class="message_author">' + format_text(users[msg.author_id].nick) + '</span>'
+ '<span class="message_author">' + format_text(users[msg.author.id].nick) + '</span>'
+ '<span class="message_content">' + format_msg_content(guild, users, msg.content) + '</span>'
+ format_msg_attachments(msg)
+ '</div>';
if (is_last_msg
|| msg.author_id !== next_msg.author_id)
|| msg.author.id !== next_msg.author.id)
msg_html += '<hr class="message_group_separator"></div>';
return accum + msg_html;
......@@ -527,7 +551,7 @@ Promise.all([load_guild, load_users]).then((values) => {
let user = users[user_idx];
let member = guild.members.find((member) => member.user_id === user.id);
let member = guild.members.find((member) => member.user.id === user.id);
if (typeof member === 'undefined' || member.nick === null)
user.nick = user.username;
else
......