diff options
Diffstat (limited to 'main')
3 files changed, 20 insertions, 7 deletions
diff --git a/main/app/sprinkles/admin/src/Controller/WormholeController.php b/main/app/sprinkles/admin/src/Controller/WormholeController.php index 889c438..68bbca7 100644 --- a/main/app/sprinkles/admin/src/Controller/WormholeController.php +++ b/main/app/sprinkles/admin/src/Controller/WormholeController.php @@ -82,10 +82,20 @@ class WormholeController extends SimpleController ->select("user_follow.user_id as id", "users.user_name as username") ->get(); + $UsersFriends = DB::select("SELECT id FROM (SELECT user_id AS id FROM user_follow WHERE followed_by_id = $user->id UNION ALL SELECT followed_by_id FROM user_follow WHERE user_id = $user->id) t GROUP BY id HAVING COUNT(id) > 1"); + foreach ($UsersFriends as $Key => $UsersFriendId) { // NOT THAT EFFICIENT... + $UsersFriendInformation = DB::table('users') + ->where('id', "=", $UsersFriendId->id) + ->select("users.id", "users.user_name as username") + ->get(); + $UsersFriends[$Key] = $UsersFriendInformation[0]; + } + $result = $user->toArray(); $result["avatar"] = $user->avatar; $result["followers"] = $UsersFollower; $result["follows"] = $UsersFollows; + $result["friends"] = $UsersFriends; return $response->withJson($result, 200, JSON_PRETTY_PRINT); } } diff --git a/main/app/sprinkles/core/assets/SiteAssets/js/chat.js b/main/app/sprinkles/core/assets/SiteAssets/js/chat.js index 96f2791..2dd97ce 100644 --- a/main/app/sprinkles/core/assets/SiteAssets/js/chat.js +++ b/main/app/sprinkles/core/assets/SiteAssets/js/chat.js @@ -293,10 +293,9 @@ function InitializeChatServer() { ReceiversUsername = $(this).attr("data-username"); ReceiversId = $(this).attr("data-id"); ChatSocket.send(JSON.stringify({ - ClientMessageType: "ChatMessage", - MessageType: "Private", - EncryptedWithKey: ReceiversUsername, - Message: EncryptedMessage + ClientMessageType: "SetReceiver", + ReceiversId: ReceiversId, + ReceiversUsername: ReceiversUsername })); }); }; diff --git a/main/app/sprinkles/core/assets/SiteAssets/php/Chatserver/src/ChatProcessor.php b/main/app/sprinkles/core/assets/SiteAssets/php/Chatserver/src/ChatProcessor.php index cf1df91..6ae111a 100644 --- a/main/app/sprinkles/core/assets/SiteAssets/php/Chatserver/src/ChatProcessor.php +++ b/main/app/sprinkles/core/assets/SiteAssets/php/Chatserver/src/ChatProcessor.php @@ -15,7 +15,7 @@ class ChatProcessor implements MessageComponentInterface private $userID; private $userInfo; private $verifiedUsers; - private $receiverID; + private $ReceiversId; public function __construct() { $this->clients = new \SplObjectStorage; @@ -23,7 +23,7 @@ class ChatProcessor implements MessageComponentInterface $this->users = []; // TEMPORARY WEBSOCKET USER $this->userID = []; // USER ID WHICH IS DECLARED IN DB $this->userInfo = []; // JSON CONTAINING ALL INFO OF USER FROM DB - $this->receiverID = []; + $this->ReceiversId = []; $this->verifiedUsers = []; } @@ -103,7 +103,11 @@ class ChatProcessor implements MessageComponentInterface } break; case "SetReceiver": // USER CLICKED ON NEW CHAT - $this->receiverID[$conn->resourceId] = $data->receiver; + foreach ($this->userInfo[$conn->resourceId]->friends as $friend) { + if ($data->ReceiversId === $friend->id) { + $this->ReceiversId[$conn->resourceId] = $data->ReceiversId; + } + } break; case "ChatMessage": // MESSAGE RECEIVED if (isset($this->channels[$conn->resourceId])) { |