effective_messaging 0.1.0 → 0.1.2

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
  SHA256:
3
- metadata.gz: 6193093b822303bfc098d13ddaa7fe17787571ba0f65a5531ac0978272381320
4
- data.tar.gz: b305d1836ab2a6f37b1236a986f36753d9194b969cc1105431733720a4d68535
3
+ metadata.gz: 84f3cb325386b6c35c631c57ab15eaa3775e892ace9128e082e57a258203008b
4
+ data.tar.gz: 3ccdcaf09dc41afd32fcd46a365ee4582fe8d06dac3efecbbd91b0e1f921982d
5
5
  SHA512:
6
- metadata.gz: b9b841f95b963670a6471bc6f28ae379ca99e43c7ee686f6d368c9853e4db1aaa2cd50dd7c1fdf15f20fefdb5f43a2d062e103074fbe01a9a9335b88bb465b20
7
- data.tar.gz: e9e6c2cd7a336d3bf1fb547bceca70c49a2089728e4927b806ae77d78c9ec04836b8217b6a854be56f8e8af3cc96a01d2ee44a1973c104bef5642a8e5a2030cd
6
+ metadata.gz: 5cb621f111776ff55f8eb354b8d86006b77bc5bed042571b66b0f51e93df0bf10ccb47c35a6da8cd5af916128d69c943f0162e62c0e926eb63689fa316eda247
7
+ data.tar.gz: daae9d060cedaeb9895d808c281069ffcb565d9268c8c64ed346a6b68f30b24b45cd5524b76015a7cb25923708ae2b55205bf03293377e271253b7b5a28f58dd
@@ -0,0 +1,38 @@
1
+ # Mostly for the callbacks
2
+
3
+ module EffectiveMessagingParent
4
+ extend ActiveSupport::Concern
5
+
6
+ module Base
7
+ def effective_messaging_parent
8
+ include ::EffectiveMessagingParent
9
+ end
10
+ end
11
+
12
+ module ClassMethods
13
+ def effective_messaging_parent?; true; end
14
+ end
15
+
16
+ included do
17
+ has_many :chats, -> { Effective::Chat.sorted }, as: :parent, class_name: 'Effective::Chat', dependent: :nullify
18
+ accepts_nested_attributes_for :chats
19
+ end
20
+
21
+ def chat
22
+ chats.first
23
+ end
24
+
25
+ def build_chat
26
+ raise('to be implemented by parent')
27
+
28
+ # chat = chats.first || chats.build()
29
+ # chat_user = chat.build_chat_user(user: user)
30
+ # reviewers.each { |reviewer| chat.build_chat_user(user: reviewer.user) }
31
+ # chat
32
+ end
33
+
34
+ def create_chat
35
+ build_chat.tap { |chat| chat.save! }
36
+ end
37
+
38
+ end
@@ -86,8 +86,10 @@ module Effective
86
86
  chat_users.find { |cu| cu.user_id == user.id && cu.user_type == user.class.name }
87
87
  end
88
88
 
89
- def build_chat_user(user:)
90
- chat_user(user: user) || chat_users.build(user: user)
89
+ def build_chat_user(user:, anonymous_name: nil)
90
+ cu = chat_user(user: user) || chat_users.build(user: user)
91
+ cu.assign_attributes(anonymous_name: anonymous_name) if anonymous_name.present?
92
+ cu
91
93
  end
92
94
 
93
95
  # Always build
@@ -1,4 +1,4 @@
1
- = render 'layout' do
1
+ = render 'effective/chats/layout' do
2
2
  - chat_user = chat.chat_user(user: current_user)
3
3
 
4
4
  - # New message form
@@ -1,10 +1,9 @@
1
- = render 'layout' do
2
-
3
- - label = content_tag(:strong, chat_message.name) + ' commented ' + time_ago_in_words(chat_message.created_at) + ' ago'
4
-
1
+ .effective-chat-message
5
2
  .card
6
3
  .card-header
7
- = label
8
- Yea
4
+ %strong= chat_message.name
5
+ commented
6
+ = time_ago_in_words(chat_message.created_at)
7
+ ago
9
8
  .card-body
10
- = simple_format chat_message.body
9
+ = simple_format(chat_message.body)
@@ -18,7 +18,7 @@
18
18
  .card-header.bg-secondary
19
19
  Send message
20
20
  .card-body
21
- %p Your name is displayed as <strong>#{chat_user.name}</strong>.
21
+ %p Your name is displayed as <strong>#{chat_user.name}</strong>
22
22
 
23
23
  = f.fields_for :chat_messages, chat_message do |fcm|
24
24
  - # The user and name are set by controller's current_user
@@ -1,10 +1,18 @@
1
+ - current_chat_user = chat.chat_user(user: current_user)
2
+ - chat_users_count = chat.chat_users.count
3
+
1
4
  %p
2
5
  - if chat.anonymous?
3
6
  = badges('anonymous')
4
7
 
5
8
  = succeed('.') do
6
9
  A chat with
7
- = pluralize(chat.chat_users.count, 'participants')
10
+
11
+ - if current_chat_user.present? && chat_users_count < 5
12
+ = (chat.chat_users - [current_chat_user]).map(&:name).to_sentence
13
+ - else
14
+ = pluralize(chat_users_count, 'participants')
15
+
8
16
  opened
9
17
  = time_ago_in_words(chat.created_at)
10
18
  ago
@@ -10,6 +10,7 @@ module EffectiveMessaging
10
10
  # Include acts_as_messaging concern and allow any ActiveRecord object to call it
11
11
  initializer 'effective_messaging.active_record' do |app|
12
12
  app.config.to_prepare do
13
+ ActiveRecord::Base.extend(EffectiveMessagingParent::Base)
13
14
  ActiveRecord::Base.extend(EffectiveMessagingUser::Base)
14
15
  end
15
16
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveMessaging
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_messaging
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-11 00:00:00.000000000 Z
11
+ date: 2023-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -229,6 +229,7 @@ files:
229
229
  - app/datatables/effective_chats_datatable.rb
230
230
  - app/helpers/effective_messaging_helper.rb
231
231
  - app/mailers/effective/messaging_mailer.rb
232
+ - app/models/concerns/effective_messaging_parent.rb
232
233
  - app/models/concerns/effective_messaging_user.rb
233
234
  - app/models/effective/chat.rb
234
235
  - app/models/effective/chat_message.rb