no message
This commit is contained in:
@@ -114,6 +114,22 @@ ProfileSchema.pre('save', function (next) {
|
||||
|
||||
const ProfileModel = Mongoose.model('profiles', ProfileSchema);
|
||||
|
||||
function getChatImages (id, match, callback) {
|
||||
callback = callback || (typeof match === 'function' ? match : function(){});
|
||||
match = typeof match === 'object' ? match : {};
|
||||
match['messages.image'] = { $exists: true };
|
||||
|
||||
ProfileModel
|
||||
.aggregate([
|
||||
{ $match: { _id: Mongoose.Types.ObjectId(profileId), 'messages.image': { $exists: true } } },
|
||||
{ $unwind: '$messages' },
|
||||
{ $match: match },
|
||||
{ $replaceRoot: { newRoot: '$messages' } }
|
||||
])
|
||||
.project('image -_id')
|
||||
.exec(callback);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
all: (e) => {
|
||||
@@ -166,32 +182,66 @@ module.exports = {
|
||||
});
|
||||
},
|
||||
|
||||
allMessageImages: (e, profileId) => {
|
||||
allChatImages: (e, profileId) => {
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
ProfileModel
|
||||
.aggregate([
|
||||
{ $match: { _id: Mongoose.Types.ObjectId(profileId), 'messages.image': { $exists: true } } },
|
||||
{ $unwind: '$messages' },
|
||||
{ $match: { 'messages.isUser': false, 'messages.image': { $exists: true } } },
|
||||
{ $replaceRoot: { newRoot: '$messages' } }
|
||||
])
|
||||
.project('image -_id')
|
||||
.exec((err, result) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
}
|
||||
|
||||
if (result) {
|
||||
resolve(result);
|
||||
}
|
||||
});
|
||||
getChatImages(profileId, (err, result) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
}
|
||||
|
||||
if (result) {
|
||||
resolve(result);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
promise.then((result) => {
|
||||
e.emit('allMessageImages', null, result);
|
||||
e.emit('allChatImages', null, result);
|
||||
})
|
||||
.catch((err) => {
|
||||
e.emit('allMessageImages', err, null);
|
||||
e.emit('allChatImages', err, null);
|
||||
});
|
||||
},
|
||||
|
||||
allChatImagesReceived: (e, profileId) => {
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
getChatImages(profileId, { 'messages.isUser': true }, (err, result) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
}
|
||||
|
||||
if (result) {
|
||||
resolve(result);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
promise.then((result) => {
|
||||
e.emit('allChatImagesReceived', null, result);
|
||||
})
|
||||
.catch((err) => {
|
||||
e.emit('allChatImagesReceived', err, null);
|
||||
});
|
||||
},
|
||||
|
||||
allChatImagesSent: (e, profileId) => {
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
getChatImages(profileId, { 'messages.isUser': false }, (err, result) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
}
|
||||
|
||||
if (result) {
|
||||
resolve(result);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
promise.then((result) => {
|
||||
e.emit('allChatImagesSent', null, result);
|
||||
})
|
||||
.catch((err) => {
|
||||
e.emit('allChatImagesSent', err, null);
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user