Added message types

This commit is contained in:
Mattias Erming 2014-03-13 16:50:33 +01:00
parent defffe5e9b
commit 87271193e2
4 changed files with 29 additions and 20 deletions

View File

@ -126,19 +126,22 @@ h2 {
bottom: 26px; bottom: 26px;
left: 0; left: 0;
overflow-y: auto; overflow-y: auto;
padding: 4px 0; padding: 4px 8px;
position: absolute; position: absolute;
right: 160px; right: 160px;
top: 36px; top: 36px;
word-wrap: break-word; word-wrap: break-word;
z-index: 0; z-index: 0;
} }
#chat .messages .message { #chat .message .time {
padding: 0 8px;
}
#chat .messages .time {
color: #bbb; color: #bbb;
} }
#chat .messages .user { #chat .message .user {
color: #f00; color: #f00;
} }
#chat .message .text {
color: #999;
}
#chat .message.normal .text {
color: #000;
}

View File

@ -50,10 +50,10 @@
<script type="text/html" id="messages"> <script type="text/html" id="messages">
{{#messages}} {{#messages}}
<div class="message"> <div class="message {{type}}">
<span class="time">{{time}}</span> <span class="time">{{time}}</span>
<span class="user">{{user}}</span> <span class="user">{{user}}</span>
{{text}} <span class="text">{{text}}</span>
</div> </div>
{{/messages}} {{/messages}}
</script> </script>

View File

@ -30,7 +30,8 @@ models.Message = Backbone.Model.extend({
defaults: { defaults: {
time: "", time: "",
user: "", user: "",
text: "" text: "",
type: "normal"
}, },
initialize: function() { initialize: function() {
this.set("time", moment().format("HH:mm")); this.set("time", moment().format("HH:mm"));

View File

@ -114,8 +114,8 @@ function handleInput(input) {
irc.notice(user, text); irc.notice(user, text);
channel.get("messages").add( channel.get("messages").add(
new models.Message({ new models.Message({
type: "notice", text: "Notice to " + user + ": " + text,
text: "Notice to " + user + ": " + text type: "notice"
}) })
); );
break; break;
@ -166,7 +166,8 @@ function handleInput(input) {
default: default:
channel.get("messages").add( channel.get("messages").add(
new models.Message({ new models.Message({
text: "Unknown command: `/" + cmd + "`" text: "Unknown command: `/" + cmd + "`",
type: "error"
}) })
); );
@ -211,7 +212,8 @@ function handleEvent(argv) {
var from = argv.nick ? argv.nick : argv.prefix; var from = argv.nick ? argv.nick : argv.prefix;
var message = new models.Message({ var message = new models.Message({
user: from, user: from,
text: "notice: " + argv.args[1] text: "notice: " + argv.args[1],
type: "notice"
}); });
channels.each(function(channel) { channels.each(function(channel) {
channel.get("messages").add(message); channel.get("messages").add(message);
@ -237,7 +239,8 @@ function handleEvent(argv) {
messages.add( messages.add(
new models.Message({ new models.Message({
user: argv.nick, user: argv.nick,
text: "has joined the channel." text: "has joined the channel.",
type: "join"
}) })
); );
} }
@ -258,7 +261,8 @@ function handleEvent(argv) {
messages.add( messages.add(
new models.Message({ new models.Message({
user: argv.nick, user: argv.nick,
text: "has left the channel." text: "has left the channel.",
type: "part"
}) })
); );
} }
@ -287,8 +291,8 @@ function handleEvent(argv) {
messages.add( messages.add(
new models.Message({ new models.Message({
user: argv.nick, user: argv.nick,
text: "changed the topic of " + argv.args[0] + " to: " text: "changed topic to: " + argv.args[1],
+ argv.args[1] type: "topic"
}) })
); );
break; break;
@ -300,8 +304,8 @@ function handleEvent(argv) {
var messages = channel.get("messages"); var messages = channel.get("messages");
messages.add( messages.add(
new models.Message({ new models.Message({
text: "Topic for " + argv.args[1] + ": " text: "Topic for " + argv.args[1] + ": " + argv.args[2],
+ argv.args[2] type: "topic"
}) })
); );
} }
@ -335,7 +339,8 @@ function handleEvent(argv) {
case "ERROR": case "ERROR":
channels.first().get("messages").add( channels.first().get("messages").add(
new models.Message({ new models.Message({
text: argv.args.slice(2).join(" ") text: argv.args.slice(2).join(" "),
type: "error"
}) })
); );
break; break;