|
|
@ -132,7 +132,10 @@ class ChatController extends SiteController {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async populateRoomId (req, res, next, roomId) {
|
|
|
|
async populateRoomId (req, res, next, roomId) {
|
|
|
|
const { chat: chatService } = this.dtp.services;
|
|
|
|
const {
|
|
|
|
|
|
|
|
chat: chatService,
|
|
|
|
|
|
|
|
logan: loganService,
|
|
|
|
|
|
|
|
} = this.dtp.services;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
res.locals.room = await chatService.getRoomById(roomId);
|
|
|
|
res.locals.room = await chatService.getRoomById(roomId);
|
|
|
|
if (!res.locals.room) {
|
|
|
|
if (!res.locals.room) {
|
|
|
@ -141,12 +144,21 @@ class ChatController extends SiteController {
|
|
|
|
return next();
|
|
|
|
return next();
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
this.log.error('failed to populate roomId', { roomId, error });
|
|
|
|
this.log.error('failed to populate roomId', { roomId, error });
|
|
|
|
|
|
|
|
loganService.sendRequestEvent(module.exports, req, {
|
|
|
|
|
|
|
|
level: 'error',
|
|
|
|
|
|
|
|
event: 'populateRoomId',
|
|
|
|
|
|
|
|
message: error.message,
|
|
|
|
|
|
|
|
data: { roomId, error },
|
|
|
|
|
|
|
|
});
|
|
|
|
return next(error);
|
|
|
|
return next(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async populateInviteId (req, res, next, inviteId) {
|
|
|
|
async populateInviteId (req, res, next, inviteId) {
|
|
|
|
const { chat: chatService } = this.dtp.services;
|
|
|
|
const {
|
|
|
|
|
|
|
|
chat: chatService,
|
|
|
|
|
|
|
|
logan: loganService,
|
|
|
|
|
|
|
|
} = this.dtp.services;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
res.locals.invite = await chatService.getRoomInviteById(inviteId);
|
|
|
|
res.locals.invite = await chatService.getRoomInviteById(inviteId);
|
|
|
|
if (!res.locals.invite) {
|
|
|
|
if (!res.locals.invite) {
|
|
|
@ -155,12 +167,21 @@ class ChatController extends SiteController {
|
|
|
|
return next();
|
|
|
|
return next();
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
this.log.error('failed to populate inviteId', { inviteId, error });
|
|
|
|
this.log.error('failed to populate inviteId', { inviteId, error });
|
|
|
|
|
|
|
|
loganService.sendRequestEvent(module.exports, req, {
|
|
|
|
|
|
|
|
level: 'error',
|
|
|
|
|
|
|
|
event: 'populateInviteId',
|
|
|
|
|
|
|
|
message: error.message,
|
|
|
|
|
|
|
|
data: { inviteId, error },
|
|
|
|
|
|
|
|
});
|
|
|
|
return next(error);
|
|
|
|
return next(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async postRoomInviteAction (req, res) {
|
|
|
|
async postRoomInviteAction (req, res) {
|
|
|
|
const { chat: chatService } = this.dtp.services;
|
|
|
|
const {
|
|
|
|
|
|
|
|
chat: chatService,
|
|
|
|
|
|
|
|
logan: loganService,
|
|
|
|
|
|
|
|
} = this.dtp.services;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const { response } = req.body;
|
|
|
|
const { response } = req.body;
|
|
|
|
const displayList = this.createDisplayList('room-invite-action');
|
|
|
|
const displayList = this.createDisplayList('room-invite-action');
|
|
|
@ -168,11 +189,27 @@ class ChatController extends SiteController {
|
|
|
|
switch (response) {
|
|
|
|
switch (response) {
|
|
|
|
case 'accept':
|
|
|
|
case 'accept':
|
|
|
|
await chatService.acceptRoomInvite(res.locals.invite);
|
|
|
|
await chatService.acceptRoomInvite(res.locals.invite);
|
|
|
|
|
|
|
|
loganService.sendRequestEvent(module.exports, req, {
|
|
|
|
|
|
|
|
level: 'info',
|
|
|
|
|
|
|
|
event: 'postRoomInviteAction',
|
|
|
|
|
|
|
|
message: 'invitation accepted successfully',
|
|
|
|
|
|
|
|
data: {
|
|
|
|
|
|
|
|
invite: res.locals.invite,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
displayList.navigateTo(`/chat/room/${res.locals.invite.room._id}`);
|
|
|
|
displayList.navigateTo(`/chat/room/${res.locals.invite.room._id}`);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case 'reject':
|
|
|
|
case 'reject':
|
|
|
|
await chatService.rejectRoomInvite(res.locals.invite);
|
|
|
|
await chatService.rejectRoomInvite(res.locals.invite);
|
|
|
|
|
|
|
|
loganService.sendRequestEvent(module.exports, req, {
|
|
|
|
|
|
|
|
level: 'info',
|
|
|
|
|
|
|
|
event: 'postRoomInviteAction',
|
|
|
|
|
|
|
|
message: 'invitation rejected successfully',
|
|
|
|
|
|
|
|
data: {
|
|
|
|
|
|
|
|
invite: res.locals.invite,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
displayList.showNotification(
|
|
|
|
displayList.showNotification(
|
|
|
|
`Chat room invite rejected`,
|
|
|
|
`Chat room invite rejected`,
|
|
|
|
'success',
|
|
|
|
'success',
|
|
|
@ -192,6 +229,12 @@ class ChatController extends SiteController {
|
|
|
|
response: req.body.response,
|
|
|
|
response: req.body.response,
|
|
|
|
error,
|
|
|
|
error,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
loganService.sendRequestEvent(module.exports, req, {
|
|
|
|
|
|
|
|
level: 'error',
|
|
|
|
|
|
|
|
event: 'postRoomInviteAction',
|
|
|
|
|
|
|
|
message: `failed to execute room invite action: ${error.message}`,
|
|
|
|
|
|
|
|
data: { error },
|
|
|
|
|
|
|
|
});
|
|
|
|
return res.status(error.statusCode || 500).json({
|
|
|
|
return res.status(error.statusCode || 500).json({
|
|
|
|
success: false,
|
|
|
|
success: false,
|
|
|
|
message: error.message,
|
|
|
|
message: error.message,
|
|
|
@ -200,7 +243,11 @@ class ChatController extends SiteController {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async postRoomInvite (req, res) {
|
|
|
|
async postRoomInvite (req, res) {
|
|
|
|
const { chat: chatService, user: userService } = this.dtp.services;
|
|
|
|
const {
|
|
|
|
|
|
|
|
chat: chatService,
|
|
|
|
|
|
|
|
logan: loganService,
|
|
|
|
|
|
|
|
user: userService,
|
|
|
|
|
|
|
|
} = this.dtp.services;
|
|
|
|
this.log.debug('room invite received', { invite: req.body });
|
|
|
|
this.log.debug('room invite received', { invite: req.body });
|
|
|
|
if (!req.body.username || !req.body.username.length) {
|
|
|
|
if (!req.body.username || !req.body.username.length) {
|
|
|
|
return res.status(400).json({ success: false, message: 'Please provide a username' });
|
|
|
|
return res.status(400).json({ success: false, message: 'Please provide a username' });
|
|
|
@ -223,7 +270,7 @@ class ChatController extends SiteController {
|
|
|
|
throw new SiteError(400, "You can't invite yourself.");
|
|
|
|
throw new SiteError(400, "You can't invite yourself.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
await chatService.sendRoomInvite(res.locals.room, member, req.body);
|
|
|
|
res.locals.invite = await chatService.sendRoomInvite(res.locals.room, member, req.body);
|
|
|
|
|
|
|
|
|
|
|
|
const displayList = this.createDisplayList('invite create');
|
|
|
|
const displayList = this.createDisplayList('invite create');
|
|
|
|
displayList.showNotification(
|
|
|
|
displayList.showNotification(
|
|
|
@ -232,9 +279,28 @@ class ChatController extends SiteController {
|
|
|
|
'top-left',
|
|
|
|
'top-left',
|
|
|
|
5000,
|
|
|
|
5000,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
loganService.sendRequestEvent(module.exports, req, {
|
|
|
|
|
|
|
|
level: 'info',
|
|
|
|
|
|
|
|
event: 'postRoomInvite',
|
|
|
|
|
|
|
|
data: {
|
|
|
|
|
|
|
|
room: {
|
|
|
|
|
|
|
|
_id: res.locals.room._id,
|
|
|
|
|
|
|
|
name: res.locals.room.name,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
invite: res.locals.invite,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
res.status(200).json({ success: true, displayList });
|
|
|
|
res.status(200).json({ success: true, displayList });
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
this.log.error('failed to create room invitation', { error });
|
|
|
|
this.log.error('failed to create room invitation', { error });
|
|
|
|
|
|
|
|
loganService.sendRequestEvent(module.exports, req, {
|
|
|
|
|
|
|
|
level: 'error',
|
|
|
|
|
|
|
|
event: 'postRoomInvite',
|
|
|
|
|
|
|
|
message: `failed to create room invitation: ${error.message}`,
|
|
|
|
|
|
|
|
data: { error },
|
|
|
|
|
|
|
|
});
|
|
|
|
return res.status(error.statusCode || 500).json({
|
|
|
|
return res.status(error.statusCode || 500).json({
|
|
|
|
success: false,
|
|
|
|
success: false,
|
|
|
|
message: error.message,
|
|
|
|
message: error.message,
|
|
|
@ -243,35 +309,78 @@ class ChatController extends SiteController {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async postRoomUpdate (req, res, next) {
|
|
|
|
async postRoomUpdate (req, res, next) {
|
|
|
|
const { chat: chatService } = this.dtp.services;
|
|
|
|
const {
|
|
|
|
|
|
|
|
chat: chatService,
|
|
|
|
|
|
|
|
logan: loganService,
|
|
|
|
|
|
|
|
} = this.dtp.services;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
res.locals.room = await chatService.updateRoom(res.locals.room, req.body);
|
|
|
|
res.locals.room = await chatService.updateRoom(res.locals.room, req.body);
|
|
|
|
|
|
|
|
loganService.sendRequestEvent(module.exports, req, {
|
|
|
|
|
|
|
|
level: 'info',
|
|
|
|
|
|
|
|
event: 'postRoomUpdate',
|
|
|
|
|
|
|
|
data: {
|
|
|
|
|
|
|
|
room: {
|
|
|
|
|
|
|
|
_id: res.locals.room._id,
|
|
|
|
|
|
|
|
name: res.locals.room.name,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
res.redirect(`/chat/room/${res.locals.room._id}`);
|
|
|
|
res.redirect(`/chat/room/${res.locals.room._id}`);
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
this.log.error('failed to update chat room', {
|
|
|
|
loganService.sendRequestEvent(module.exports, req, {
|
|
|
|
// roomId: res.locals.room._id,
|
|
|
|
level: 'error',
|
|
|
|
error,
|
|
|
|
event: 'postRoomUpdate',
|
|
|
|
|
|
|
|
message: `failed to update chat room: ${error.message}`,
|
|
|
|
|
|
|
|
data: { error },
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return next(error);
|
|
|
|
return next(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async postRoomCreate (req, res, next) {
|
|
|
|
async postRoomCreate (req, res, next) {
|
|
|
|
const { chat: chatService } = this.dtp.services;
|
|
|
|
const {
|
|
|
|
|
|
|
|
chat: chatService,
|
|
|
|
|
|
|
|
logan: loganService,
|
|
|
|
|
|
|
|
} = this.dtp.services;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
res.locals.room = await chatService.createRoom(req.user, req.body);
|
|
|
|
res.locals.room = await chatService.createRoom(req.user, req.body);
|
|
|
|
|
|
|
|
loganService.sendRequestEvent(module.exports, req, {
|
|
|
|
|
|
|
|
level: 'info',
|
|
|
|
|
|
|
|
event: 'postRoomCreate',
|
|
|
|
|
|
|
|
message: 'chat room created',
|
|
|
|
|
|
|
|
data: {
|
|
|
|
|
|
|
|
room: res.locals.room,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
res.redirect(`/chat/room/${res.locals.room._id}`);
|
|
|
|
res.redirect(`/chat/room/${res.locals.room._id}`);
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
this.log.error('failed to create chat room', { error });
|
|
|
|
loganService.sendRequestEvent(module.exports, req, {
|
|
|
|
|
|
|
|
level: 'error',
|
|
|
|
|
|
|
|
event: 'postRoomCreate',
|
|
|
|
|
|
|
|
message: `failed to create chat room: ${error.message}`,
|
|
|
|
|
|
|
|
data: { error },
|
|
|
|
|
|
|
|
});
|
|
|
|
return next(error);
|
|
|
|
return next(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async getRoomEditor (req, res) {
|
|
|
|
async getRoomEditor (req, res) {
|
|
|
|
|
|
|
|
const { logan: loganService } = this.dtp.services;
|
|
|
|
|
|
|
|
loganService.sendRequestEvent(module.exports, req, {
|
|
|
|
|
|
|
|
level: 'info',
|
|
|
|
|
|
|
|
event: 'getRoomEditor',
|
|
|
|
|
|
|
|
data: {
|
|
|
|
|
|
|
|
room: {
|
|
|
|
|
|
|
|
_id: res.locals.room._id,
|
|
|
|
|
|
|
|
name: res.locals.room.name,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
res.render('chat/room/editor');
|
|
|
|
res.render('chat/room/editor');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async getRoomForm (req, res, next) {
|
|
|
|
async getRoomForm (req, res, next) {
|
|
|
|
|
|
|
|
const { logan: loganService } = this.dtp.services;
|
|
|
|
const validFormNames = [
|
|
|
|
const validFormNames = [
|
|
|
|
'invite-member',
|
|
|
|
'invite-member',
|
|
|
|
];
|
|
|
|
];
|
|
|
@ -280,65 +389,148 @@ class ChatController extends SiteController {
|
|
|
|
return next(new SiteError(404, 'Form not found'));
|
|
|
|
return next(new SiteError(404, 'Form not found'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
loganService.sendRequestEvent(module.exports, req, {
|
|
|
|
|
|
|
|
level: 'info',
|
|
|
|
|
|
|
|
event: 'getRoomForm',
|
|
|
|
|
|
|
|
data: { formName },
|
|
|
|
|
|
|
|
});
|
|
|
|
res.render(`chat/room/form/${formName}`);
|
|
|
|
res.render(`chat/room/form/${formName}`);
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
this.log.error('failed to render form', { formName, error });
|
|
|
|
this.log.error('failed to render form', { formName, error });
|
|
|
|
|
|
|
|
loganService.sendRequestEvent(module.exports, req, {
|
|
|
|
|
|
|
|
level: 'error',
|
|
|
|
|
|
|
|
event: 'getRoomForm',
|
|
|
|
|
|
|
|
message: `failed to render form: ${error.message}`,
|
|
|
|
|
|
|
|
data: { formName, error },
|
|
|
|
|
|
|
|
});
|
|
|
|
return next(error);
|
|
|
|
return next(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async getRoomInviteView (req, res) {
|
|
|
|
async getRoomInviteView (req, res) {
|
|
|
|
|
|
|
|
const { logan: loganService } = this.dtp.services;
|
|
|
|
|
|
|
|
loganService.sendRequestEvent(module.exports, req, {
|
|
|
|
|
|
|
|
level: 'info',
|
|
|
|
|
|
|
|
event: 'getRoomInviteView',
|
|
|
|
|
|
|
|
data: {
|
|
|
|
|
|
|
|
invite: res.locals.invite,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
res.render('chat/room/invite/view');
|
|
|
|
res.render('chat/room/invite/view');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async getRoomInviteHome (req, res, next) {
|
|
|
|
async getRoomInviteHome (req, res, next) {
|
|
|
|
const { chat: chatService } = this.dtp.services;
|
|
|
|
const {
|
|
|
|
|
|
|
|
chat: chatService,
|
|
|
|
|
|
|
|
logan: loganService,
|
|
|
|
|
|
|
|
} = this.dtp.services;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
res.locals.invites = {
|
|
|
|
res.locals.invites = {
|
|
|
|
new: await chatService.getRoomInvites(res.locals.room, 'new'),
|
|
|
|
new: await chatService.getRoomInvites(res.locals.room, 'new'),
|
|
|
|
accepted: await chatService.getRoomInvites(res.locals.room, 'accepted'),
|
|
|
|
accepted: await chatService.getRoomInvites(res.locals.room, 'accepted'),
|
|
|
|
rejected: await chatService.getRoomInvites(res.locals.room, 'rejected'),
|
|
|
|
rejected: await chatService.getRoomInvites(res.locals.room, 'rejected'),
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
loganService.sendRequestEvent(module.exports, req, {
|
|
|
|
|
|
|
|
level: 'info',
|
|
|
|
|
|
|
|
event: 'getRoomInviteHome',
|
|
|
|
|
|
|
|
});
|
|
|
|
res.render('chat/room/invite');
|
|
|
|
res.render('chat/room/invite');
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
this.log.error('failed to render the room invites view', { error });
|
|
|
|
loganService.sendRequestEvent(module.exports, req, {
|
|
|
|
|
|
|
|
level: 'error',
|
|
|
|
|
|
|
|
event: 'getRoomInviteHome',
|
|
|
|
|
|
|
|
message: `failed to render the view: ${error.message}`,
|
|
|
|
|
|
|
|
data: { error },
|
|
|
|
|
|
|
|
});
|
|
|
|
return next(error);
|
|
|
|
return next(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async getRoomSettings (req, res) {
|
|
|
|
async getRoomSettings (req, res) {
|
|
|
|
|
|
|
|
const { logan: loganService } = this.dtp.services;
|
|
|
|
|
|
|
|
loganService.sendRequestEvent(module.exports, req, {
|
|
|
|
|
|
|
|
level: 'info',
|
|
|
|
|
|
|
|
event: 'getRoomSettings',
|
|
|
|
|
|
|
|
data: {
|
|
|
|
|
|
|
|
room: {
|
|
|
|
|
|
|
|
_id: res.locals.room._id,
|
|
|
|
|
|
|
|
name: res.locals.room.name,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
res.render('chat/room/editor');
|
|
|
|
res.render('chat/room/editor');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async getRoomView (req, res, next) {
|
|
|
|
async getRoomView (req, res, next) {
|
|
|
|
const { chat: chatService } = this.dtp.services;
|
|
|
|
const {
|
|
|
|
|
|
|
|
chat: chatService,
|
|
|
|
|
|
|
|
logan: loganService,
|
|
|
|
|
|
|
|
} = this.dtp.services;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
res.locals.pageTitle = res.locals.room.name;
|
|
|
|
res.locals.pageTitle = res.locals.room.name;
|
|
|
|
|
|
|
|
|
|
|
|
const pagination = { skip: 0, cpp: 20 };
|
|
|
|
const pagination = { skip: 0, cpp: 20 };
|
|
|
|
res.locals.chatMessages = await chatService.getChannelHistory(res.locals.room, pagination);
|
|
|
|
res.locals.chatMessages = await chatService.getChannelHistory(res.locals.room, pagination);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
loganService.sendRequestEvent(module.exports, req, {
|
|
|
|
|
|
|
|
level: 'info',
|
|
|
|
|
|
|
|
event: 'getRoomView',
|
|
|
|
|
|
|
|
data: {
|
|
|
|
|
|
|
|
room: {
|
|
|
|
|
|
|
|
_id: res.locals.room._id,
|
|
|
|
|
|
|
|
name: res.locals.room.name,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
res.render('chat/room/view');
|
|
|
|
res.render('chat/room/view');
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
this.log.error('failed to render chat room view', { roomId: req.params.roomId, error });
|
|
|
|
this.log.error('failed to render chat room view', { roomId: req.params.roomId, error });
|
|
|
|
|
|
|
|
loganService.sendRequestEvent(module.exports, req, {
|
|
|
|
|
|
|
|
level: 'error',
|
|
|
|
|
|
|
|
event: 'getRoomView',
|
|
|
|
|
|
|
|
message: `failed to render the view: ${error.message}`,
|
|
|
|
|
|
|
|
data: {
|
|
|
|
|
|
|
|
room: {
|
|
|
|
|
|
|
|
_id: res.locals.room._id,
|
|
|
|
|
|
|
|
name: res.locals.room.name,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
error,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
return next(error);
|
|
|
|
return next(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async getRoomHome (req, res, next) {
|
|
|
|
async getRoomHome (req, res, next) {
|
|
|
|
const { chat: chatService } = this.dtp.services;
|
|
|
|
const {
|
|
|
|
|
|
|
|
chat: chatService,
|
|
|
|
|
|
|
|
logan: loganService,
|
|
|
|
|
|
|
|
} = this.dtp.services;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
res.locals.pagination = this.getPaginationParameters(req, 20);
|
|
|
|
res.locals.pagination = this.getPaginationParameters(req, 20);
|
|
|
|
res.locals.publicRooms = await chatService.getPublicRooms(req.user, res.locals.pagination);
|
|
|
|
res.locals.publicRooms = await chatService.getPublicRooms(req.user, res.locals.pagination);
|
|
|
|
|
|
|
|
loganService.sendRequestEvent(module.exports, req, {
|
|
|
|
|
|
|
|
level: 'info',
|
|
|
|
|
|
|
|
event: 'getRoomHome',
|
|
|
|
|
|
|
|
});
|
|
|
|
res.render('chat/room/index');
|
|
|
|
res.render('chat/room/index');
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
this.log.error('failed to render room home', { error });
|
|
|
|
loganService.sendRequestEvent(module.exports, req, {
|
|
|
|
|
|
|
|
level: 'error',
|
|
|
|
|
|
|
|
event: 'getRoomHome',
|
|
|
|
|
|
|
|
message: `failed to render the view: ${error.message}`,
|
|
|
|
|
|
|
|
data: { error },
|
|
|
|
|
|
|
|
});
|
|
|
|
return next(error);
|
|
|
|
return next(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async getHome (req, res, next) {
|
|
|
|
async getHome (req, res, next) {
|
|
|
|
const { chat: chatService } = this.dtp.services;
|
|
|
|
const {
|
|
|
|
|
|
|
|
chat: chatService,
|
|
|
|
|
|
|
|
logan: loganService,
|
|
|
|
|
|
|
|
} = this.dtp.services;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
res.locals.pageTitle = 'Chat Home';
|
|
|
|
res.locals.pageTitle = 'Chat Home';
|
|
|
|
|
|
|
|
|
|
|
@ -349,15 +541,28 @@ class ChatController extends SiteController {
|
|
|
|
res.locals.joinedChatRooms.forEach((room) => roomIds.push(room._id));
|
|
|
|
res.locals.joinedChatRooms.forEach((room) => roomIds.push(room._id));
|
|
|
|
res.locals.timeline = await chatService.getMultiRoomTimeline(roomIds, res.locals.pagination);
|
|
|
|
res.locals.timeline = await chatService.getMultiRoomTimeline(roomIds, res.locals.pagination);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
loganService.sendRequestEvent(module.exports, req, {
|
|
|
|
|
|
|
|
level: 'info',
|
|
|
|
|
|
|
|
event: 'getHome',
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
res.render('chat/index');
|
|
|
|
res.render('chat/index');
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
this.log.error('failed to render chat home', { error });
|
|
|
|
loganService.sendRequestEvent(module.exports, req, {
|
|
|
|
|
|
|
|
level: 'error',
|
|
|
|
|
|
|
|
event: 'getHome',
|
|
|
|
|
|
|
|
message: `failed to render the view: ${error.message}`,
|
|
|
|
|
|
|
|
data: { error },
|
|
|
|
|
|
|
|
});
|
|
|
|
return next(error);
|
|
|
|
return next(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async deleteInvite (req, res, next) {
|
|
|
|
async deleteInvite (req, res, next) {
|
|
|
|
const { chat: chatService } = this.dtp.services;
|
|
|
|
const {
|
|
|
|
|
|
|
|
chat: chatService,
|
|
|
|
|
|
|
|
logan: loganService,
|
|
|
|
|
|
|
|
} = this.dtp.services;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (res.locals.room.owner._id.equals(req.user._id)) {
|
|
|
|
if (res.locals.room.owner._id.equals(req.user._id)) {
|
|
|
|
throw new SiteError(403, 'This is not your invitiation');
|
|
|
|
throw new SiteError(403, 'This is not your invitiation');
|
|
|
@ -374,15 +579,34 @@ class ChatController extends SiteController {
|
|
|
|
5000,
|
|
|
|
5000,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
loganService.sendRequestEvent(module.exports, req, {
|
|
|
|
|
|
|
|
level: 'info',
|
|
|
|
|
|
|
|
event: 'deleteInvite',
|
|
|
|
|
|
|
|
message: 'room invitation deleted',
|
|
|
|
|
|
|
|
data: {
|
|
|
|
|
|
|
|
invite: {
|
|
|
|
|
|
|
|
_id: res.locals.invite._id,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
res.status(200).json({ success: true, displayList });
|
|
|
|
res.status(200).json({ success: true, displayList });
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
this.log.error('failed to delete chat room invite', { error });
|
|
|
|
loganService.sendRequestEvent(module.exports, req, {
|
|
|
|
|
|
|
|
level: 'error',
|
|
|
|
|
|
|
|
event: 'deleteInvite',
|
|
|
|
|
|
|
|
message: `failed to delete chat room invite: ${error.message}`,
|
|
|
|
|
|
|
|
data: { error },
|
|
|
|
|
|
|
|
});
|
|
|
|
return next(error);
|
|
|
|
return next(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async deleteRoom (req, res, next) {
|
|
|
|
async deleteRoom (req, res, next) {
|
|
|
|
const { chat: chatService } = this.dtp.services;
|
|
|
|
const {
|
|
|
|
|
|
|
|
chat: chatService,
|
|
|
|
|
|
|
|
logan: loganService,
|
|
|
|
|
|
|
|
} = this.dtp.services;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (res.locals.room.owner._id.equals(req.user._id)) {
|
|
|
|
if (res.locals.room.owner._id.equals(req.user._id)) {
|
|
|
|
throw new SiteError(403, 'This is not your chat room');
|
|
|
|
throw new SiteError(403, 'This is not your chat room');
|
|
|
@ -393,9 +617,26 @@ class ChatController extends SiteController {
|
|
|
|
const displayList = this.createDisplayList('delete chat invite');
|
|
|
|
const displayList = this.createDisplayList('delete chat invite');
|
|
|
|
displayList.navigateTo('/chat');
|
|
|
|
displayList.navigateTo('/chat');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
loganService.sendRequestEvent(module.exports, req, {
|
|
|
|
|
|
|
|
level: 'info',
|
|
|
|
|
|
|
|
event: 'deleteRoom',
|
|
|
|
|
|
|
|
message: 'chat room deleted',
|
|
|
|
|
|
|
|
data: {
|
|
|
|
|
|
|
|
room: {
|
|
|
|
|
|
|
|
_id: res.locals.room._id,
|
|
|
|
|
|
|
|
name: res.locals.room.name,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
res.status(200).json({ success: true, displayList });
|
|
|
|
res.status(200).json({ success: true, displayList });
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
this.log.error('failed to delete chat room invite', { error });
|
|
|
|
loganService.sendRequestEvent(module.exports, req, {
|
|
|
|
|
|
|
|
level: 'error',
|
|
|
|
|
|
|
|
event: 'deleteRoom',
|
|
|
|
|
|
|
|
message: `failed to delete chat room: ${error.message}`,
|
|
|
|
|
|
|
|
data: { error },
|
|
|
|
|
|
|
|
});
|
|
|
|
return next(error);
|
|
|
|
return next(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -404,5 +645,6 @@ class ChatController extends SiteController {
|
|
|
|
module.exports = {
|
|
|
|
module.exports = {
|
|
|
|
slug: 'chat',
|
|
|
|
slug: 'chat',
|
|
|
|
name: 'chat',
|
|
|
|
name: 'chat',
|
|
|
|
|
|
|
|
className: 'ChatController',
|
|
|
|
create: async (dtp) => { return new ChatController(dtp); },
|
|
|
|
create: async (dtp) => { return new ChatController(dtp); },
|
|
|
|
};
|
|
|
|
};
|