mailboxer 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/app/models/mailbox.rb +6 -2
- data/app/models/notification.rb +17 -2
- data/lib/mailboxer/models/messageable.rb +12 -12
- data/mailboxer.gemspec +1 -1
- metadata +4 -4
data/app/models/mailbox.rb
CHANGED
@@ -9,7 +9,11 @@ class Mailbox
|
|
9
9
|
#Returns the notifications for the messageable
|
10
10
|
def notifications(options = {})
|
11
11
|
#:type => nil is a hack not to give Messages as Notifications
|
12
|
-
|
12
|
+
notifs = Notification.recipient(@messageable).where(:type => nil).order("notifications.created_at DESC")
|
13
|
+
if (options[:read].present? and options[:read]==false) or (options[:unread].present? and options[:unread]==true)
|
14
|
+
notifs = notifs.unread
|
15
|
+
end
|
16
|
+
return notifs
|
13
17
|
end
|
14
18
|
|
15
19
|
#Returns the conversations for the messageable
|
@@ -39,7 +43,7 @@ class Mailbox
|
|
39
43
|
end
|
40
44
|
|
41
45
|
if (options[:read].present? and options[:read]==false) or (options[:unread].present? and options[:unread]==true)
|
42
|
-
|
46
|
+
conv = conv.unread(@messageable)
|
43
47
|
end
|
44
48
|
|
45
49
|
return conv.uniq
|
data/app/models/notification.rb
CHANGED
@@ -21,12 +21,27 @@ class Notification < ActiveRecord::Base
|
|
21
21
|
|
22
22
|
class << self
|
23
23
|
#Sends a Notification to all the recipients
|
24
|
-
def notify_all(recipients,subject,body,obj = nil)
|
24
|
+
def notify_all(recipients,subject,body,obj = nil,sanitize_text = true)
|
25
25
|
notification = Notification.new({:body => body, :subject => subject})
|
26
26
|
notification.recipients = recipients.is_a?(Array) ? recipients : [recipients]
|
27
27
|
notification.recipients = notification.recipients.uniq
|
28
28
|
notification.notified_object = obj if obj.present?
|
29
|
-
return notification.deliver
|
29
|
+
return notification.deliver sanitize_text
|
30
|
+
end
|
31
|
+
|
32
|
+
#Takes a +Receipt+ or an +Array+ of them and returns +true+ if the delivery was
|
33
|
+
#successful or +false+ if some error raised
|
34
|
+
def successful_delivery? receipts
|
35
|
+
case receipts
|
36
|
+
when Receipt
|
37
|
+
receipts.valid?
|
38
|
+
return receipts.errors.empty?
|
39
|
+
when Array
|
40
|
+
receipts.each(&:valid?)
|
41
|
+
return receipts.all? { |t| t.errors.empty? }
|
42
|
+
else
|
43
|
+
return false
|
44
|
+
end
|
30
45
|
end
|
31
46
|
end
|
32
47
|
|
@@ -41,52 +41,52 @@ module Mailboxer
|
|
41
41
|
end
|
42
42
|
|
43
43
|
#Sends a notification to the messageable
|
44
|
-
def notify(subject,body,obj = nil)
|
44
|
+
def notify(subject,body,obj = nil,sanitize_text=true)
|
45
45
|
notification = Notification.new({:body => body, :subject => subject})
|
46
46
|
notification.recipients = [self]
|
47
47
|
notification.notified_object = obj if obj.present?
|
48
|
-
return notification.deliver
|
48
|
+
return notification.deliver sanitize_text
|
49
49
|
end
|
50
50
|
|
51
51
|
#Sends a messages, starting a new conversation, with the messageable
|
52
52
|
#as originator
|
53
|
-
def send_message(recipients, msg_body, subject)
|
53
|
+
def send_message(recipients, msg_body, subject,sanitize_text=true)
|
54
54
|
convo = Conversation.new({:subject => subject})
|
55
55
|
message = Message.new({:sender => self, :conversation => convo, :body => msg_body, :subject => subject})
|
56
56
|
message.recipients = recipients.is_a?(Array) ? recipients : [recipients]
|
57
57
|
message.recipients = message.recipients.uniq
|
58
|
-
return message.deliver
|
58
|
+
return message.deliver false,sanitize_text
|
59
59
|
end
|
60
60
|
|
61
61
|
#Basic reply method. USE NOT RECOMENDED.
|
62
62
|
#Use reply_to_sender, reply_to_all and reply_to_conversation instead.
|
63
|
-
def reply(conversation, recipients, reply_body, subject = nil)
|
63
|
+
def reply(conversation, recipients, reply_body, subject = nil,sanitize_text=true)
|
64
64
|
subject = subject || "RE: #{conversation.subject}"
|
65
65
|
response = Message.new({:sender => self, :conversation => conversation, :body => reply_body, :subject => subject})
|
66
66
|
response.recipients = recipients.is_a?(Array) ? recipients : [recipients]
|
67
67
|
response.recipients = response.recipients.uniq
|
68
68
|
response.recipients.delete(self)
|
69
|
-
return response.deliver
|
69
|
+
return response.deliver true,sanitize_text
|
70
70
|
end
|
71
71
|
|
72
72
|
#Replies to the sender of the message in the conversation
|
73
|
-
def reply_to_sender(receipt, reply_body, subject = nil)
|
74
|
-
return reply(receipt.conversation, receipt.message.sender, reply_body, subject)
|
73
|
+
def reply_to_sender(receipt, reply_body, subject = nil,sanitize_text=true)
|
74
|
+
return reply(receipt.conversation, receipt.message.sender, reply_body, subject,sanitize_text)
|
75
75
|
end
|
76
76
|
|
77
77
|
#Replies to all the recipients of the message in the conversation
|
78
|
-
def reply_to_all(receipt, reply_body, subject = nil)
|
79
|
-
return reply(receipt.conversation, receipt.message.recipients, reply_body, subject)
|
78
|
+
def reply_to_all(receipt, reply_body, subject = nil,sanitize_text=true)
|
79
|
+
return reply(receipt.conversation, receipt.message.recipients, reply_body, subject,sanitize_text)
|
80
80
|
end
|
81
81
|
|
82
82
|
#Replies to all the recipients of the last message in the conversation and untrash any trashed message by messageable
|
83
83
|
#if should_untrash is set to true (this is so by default)
|
84
|
-
def reply_to_conversation(conversation, reply_body, subject = nil, should_untrash = true)
|
84
|
+
def reply_to_conversation(conversation, reply_body, subject = nil, should_untrash = true,sanitize_text=true)
|
85
85
|
#move conversation to inbox if it is currently in the trash and should_untrash parameter is true.
|
86
86
|
if should_untrash && mailbox.is_trashed?(conversation)
|
87
87
|
mailbox.receipts_for(conversation).untrash
|
88
88
|
end
|
89
|
-
return reply(conversation, conversation.last_message.recipients, reply_body, subject)
|
89
|
+
return reply(conversation, conversation.last_message.recipients, reply_body, subject,sanitize_text)
|
90
90
|
end
|
91
91
|
|
92
92
|
#Mark the object as read for messageable.
|
data/mailboxer.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "mailboxer"
|
3
|
-
s.version = "0.5.
|
3
|
+
s.version = "0.5.1"
|
4
4
|
s.authors = ["Eduardo Casanova Cuesta"]
|
5
5
|
s.summary = "Messaging system for rails apps."
|
6
6
|
s.description = "A Rails engine that allows any model to act as messageable, allowing it to exchange messages " +
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mailboxer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 5
|
9
|
-
-
|
10
|
-
version: 0.5.
|
9
|
+
- 1
|
10
|
+
version: 0.5.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Eduardo Casanova Cuesta
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-09-03 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|