... | ... |
@@ -29,8 +29,8 @@ this.App = |
29 | 29 |
|
30 | 30 |
windowHeight = $(window).height() |
31 | 31 |
toolboxHeight = $("#height-setter-1 .toolbox").height() |
32 |
- $(".friends").css({height: windowHeight - toolboxHeight - $('#js-me').height() - 40}) |
|
33 |
- $("#height-setter-1").css({height: windowHeight - toolboxHeight - $('#js-active-friends').height() - 120}) |
|
32 |
+ $(".friends").css({height: windowHeight - toolboxHeight - $('#js-me').height() - 14}) |
|
33 |
+ $("#height-setter-1").css({height: windowHeight - toolboxHeight - $('#js-active-friends').height() - 119}) |
|
34 | 34 |
|
35 | 35 |
resizeMessages: -> |
36 | 36 |
windowHeight = $(window).height() |
... | ... |
@@ -259,7 +259,7 @@ this.App = |
259 | 259 |
|
260 | 260 |
tab.showChat() |
261 | 261 |
contact = App.Collections.contacts.findByJid(App.stripJid(result.from)) |
262 |
- tab.chatWindow.appendMessage(contact, new Date(), result.message) |
|
262 |
+ tab.chatWindow.appendMessage(contact, new Date(), result.message, result.id_message) |
|
263 | 263 |
else |
264 | 264 |
#TODO: prepisat tuto hrozu |
265 | 265 |
|
... | ... |
@@ -284,7 +284,7 @@ this.App = |
284 | 284 |
tab.hasParticipants(App.Models.me, contact) |
285 | 285 |
) |
286 | 286 |
|
287 |
- tab.chatWindow.appendMessage(contact, new Date(), result.message) |
|
287 |
+ tab.chatWindow.appendMessage(contact, new Date(), result.message, result.id_message) |
|
288 | 288 |
) |
289 | 289 |
|
290 | 290 |
Models: |
... | ... |
@@ -11,6 +11,7 @@ class Xmpp.Views.Chat.MessageView extends Backbone.View |
11 | 11 |
@dateSent = parts.date |
12 | 12 |
@fromMe = parts.fromMe |
13 | 13 |
@message = parts.message |
14 |
+ @idMessage = parts.idMessage |
|
14 | 15 |
|
15 | 16 |
render: -> |
16 | 17 |
$(@el).html(@template(username: @user.get('name'), avatar: @user.get('avatar'), date: @formatTime(), message: @message)) |
... | ... |
@@ -86,8 +86,11 @@ class Xmpp.Views.Chat.WindowView extends Backbone.View |
86 | 86 |
App.debug ['append event', msg] |
87 | 87 |
# @log(eventView) if logMe == true |
88 | 88 |
|
89 |
- appendMessage: (user, date, msg) -> |
|
90 |
- messageView = new Xmpp.Views.Chat.MessageView(user: user, date: date, message: msg, fromMe: user.get('jid') == App.Models.me.get('jid')) |
|
89 |
+ appendMessage: (user, date, msg, idMessage) -> |
|
90 |
+ if idMessage |
|
91 |
+ return if @_checkIfMessageExists(idMessage) |
|
92 |
+ |
|
93 |
+ messageView = new Xmpp.Views.Chat.MessageView(user: user, date: date, message: msg, fromMe: user.get('jid') == App.Models.me.get('jid'), idMessage: idMessage) |
|
91 | 94 |
$(@el).find('.messages').append(messageView.render().el) |
92 | 95 |
@log(messageView) |
93 | 96 |
Backbone.Events.trigger('resizeWorkspace') |
... | ... |
@@ -123,8 +126,11 @@ class Xmpp.Views.Chat.WindowView extends Backbone.View |
123 | 123 |
$(@el).find(".action#{toEnable}, .current#{toEnable}").show() |
124 | 124 |
$(@el).find(".action#{toDisable}, .current#{toDisable}").hide() |
125 | 125 |
|
126 |
- prependHistoryMessage: (user, date, msg) -> |
|
127 |
- messageView = new Xmpp.Views.Chat.MessageView(user: user, date: date, message: msg, fromMe: user.get('jid') == App.Models.me.get('jid')) |
|
126 |
+ prependHistoryMessage: (user, date, msg, msgId) -> |
|
127 |
+ if msgId |
|
128 |
+ return if @_checkIfMessageExists(msgId) |
|
129 |
+ |
|
130 |
+ messageView = new Xmpp.Views.Chat.MessageView(user: user, date: date, message: msg, fromMe: user.get('jid') == App.Models.me.get('jid'), idMessage: msgId) |
|
128 | 131 |
$(@el).find('.messages').prepend(messageView.render().el) |
129 | 132 |
@log(messageView, true) |
130 | 133 |
|
... | ... |
@@ -142,8 +148,13 @@ class Xmpp.Views.Chat.WindowView extends Backbone.View |
142 | 142 |
else |
143 | 143 |
contact = App.Collections.contacts.findByJid(jid) || Xmpp.Collections.ChatsCollection.createTempContact(jid) |
144 | 144 |
|
145 |
- @prependHistoryMessage(contact, new Date(message.created_at), message.message) |
|
145 |
+ @prependHistoryMessage(contact, new Date(message.created_at), message.message, message.id) |
|
146 | 146 |
) |
147 | 147 |
|
148 | 148 |
@historyStep++ unless _.isEmpty(result.history) |
149 | 149 |
) |
150 |
+ |
|
151 |
+ _checkIfMessageExists: (idMessage) -> |
|
152 |
+ _.find(@historyStack, (message) -> |
|
153 |
+ message.idMessage == idMessage |
|
154 |
+ ) |
|
150 | 155 |
\ No newline at end of file |
... | ... |
@@ -261,14 +261,17 @@ class WsChatController < WsController |
261 | 261 |
|
262 | 262 |
if can_save_conversation?(stripped_me, stripped_from, chat_id) |
263 | 263 |
Rails.logger.debug ['saving received message', stripped_me, chat_id] |
264 |
- save_encrypted_message(body, stripped_me, stripped_from, stripped_from, chat_id) |
|
264 |
+ id_message = save_encrypted_message(body, stripped_me, stripped_from, stripped_from, chat_id) |
|
265 |
+ else |
|
266 |
+ id_message = nil |
|
265 | 267 |
end |
266 | 268 |
|
267 | 269 |
send_message 'app.chat.messageReceived', |
268 | 270 |
from: from.to_s, |
269 | 271 |
to: stripped_me, |
270 | 272 |
message: body, |
271 |
- chat_id: chat_id |
|
273 |
+ chat_id: chat_id, |
|
274 |
+ id_message: id_message |
|
272 | 275 |
end |
273 | 276 |
|
274 | 277 |
def send_contacts(to, me, chat_id) |
... | ... |
@@ -23,6 +23,7 @@ class History |
23 | 23 |
history.messages << record |
24 | 24 |
|
25 | 25 |
history.save |
26 |
+ record.id |
|
26 | 27 |
end |
27 | 28 |
|
28 | 29 |
def self.page_history(me, with, page, per_page) |
... | ... |
@@ -36,7 +37,7 @@ class History |
36 | 36 |
{'$skip' => page * per_page}, |
37 | 37 |
{'$limit' => per_page}, |
38 | 38 |
{'$sort' => {'messages.created_at' => 1}}, |
39 |
- {'$project' => {message: '$messages.message', from: '$messages.from', created_at: '$messages.created_at'}} |
|
39 |
+ {'$project' => {message: '$messages.message', from: '$messages.from', created_at: '$messages.created_at', id: '$messages._id'}} |
|
40 | 40 |
]) |
41 | 41 |
end |
42 | 42 |
end |