Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
frankpagan committed Oct 24, 2023
2 parents 3142ddd + bb9a929 commit c06efbe
Showing 1 changed file with 38 additions and 35 deletions.
73 changes: 38 additions & 35 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,45 +61,48 @@ class SocketServer extends EventEmitter {
socket.host = url.host || socket.origin;
}

let data = {
socket,
method: 'read.object',
array: 'message_log',
$filter: {
sort: [
{ key: '_id', direction: 'desc' }
if (organization && organization.status !== false) {
let data = {
socket,
method: 'read.object',
array: 'message_log',
$filter: {
sort: [
{ key: '_id', direction: 'desc' }
]
},
sync: true,
organization_id
}

if (options.lastSynced)
data.$filter.query = [
{ key: '_id', value: options.lastSynced, operator: '$gt' }
]
},
sync: true,
organization_id
}
else
data.$filter.limit = 1

self.emit('read.object', data);

if (self.authenticate) {
const { user_id, expires } = self.authenticate.decodeToken(options.token)
const userStatus = { socket, method: 'userStatus', user_id: options.user_id, userStatus: 'off', organization_id }
if (user_id) {
options.user_id = user_id
socket.user_id = user_id;
socket.expires = expires;
userStatus.userStatus = 'on'
self.emit("notification.user", socket)
}

if (options.lastSynced)
data.$filter.query = [
{ key: '_id', value: options.lastSynced, operator: '$gt' }
]
else
data.$filter.limit = 1

self.emit('read.object', data);

if (self.authenticate) {
const { user_id, expires } = self.authenticate.decodeToken(options.token)
const userStatus = { socket, method: 'userStatus', user_id: options.user_id, userStatus: 'off', organization_id }
if (user_id) {
options.user_id = user_id
socket.user_id = user_id;
socket.expires = expires;
userStatus.userStatus = 'on'
self.emit("notification.user", socket)
}
self.emit('userStatus', userStatus);

self.emit('userStatus', userStatus);
self.onWebSocket(socket);

self.onWebSocket(socket);
} else
self.onWebSocket(socket);
}

} else
self.onWebSocket(socket);
} else {
socket.send(JSON.stringify({ method: 'Access Denied', error: 'An organization_id is required' }))
}
Expand Down Expand Up @@ -420,7 +423,7 @@ class SocketServer extends EventEmitter {
if (authorized && authorized.authorized)
data = authorized.authorized

if (!data.method.startsWith('read.') && data.method !== 'updateUserStatus' && data.method !== 'userStatus' && data.method !== 'signIn' && data.method !== 'signUp') {
if (data.log !== false && data.log !== 'false' && !data.method.startsWith('read.') && data.method !== 'updateUserStatus' && data.method !== 'userStatus' && data.method !== 'signIn' && data.method !== 'signUp') {
let object = { url: socket.socketUrl, data }
delete object.socket
this.emit('create.object', {
Expand Down

0 comments on commit c06efbe

Please sign in to comment.