The DTP Sites web app development engine.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

53 lines
1.1 KiB

// chat.js
// Copyright (C) 2022 DTP Technologies, LLC
// License: Apache-2.0
'use strict';
const mongoose = require('mongoose');
const ChatMessage = mongoose.model('ChatMessage');
const ioEmitter = require('socket.io-emitter');
const { SiteService } = require('../../lib/site-lib');
class ChatService extends SiteService {
constructor (dtp) {
super(dtp, module.exports);
this.populateContentReport = [
{
path: 'user',
select: '_id username username_lc displayName picture',
},
{
path: 'resource',
populate: [
{
path: 'author',
select: '_id username username_lc displayName picture',
},
],
},
];
}
async start ( ) {
this.emitter = ioEmitter(this.dtp.redis);
}
async removeMessage (message) {
await ChatMessage.deleteOne({ _id: message._id });
this.emitter(`site:${this.dtp.config.site.domainKey}:chat`, {
command: 'removeMessage',
params: { messageId: message._id },
});
}
}
module.exports = {
slug: 'chat',
name: 'chat',
create: (dtp) => { return new ChatService(dtp); },
};