mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 12:05:57 +01:00
added methods and socket listeners for group joining and leaving, #2588
This commit is contained in:
26
public/src/client/groups/list.js
Normal file
26
public/src/client/groups/list.js
Normal file
@@ -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;
|
||||||
|
});
|
||||||
23
src/socket.io/groups.js
Normal file
23
src/socket.io/groups.js
Normal file
@@ -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;
|
||||||
Reference in New Issue
Block a user