I have a problem when working with node.js. All have tried to describe in comments to the code.
The first thing I need to build an array of dialogs with some information about the interlocutors and the last meggase.
IM = {
iUserId: false,
socket: false,
checkDialog: function(socket) {
this.socket = socket;
// Returned [{owner: 123, viewer: 432}]
var sql = 'SELECT DISTINCT(`owner_user_id`), `viewer_user_id` FROM `phpfox_mail` WHERE `owner_user_id` = ' + this.iUserId + ' GROUP BY 1,2 UNION SELECT DISTINCT (`viewer_user_id`), `owner_user_id` FROM `phpfox_mail` WHERE `viewer_user_id` = ' + this.iUserId + ' GROUP BY 1,2 ORDER BY 1 ';
connection.query(sql, function(err, rows) {
if (err) throw err;
async.map(rows, function(item, nextParent) {
var sql = 'SELECT `mail_id`, `subject`, `preview`, `owner_user_id`, `viewer_user_id`, `viewer_is_new`, `time_stamp` FROM `phpfox_mail` WHERE (`viewer_user_id` = ' + item.viewer_user_id + ' OR `owner_user_id` = ' + item.viewer_user_id + ') AND (`viewer_user_id` = ' + item.owner_user_id + ' OR `owner_user_id` = ' + item.owner_user_id + ') ORDER BY `mail_id` DESC LIMIT 1';
var dialogs = [];
connection.query(sql, function(err, rows) {
// ???
});
}, function(err, item) {
// Here I have to get the generated array with all the necessary dialogue.
console.log(item);
IM.socket.emit('logger', {text: 'dataIsABuilding', key: 'success'});
IM.socket.emit('dialogsBuilding', item);
});
});
}
};
Objective: To create an array of information about the message and interlocutors.
Scheme:
- Get an array with all interlocutors. [{owner_user_id: 5757, viewer_user_id: 5866}, {etc...}]
- Using the result of paragraph number 1, to get an array of information on the latest report from the dialogue. [{mail_id: 98, subject: test, owner: 5757, viewer: 5866, timestamp: 123566544}, {etc...}]
- Get information about users for the specified identifier (owner_user_id/viewer_user_id).
- Collect all the data on the dialogues in the same array.
I stopped at the third paragraph. Namely, I do not know how to consistently obtain information about users who are in the first two arrays.
Please, help my!