... | ... |
@@ -71,11 +71,18 @@ this.App = |
71 | 71 |
openNewMultiChat: (chatOwner, attendant, chat) -> |
72 | 72 |
@trigger(event: 'app.chat.newMultiChat', data: {chatOwner: chatOwner.get('jid')}, success: (response) => |
73 | 73 |
chat.setChatId(response.id) |
74 |
+ chat.appendWithWhom(attendant) |
|
74 | 75 |
@trigger(event: 'app.chat.addToMultiChat', data: {chatOwner: chatOwner.get('jid'), chatId: response.id, jid: attendant.get('jid')}, success: -> |
75 | 76 |
Backbone.Events.trigger('openChat', chat) |
76 | 77 |
) |
77 | 78 |
) |
78 | 79 |
|
80 |
+ inviteToChat: (chat, toAdd, me) -> |
|
81 |
+ @trigger(event: 'app.chat.addToMultiChat', data: {chatOwner: me, chatId: chat.get('chatId'), jid: toAdd.get('jid')}, success: -> |
|
82 |
+ chat.appendWithWhom(toAdd) |
|
83 |
+ Backbone.Events.trigger('openChat', chat) |
|
84 |
+ ) |
|
85 |
+ |
|
79 | 86 |
iClosedMultichat: (chatId, jid) -> |
80 | 87 |
@trigger(event: 'app.chat.iClosedMultichat', data: {chatId: chatId, me: jid}) |
81 | 88 |
|
... | ... |
@@ -131,16 +138,19 @@ this.App = |
131 | 131 |
) |
132 | 132 |
|
133 | 133 |
App._dispatcher.bind('app.chat.importChat', (chatData) -> |
134 |
- newChat = new Xmpp.Models.Chat( |
|
135 |
- chatId: chatData.chat_id, |
|
136 |
- isMultiChat: true |
|
137 |
- ); |
|
134 |
+ chatId = chatData.chat_id |
|
135 |
+ chat = App.Collections.chats.findById(chatId) |
|
136 |
+ |
|
137 |
+ if not chat |
|
138 |
+ chat = new Xmpp.Models.Chat( |
|
139 |
+ chatId: chatId, |
|
140 |
+ isMultiChat: true |
|
141 |
+ ) |
|
138 | 142 |
|
139 |
- App.debug newChat.get('chatId') |
|
143 |
+ App.Collections.chats.add(chat); |
|
140 | 144 |
|
141 |
- App.Collections.chats.add(newChat); |
|
142 |
- newChat.syncContacts(chatData.contacts, chatData.owner); |
|
143 |
- Backbone.Events.trigger('openChat', newChat) |
|
145 |
+ chat.syncContacts(chatData.contacts, chatData.owner) |
|
146 |
+ Backbone.Events.trigger('openChat', chat) |
|
144 | 147 |
) |
145 | 148 |
|
146 | 149 |
App._dispatcher.bind('app.chat.messageReceived', (result) -> |
... | ... |
@@ -60,18 +60,21 @@ class Xmpp.Views.Contacts.ContactView extends Backbone.View |
60 | 60 |
inviteToMultichat: (e) -> |
61 | 61 |
e.stopPropagation(); |
62 | 62 |
App.debug 'iniviting to multichat' |
63 |
+ multichat = App.Collections.chats.activeChat |
|
64 |
+ if not multichat or not multichat.get('isMultiChat') |
|
65 |
+ return |
|
66 |
+ |
|
67 |
+ App.Com.inviteToChat(multichat, @model, App.Models.me.get('jid')) |
|
63 | 68 |
|
64 | 69 |
newMultiChat: (e) -> |
65 | 70 |
e.stopPropagation(); |
66 | 71 |
App.debug 'new multichat' |
67 |
- withWhom = @model |
|
68 | 72 |
|
69 | 73 |
newChat = new Xmpp.Models.Chat(isMultiChat: true) |
70 | 74 |
newChat.set('who', App.Models.me) |
71 |
- newChat.appendWithWhom(withWhom) |
|
72 | 75 |
|
73 | 76 |
App.Collections.chats.add(newChat) |
74 |
- App.Com.openNewMultiChat(App.Models.me, withWhom, newChat) |
|
77 |
+ App.Com.openNewMultiChat(App.Models.me, @model, newChat) |
|
75 | 78 |
|
76 | 79 |
kickFromMultiChat: (e) -> |
77 | 80 |
e.stopPropagation(); |
... | ... |
@@ -41,16 +41,12 @@ class WsChatController < WsController |
41 | 41 |
|
42 | 42 |
connection_store[:opened_chats] = {} if ! connection_store[:opened_chats] |
43 | 43 |
connection_store[:opened_chats][client] = {} if ! connection_store[:opened_chats][client] |
44 |
- connection_store[:opened_chats][client][chat_id] = {attendants: contacts, owner: message.from.node + '@' + message.from.domain} |
|
44 |
+ connection_store[:opened_chats][client][chat_id] = {attendants: contacts, owner: message.from.strip.to_s} |
|
45 | 45 |
|
46 |
- #Rails.logger.debug [ |
|
47 |
- # owner: message.from.node + '@' + message.from.domain, |
|
48 |
- # chat_id: chat_id, |
|
49 |
- # contacts: contacts |
|
50 |
- #] |
|
46 |
+ #Rails.logger.debug [connection_store[:opened_chats][client], client.jid.to_s] |
|
51 | 47 |
|
52 | 48 |
send_message 'app.chat.importChat', |
53 |
- owner: message.from.node + '@' + message.from.domain, |
|
49 |
+ owner: message.from.strip.to_s, |
|
54 | 50 |
chat_id: chat_id, |
55 | 51 |
contacts: contacts |
56 | 52 |
end |
... | ... |
@@ -74,12 +70,15 @@ class WsChatController < WsController |
74 | 74 |
client = find_client(message[:chatOwner]) |
75 | 75 |
|
76 | 76 |
chat_id = message[:chatId] |
77 |
- somebody = message[:jid] |
|
77 |
+ add = message[:jid] |
|
78 | 78 |
|
79 |
- connection_store[:opened_chats][client][chat_id][:attendants] << somebody |
|
79 |
+ connection_store[:opened_chats][client][chat_id][:attendants] << add |
|
80 | 80 |
|
81 | 81 |
contacts = connection_store[:opened_chats][client][chat_id][:attendants] |
82 |
- client.send(MessageBuilder::export_multichat(client.jid.strip.to_s, somebody, chat_id, contacts)) |
|
82 |
+ |
|
83 |
+ contacts.each do |contact| |
|
84 |
+ client.send(MessageBuilder::export_multichat(client.jid.strip.to_s, contact, chat_id, contacts)) |
|
85 |
+ end |
|
83 | 86 |
|
84 | 87 |
trigger_success |
85 | 88 |
end |
... | ... |
@@ -95,13 +94,13 @@ class WsChatController < WsController |
95 | 95 |
attendants -= [client.jid.strip.to_s] |
96 | 96 |
|
97 | 97 |
messages = MessageBuilder::build_multi_messages(message[:message], client.jid.strip.to_s, attendants, chat_id) |
98 |
+ #Rails.logger.debug messages |
|
98 | 99 |
else |
99 | 100 |
messages = [MessageBuilder::build_message(message[:message], client.jid.strip.to_s, message[:to])] |
100 | 101 |
end |
101 | 102 |
|
102 | 103 |
# Xmpp4r doesn't support XEP-0033 (multicast messages) |
103 | 104 |
messages.each do |message| |
104 |
- #Rails.logger.debug message.to_s |
|
105 | 105 |
client.send(message) |
106 | 106 |
end |
107 | 107 |
|
... | ... |
@@ -162,7 +161,7 @@ class WsChatController < WsController |
162 | 162 |
private |
163 | 163 |
|
164 | 164 |
def process_incoming_message(message) |
165 |
- #Rails.logger.debug message |
|
165 |
+ #Rails.logger.debug [message, message.to.strip.to_s] |
|
166 | 166 |
send_message 'app.chat.messageReceived', |
167 | 167 |
from: message.from.strip.to_s, |
168 | 168 |
to: message.to.strip.to_s, |