mirror of
https://github.com/wbbaddons/Tims-Chat.git
synced 2024-10-31 14:10:08 +00:00
Allow showing the number of chatters in main menu
This commit is contained in:
parent
c745c6f663
commit
ca203333d7
@ -18,6 +18,34 @@ class ChatPageMenuItemProvider extends \wcf\system\menu\page\DefaultPageMenuItem
|
||||
*/
|
||||
protected $room = null;
|
||||
|
||||
/**
|
||||
* available chat rooms
|
||||
*
|
||||
* @var array<\chat\data\room\Room>
|
||||
*/
|
||||
protected $rooms = null;
|
||||
|
||||
/**
|
||||
* Returns the available chat rooms
|
||||
*
|
||||
* @return array<\chat\data\room\Room>
|
||||
*/
|
||||
protected function getRooms() {
|
||||
if ($this->rooms !== null) return $this->rooms;
|
||||
|
||||
$rooms = \chat\data\room\RoomCache::getInstance()->getRooms();
|
||||
|
||||
foreach ($rooms as $room) {
|
||||
if ($room->canEnter()) {
|
||||
if ($this->room === null) $this->room = $room;
|
||||
|
||||
$this->rooms[] = $room;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->rooms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hides the button when there is no valid room
|
||||
*
|
||||
@ -27,15 +55,9 @@ public function isVisible() {
|
||||
// guests are not supported
|
||||
if (!\wcf\system\WCF::getUser()->userID) return false;
|
||||
|
||||
$rooms = \chat\data\room\RoomCache::getInstance()->getRooms();
|
||||
$rooms = $this->getRooms();
|
||||
|
||||
foreach ($rooms as $this->room) {
|
||||
if ($this->room->canEnter()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return !empty($rooms);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -46,10 +68,25 @@ public function isVisible() {
|
||||
public function getLink() {
|
||||
if (CHAT_FORCE_ROOM_SELECT) return parent::getLink();
|
||||
|
||||
$this->getRooms();
|
||||
|
||||
return \wcf\system\request\LinkHandler::getInstance()->getLink('Chat', array(
|
||||
'application' => 'chat',
|
||||
'object' => $this->room,
|
||||
'forceFrontend' => true
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the number of users across all visible rooms.
|
||||
*
|
||||
* @see \wcf\system\menu\page\PageMenuItemProvider::getNotifications()
|
||||
*/
|
||||
public function getNotifications() {
|
||||
if (!CHAT_FORCE_ROOM_SELECT) return 0;
|
||||
if (!CHAT_ENABLE_MENU_BADGE) return 0;
|
||||
|
||||
$rooms = $this->getRooms();
|
||||
return array_reduce($rooms, function ($carry, $room) { return $carry + count($room->getUsers()); }, 0);
|
||||
}
|
||||
}
|
||||
|
@ -104,6 +104,8 @@
|
||||
<item name="wcf.acp.option.chat_command_aliases.description"><![CDATA[Geben Sie zeilenweise eine Kombination aus Alias und Zielbefehl an. Alias und Zielbefehl werden durch einen Doppelpunkt voneinander getrennt.]]></item>
|
||||
<item name="wcf.acp.option.chat_force_room_select"><![CDATA[Raumauswahl anzeigen]]></item>
|
||||
<item name="wcf.acp.option.chat_force_room_select.description"><![CDATA[Zeigt eine Auswahl der verfügbaren Räume an, anstatt den ersten verfügbaren Raum zu betreten.]]></item>
|
||||
<item name="wcf.acp.option.chat_enable_menu_badge"><![CDATA[Chatter im Hauptmenü]]></item>
|
||||
<item name="wcf.acp.option.chat_enable_menu_badge.description"><![CDATA[Zeigt die Anzahl der Chatter als Badge im Hauptmenü an.]]></item>
|
||||
|
||||
<item name="wcf.acp.option.category.chat.log"><![CDATA[Protokoll]]></item>
|
||||
<item name="wcf.acp.option.chat_log_archivetime"><![CDATA[Speicherzeit]]></item>
|
||||
|
@ -104,6 +104,8 @@
|
||||
<item name="wcf.acp.option.chat_command_aliases.description"><![CDATA[Enter a combination of alias and target separated by newlines. Alias and target are separated by colons.]]></item>
|
||||
<item name="wcf.acp.option.chat_force_room_select"><![CDATA[Show Room Selection]]></item>
|
||||
<item name="wcf.acp.option.chat_force_room_select.description"><![CDATA[Shows a list of available rooms instead of joining the first available one.]]></item>
|
||||
<item name="wcf.acp.option.chat_enable_menu_badge"><![CDATA[Chatter Count in main menu]]></item>
|
||||
<item name="wcf.acp.option.chat_enable_menu_badge.description"><![CDATA[Shows the number of active chatters as a badge in the main menu.]]></item>
|
||||
|
||||
<item name="wcf.acp.option.category.chat.log"><![CDATA[Protocol]]></item>
|
||||
<item name="wcf.acp.option.chat_log_archivetime"><![CDATA[Archive Time]]></item>
|
||||
|
@ -22,6 +22,12 @@
|
||||
<categoryname>chat.general</categoryname>
|
||||
<optiontype>boolean</optiontype>
|
||||
<defaultvalue>0</defaultvalue>
|
||||
<enableoptions>chat_enable_menu_badge</enableoptions>
|
||||
</option>
|
||||
<option name="chat_enable_menu_badge">
|
||||
<categoryname>chat.general</categoryname>
|
||||
<optiontype>boolean</optiontype>
|
||||
<defaultvalue>0</defaultvalue>
|
||||
</option>
|
||||
<option name="chat_reloadtime">
|
||||
<categoryname>chat.general</categoryname>
|
||||
@ -70,4 +76,4 @@ gunmute:ungmute</defaultvalue>
|
||||
<!--log options end-->
|
||||
</options>
|
||||
</import>
|
||||
</data>
|
||||
</data>
|
||||
|
Loading…
Reference in New Issue
Block a user