From 47d39d3346b11ab5c2a62475ab218242fd3eef78 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Fri, 25 Sep 2015 10:49:44 -0400 Subject: [PATCH] closes #3673 --- public/src/client/chats.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/public/src/client/chats.js b/public/src/client/chats.js index 333c022658..d34b47667f 100644 --- a/public/src/client/chats.js +++ b/public/src/client/chats.js @@ -42,7 +42,7 @@ define('forum/chats', ['components', 'string', 'sounds', 'forum/infinitescroll', if (env === 'xs' || env === 'sm') { app.openChat($(this).attr('data-username'), $(this).attr('data-uid')); } else { - ajaxify.go('chats/' + utils.slugify($(this).attr('data-username'))); + Chats.switchChat(parseInt($(this).attr('data-uid'), 10), $(this).attr('data-username')); } }); @@ -114,6 +114,27 @@ define('forum/chats', ['components', 'string', 'sounds', 'forum/infinitescroll', }); }; + Chats.switchChat = function(uid, username) { + if (!$('[component="chat/messages"]').length) { + ajaxify.go('chats/' + username); + } + + Chats.loadChatSince(uid, $('.chat-content'), 'recent'); + Chats.addSendHandlers(uid, $('[component="chat/input"]'), $('[data-action="send"]')); + $(this).addClass('bg-primary').siblings().removeClass('bg-primary'); + $('[component="chat/title"]').text(username); + $('[component="chat/messages"]').attr('data-uid', uid).attr('data-username', username); + $('[component="breadcrumb/current"]').text(username); + + if (window.history && window.history.pushState) { + var url = 'chats/' + utils.slugify(username); + + window.history.replaceState({ + url: url + }, url, RELATIVE_PATH + '/' + url); + } + }; + Chats.loadChatSince = function(toUid, chatContentEl, since) { if (!toUid) { return;