Browse code

Neprekreslovat chatovacie okno, ak netreba a pride nova sprava

Cinan Rakosnik authored on 29/05/2013 at 19:36:23
Showing 1 changed files
... ...
@@ -249,15 +249,23 @@ this.App =
249 249
         App.debug ['message received', result]
250 250
 
251 251
         if (result.chat_id)
252
-          chat = App.Collections.chats.findById(result.chat_id)
253
-
254
-          Backbone.Events.trigger('openChat', chat)
252
+          chatId = result.chat_id
255 253
 
256 254
           tab = _.find(App.Views.tabbar.tabs, (tab) ->
257
-            tab.getChatId() == result.chat_id
255
+            tab.getChatId() == chatId
258 256
           )
259 257
 
260
-          tab.showChat()
258
+          if App.Views.tabbar and App.Views.tabbar.activeTab
259
+            if App.Views.tabbar.activeTab.model.get('chatId') != chatId
260
+              refreshScreen = true
261
+          else
262
+            refreshScreen = true
263
+
264
+          if refreshScreen
265
+            chat = App.Collections.chats.findById(chatId)
266
+            Backbone.Events.trigger('openChat', chat)
267
+            tab.showChat()
268
+
261 269
           contact = App.Collections.contacts.findByJid(App.stripJid(result.from))
262 270
           tab.chatWindow.appendMessage(contact, new Date(), result.message, result.id_message)
263 271
         else
... ...
@@ -278,7 +286,12 @@ this.App =
278 278
             contactView = App.Collections.contacts.friendsList.hasContact(contact)
279 279
 
280 280
           contact.setPreferredResource(result.from)
281
-          contactView.startChat()
281
+
282
+          if App.Views.tabbar and App.Views.tabbar.activeTab
283
+            if App.Views.tabbar.activeTab.model.get('withWhom') != contact
284
+              contactView.startChat()
285
+          else
286
+              contactView.startChat()
282 287
 
283 288
           tab = _.find(App.Views.tabbar.tabs, (tab) ->
284 289
             tab.hasParticipants(App.Models.me, contact)