chatty 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d6c0e4fba05a323b0b54c5e2c094e961048cc7cf
4
- data.tar.gz: 3cea5a15dc30dc14eb841080dd31535529590a9f
3
+ metadata.gz: 87ca9a98ed8b49169259e0ca3a389af4abad3c52
4
+ data.tar.gz: 36c4b26cb9ba44b6d77f54edbc8cbd8810ee9628
5
5
  SHA512:
6
- metadata.gz: a842d79f49e4ec07c1209dd8be1a3a5d6b75628b8ae0d1bc39cf677617ca84aca510d87edc40ed3d0f1da92078d4b1bcb4ab8d556c1bb6a77a536b89baa7d48e
7
- data.tar.gz: cad89e6ad27ae91910c7caa6d99f84a6ab99c64a921178e667b8cad512c46427f87b31d3c90a3c41a0025ad05885e14892a1d3bf24c0dd89b3ef0924dff7538c
6
+ metadata.gz: 9e05424786e767ef69a3095ca45ac2adc1798b22473f0db8bd0536d6f481363805ce97e6c11a0ee98168e0fd527cb67429f6fcb0407034bbc82b9ba5668d6ca4
7
+ data.tar.gz: 6ced35306e8623cdd13f9f3933afd4923fde8336b515b365950dd0c8bc49671eb9382fdf57966004143ab9821182c08a905f04f895bf724e1e041d5e4b9b1ff0
@@ -30,21 +30,18 @@ $ ->
30
30
  })
31
31
  chat.prepend(error)
32
32
 
33
- chatty_handled(chat, ->
34
- chatty_init_messages(chat, ->
35
- chatty_init_form(chat, ->
33
+ chatty_handled chat, ->
34
+ chatty_init_messages chat, ->
35
+ chatty_init_form chat, ->
36
36
  chatty_refresh_messages(chat)
37
37
  chatty_check_new_messages(chat)
38
- )
39
- )
40
- )
41
38
 
42
39
  chatty_check_new_messages = (chat) ->
43
40
  setTimeout((->
44
41
  chatty_refresh_messages(chat)
45
42
 
46
43
  # Handle changed chat state.
47
- chatty_with_state(chat, (data) ->
44
+ chatty_with_state chat, (data) ->
48
45
  if data.chat.state != "handled"
49
46
  chatty_hide_form() unless chatty_form_hidden()
50
47
  else
@@ -54,7 +51,6 @@ $ ->
54
51
  chatty_show_not_allowed_to_add_messages() if chatty_not_allowed_to_add_messages_hidden()
55
52
  else
56
53
  chatty_hide_not_allowed_to_add_messages() unless chatty_not_allowed_to_add_messages_hidden()
57
- )
58
54
 
59
55
  chatty_check_new_messages(chat)
60
56
  ), 1000)
@@ -108,14 +104,13 @@ $ ->
108
104
  chat.data("last-message-id", 0)
109
105
  messages_container = $(".chatty_messages", chat)
110
106
  messages_container.html("")
111
- messages_container.slideDown("fast", ->
107
+ messages_container.slideDown "fast", ->
112
108
  $.ajax({type: "GET", url: "/chatty/messages/?q[chat_id_eq]=" + chat.data("chat-id"), cache: false, async: true, dataType: "json", success: (data) ->
113
109
  for message in data.messages
114
110
  chatty_add_message(chat, message)
115
111
 
116
112
  callback.call()
117
113
  })
118
- )
119
114
 
120
115
  chatty_add_message = (chat, message) ->
121
116
  msg_id = parseInt(message.id)
@@ -129,21 +124,27 @@ $ ->
129
124
  messages_container = $(".chatty_messages", chat)
130
125
  message_class = "chatty_message_" + msg_id
131
126
 
127
+ if message.self
128
+ self_class = "chatty_message_self"
129
+ else
130
+ self_class = "chatty_message_other"
131
+
132
132
  container = $("<div />", {
133
- "class": "chatty_message " + message_class,
133
+ "class": "chatty_message " + message_class + " " + self_class,
134
134
  "data": {
135
- "message_id": message.id
135
+ "message_id": message.id,
136
+ "self": message.self
136
137
  },
137
138
  "css": {
138
139
  "display": "none"
139
140
  }
140
141
  })
141
142
 
