Updating user modes on change
authorDarren <darren@darrenwhitlen.com>
Sat, 25 Aug 2012 19:33:08 +0000 (20:33 +0100)
committerDarren <darren@darrenwhitlen.com>
Sat, 25 Aug 2012 19:33:08 +0000 (20:33 +0100)
client_backbone/model.js
client_backbone/model_application.js

index 40d0e9db25c12f248f6e88fad1054db2cbf52c37..4009cd0da12ebdfdd59ad489a7412b5399e6daea 100644 (file)
@@ -96,18 +96,26 @@ kiwi.model.Member = Backbone.Model.extend({
         this.set({"nick": nick, "modes": modes, "prefix": this.getPrefix(modes)}, {silent: true});\r
     },\r
     addMode: function (mode) {\r
-        var modes, prefix;\r
+        var modes_to_add = mode.split(''),\r
+            modes, prefix;\r
+\r
         modes = this.get("modes");\r
-        modes.push(mode);\r
+        $.each(modes_to_add, function (index, item) {\r
+            modes.push(item);\r
+        });\r
+        \r
         modes = this.sortModes(modes);\r
         this.set({"prefix": this.getPrefix(modes), "modes": modes});\r
     },\r
     removeMode: function (mode) {\r
-        var modes, prefix;\r
+        var modes_to_remove = mode.split(''),\r
+            modes, prefix;\r
+\r
         modes = this.get("modes");\r
         modes = _.reject(modes, function (m) {\r
-            return m === mode;\r
+            return (modes_to_remove.indexOf(m) !== -1);\r
         });\r
+        \r
         this.set({"prefix": this.getPrefix(modes), "modes": modes});\r
     },\r
     getPrefix: function (modes) {\r
index 2ae0dd11d35aaea23d0f069733c909a9283b5aa4..74c6a518d1a80c08c100490e74e3fba455282c68 100644 (file)
@@ -171,6 +171,28 @@ kiwi.model.Application = Backbone.Model.extend(new (function () {
             // Clear the temporary userlist\r
             delete channel.temp_userlist;\r
         });\r
+\r
+\r
+        gw.on('onmode', function (event) {\r
+            var channel, members, member;\r
+\r
+            if (!event.channel) return;\r
+            channel = that.panels.getByName(event.channel);\r
+            if (!channel) return;\r
+\r
+            members = channel.get('members');\r
+            if (!members) return;\r
+\r
+            member = members.getByNick(event.effected_nick);\r
+            if (!member) return;\r
+\r
+            if (event.mode[0] === '+') {\r
+                member.addMode(event.mode.substr(1));\r
+            } else if (event.mode[0] === '-') {\r
+                member.removeMode(event.mode.substr(1));\r
+            }\r
+\r
+        });\r
     };\r
 \r
 \r