effective_messaging 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/mailers/effective/messaging_mailer.rb +7 -3
- data/app/models/concerns/effective_messaging_parent.rb +43 -0
- data/app/models/effective/chat.rb +4 -2
- data/app/views/effective/chats/_chat.html.haml +1 -1
- data/app/views/effective/chats/_chat_message.html.haml +1 -2
- data/app/views/effective/chats/_summary.html.haml +9 -1
- data/lib/effective_messaging/engine.rb +1 -0
- data/lib/effective_messaging/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 100add48efce4abb6b4604310d8adfc37df3edae84bd69f2dc350f2239488f65
|
4
|
+
data.tar.gz: fc5e27126372377ea850672ebb9db003698795a63b896773ffc992686e61ed5a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52e97742d99e634c3dbfb3c723c0767386fec0f63e52c3d78215b4fdcbb01863f34a6848aa9ff291141358d0fa075e0a95f3bb6221390220900796d907344e19
|
7
|
+
data.tar.gz: c980d9cc678826ae1f8ea2c94b5e603b3a13de884dac5159eca6f2481c8aa5377054f1d3be8b145a24978bc99762e27bb281bc40377aad147ed8c74e0a3da6d4
|
@@ -11,7 +11,7 @@ module Effective
|
|
11
11
|
user = chat_user.user
|
12
12
|
raise('expected user to have an email') unless user.try(:email).present?
|
13
13
|
|
14
|
-
@assigns =
|
14
|
+
@assigns = chat_assigns(chat, user: user).merge(assigns_for(chat_user))
|
15
15
|
|
16
16
|
subject = subject_for(__method__, "New Message - #{chat}", chat, opts)
|
17
17
|
headers = headers_for(chat, opts)
|
@@ -33,13 +33,17 @@ module Effective
|
|
33
33
|
raise('unexpected resource')
|
34
34
|
end
|
35
35
|
|
36
|
-
def chat_assigns(chat)
|
36
|
+
def chat_assigns(chat, user:)
|
37
37
|
raise('expected a chat') unless chat.kind_of?(Chat)
|
38
|
+
raise('expected a user') unless user.present?
|
39
|
+
|
40
|
+
url = chat.parent&.chat_url(chat: chat, user: user, root_url: root_url)
|
41
|
+
url ||= effective_messaging.chat_url(chat)
|
38
42
|
|
39
43
|
values = {
|
40
44
|
date: chat.created_at.strftime('%F'),
|
41
45
|
title: chat.title,
|
42
|
-
url:
|
46
|
+
url: url
|
43
47
|
}.compact
|
44
48
|
|
45
49
|
{ chat: values }
|
@@ -0,0 +1,43 @@
|
|
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
|
+
# Hook so the parent can specify the correct url for this user to visit to see the new chat message
|
39
|
+
def chat_url(chat:, user:, root_url:)
|
40
|
+
nil
|
41
|
+
end
|
42
|
+
|
43
|
+
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,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
|
-
|
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
|
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.
|
4
|
+
version: 0.1.3
|
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
|
+
date: 2023-01-27 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
|