midnight commit

This commit is contained in:
flash 2015-11-11 01:30:22 +01:00
parent 4093327895
commit edb7a9e15d
3 changed files with 49 additions and 3 deletions

View file

@ -341,7 +341,7 @@ class User
} }
// Get all the friend of this user // Get all the friend of this user
public function friends($level = 0) public function friends($level = 0, $noObj = false)
{ {
// User ID container // User ID container
$users = []; $users = [];
@ -381,10 +381,16 @@ class User
break; break;
} }
// Check if we only requested the IDs
if ($noObj) {
// If so just return $users
return $users;
}
// Create the storage array // Create the storage array
$objects = []; $objects = [];
// Get all users // Create the user objects
foreach ($users as $user) { foreach ($users as $user) {
// Create new object // Create new object
$objects[$user] = new User($user); $objects[$user] = new User($user);

View file

@ -8,7 +8,7 @@
namespace Sakura; namespace Sakura;
// Define Sakura version // Define Sakura version
define('SAKURA_VERSION', '20151110'); define('SAKURA_VERSION', '20151111');
define('SAKURA_VLABEL', 'Eminence'); define('SAKURA_VLABEL', 'Eminence');
define('SAKURA_COLOUR', '#6C3082'); define('SAKURA_COLOUR', '#6C3082');
define('SAKURA_STABLE', false); define('SAKURA_STABLE', false);

View file

@ -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 // Set header, convert the array to json, print it and exit
print json_encode($notifications); print json_encode($notifications);
exit; exit;