... | ... |
@@ -65,10 +65,12 @@ this.App = |
65 | 65 |
sendMultiMessage: (message, chatId, from, callbackOk, callbackFail) -> |
66 | 66 |
App.Com.trigger(event: 'app.chat.sendMessage', data: {message: message, chatId: chatId, from: from}, success: callbackOk, error: callbackFail) |
67 | 67 |
|
68 |
- openNewMultiChatId: (chatOwner, attendant, chat) -> |
|
69 |
- @trigger(event: 'app.chat.newMultiChatId', data: {chatOwner: chatOwner}, success: (response) => |
|
68 |
+ openNewMultiChat: (chatOwner, attendant, chat) -> |
|
69 |
+ @trigger(event: 'app.chat.newMultiChat', data: {chatOwner: chatOwner.get('jid')}, success: (response) => |
|
70 | 70 |
chat.setChatId(response.id) |
71 |
- @trigger(event: 'app.chat.addToMultiChat', data: {chatOwner: chatOwner, chatId: response.id, jid: attendant} ) |
|
71 |
+ @trigger(event: 'app.chat.addToMultiChat', data: {chatOwner: chatOwner.get('jid'), chatId: response.id, jid: attendant.get('jid')}, success: -> |
|
72 |
+ Backbone.Events.trigger('openChat', chat) |
|
73 |
+ ) |
|
72 | 74 |
) |
73 | 75 |
|
74 | 76 |
syncMultiChatContacts: (me, chatId) -> |
... | ... |
@@ -5,14 +5,28 @@ class Xmpp.Models.Chat extends Xmpp.Models.Model |
5 | 5 |
who: null |
6 | 6 |
withWhom: null |
7 | 7 |
chatId: null |
8 |
+ isMultiChat: false |
|
8 | 9 |
|
9 | 10 |
initialize: -> |
10 | 11 |
_.bindAll(this) |
11 | 12 |
|
13 |
+ if (@get('isMultiChat')) |
|
14 |
+ @set('withWhom', []) |
|
15 |
+ |
|
12 | 16 |
#App.Com.openNewMultiChatId(@get('who').get('jid'), @get('withWhom').get('jid'), this) |
13 | 17 |
|
18 |
+ appendWithWhom: (newPerson) -> |
|
19 |
+ allWithWhom = @get('withWhom'); |
|
20 |
+ |
|
21 |
+ exists = _.find(allWithWhom, (withWhom) -> |
|
22 |
+ withWhom == newPerson |
|
23 |
+ )? |
|
24 |
+ |
|
25 |
+ if not exists |
|
26 |
+ allWithWhom.push(newPerson) |
|
27 |
+ |
|
14 | 28 |
setChatId: (id) -> |
15 |
- App.debug ['chat has id', id] |
|
29 |
+ App.debug ['multichat has id', id] |
|
16 | 30 |
@set('chatId', id) |
17 | 31 |
|
18 | 32 |
class Xmpp.Collections.ChatsCollection extends Backbone.Collection |
... | ... |
@@ -1,4 +1,9 @@ |
1 |
-%a{ href: "#" } |
|
2 |
- %div{ title: "#{@withWhom} #{I18n.t('chat.tabbar.and')} #{@who}"} |
|
3 |
- #{@withWhom} #{I18n.t('chat.tabbar.and')} #{@who} |
|
4 |
- %span.right.icon.icon-x.js-close |
|
5 | 1 |
\ No newline at end of file |
2 |
+%a{ href: '#' } |
|
3 |
+ -if @multiChat |
|
4 |
+ %div{ title: 'multichat'} |
|
5 |
+ MultiChat |
|
6 |
+ %span.right.icon.icon-x.js-close |
|
7 |
+ -else |
|
8 |
+ %div{ title: "#{@withWhom} #{I18n.t('chat.tabbar.and')} #{@who}"} |
|
9 |
+ #{@withWhom} #{I18n.t('chat.tabbar.and')} #{@who} |
|
10 |
+ %span.right.icon.icon-x.js-close |
|
6 | 11 |
\ No newline at end of file |
... | ... |
@@ -6,7 +6,9 @@ class Xmpp.Views.Contacts.ContactView extends Backbone.View |
6 | 6 |
className: 'clear user' |
7 | 7 |
|
8 | 8 |
events: |
9 |
- click: 'startChat' |
|
9 |
+ 'click .invite': 'inviteToMultichat' |
|
10 |
+ 'click .chat': 'newMultiChat' |
|
11 |
+ 'click': 'startChat', |
|
10 | 12 |
|
11 | 13 |
initialize: () -> |
12 | 14 |
_.bindAll(this) |
... | ... |
@@ -52,5 +54,20 @@ class Xmpp.Views.Contacts.ContactView extends Backbone.View |
52 | 52 |
|
53 | 53 |
Backbone.Events.trigger('openChat', chat) |
54 | 54 |
|
55 |
+ inviteToMultichat: (e) -> |
|
56 |
+ e.stopPropagation(); |
|
57 |
+ App.debug 'iniviting to multichat' |
|
58 |
+ |
|
59 |
+ newMultiChat: (e) -> |
|
60 |
+ e.stopPropagation(); |
|
61 |
+ App.debug 'new multichat' |
|
62 |
+ withWhom = @model |
|
63 |
+ |
|
64 |
+ newChat = new Xmpp.Models.Chat(isMultiChat: true); |
|
65 |
+ newChat.set('who', App.Models.me); |
|
66 |
+ newChat.appendWithWhom(withWhom); |
|
67 |
+ |
|
68 |
+ App.Com.openNewMultiChat(App.Models.me, withWhom, newChat) |
|
69 |
+ |
|
55 | 70 |
openChatById: (chatId) -> |
56 | 71 |
chat = App.Collections.chats.findById(chatId) |
57 | 72 |
\ No newline at end of file |
... | ... |
@@ -24,10 +24,17 @@ class Xmpp.Views.Tabbar.TabView extends Backbone.View |
24 | 24 |
@render() |
25 | 25 |
|
26 | 26 |
render: -> |
27 |
- $(@el).html(@template( |
|
28 |
- who: @model.get('who').firstname(), |
|
29 |
- withWhom: @model.get('withWhom').firstname() |
|
30 |
- )) |
|
27 |
+ if (@model.get('isMultiChat')) |
|
28 |
+ $(@el).html(@template( |
|
29 |
+ who: @model.get('who').firstname(), |
|
30 |
+ multiChat: true |
|
31 |
+ )) |
|
32 |
+ else |
|
33 |
+ $(@el).html(@template( |
|
34 |
+ who: @model.get('who').firstname(), |
|
35 |
+ withWhom: @model.get('withWhom').firstname(), |
|
36 |
+ multiChat: false |
|
37 |
+ )) |
|
31 | 38 |
return this |
32 | 39 |
|
33 | 40 |
showChat: -> |
... | ... |
@@ -39,14 +39,16 @@ class WsChatController < WsController |
39 | 39 |
connection_store[:opened_chats][client][chat_id] = {attendants: contacts, owner: message.from} |
40 | 40 |
end |
41 | 41 |
|
42 |
+ # Owner vytvori najprv u seba novy multichat |
|
42 | 43 |
def new_multichat |
43 |
- id = Time.now.to_f |
|
44 | 44 |
me = message[:chatOwner] |
45 |
+ hash = Digest::SHA2.hexdigest(me) |
|
46 |
+ id = hash + Time.now.to_f.to_s |
|
45 | 47 |
client = find_client(me) |
46 | 48 |
|
47 | 49 |
connection_store[:opened_chats] = {} if ! connection_store[:opened_chats] |
48 | 50 |
connection_store[:opened_chats][client] = {} if ! connection_store[:opened_chats][client] |
49 |
- connection_store[:opened_chats][client][id] = {attendants: [], owner: nil} |
|
51 |
+ connection_store[:opened_chats][client][id] = {attendants: [], owner: me} |
|
50 | 52 |
|
51 | 53 |
trigger_success id: id |
52 | 54 |
end |
... | ... |
@@ -62,6 +64,8 @@ class WsChatController < WsController |
62 | 62 |
|
63 | 63 |
contacts = connection_store[:opened_chats][client][chat_id][:attendants] |
64 | 64 |
client.send(MessageBuilder::export_multichat(client.jid.strip.to_s, somebody, chat_id, contacts)) |
65 |
+ |
|
66 |
+ trigger_success |
|
65 | 67 |
end |
66 | 68 |
|
67 | 69 |
def send_chat_message |
... | ... |
@@ -60,7 +60,7 @@ WebsocketRails::EventMap.describe do |
60 | 60 |
end |
61 | 61 |
|
62 | 62 |
namespace :chat do |
63 |
- subscribe :newMultiChatId, to: WsChatController, with_method: :new_multichat |
|
63 |
+ subscribe :newMultiChat, to: WsChatController, with_method: :new_multichat |
|
64 | 64 |
subscribe :addToMultiChat, to: WsChatController, with_method: :add_to_multichat |
65 | 65 |
subscribe :sendMessage, to: WsChatController, with_method: :send_chat_message |
66 | 66 |
subscribe :startPollingMessages, to: WsChatController, with_method: :start_polling_messages |