From c0d348a6780dc3417c10de8b1b869dccb86f3b82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Astori?= Date: Wed, 29 Nov 2017 02:15:27 -0500 Subject: [PATCH] Fix default value given to `Msg.from` - `{}` is not falsey so Handlebars would try to render the block (see http://handlebarsjs.com/builtin_helpers.html#conditionals), therefore with a `nick` of `undefined`, which breaks `colorClass` (doing `undefined.length) - There does not seem to be a way to check for empty objects in Handlebars (sigh) so checking `from.nick` seems like the most reliable way to check for a non-empty value. Alternatively, we could use a helper to check `{}` but meh. --- client/views/actions/topic.tpl | 2 +- client/views/msg.tpl | 2 +- src/models/msg.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/client/views/actions/topic.tpl b/client/views/actions/topic.tpl index 825b0d1e..b4c26f9a 100644 --- a/client/views/actions/topic.tpl +++ b/client/views/actions/topic.tpl @@ -1,4 +1,4 @@ -{{#if from}} +{{#if from.nick}} {{> ../user_name from}} has changed the topic to: {{else}} diff --git a/client/views/msg.tpl b/client/views/msg.tpl index 64ec97e7..c4087c0c 100644 --- a/client/views/msg.tpl +++ b/client/views/msg.tpl @@ -3,7 +3,7 @@ {{tz time}} - {{#if from}} + {{#if from.nick}} {{> user_name from}} {{/if}} diff --git a/src/models/msg.js b/src/models/msg.js index c48de927..81b8e396 100644 --- a/src/models/msg.js +++ b/src/models/msg.js @@ -7,7 +7,7 @@ var id = 0; class Msg { constructor(attr) { _.defaults(this, attr, { - from: "", + from: {}, id: id++, previews: [], text: "",