Skip to content

Commit

Permalink
Dialogs: fix getting dialogs list on begining
Browse files Browse the repository at this point in the history
  • Loading branch information
DrEhsan committed Aug 29, 2019
1 parent df94939 commit 7886c62
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions source/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ io.on('connection', async socket => {
return socket.disconnect();
}

/*
if (socket.handshake.headers.apikey == undefined){
return socket.disconnect();
}*/


let apikey = socket.handshake.query.apikey;

let res = await app.service('users').Model
Expand Down Expand Up @@ -60,14 +54,25 @@ io.on('connection', async socket => {
socket.user = res;

// every user has his own channel after authentication
socket.join('user_'+socket.user._id);
socket.join('user_'+ socket.user._id);

// lets fire client that it has been connected successfully
socket.emit('connected', { status: true, payload: { connected : true } });


// subscribe on dialog rooms
res.dialogs.forEach(async dialog => {
let _dialogRoom = 'dialog_' + dialog._id;

// check if socket joiend room before to not redunduncy joining
if (io.sockets.adapter.rooms){
var socksInRoom = io.sockets.adapter.rooms[_dialogRoom];
if (socksInRoom != undefined){
if (!socksInRoom.sockets[socket.id]){
socket.join(_dialogRoom);
}
}
}
});

// this event handles message sending from clients
socket.on('sendMessage', async data => {
Expand Down Expand Up @@ -128,7 +133,6 @@ io.on('connection', async socket => {
}
})


socket.on('gotMessage', data => {

/**
Expand All @@ -139,7 +143,6 @@ io.on('connection', async socket => {

let dialogRoom = 'dialog_' + data.dialog;


// check if socket joiend room before to not redunduncy joining
if (io.sockets.adapter.rooms){
var socksInRoom = io.sockets.adapter.rooms[dialogRoom];
Expand Down

0 comments on commit 7886c62

Please sign in to comment.