Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Apr 25, 2025. It is now read-only.
/chat_servicePublic archive

Commit0a0e84f

Browse files
committed
__ADD__ adding choose psychologist socket
1 parent5d981a5 commit0a0e84f

File tree

4 files changed

+67
-9
lines changed

4 files changed

+67
-9
lines changed

‎lib/controllers/chat_controller.js‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ exports.newMessage = async (io, socket, data, callback) => {
2929
const{
3030
text,
3131
room_id,
32-
primary_key
32+
primary_key,
33+
sender_id,
34+
creator_id
3335
}=data;
3436
try{
3537
log({'newMessage data':data});
@@ -43,7 +45,6 @@ exports.newMessage = async (io, socket, data, callback) => {
4345
}));
4446
}else{
4547
constmessage_id=mongoose.Types.ObjectId();
46-
constsender_id=awaitchat_dao.getSenderIdBySocket(room_id,socket.id);
4748
constincremental_id=awaitchat_dao.incrementId(room_id);
4849
constmsg={
4950
incremental_id,
@@ -52,15 +53,15 @@ exports.newMessage = async (io, socket, data, callback) => {
5253
timestamp:newDate().getTime(),
5354
moment:moment().format('jYYYY/jMM/jDD HH:mm:ss'),
5455
sender_id,
55-
creator_id:sender_id,
56+
creator_id,
5657
message_id,
5758
is_read:1,
5859
type:'text',
5960
};
6061
constkeyedMessage=newkm('newMessage',JSON.stringify(msg));
6162
msg.primary_key=primary_key||1;
6263
log({'newMessage message':msg});
63-
producer.send([Object.assign(config.PAYLOAD,{
64+
producer.send([Object.assign({},config.PAYLOAD,{
6465
messages:[keyedMessage]
6566
})],function(e,result){
6667
if(e){
@@ -193,7 +194,6 @@ exports.isTyping = async (io, socket, data, callback) => {
193194
*/
194195

195196
exports.readMessage=async(io,socket,data,callback)=>{
196-
log({data});
197197
const{
198198
message_id,
199199
room_id,
@@ -218,7 +218,7 @@ exports.readMessage = async (io, socket, data, callback) => {
218218
room_id,
219219
message_id
220220
}));
221-
producer.send([Object.assign(config.PAYLOAD,{
221+
producer.send([Object.assign({},config.PAYLOAD,{
222222
messages:[keyedMessage]
223223
})],function(e,result){
224224
if(e){

‎lib/controllers/room_controller.js‎

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ exports.createRoom = async (io, socket, data, callback) => {
152152
'createRoom sockets to be notified':sockets
153153
});
154154
constkeyedMessage=newkm('newMessage',JSON.stringify(lastMessage));
155-
producer.send([Object.assign(config.PAYLOAD,{
155+
producer.send([Object.assign({},config.PAYLOAD,{
156156
messages:[keyedMessage]
157157
})],function(e,result){
158158
if(e){
@@ -245,7 +245,7 @@ exports.isNew = async (io, socket, data, callback) => {
245245
constkeyedMessage=newkm('notNew',JSON.stringify({
246246
room_id
247247
}));
248-
producer.send([Object.assign(config.PAYLOAD,{
248+
producer.send([Object.assign({},config.PAYLOAD,{
249249
messages:[keyedMessage]
250250
})],function(e,result){
251251
if(e){
@@ -326,4 +326,47 @@ exports.disconnecting = async (io, socket) => {
326326
});
327327
winston.error(`error in disconnect -${e}`);
328328
}
329-
};
329+
};
330+
331+
exports.choosePsychologist=async(io,socket,data,callback)=>{
332+
const{
333+
room_id,
334+
psychologist_id
335+
}=data;
336+
try{
337+
log({'choosePsychologist data':data});
338+
constvalid=validator.joi.validate(data,validator.choosePsychologist);
339+
if(valid.error){
340+
elog({'choosePsychologist validation error':valid.error});
341+
callback(Object.assign({},config.RESPONSE,{
342+
result:false,
343+
message:'input is not valid',
344+
data:valid.error
345+
}));
346+
}else{
347+
constkeyedMessage=newkm('choosePsychologist',JSON.stringify(data));
348+
producer.send([Object.assign({},config.PAYLOAD,{
349+
messages:[keyedMessage]
350+
})],function(e,result){
351+
if(e){
352+
elog({'error in choosePsychologist producer':e});
353+
winston.error(`error in choosePsychologist producer -${e}`);
354+
Promise.reject(e);
355+
}else{
356+
log({'choosePsychologist producer result':result});
357+
callback(Object.assign({},config.RESPONSE,{
358+
message:'success',
359+
}));
360+
io.to(room_id).emit('choosePsychologist',data);
361+
}
362+
});
363+
}
364+
}catch(e){
365+
elog({'error in choosePsychologist':e});
366+
winston.error(`error in isTyping -${e}`);
367+
callback(Object.assign({},config.RESPONSE,{
368+
result:false,
369+
message:'error in choosePsychologist'
370+
}));
371+
}
372+
}

‎lib/handlers/socket_handler.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,5 +130,12 @@ module.exports = (io) => {
130130

131131
});
132132

133+
134+
socket.on('choose_psychologist',(data,callback)=>{
135+
136+
log('choose_psychologist triggered');
137+
room_controller.choosePsychologist(io,socket,data,callback);
138+
139+
});
133140
});
134141
};

‎lib/utils/validator.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ exports.createRoom = joi.object().keys({
3030
exports.newMessage=joi.object().keys({
3131
text:joi.string().required(),
3232
room_id:joi.string().required().regex(/^[a-f\d]{24}$/i),
33+
sender_id:joi.string().required().regex(/^[a-f\d]{24}$/i),
34+
creator_id:joi.string().required().regex(/^[a-f\d]{24}$/i),
3335
time:joi.date().optional(),
3436
primary_key:joi.number().optional(),
3537
access_token:joi.optional()
@@ -50,4 +52,10 @@ exports.readMessage = joi.object().keys({
5052
access_token:joi.optional()
5153
});
5254

55+
exports.choosePsychologist=joi.object().keys({
56+
room_id:joi.string().required().regex(/^[a-f\d]{24}$/i),
57+
psychologist_id:joi.string().required().regex(/^[a-f\d]{24}$/i),
58+
});
59+
60+
5361
exports.joi=joi;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp