Skip to content

Node.js based forum software built for the modern web

added methods and socket listeners for group joining and leaving, #2588

Julian Lam9fa3675424a5
diff --git a/public/src/client/groups/list.js b/public/src/client/groups/list.js
new file mode 100644
index 0000000000..e7daf195f1
--- /dev/null
+++ b/public/src/client/groups/list.js
@@ -0,0 +1,26 @@
+"use strict";
+/* globals define, ajaxify, socket */
+
+define('forum/groups/list', function() {
+ var Groups = {};
+
+ Groups.init = function() {
+ var groupsEl = $('.groups.row');
+
+ // Group joining and leaving
+ groupsEl.on('click', '[data-action]', function() {
+ var action = $(this).attr('data-action'),
+ groupName = $(this).parents('[data-group]').attr('data-group');
+
+ socket.emit('groups.' + action, {
+ groupName: groupName
+ }, function(err) {
+ if (!err) {
+ ajaxify.refresh();
+ }
+ });
+ });
+ };
+
+ return Groups;
+});
\ No newline at end of file
diff --git a/src/socket.io/groups.js b/src/socket.io/groups.js
new file mode 100644
index 0000000000..9fd29bc2d4
--- /dev/null
+++ b/src/socket.io/groups.js
@@ -0,0 +1,23 @@
+"use strict";
+
+var groups = require('../groups'),
+
+ SocketGroups = {};
+
+SocketGroups.join = function(socket, data, callback) {
+ if (!data) {
+ return callback(new Error('[[error:invalid-data]]'));
+ }
+
+ groups.join(data.groupName, socket.uid, callback);
+};
+
+SocketGroups.leave = function(socket, data, callback) {
+ if (!data) {
+ return callback(new Error('[[error:invalid-data]]'));
+ }
+
+ groups.leave(data.groupName, socket.uid, callback);
+};
+
+module.exports = SocketGroups;