Skip to content

Commit be3e2c0

Browse files
authored
Merge pull request hernansartorio#50 from kumargugloth/develop
join date
2 parents fef9abc + 7995e8f commit be3e2c0

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

chat/ChatroomManager.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ module.exports = function () {
3434
const conversation = await Conversation.create(obj).then(convo=>{
3535
return User.find({_id: {$in : convo.members}},{activity_log:0,followers:0,following:0,}).then(users=> {
3636
const x = users.map((u)=>{ return ({user_id:u._id,last_active:u.last_active ? u.last_active : new Date()})})
37-
return Conversation.findByIdAndUpdate({_id:convo._id},{last_active:x}).then(conversation=>{
37+
const y = users.map((u)=>{ return ({user_id:u._id,join_date:u.join_date ? u.join_date : new Date()})})
38+
return Conversation.findByIdAndUpdate({_id:convo._id},{last_active:x,join_date:y}).then(conversation=>{
3839
return convo
3940
}).catch((e)=>console.log(e))
4041
}).catch((e)=>console.log(e))
@@ -253,7 +254,8 @@ module.exports = function () {
253254
return Game.findByIdAndUpdate({_id: game_id},{ $addToSet: { users: { $each: [userId] } } }).then(game=> {
254255
return Conversation.findByIdAndUpdate({_id: game.conversation},{ $pull: { invites: userId } }).then(conversation1=> {
255256
return Conversation.findByIdAndUpdate({_id: game.conversation},{ $addToSet: { members: { $each: [userId] } } }).then(conversation1=> {
256-
return Conversation.findByIdAndUpdate({_id: game.conversation},{ $addToSet: { last_active: { $each: [{user_id:userId,last_active:new Date()}] } } }).then(conversation1=> {
257+
return Conversation.findByIdAndUpdate({_id: game.conversation},{ $addToSet: { join_date: { $each: [{user_id:userId,join_date:new Date()}] } } },{ $addToSet: { last_active: { $each: [{user_id:userId,last_active:new Date()}] } } }).then(conversation1=> {
258+
console.log("convera",conversation1)
257259
//above to update below to show and save message
258260
return Conversation.findById({_id: game.conversation}).lean().populate('members','_id device_token').then(conversation2=> {
259261
return User.findById({_id: userId},{activity_log:0,}).lean().then(user=> {

models/conversation.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const schema = new Schema({
1919
unread:Number,
2020
members: [{ type: Schema.Types.ObjectId, ref: 'user' }] ,
2121
type:String,
22+
join_date:Array
2223
});
2324

2425
//Model

routes/user.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,8 @@ router.post('/host_game',verifyToken, (req, res, next) => {
484484
Message.create({conversation:convo._id,message:`${req.name} created the game`,read_status:false,name:req.name,author:req.body.userId,type:'bot',created_at:new Date()}).then(message1=>{
485485
User.find({_id: {$in : convo.members}},{activity_log:0,followers:0,following:0,}).then(users=> {
486486
const x = users.map((u)=>{ return ({user_id:u._id,last_active:u.last_active ? u.last_active : new Date()})})
487-
Conversation.findByIdAndUpdate({_id:message1.conversation},{last_active:x,last_message:message1._id,last_updated:new Date()}).then(conversation=>{
487+
const y = users.map((u)=>{ return ({user_id:u._id,join_date:u.join_date ? u.join_date : new Date()})})
488+
Conversation.findByIdAndUpdate({_id:message1.conversation},{last_active:x,join_date:y,last_message:message1._id,last_updated:new Date()}).then(conversation=>{
488489
console.log(conversation)
489490
//since he is a host who is accessing this api
490491
convo['invite'] = false
@@ -888,7 +889,8 @@ router.post('/book_slot_and_host', verifyToken, (req, res, next) => {
888889
Message.create({conversation:convo._id,message:`${req.name} created the game`,read_status:false,name:req.name,author:req.userId,type:'bot',created_at:new Date()}).then(message1=>{
889890
User.find({_id: {$in : convo.members}},{activity_log:0,followers:0,following:0,}).then(users=> {
890891
const x = users.map((u)=>{ return ({user_id:u._id,last_active:u.last_active ? u.last_active : new Date()})})
891-
Conversation.findByIdAndUpdate({_id:message1.conversation},{last_active:x,last_message:message1._id,last_updated:new Date()}).then(conversation=>{
892+
const y = users.map((u)=>{ return ({user_id:u._id,join_date:u.join_date ? u.join_date : new Date()})})
893+
Conversation.findByIdAndUpdate({_id:message1.conversation},{last_active:x,join_date:y,last_message:message1._id,last_updated:new Date()}).then(conversation=>{
892894
convo['invite'] = false
893895
res.send({status:"success", message:"slot booked",data: {game:game,convo:convo}})
894896
let booking_id = values[0].booking_id

0 commit comments

Comments
 (0)