mirror of
https://github.com/wbbaddons/Tims-Chat.git
synced 2024-12-22 21:40:08 +00:00
parent
8b8bf4649c
commit
46d86de030
@ -651,7 +651,7 @@ Fetch the roomlist from the server and update it in the GUI.
|
|||||||
for room in data.returnValues
|
for room in data.returnValues
|
||||||
li = $ '<li></li>'
|
li = $ '<li></li>'
|
||||||
li.addClass 'active' if room.active
|
li.addClass 'active' if room.active
|
||||||
$("""<a href="#{room.link}">#{room.title}</a>""").addClass('timsChatRoom').data('roomID', room.roomID).appendTo li
|
$("""<a href="#{room.link}">#{room.title} <span class="badge">#{WCF.String.formatNumeric room.userCount}</span></a>""").addClass('timsChatRoom').data('roomID', room.roomID).appendTo li
|
||||||
$('#timsChatRoomList ul').append li
|
$('#timsChatRoomList ul').append li
|
||||||
|
|
||||||
if window.history?.replaceState?
|
if window.history?.replaceState?
|
||||||
|
@ -23,6 +23,13 @@ class Room extends \chat\data\CHATDatabaseObject implements \wcf\system\request\
|
|||||||
*/
|
*/
|
||||||
protected static $databaseTableIndexName = 'roomID';
|
protected static $databaseTableIndexName = 'roomID';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cached users
|
||||||
|
*
|
||||||
|
* @var array<\wcf\data\user\UserProfile>
|
||||||
|
*/
|
||||||
|
protected static $users = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see \wcf\data\chat\room\ChatRoom::getTitle();
|
* @see \wcf\data\chat\room\ChatRoom::getTitle();
|
||||||
*/
|
*/
|
||||||
@ -133,36 +140,27 @@ public function getTopic() {
|
|||||||
return \wcf\system\WCF::getLanguage()->get($this->topic);
|
return \wcf\system\WCF::getLanguage()->get($this->topic);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the number of users currently active in this room.
|
|
||||||
*
|
|
||||||
* @return integer
|
|
||||||
*/
|
|
||||||
public function countUsers() {
|
|
||||||
$sql = "SELECT
|
|
||||||
COUNT(*)
|
|
||||||
FROM
|
|
||||||
wcf".WCF_N."_user
|
|
||||||
WHERE
|
|
||||||
chatRoomID = ?";
|
|
||||||
$stmt = WCF::getDB()->prepareStatement($sql);
|
|
||||||
$stmt->execute(array($this->roomID));
|
|
||||||
|
|
||||||
return $stmt->fetchColumn();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the users that are currently active in this room.
|
* Returns the users that are currently active in this room.
|
||||||
*
|
*
|
||||||
* @return \wcf\data\user\UserProfileList
|
* @return array<\wcf\data\user\UserProfile>
|
||||||
*/
|
*/
|
||||||
public function getUsers() {
|
public function getUsers() {
|
||||||
$userList = new \wcf\data\user\UserProfileList();
|
if (self::$users === null) {
|
||||||
$userList->getConditionBuilder()->add('user_table.chatRoomID = ?', array($this->roomID));
|
$userList = new \wcf\data\user\UserProfileList();
|
||||||
|
$userList->getConditionBuilder()->add('user_table.chatRoomID IS NOT NULL', array());
|
||||||
|
|
||||||
|
$userList->readObjects();
|
||||||
|
$users = $userList->getObjects();
|
||||||
|
|
||||||
|
foreach ($users as $user) {
|
||||||
|
if (!isset(self::$users[$user->chatRoomID])) self::$users[$user->chatRoomID] = array();
|
||||||
|
self::$users[$user->chatRoomID][] = $user;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!isset(self::$users[$this->roomID])) self::$users[$this->roomID] = array();
|
||||||
|
|
||||||
$userList->readObjects();
|
return self::$users[$this->roomID];
|
||||||
|
|
||||||
return $userList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -149,7 +149,8 @@ public function getRoomList() {
|
|||||||
'object' => $room
|
'object' => $room
|
||||||
)),
|
)),
|
||||||
'roomID' => $room->roomID,
|
'roomID' => $room->roomID,
|
||||||
'active' => $room->roomID == $this->parameters['room']->roomID
|
'active' => $room->roomID == $this->parameters['room']->roomID,
|
||||||
|
'userCount' => count($room->getUsers())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ class NewMessagesPage extends \wcf\page\AbstractPage {
|
|||||||
/**
|
/**
|
||||||
* All the users that are currently in the room $this->room.
|
* All the users that are currently in the room $this->room.
|
||||||
*
|
*
|
||||||
* @var array<\wcf\data\user\User>
|
* @var array<\wcf\data\user\UserProfile>
|
||||||
*/
|
*/
|
||||||
public $users = array();
|
public $users = array();
|
||||||
|
|
||||||
@ -114,7 +114,7 @@ public function show() {
|
|||||||
$json['messages'][] = $message->jsonify(true);
|
$json['messages'][] = $message->jsonify(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
\wcf\system\user\storage\UserStorageHandler::getInstance()->loadStorage(array_keys($this->users->getObjects()));
|
\wcf\system\user\storage\UserStorageHandler::getInstance()->loadStorage(array_keys($this->users));
|
||||||
|
|
||||||
foreach ($this->users as $user) {
|
foreach ($this->users as $user) {
|
||||||
$json['users'][] = array(
|
$json['users'][] = array(
|
||||||
|
Loading…
Reference in New Issue
Block a user