mirror of
https://github.com/wbbaddons/Tims-Chat.git
synced 2024-12-22 21:40:08 +00:00
Add permission check to user menu
Also export getUserList and getRoomList
This commit is contained in:
parent
be0dc70a5b
commit
16afdf6ce4
@ -33,23 +33,23 @@ exposed by a function if necessary.
|
|||||||
newMessageCount = 0
|
newMessageCount = 0
|
||||||
scrollUpNotifications = off
|
scrollUpNotifications = off
|
||||||
chatSession = Date.now()
|
chatSession = Date.now()
|
||||||
|
|
||||||
userList =
|
userList =
|
||||||
current: {}
|
current: {}
|
||||||
allTime: {}
|
allTime: {}
|
||||||
currentRoom = {}
|
|
||||||
fileUploaded = no
|
|
||||||
|
|
||||||
|
roomList =
|
||||||
|
active: {}
|
||||||
|
available: {}
|
||||||
|
|
||||||
|
fileUploaded = no
|
||||||
errorVisible = false
|
errorVisible = false
|
||||||
inputErrorHidingTimer = null
|
inputErrorHidingTimer = null
|
||||||
|
|
||||||
lastMessage = null
|
lastMessage = null
|
||||||
openChannel = 0
|
openChannel = 0
|
||||||
|
|
||||||
messageContainerSize = 0
|
messageContainerSize = 0
|
||||||
userListSize = 0
|
userListSize = 0
|
||||||
|
|
||||||
remainingFailures = 3
|
remainingFailures = 3
|
||||||
|
|
||||||
overlaySmileyList = null
|
overlaySmileyList = null
|
||||||
markedMessages = {}
|
markedMessages = {}
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ Initialize **Tims Chat**. Bind needed DOM events and initialize data structures.
|
|||||||
When **Tims Chat** becomes focused mark the chat as active and remove the number of new messages from the title.
|
When **Tims Chat** becomes focused mark the chat as active and remove the number of new messages from the title.
|
||||||
|
|
||||||
$(window).focus ->
|
$(window).focus ->
|
||||||
document.title = v.titleTemplate.fetch currentRoom
|
document.title = v.titleTemplate.fetch(roomList.active) if roomList.active?.title? and roomList.active.topic.trim() isnt ''
|
||||||
|
|
||||||
newMessageCount = 0
|
newMessageCount = 0
|
||||||
isActive = true
|
isActive = true
|
||||||
@ -718,7 +718,9 @@ Build HTML of the user and insert it into the list, if the users was not found i
|
|||||||
|
|
||||||
li.append v.userTemplate.fetch user
|
li.append v.userTemplate.fetch user
|
||||||
|
|
||||||
menu = $(v.userMenuTemplate.fetch user)
|
menu = $ v.userMenuTemplate.fetch
|
||||||
|
user: user
|
||||||
|
room: roomList.active
|
||||||
|
|
||||||
if menu.find('li').length
|
if menu.find('li').length
|
||||||
li.append menu
|
li.append menu
|
||||||
@ -783,7 +785,7 @@ Send out notifications for the given `message`. The number of unread messages wi
|
|||||||
|
|
||||||
return if isActive or $('#timsChatNotify').data('status') is 0
|
return if isActive or $('#timsChatNotify').data('status') is 0
|
||||||
|
|
||||||
document.title = v.titleTemplate.fetch $.extend {}, currentRoom,
|
document.title = v.titleTemplate.fetch $.extend {}, roomList.active,
|
||||||
newMessageCount: ++newMessageCount
|
newMessageCount: ++newMessageCount
|
||||||
|
|
||||||
title = WCF.Language.get 'chat.global.notify.title'
|
title = WCF.Language.get 'chat.global.notify.title'
|
||||||
@ -812,10 +814,17 @@ Fetch the roomlist from the server and update it in the GUI.
|
|||||||
showLoadingOverlay: false
|
showLoadingOverlay: false
|
||||||
suppressErrors: true
|
suppressErrors: true
|
||||||
success: (data) ->
|
success: (data) ->
|
||||||
|
roomList =
|
||||||
|
active: {}
|
||||||
|
available: {}
|
||||||
|
|
||||||
do $('.timsChatRoom').remove
|
do $('.timsChatRoom').remove
|
||||||
$('#toggleRooms .badge').text data.returnValues.length
|
$('#toggleRooms .badge').text data.returnValues.length
|
||||||
|
|
||||||
for room in data.returnValues
|
for room in data.returnValues
|
||||||
|
roomList.available[room.roomID] = room
|
||||||
|
roomList.active = room if room.active
|
||||||
|
|
||||||
li = $ '<li></li>'
|
li = $ '<li></li>'
|
||||||
li.addClass('timsChatRoom').data('roomID', room.roomID)
|
li.addClass('timsChatRoom').data('roomID', room.roomID)
|
||||||
li.addClass 'active' if room.active
|
li.addClass 'active' if room.active
|
||||||
@ -875,20 +884,21 @@ Joins a room.
|
|||||||
success: (data) ->
|
success: (data) ->
|
||||||
loading = false
|
loading = false
|
||||||
|
|
||||||
$('#timsChatTopic').removeClass 'invisible'
|
roomList.active = data.returnValues
|
||||||
currentRoom = data.returnValues
|
roomList.active.roomID = roomID
|
||||||
currentRoom.roomID = roomID
|
|
||||||
|
|
||||||
$('#timsChatTopic > .topic').text currentRoom.topic
|
$('#timsChatTopic').removeClass 'invisible'
|
||||||
if currentRoom.topic.trim() is ''
|
|
||||||
|
$('#timsChatTopic > .topic').text roomList.active.topic
|
||||||
|
if roomList.active.topic.trim() is ''
|
||||||
$('#timsChatTopic').addClass 'invisible'
|
$('#timsChatTopic').addClass 'invisible'
|
||||||
else
|
else
|
||||||
$('#timsChatTopic').removeClass 'invisible'
|
$('#timsChatTopic').removeClass 'invisible'
|
||||||
|
|
||||||
$('.timsChatMessage').addClass 'unloaded'
|
$('.timsChatMessage').addClass 'unloaded'
|
||||||
|
|
||||||
document.title = v.titleTemplate.fetch currentRoom
|
document.title = v.titleTemplate.fetch roomList.active
|
||||||
handleMessages currentRoom.messages
|
handleMessages roomList.active.messages
|
||||||
do getMessages
|
do getMessages
|
||||||
do refreshRoomList
|
do refreshRoomList
|
||||||
failure: (data) ->
|
failure: (data) ->
|
||||||
@ -944,8 +954,8 @@ Open private channel
|
|||||||
$('#timsChatMessageTabMenu').wcfTabs 'refresh'
|
$('#timsChatMessageTabMenu').wcfTabs 'refresh'
|
||||||
WCF.System.FlexibleMenu.rebuild $('#timsChatMessageTabMenu > .tabMenu').attr 'id'
|
WCF.System.FlexibleMenu.rebuild $('#timsChatMessageTabMenu > .tabMenu').attr 'id'
|
||||||
else
|
else
|
||||||
$('#timsChatTopic > .topic').text currentRoom.topic
|
$('#timsChatTopic > .topic').text roomList.active.topic
|
||||||
if currentRoom.topic.trim() is ''
|
if roomList.active.topic.trim() is ''
|
||||||
$('#timsChatTopic').addClass 'invisible'
|
$('#timsChatTopic').addClass 'invisible'
|
||||||
else
|
else
|
||||||
$('#timsChatTopic').removeClass 'invisible'
|
$('#timsChatTopic').removeClass 'invisible'
|
||||||
@ -1036,7 +1046,7 @@ See WCF.Attachment.Upload._getParameters()
|
|||||||
|
|
||||||
_getParameters: ->
|
_getParameters: ->
|
||||||
@_tmpHash = do Math.random
|
@_tmpHash = do Math.random
|
||||||
@_parentObjectID = currentRoom.roomID
|
@_parentObjectID = roomList.active.roomID
|
||||||
|
|
||||||
do @_super
|
do @_super
|
||||||
|
|
||||||
@ -1218,6 +1228,8 @@ And finally export the public methods and variables.
|
|||||||
Return a copy of the object containing the IDs of the marked messages
|
Return a copy of the object containing the IDs of the marked messages
|
||||||
|
|
||||||
getMarkedMessages: -> JSON.parse JSON.stringify markedMessages
|
getMarkedMessages: -> JSON.parse JSON.stringify markedMessages
|
||||||
|
getUserList: -> JSON.parse JSON.stringify userList
|
||||||
|
getRoomList: -> JSON.parse JSON.stringify roomList
|
||||||
|
|
||||||
refreshRoomList: refreshRoomList
|
refreshRoomList: refreshRoomList
|
||||||
insertText: insertText
|
insertText: insertText
|
||||||
|
@ -113,6 +113,32 @@ public function canWrite(\wcf\data\user\User $user = null) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the user is allowed to mute other users in this room.
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function canMute() {
|
||||||
|
if (WCF::getSession()->getPermission('admin.chat.canManageSuspensions')) return true;
|
||||||
|
if (WCF::getSession()->getPermission('mod.chat.canGmute')) return true;
|
||||||
|
|
||||||
|
$ph = new \chat\system\permission\PermissionHandler();
|
||||||
|
return $ph->getPermission($this, 'mod.canMute');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the user is allowed to ban other users in this room.
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function canBan() {
|
||||||
|
if (WCF::getSession()->getPermission('admin.chat.canManageSuspensions')) return true;
|
||||||
|
if (WCF::getSession()->getPermission('mod.chat.canGban')) return true;
|
||||||
|
|
||||||
|
$ph = new \chat\system\permission\PermissionHandler();
|
||||||
|
return $ph->getPermission($this, 'mod.canBan');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the ID of this chatroom.
|
* Returns the ID of this chatroom.
|
||||||
*
|
*
|
||||||
|
@ -143,13 +143,18 @@ public function getRoomList() {
|
|||||||
|
|
||||||
$result[] = array(
|
$result[] = array(
|
||||||
'title' => (string) $room,
|
'title' => (string) $room,
|
||||||
|
'topic' => $room->getTopic(),
|
||||||
'link' => \wcf\system\request\LinkHandler::getInstance()->getLink('Chat', array(
|
'link' => \wcf\system\request\LinkHandler::getInstance()->getLink('Chat', array(
|
||||||
'application' => 'chat',
|
'application' => 'chat',
|
||||||
'object' => $room
|
'object' => $room
|
||||||
)),
|
)),
|
||||||
'roomID' => (int) $room->roomID,
|
'roomID' => (int) $room->roomID,
|
||||||
'active' => $this->parameters['room'] && $room->roomID == $this->parameters['room']->roomID,
|
'active' => $this->parameters['room'] && $room->roomID == $this->parameters['room']->roomID,
|
||||||
'userCount' => count($room->getUsers())
|
'userCount' => count($room->getUsers()),
|
||||||
|
'permissions' => array(
|
||||||
|
'canBan' => (boolean) $room->canBan(),
|
||||||
|
'canMute' => (boolean) $room->canMute()
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,7 +258,16 @@ public function join() {
|
|||||||
return array(
|
return array(
|
||||||
'title' => (string) $room,
|
'title' => (string) $room,
|
||||||
'topic' => $room->getTopic(),
|
'topic' => $room->getTopic(),
|
||||||
'messages' => $messages
|
'link' => \wcf\system\request\LinkHandler::getInstance()->getLink('Chat', array(
|
||||||
|
'application' => 'chat',
|
||||||
|
'object' => $room
|
||||||
|
)),
|
||||||
|
'userCount' => count($room->getUsers()),
|
||||||
|
'permissions' => array(
|
||||||
|
'canBan' => (boolean) $room->canBan(),
|
||||||
|
'canMute' => (boolean) $room->canMute()
|
||||||
|
),
|
||||||
|
'messages' => $messages,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,6 +171,7 @@ Probieren Sie, den Chat neu zu laden<!-- , bei Risiken und Nebenwirkungen fragen
|
|||||||
<item name="chat.global.query"><![CDATA[Privates Gespräch]]></item>
|
<item name="chat.global.query"><![CDATA[Privates Gespräch]]></item>
|
||||||
<item name="chat.global.kick"><![CDATA[Kicken]]></item>
|
<item name="chat.global.kick"><![CDATA[Kicken]]></item>
|
||||||
<item name="chat.global.ban"><![CDATA[Bannen]]></item>
|
<item name="chat.global.ban"><![CDATA[Bannen]]></item>
|
||||||
|
<item name="chat.global.mute"><![CDATA[Knebeln]]></item>
|
||||||
<item name="chat.global.profile"><![CDATA[Profil]]></item>
|
<item name="chat.global.profile"><![CDATA[Profil]]></item>
|
||||||
|
|
||||||
<item name="chat.global.message"><![CDATA[Nachricht]]></item>
|
<item name="chat.global.message"><![CDATA[Nachricht]]></item>
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
'chat.global.closePrivateChannel': '{lang}chat.global.closePrivateChannel{/lang}',
|
'chat.global.closePrivateChannel': '{lang}chat.global.closePrivateChannel{/lang}',
|
||||||
'chat.global.closeTopic': '{lang}chat.global.closeTopic{/lang}',
|
'chat.global.closeTopic': '{lang}chat.global.closeTopic{/lang}',
|
||||||
'chat.global.notify.title': '{lang}chat.global.notify.title{/lang}',
|
'chat.global.notify.title': '{lang}chat.global.notify.title{/lang}',
|
||||||
|
'chat.global.mute': '{lang}chat.global.mute{/lang}',
|
||||||
'chat.global.privateChannelTopic': '{lang}chat.global.privateChannelTopic{/lang}',
|
'chat.global.privateChannelTopic': '{lang}chat.global.privateChannelTopic{/lang}',
|
||||||
'chat.global.profile': '{lang}chat.global.profile{/lang}',
|
'chat.global.profile': '{lang}chat.global.profile{/lang}',
|
||||||
'chat.global.query': '{lang}chat.global.query{/lang}',
|
'chat.global.query': '{lang}chat.global.query{/lang}',
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
{literal}
|
{literal}
|
||||||
<ul data-user-id="{$userID}">
|
<ul data-user-id="{$user.userID}">
|
||||||
<li><a class="jsTimsChatUserMenuWhisper">{lang}chat.global.whisper{/lang}</a></li>
|
<li><a class="jsTimsChatUserMenuWhisper">{lang}chat.global.whisper{/lang}</a></li>
|
||||||
<li><a class="jsTimsChatUserMenuQuery">{lang}chat.global.query{/lang}</a></li>
|
<li><a class="jsTimsChatUserMenuQuery">{lang}chat.global.query{/lang}</a></li>
|
||||||
<li><a class="jsTimsChatUserMenuBan">{lang}chat.global.ban{/lang}</a></li>
|
{if $room.permissions.canMute}<li><a class="jsTimsChatUserMenuMute">{lang}chat.global.mute{/lang}</a></li>{/if}
|
||||||
<li><a href="{$link}" class="userLink" data-user-id="{$userID}">{lang}chat.global.profile{/lang}</a></li>
|
{if $room.permissions.canBan}<li><a class="jsTimsChatUserMenuBan">{lang}chat.global.ban{/lang}</a></li>{/if}
|
||||||
|
<li><a href="{$user.link}" class="userLink" data-user-id="{$user.userID}">{lang}chat.global.profile{/lang}</a></li>
|
||||||
{/literal}
|
{/literal}
|
||||||
{event name='menuItems'}
|
{event name='menuItems'}
|
||||||
</ul>
|
</ul>
|
||||||
|
Loading…
Reference in New Issue
Block a user