Skip to content

Commit

Permalink
bug patch
Browse files Browse the repository at this point in the history
  • Loading branch information
toddync committed Oct 18, 2023
1 parent 476aeb5 commit ebffae3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 23 deletions.
Binary file modified images/profile_images/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 5 additions & 3 deletions javascript/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ conn.onmessage = function(e) {

data.msgs.forEach(msg => {

document.getElementById("result").innerHTML += buildMsg(msg, data.reqId, data.chat);
document.getElementById("result").innerHTML += buildMsg(msg, data.reqId, data.chat, data.img);

})

Expand Down Expand Up @@ -490,7 +490,7 @@ function leave() {
}
}

function buildMsg(msg, id, chat) {
function buildMsg(msg, id, chat, img) {
var date = new Date();
msg.date = new Date(msg.date);
msg.date = timeSince(msg.date, "msg");
Expand Down Expand Up @@ -519,7 +519,7 @@ function buildMsg(msg, id, chat) {
var r = `
<div class='chat-msg'>
<div class='chat-msg-profile'>
<img class='chat-msg-img' src='${msg.img}' alt=''>
<img class='chat-msg-img' src='${img}' alt=''>
<div class='chat-msg-date'>${msg.date}</div>
</div>
<div class='chat-msg-content'>
Expand Down Expand Up @@ -548,6 +548,8 @@ function buildUser(user){
</div>
</div>`;

console.log(r.Image)

return r;
/*
$return .= "
Expand Down
12 changes: 2 additions & 10 deletions nodeSocket/Server.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
const Ws = require("ws");
const dump = require('var_dump');
const url = require("node:url")

const handlers = require("./handlers.js")
const user = require("./user.js")

var mysql = require('./db.js');
mysql = mysql.getSql();


const v8 = require('v8');

const structuredClone = obj => {
return v8.deserialize(v8.serialize(obj));
};


async function main() {

var u = await mysql.query("SELECT * FROM chat")
Expand Down Expand Up @@ -48,7 +40,7 @@ async function main() {

case "request":

handlers.requestHandler(msg, ws, users[msg.chat][0].Name);
handlers.requestHandler(msg, ws, users[msg.chat][0]);
break;

case "send":
Expand Down
11 changes: 6 additions & 5 deletions nodeSocket/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ async function requestHandler(req, ws, chat) {
case "msg":

response = await message.getMessageArray(ws.userId, req.chat, 50);

console.log(chat.Image)
ws.send(JSON.stringify({
act: "response",
ctx: "loadChat",
status: "success",
reqId: ws.userId,
chat: chat,
chat: chat.Name,
img: chat.Image,
msgs: response
}))

Expand Down Expand Up @@ -60,9 +61,9 @@ async function messageHandler(msg, from, to, conn){
act:"recieve",
ctx:"msg",
status:"success",
msg: req.msg,
from: req.user,
date: req.msg_date
msg: msg.msg,
from: msg.user,
date: msg.msg_date
}))
}
}
Expand Down
17 changes: 12 additions & 5 deletions nodeSocket/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const message = require("./message.js");
async function getUserArray(id) {

var r = await mysql.query(`
SELECT Name, Status, grp, Image
SELECT Name, Status, grp, Image, id
FROM chat
INNER JOIN users_relation ON chat.id = users_relation.usr2
WHERE users_relation.usr1 = ${id};`);
Expand All @@ -32,10 +32,17 @@ async function getUserArray(id) {
async function finalize(id, r){

for(let i = 0; i < r[0].length; i++){

var resp = await message.getMessageArray(id, r[0][i].id, 1)
r[0][i].lastMsg = resp[0];
r[0][i].unseen = await message.getUnseen(id, r[0][i].id)

if(r[0][i]){

var resp = await message.getMessageArray(id, r[0][i].id, 1)
r[0][i].lastMsg = resp[0];
r[0][i].unseen = await message.getUnseen(id, r[0][i].id)
} else {

r[0][i].lastMsg = "";
r[0][i].unseen = 0
}
}

return r;
Expand Down

0 comments on commit ebffae3

Please sign in to comment.