Commit | Line | Data |
---|---|---|
9df70c63 D |
1 | // TODO: Channel modes\r |
2 | // TODO: Listen to gateway events for anythign related to this channel\r | |
eaaf73b0 | 3 | _kiwi.model.Channel = _kiwi.model.Panel.extend({\r |
9df70c63 D |
4 | initialize: function (attributes) {\r |
5 | var name = this.get("name") || "",\r | |
fdf0c026 | 6 | members;\r |
9df70c63 | 7 | \r |
9df70c63 | 8 | this.set({\r |
eaaf73b0 | 9 | "members": new _kiwi.model.MemberList(),\r |
9df70c63 D |
10 | "name": name,\r |
11 | "scrollback": [],\r | |
12 | "topic": ""\r | |
13 | }, {"silent": true});\r | |
14 | \r | |
fdf0c026 D |
15 | this.view = new _kiwi.view.Channel({"model": this, "name": name});\r |
16 | \r | |
9df70c63 | 17 | members = this.get("members");\r |
062bae80 | 18 | members.channel = this;\r |
697a76c5 | 19 | members.bind("add", function (member, members, options) {\r |
ddd74e86 | 20 | var show_message = _kiwi.global.settings.get('show_joins_parts');\r |
93fa049c D |
21 | if (show_message === false) {\r |
22 | return;\r | |
23 | }\r | |
9966ae4a | 24 | \r |
697a76c5 | 25 | this.addMsg(' ', '== ' + _kiwi.global.i18n.translate('client_models_channel_join').fetch(member.displayNick(true)), 'action join', {time: options.kiwi.time});\r |
9df70c63 D |
26 | }, this);\r |
27 | \r | |
28 | members.bind("remove", function (member, members, options) {\r | |
ddd74e86 | 29 | var show_message = _kiwi.global.settings.get('show_joins_parts');\r |
697a76c5 | 30 | var msg = (options.kiwi.message) ? '(' + options.kiwi.message + ')' : '';\r |
9df70c63 | 31 | \r |
697a76c5 JA |
32 | if (options.kiwi.type === 'quit' && show_message) {\r |
33 | this.addMsg(' ', '== ' + _kiwi.global.i18n.translate('client_models_channel_quit').fetch(member.displayNick(true), msg), 'action quit', {time: options.kiwi.time});\r | |
57523ba3 | 34 | \r |
697a76c5 | 35 | } else if (options.kiwi.type === 'kick') {\r |
57523ba3 | 36 | \r |
697a76c5 | 37 | if (!options.kiwi.current_user_kicked) {\r |
b8c035b2 | 38 | //If user kicked someone, show the message regardless of settings.\r |
697a76c5 JA |
39 | if (show_message || options.kiwi.current_user_initiated) {\r |
40 | this.addMsg(' ', '== ' + _kiwi.global.i18n.translate('client_models_channel_kicked').fetch(member.displayNick(true), options.kiwi.by, msg), 'action kick', {time: options.kiwi.time});\r | |
b8c035b2 VDF |
41 | }\r |
42 | } else {\r | |
697a76c5 | 43 | this.addMsg(' ', '== ' + _kiwi.global.i18n.translate('client_models_channel_selfkick').fetch(options.kiwi.by, msg), 'action kick', {time: options.kiwi.time});\r |
eed5ac29 | 44 | }\r |
3949df87 | 45 | } else if (show_message) {\r |
697a76c5 | 46 | this.addMsg(' ', '== ' + _kiwi.global.i18n.translate('client_models_channel_part').fetch(member.displayNick(true), msg), 'action part', {time: options.kiwi.time});\r |
9df70c63 D |
47 | }\r |
48 | }, this);\r | |
f8508c7a D |
49 | },\r |
50 | \r | |
51 | \r | |
52 | addMsg: function (nick, msg, type, opts) {\r | |
53 | var message_obj, bs, d,\r | |
54 | scrollback = (parseInt(_kiwi.global.settings.get('scrollback'), 10) || 250);\r | |
55 | \r | |
56 | opts = opts || {};\r | |
57 | \r | |
58 | // Time defaults to now\r | |
50263ea0 D |
59 | if (typeof opts.time === 'number') {\r |
60 | opts.time = new Date(opts.time);\r | |
61 | } else {\r | |
697a76c5 | 62 | opts.time = new Date();\r |
f8508c7a D |
63 | }\r |
64 | \r | |
65 | // CSS style defaults to empty string\r | |
66 | if (!opts || typeof opts.style === 'undefined') {\r | |
67 | opts.style = '';\r | |
68 | }\r | |
69 | \r | |
70 | // Run through the plugins\r | |
71 | message_obj = {"msg": msg, "date": opts.date, "time": opts.time, "nick": nick, "chan": this.get("name"), "type": type, "style": opts.style};\r | |
72 | //tmp = _kiwi.plugs.run('addmsg', message_obj);\r | |
73 | if (!message_obj) {\r | |
74 | return;\r | |
75 | }\r | |
76 | \r | |
77 | // The CSS class (action, topic, notice, etc)\r | |
78 | if (typeof message_obj.type !== "string") {\r | |
79 | message_obj.type = '';\r | |
80 | }\r | |
81 | \r | |
82 | // Make sure we don't have NaN or something\r | |
83 | if (typeof message_obj.msg !== "string") {\r | |
84 | message_obj.msg = '';\r | |
85 | }\r | |
86 | \r | |
87 | // Update the scrollback\r | |
88 | bs = this.get("scrollback");\r | |
89 | if (bs) {\r | |
90 | bs.push(message_obj);\r | |
91 | \r | |
92 | // Keep the scrolback limited\r | |
93 | if (bs.length > scrollback) {\r | |
94 | bs.splice(scrollback);\r | |
95 | }\r | |
96 | this.set({"scrollback": bs}, {silent: true});\r | |
97 | }\r | |
98 | \r | |
99 | this.trigger("msg", message_obj);\r | |
100 | },\r | |
101 | \r | |
102 | \r | |
103 | clearMessages: function () {\r | |
104 | this.set({'scrollback': []}, {silent: true});\r | |
105 | this.addMsg('', 'Window cleared');\r | |
106 | \r | |
107 | this.view.render();\r | |
72db27e4 D |
108 | },\r |
109 | \r | |
110 | \r | |
111 | setMode: function(mode_string) {\r | |
112 | this.get('network').gateway.mode(this.get('name'), mode_string);\r | |
425efe7a JA |
113 | },\r |
114 | \r | |
115 | isChannel: function() {\r | |
116 | return true;\r | |
9df70c63 | 117 | }\r |
eed5ac29 | 118 | });\r |