1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-12-22 21:40:08 +00:00

Improve MessageList

This commit is contained in:
Tim Düsterhus 2013-05-15 22:11:47 +02:00
parent abc6ba66f4
commit 7cf3363728
2 changed files with 12 additions and 15 deletions

View File

@ -13,8 +13,7 @@ everything that happens in the GUI of **Tims Chat**.
## Code ## Code
We start by setting up our environment by ensuring some sane values for both `$` and `window`, We start by setting up our environment by ensuring some sane values for both `$` and `window`,
enabling EMCAScript 5 strict mode, creating the namespace object and overwriting console to prepend enabling EMCAScript 5 strict mode and overwriting console to prepend the name of the class.
the name of the class.
(($, window) -> (($, window) ->
"use strict"; "use strict";
@ -27,7 +26,7 @@ the name of the class.
error: (message) -> error: (message) ->
window.console.error "[be.bastelstu.Chat] #{message}" window.console.error "[be.bastelstu.Chat] #{message}"
We continue with defining the needed variables. All variables are local to our closure and will be Continue with defining the needed variables. All variables are local to our closure and will be
exposed by a function if necessary. exposed by a function if necessary.
isActive = true isActive = true
@ -415,14 +414,13 @@ Rebuild the userlist based on the given `users`.
foundUsers = { } foundUsers = { }
for user in users for user in users
id = "timsChatUser-#{user.userID}" id = "timsChatUser#{user.userID}"
element = $ "##{id}"
Move the user to the new position if he was found in the old list. Move the user to the new position if he was found in the old list.
if element.length if $.wcfIsset id
console.log "Moving User: '#{user.username}'" console.log "Moving User: '#{user.username}'"
element = element.detach() element = $("##{id}").detach()
if user.awayStatus? if user.awayStatus?
element.addClass 'away' element.addClass 'away'
@ -463,9 +461,10 @@ Build HTML of the user and insert it into the list, if the users was not found i
menu.append $ "<li><a>#{WCF.Language.get('chat.general.kick')}</a></li>" menu.append $ "<li><a>#{WCF.Language.get('chat.general.kick')}</a></li>"
menu.append $ "<li><a>#{WCF.Language.get('chat.general.ban')}</a></li>" menu.append $ "<li><a>#{WCF.Language.get('chat.general.ban')}</a></li>"
menu.append $ """<li><a href="#{user.link}">#{WCF.Language.get('chat.general.profile')}</a></li>""" menu.append $ """<li><a href="#{user.link}">#{WCF.Language.get('chat.general.profile')}</a></li>"""
events.userMenu.fire user, menu
li.append menu
events.userMenu.fire user, menu
li.append menu
li.appendTo $ '#timsChatUserList > ul' li.appendTo $ '#timsChatUserList > ul'
foundUsers[id] = true foundUsers[id] = true
@ -508,7 +507,6 @@ Send out notifications for the given `message`. The number of unread messages wi
title: $('#timsChatRoomList .active a').text() title: $('#timsChatRoomList .active a').text()
newMessageCount: ++newMessageCount newMessageCount: ++newMessageCount
# Desktop Notifications
title = WCF.Language.get 'chat.general.notify.title' title = WCF.Language.get 'chat.general.notify.title'
content = "#{message.username}#{message.separator} #{message.message}" content = "#{message.username}#{message.separator} #{message.message}"

View File

@ -27,11 +27,8 @@ public static function getNewestMessages(\chat\data\room\Room $room, $number = C
$messageList = new static(); $messageList = new static();
$messageList->sqlOrderBy = "message.messageID DESC"; $messageList->sqlOrderBy = "message.messageID DESC";
$messageList->sqlLimit = $number; $messageList->sqlLimit = $number;
$messageList->getConditionBuilder()->add(' $messageList->getConditionBuilder()->add('message.receiver IS NULL', array());
( $messageList->getConditionBuilder()->add('message.roomID = ?', array($room->roomID));
message.receiver IS NULL
AND message.roomID = ?
)', array($room->roomID));
$messageList->readObjects(); $messageList->readObjects();
return array_reverse($messageList->getObjects()); return array_reverse($messageList->getObjects());
@ -54,7 +51,9 @@ public static function getMessagesSince(\chat\data\room\Room $room, $since) {
AND message.roomID = ? AND message.roomID = ?
) )
OR message.receiver = ? OR message.receiver = ?
OR message.sender = ?)', array($room->roomID, \wcf\system\WCF::getUser()->userID, \wcf\system\WCF::getUser()->userID)); OR message.sender = ?)',
array($room->roomID, \wcf\system\WCF::getUser()->userID, \wcf\system\WCF::getUser()->userID)
);
$messageList->readObjects(); $messageList->readObjects();
return $messageList->getObjects(); return $messageList->getObjects();