142
- author_div = $("<div />", {
143
- "class": "chatty_message_author",
144
- "text": message.author_name
143
+ user_div = $("<div />", {
144
+ "class": "chatty_message_user",
145
+ "text": message.user_name
145
146
  })
146
- container.append(author_div)
147
+ container.append(user_div)
147
148
 
148
149
  message_div = $("<div />", {
149
150
  "class": "chatty_message_message",
@@ -25,7 +25,7 @@ class Chatty::MessagesController < Chatty::ApplicationController
25
25
  @messages = @ransack.result.order(:created_at, :id)
26
26
 
27
27
  respond_to do |format|
28
- format.json { render(:json => {:messages => @messages.map{ |message| message.json } }) }
28
+ format.json { render(:json => {:messages => messages_json(@messages)}) }
29
29
  end
30
30
  end
31
31
 
@@ -45,4 +45,18 @@ private
45
45
  def message_params
46
46
  params.require(:message).permit(:chat_id, :message)
47
47
  end
48
+
49
+ def messages_json messages
50
+ @messages.map do |message|
51
+ message_json = message.json
52
+
53
+ if message.user == current_user
54
+ message_json[:self] = true
55
+ else
56
+ message_json[:self] = false
57
+ end
58
+
59
+ message_json
60
+ end
61
+ end
48
62
  end
@@ -9,7 +9,8 @@ class Chatty::Message < ActiveRecord::Base
9
9
  return {
10
10
  :id => id,
11
11
  :message => message,
12
- :author_name => (user[:name].presence || user[:email].presence || user.id),
12
+ :user_id => user.id,
13
+ :user_name => (user[:name].presence || user[:email].presence || user.id),
13
14
  :created_at => created_at.strftime("%Y-%m-%d %H:%M:%S")
14
15
  }
15
16
  end
@@ -1,3 +1,3 @@
1
1
  module Chatty
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chatty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kasper Johansen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-11 00:00:00.000000000 Z
11
+ date: 2014-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -255,36 +255,35 @@ executables: []
255
255
  extensions: []
256
256
  extra_rdoc_files: []
257
257
  files:
258
- - app/controllers/chatty/admin_chats_controller.rb
259
- - app/controllers/chatty/messages_controller.rb
260
- - app/controllers/chatty/application_controller.rb
261
- - app/controllers/chatty/chats_controller.rb
262
- - app/views/chatty/messages/_form.html.haml
263
- - app/views/chatty/messages/new.html.haml
264
- - app/views/chatty/chats/show.html.haml
265
- - app/views/chatty/chats/index.html.haml
266
- - app/helpers/chatty/chats_helper.rb
267
- - app/helpers/chatty/application_helper.rb
258
+ - app/models/chatty/message.rb
259
+ - app/models/chatty/chat.rb
268
260
  - app/assets/stylesheets/scaffold.css
269
- - app/assets/stylesheets/chatty/chats.css
270
261
  - app/assets/stylesheets/chatty/application.css
262
+ - app/assets/stylesheets/chatty/chats.css
271
263
  - app/assets/stylesheets/chatty.css.scss
272
- - app/assets/javascripts/chatty.js.coffee
273
- - app/assets/javascripts/chatty/application.js
274
264
  - app/assets/javascripts/chatty/chats.js
275
- - app/models/chatty/message.rb
276
- - app/models/chatty/chat.rb
265
+ - app/assets/javascripts/chatty/application.js
266
+ - app/assets/javascripts/chatty.js.coffee
267
+ - app/helpers/chatty/application_helper.rb
268
+ - app/helpers/chatty/chats_helper.rb
269
+ - app/controllers/chatty/application_controller.rb
270
+ - app/controllers/chatty/chats_controller.rb
271
+ - app/controllers/chatty/messages_controller.rb
272
+ - app/controllers/chatty/admin_chats_controller.rb
273
+ - app/views/chatty/chats/index.html.haml
274
+ - app/views/chatty/chats/show.html.haml
275
+ - app/views/chatty/messages/_form.html.haml
276
+ - app/views/chatty/messages/new.html.haml
277
277
  - config/routes.rb
278
- - db/plugin_migrate/20140520083510_create_chatty_chats.rb
279
- - db/plugin_migrate/20140520083027_create_chatty_messages.rb
280
278
  - db/plugin_migrate/20140521072854_create_activities.rb
281
- - lib/chatty.rb
279
+ - db/plugin_migrate/20140520083027_create_chatty_messages.rb
280
+ - db/plugin_migrate/20140520083510_create_chatty_chats.rb
282
281
  - lib/chatty/engine.rb
283
282
  - lib/chatty/version.rb
283
+ - lib/chatty.rb
284
284
  - lib/tasks/chatty_tasks.rake
285
285
  - MIT-LICENSE
286
286
  - Rakefile
287
- - README.rdoc
288
287
  homepage: https://www.github.com/kaspernj/chatty
289
288
  licenses: []
290
289
  metadata: {}
@@ -1,3 +0,0 @@
1
- = Chatty
2
-
3
- This project rocks and uses MIT-LICENSE.