From edb7a9e15d495fa14869d292b737aef9e6947baa Mon Sep 17 00:00:00 2001 From: flashwave Date: Wed, 11 Nov 2015 01:30:22 +0100 Subject: [PATCH] midnight commit --- _sakura/components/User.php | 10 ++++++++-- _sakura/sakura.php | 2 +- public/settings.php | 40 +++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/_sakura/components/User.php b/_sakura/components/User.php index 42fcb81..e0a8b7b 100755 --- a/_sakura/components/User.php +++ b/_sakura/components/User.php @@ -341,7 +341,7 @@ class User } // Get all the friend of this user - public function friends($level = 0) + public function friends($level = 0, $noObj = false) { // User ID container $users = []; @@ -381,10 +381,16 @@ class User break; } + // Check if we only requested the IDs + if ($noObj) { + // If so just return $users + return $users; + } + // Create the storage array $objects = []; - // Get all users + // Create the user objects foreach ($users as $user) { // Create new object $objects[$user] = new User($user); diff --git a/_sakura/sakura.php b/_sakura/sakura.php index 6de969d..99c0746 100755 --- a/_sakura/sakura.php +++ b/_sakura/sakura.php @@ -8,7 +8,7 @@ namespace Sakura; // Define Sakura version -define('SAKURA_VERSION', '20151110'); +define('SAKURA_VERSION', '20151111'); define('SAKURA_VLABEL', 'Eminence'); define('SAKURA_COLOUR', '#6C3082'); define('SAKURA_STABLE', false); diff --git a/public/settings.php b/public/settings.php index e7bcd58..11bcdb0 100755 --- a/public/settings.php +++ b/public/settings.php @@ -50,6 +50,46 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification } } + // Check if friendOnline is set (so it doesn't tell you all your friends all online on first visit) + $onlineNotify = isset($_SESSION['friendsOnline']) ? $_SESSION['friendsOnline'] : []; + + // Populate the array + foreach ($currentUser->friends(1) as $friend) { + // Online status + $online = $friend->isOnline(); + + // If true check if they're already in the array + if($online && !in_array($friend->id(), $onlineNotify)) { + // Add user to the online array + $_SESSION['friendsOnline'][$friend->id()] = $friend->id(); + + // Add the notification to the display array + $notifications[time()] = [ + 'read' => 0, + 'title' => $friend->username() . ' is online.', + 'text' => '', + 'link' => '', + 'img' => '/a/' . $friend->id(), + 'timeout' => 2000, + 'sound' => false, + ]; + } elseif(!$online && in_array($friend->id(), $onlineNotify)) { + // Remove the person from the array + unset($_SESSION['friendsOnline'][$friend->id()]); + + // Add the notification to the display array + $notifications[time()] = [ + 'read' => 0, + 'title' => $friend->username() . ' is offline.', + 'text' => '', + 'link' => '', + 'img' => '/a/' . $friend->id(), + 'timeout' => 2000, + 'sound' => false, + ]; + } + } + // Set header, convert the array to json, print it and exit print json_encode($notifications); exit;