| ... | ... |
@@ -2,6 +2,14 @@ this.App = |
| 2 | 2 |
debug: (msg) -> |
| 3 | 3 |
console.log msg |
| 4 | 4 |
|
| 5 |
+ stripJid: (jid) -> |
|
| 6 |
+ r = new RegExp('(^.*)\/.*$')
|
|
| 7 |
+ match = r.exec(jid) |
|
| 8 |
+ if match and (match.length > 0) |
|
| 9 |
+ return match[1] |
|
| 10 |
+ else |
|
| 11 |
+ return jid |
|
| 12 |
+ |
|
| 5 | 13 |
UI: |
| 6 | 14 |
setAutoHeight: -> |
| 7 | 15 |
height = $(window).height() |
| ... | ... |
@@ -198,7 +206,8 @@ this.App = |
| 198 | 198 |
#TODO: prepisat tuto hrozu |
| 199 | 199 |
|
| 200 | 200 |
|
| 201 |
- contact = App.Collections.contacts.findByJid(result.from) |
|
| 201 |
+ contact = App.Collections.contacts.findByJid(App.stripJid(result.from)) |
|
| 202 |
+ contact.setPreferredResource(result.from) |
|
| 202 | 203 |
|
| 203 | 204 |
if contact |
| 204 | 205 |
contactView = App.Collections.contacts.friendsList.hasContact(contact) || |
| ... | ... |
@@ -3,6 +3,7 @@ class Xmpp.Models.Contact extends Xmpp.Models.Model |
| 3 | 3 |
|
| 4 | 4 |
defaults: |
| 5 | 5 |
jid: '' |
| 6 |
+ preferredJid: null |
|
| 6 | 7 |
name: '' |
| 7 | 8 |
status: 'offline' |
| 8 | 9 |
message: '' |
| ... | ... |
@@ -24,6 +25,12 @@ class Xmpp.Models.Contact extends Xmpp.Models.Model |
| 24 | 24 |
setUsingMyApp: -> |
| 25 | 25 |
@set('usingMyApp', true)
|
| 26 | 26 |
|
| 27 |
+ setPreferredResource: (jid) -> |
|
| 28 |
+ @set('preferredJid', jid)
|
|
| 29 |
+ |
|
| 30 |
+ getPreferredResource: -> |
|
| 31 |
+ @get('preferredJid') || @get('jid')
|
|
| 32 |
+ |
|
| 27 | 33 |
class Xmpp.Collections.ContactsCollection extends Backbone.Collection |
| 28 | 34 |
model: Xmpp.Models.Contact |
| 29 | 35 |
|
| ... | ... |
@@ -83,7 +90,12 @@ class Xmpp.Collections.ContactsCollection extends Backbone.Collection |
| 83 | 83 |
@_switchContactBelongingList(@get(contact), @activeList, @friendsList) && @friendsList.reOrder() |
| 84 | 84 |
|
| 85 | 85 |
updateStatus: (response) -> |
| 86 |
- @get(response.jid).set(message: response.status.message, status: response.status.status) |
|
| 86 |
+ contact = @get(response.jid) |
|
| 87 |
+ return unless contact |
|
| 88 |
+ |
|
| 89 |
+ contact.set(message: response.status.message, status: response.status.status) |
|
| 90 |
+ if response.status.status == 'offline' |
|
| 91 |
+ contact.setPreferredResource(null) |
|
| 87 | 92 |
|
| 88 | 93 |
udpateVcard: (response) -> |
| 89 | 94 |
@get(response.jid).set(name: response.vcard.name, avatar: response.vcard.avatar) |
| ... | ... |
@@ -52,7 +52,7 @@ class Xmpp.Views.Chat.WindowView extends Backbone.View |
| 52 | 52 |
|
| 53 | 53 |
if (message.trim()) |
| 54 | 54 |
chatId = @tab.getChatId() |
| 55 |
- attendant = if not chatId then @tab.getAttendant().get('jid') else null
|
|
| 55 |
+ attendant = if not chatId then @tab.getAttendant().getPreferredResource() else null |
|
| 56 | 56 |
|
| 57 | 57 |
App.Models.me.sendMessage(message, chatId, attendant |
| 58 | 58 |
, (message) => |
| ... | ... |
@@ -3,29 +3,27 @@ class WsChatController < WsController |
| 3 | 3 |
def start_polling_messages |
| 4 | 4 |
connection_store[:clients].each do |client| |
| 5 | 5 |
client.add_message_callback do |message| |
| 6 |
- from = message.from.strip.to_s |
|
| 7 |
- to = message.to.strip.to_s |
|
| 8 | 6 |
chat_id = message.attribute('chat_id').to_s
|
| 9 | 7 |
|
| 10 | 8 |
#noinspection RubyAssignmentExpressionInConditionalInspection |
| 11 | 9 |
if message.body |
| 12 |
- process_incoming_message(from, to, message.body, chat_id) |
|
| 13 |
- elsif request = message.first_element('sync_contacts_request')
|
|
| 14 |
- # toto mozem prijat len ako admin multichatu |
|
| 15 |
- send_contacts(from, to, request.attribute('chat_id').to_s)
|
|
| 16 |
- elsif answer = message.first_element('synced_contacts')
|
|
| 17 |
- # toto mozem prijat len ako ucastnik multichatu (nie admin) |
|
| 18 |
- contacts = xml_contacts_to_array(answer) |
|
| 19 |
- sync_contacts_frontend(from, to, answer.attribute('chat_id').to_s, contacts)
|
|
| 20 |
- elsif answer = message.first_element('exported_chat')
|
|
| 21 |
- contacts = xml_contacts_to_array(message.first_element('exported_chat'))
|
|
| 22 |
- import_people_in_chat(from, to, answer.attribute('chat_id').to_s, contacts)
|
|
| 23 |
- elsif message.attribute('destroy_multichat')
|
|
| 24 |
- destroy_multichat(to, chat_id) |
|
| 25 |
- elsif message.attribute('req_update_contacts')
|
|
| 26 |
- added = xml_contacts_to_array(message.first_element('added'))
|
|
| 27 |
- removed = xml_contacts_to_array(message.first_element('removed'))
|
|
| 28 |
- update_attendants_in_multichat(from, to, chat_id, removed, added) |
|
| 10 |
+ process_incoming_message(message.from, message.to, message.body, chat_id) |
|
| 11 |
+ #elsif request = message.first_element('sync_contacts_request')
|
|
| 12 |
+ # # toto mozem prijat len ako admin multichatu |
|
| 13 |
+ # send_contacts(message.from, message.to, request.attribute('chat_id').to_s)
|
|
| 14 |
+ #elsif answer = message.first_element('synced_contacts')
|
|
| 15 |
+ # # toto mozem prijat len ako ucastnik multichatu (nie admin) |
|
| 16 |
+ # contacts = xml_contacts_to_array(answer) |
|
| 17 |
+ # sync_contacts_frontend(message.from, message.to, answer.attribute('chat_id').to_s, contacts)
|
|
| 18 |
+ #elsif answer = message.first_element('exported_chat')
|
|
| 19 |
+ # contacts = xml_contacts_to_array(message.first_element('exported_chat'))
|
|
| 20 |
+ # import_people_in_chat(message.from, message.to, answer.attribute('chat_id').to_s, contacts)
|
|
| 21 |
+ #elsif message.attribute('destroy_multichat')
|
|
| 22 |
+ # destroy_multichat(to, chat_id) |
|
| 23 |
+ #elsif message.attribute('req_update_contacts')
|
|
| 24 |
+ # added = xml_contacts_to_array(message.first_element('added'))
|
|
| 25 |
+ # removed = xml_contacts_to_array(message.first_element('removed'))
|
|
| 26 |
+ # update_attendants_in_multichat(message.from, message.to, chat_id, removed, added) |
|
| 29 | 27 |
end |
| 30 | 28 |
#TODO: upozornit na pisanie spravy |
| 31 | 29 |
#TODO: odoslat informaciu o tom, ze pisem spravu |
| ... | ... |
@@ -139,10 +137,9 @@ class WsChatController < WsController |
| 139 | 139 |
private |
| 140 | 140 |
|
| 141 | 141 |
def process_incoming_message(from, to, body, chat_id = nil) |
| 142 |
- #Rails.logger.debug [message, message.to.strip.to_s] |
|
| 143 | 142 |
send_message 'app.chat.messageReceived', |
| 144 |
- from: from, |
|
| 145 |
- to: to, |
|
| 143 |
+ from: from.to_s, |
|
| 144 |
+ to: to.strip.to_s, |
|
| 146 | 145 |
message: body, |
| 147 | 146 |
chat_id: chat_id |
| 148 | 147 |
end |