-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
solved uni-directional message bug, starting user listing
- Loading branch information
Showing
5 changed files
with
112 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules | ||
nodeSocket/db.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,20 @@ | ||
var mysql = require('./db.js'); | ||
mysql = mysql.getSql(); | ||
|
||
//$query = "SELECT * FROM (SELECT * FROM mensagens WHERE message LIKE '%".$search."%' AND sender = '".$chat."' AND reciever = '".$user."' OR message LIKE '%".$search."%' AND sender = '".$user."' AND reciever = '".$chat."' ORDER BY msg_id DESC LIMIT 50)Var1 ORDER BY msg_id ASC "; | ||
|
||
async function getMessageArray(from, to){ | ||
|
||
var result = await mysql.query(`SELECT * FROM (SELECT * FROM mensagens WHERE sender=${from} AND reciever=${to} ORDER BY msg_id DESC LIMIT 50)Var1 ORDER BY msg_id ASC`); | ||
var result = await mysql.query(` | ||
SELECT * FROM | ||
(SELECT * FROM mensagens WHERE | ||
(sender=${from} AND reciever=${to} OR sender=${to} AND reciever=${from}) | ||
ORDER BY msg_id DESC LIMIT 50)Var1 | ||
ORDER BY date ASC`); | ||
|
||
mysql.query(`UPDATE mensagens SET seen='1' WHERE sender=${from} AND reciever=${to}`); | ||
|
||
return result[0]; | ||
return result[0] | ||
|
||
} | ||
|
||
module.exports = {getMessageArray: getMessageArray} | ||
module.exports = {getMessageArray: getMessageArray} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
var mysql = require('./db.js'); | ||
mysql = mysql.getSql(); | ||
|
||
async function getUserArray(id) { | ||
|
||
var r = await mysql.query(` | ||
SELECT chat.* | ||
FROM chat | ||
INNER JOIN users_relation ON chat.id = users_relation.usr2 | ||
WHERE users_relation.usr1 = ${id};`); | ||
|
||
return r[0]; | ||
|
||
console.log("\n\n") | ||
|
||
var r = await mysql.query(` | ||
SELECT DISTINCT chat.* | ||
FROM chat | ||
INNER JOIN users_relation ON chat.id = users_relation.usr2 | ||
INNER JOIN mensagens ON chat.id = mensagens.sender OR chat.id = mensagens.reciever | ||
WHERE users_relation.usr1 = ${id} | ||
ORDER BY mensagens.date;`); | ||
|
||
console.log(JSON.stringify(r[0], null, 2)); | ||
|
||
} | ||
|
||
module.exports = { | ||
getUserArray: getUserArray | ||
}; |