From 774ded9fb28abea355e786a5f38ebe55dc0cf4cc Mon Sep 17 00:00:00 2001 From: Matteo Pagliazzi Date: Mon, 4 Nov 2013 15:17:09 +0100 Subject: [PATCH] fix #1740 --- public/js/controllers/groupsCtrl.js | 10 ++++++---- src/controllers/groups.js | 3 --- views/options/social/chat-box.jade | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/public/js/controllers/groupsCtrl.js b/public/js/controllers/groupsCtrl.js index 6a775f0a7e..660d0915dc 100644 --- a/public/js/controllers/groupsCtrl.js +++ b/public/js/controllers/groupsCtrl.js @@ -80,14 +80,16 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Groups', '$http', 'A .controller('ChatCtrl', ['$scope', 'Groups', 'User', function($scope, Groups, User){ $scope._chatMessage = ''; + $scope._sending = false; $scope.postChat = function(group, message){ - if (_.isEmpty(message)) return - $('.chat-btn').addClass('disabled'); + console.log($scope._sending) + if (_.isEmpty(message) || $scope._sending) return; + $scope._sending = true; group.$postChat({message:message}, function(data){ - $scope._chatMessage = ''; group.chat = data.chat; - $('.chat-btn').removeClass('disabled'); + $scope._chatMessage = ''; + $scope._sending = false; }); } diff --git a/src/controllers/groups.js b/src/controllers/groups.js index 8d16812b00..a6d4b350a5 100644 --- a/src/controllers/groups.js +++ b/src/controllers/groups.js @@ -210,9 +210,6 @@ api.postChat = function(req, res, next) { timestamp: +(new Date) }; - // workaround for preventing duplicate chat messages. Real solution is to prevent between sends on the client - if (group.chat[0].uuid == message.uuid && group.chat[0].text == message.text) return res.json(group); - group.chat.unshift(message); group.chat.splice(200); diff --git a/views/options/social/chat-box.jade b/views/options/social/chat-box.jade index cfe3f6fb55..a62ee51f59 100644 --- a/views/options/social/chat-box.jade +++ b/views/options/social/chat-box.jade @@ -6,7 +6,7 @@ form(ng-submit='postChat(group,_chatMessage)') table.pull-right tr td - input.btn.chat-btn(type='submit', value='Send Chat') + input.btn.chat-btn(type='submit', value='Send Chat', ng-class='{disabled: _sending == true}') td button.btn(type="button", ng-click='sync(group)', tooltip='Fetch Recent Messages') i(class='pull-right icon-refresh')