Giter Club home page Giter Club logo

mailboxer's Introduction

Mailboxer Build Status Gem Version

This project is based on the need for a private message system for ging / social_stream. Instead of creating our core message system heavily dependent on our development, we are trying to implement a generic and potent messaging gem.

After looking for a good gem to use we noticed the lack of messaging gems and functionality in them. Mailboxer tries to fill this void delivering a powerful and flexible message system. It supports the use of conversations with two or more participants, sending notifications to recipients (intended to be used as system notifications “Your picture has new comments”, “John Doe has updated his document”, etc.), and emailing the messageable model (if configured to do so). It has a complete implementation of a Mailbox object for each messageable with inbox, sentbox and trash.

The gem is constantly growing and improving its functionality. As it is used with our parallel development ging / social_stream we are finding and fixing bugs continously. If you want some functionality not supported yet or marked as TODO, you can create an issue to ask for it. It will be great feedback for us, and we will know what you may find useful in the gem.

Mailboxer was born from the great, but outdated, code from lpsergi / acts_as_messageable.

We are now working to make exhaustive documentation and some wiki pages in order to make it even easier to use the gem to its full potential. Please, give us some time if you find something missing or ask for it. You can also find us on the Gitter room for this repo. Join us there to talk.

Installation

Add to your Gemfile:

gem 'mailboxer'

Then run:

$ bundle install

Run install script:

$ rails g mailboxer:install

And don't forget to migrate your database:

$ rake db:migrate

You can also generate email views:

$ rails g mailboxer:views

Upgrading

If upgrading from 0.11.0 to 0.12.0, run the following generators:

$ rails generate mailboxer:namespacing_compatibility
$ rails generate mailboxer:install -s

Then, migrate your database:

$ rake db:migrate

Requirements & Settings

Emails

We are now adding support for sending emails when a Notification or a Message is sent to one or more recipients. You should modify the mailboxer initializer (/config/initializer/mailboxer.rb) to edit these settings:

Mailboxer.setup do |config|
  #Enables or disables email sending for Notifications and Messages
  config.uses_emails = true
  #Configures the default `from` address for the email sent for Messages and Notifications of Mailboxer
  config.default_from = "[email protected]"
  ...
end

You can change the way in which emails are delivered by specifying a custom implementation of notification and message mailers:

Mailboxer.setup do |config|
  config.notification_mailer = CustomNotificationMailer
  config.message_mailer = CustomMessageMailer
  ...
end

If you have subclassed the Mailboxer::Notification class, you can specify the mailers using a member method:

class NewDocumentNotification < Mailboxer::Notification
  def mailer_class
    NewDocumentNotificationMailer
  end
end

class NewCommentNotification < Mailboxer::Notification
  def mailer_class
    NewDocumentNotificationMailer
  end
end

Otherwise, the mailer class will be determined by appending 'Mailer' to the mailable class name.

User identities

Users must have an identity defined by a name and an email. We must ensure that Messageable models have some specific methods. These methods are:

#Returning any kind of identification you want for the model
def name
  return "You should add method :name in your Messageable model"
end
#Returning the email address of the model if an email should be sent for this object (Message or Notification).
#If no mail has to be sent, return nil.
def mailboxer_email(object)
  #Check if an email should be sent for that object
  #if true
  return "define_email@on_your.model"
  #if false
  #return nil
end

These names are explicit enough to avoid colliding with other methods, but as long as you need to change them you can do it by using mailboxer initializer (/config/initializer/mailboxer.rb). Just add or uncomment the following lines:

Mailboxer.setup do |config|
  # ...
  #Configures the methods needed by mailboxer
  config.email_method = :mailboxer_email
  config.name_method = :name
  config.notify_method = :notify
  # ...
end

You may change whatever you want or need. For example:

config.email_method = :notification_email
config.name_method = :display_name
config.notify_method = :notify_mailboxer

Will use the method notification_email(object) instead of mailboxer_email(object), display_name for name and notify_mailboxer for notify.

Using default or custom method names, if your model doesn't implement them, Mailboxer will use dummy methods so as to notify you of missing methods rather than crashing.

Preparing your models

In your model:

class User < ActiveRecord::Base
  acts_as_messageable
end

You are not limited to the User model. You can use Mailboxer in any other model and use it in several different models. If you have ducks and cylons in your application and you want to exchange messages as if they were the same, just add acts_as_messageable to each one and you will be able to send duck-duck, duck-cylon, cylon-duck and cylon-cylon messages. Of course, you can extend it for as many classes as you need.

Example:

class Duck < ActiveRecord::Base
  acts_as_messageable
end
class Cylon < ActiveRecord::Base
  acts_as_messageable
end

Mailboxer API

Warning for version 0.8.0

Version 0.8.0 sees Messageable#read and Messageable#unread renamed to mark_as_(un)read, and Receipt#read and Receipt#unread to is_(un)read. This may break existing applications, but read is a reserved name for Active Record, and the best pratice in this case is simply avoid using it.

How can I send a message?

#alfa wants to send a message to beta
alfa.send_message(beta, "Body", "subject")

How can I read the messages of a conversation?

As a messageable, what you receive are receipts, which are associated with the message itself. You should retrieve your receipts for the conversation and get the message associated with them.

This is done this way because receipts save the information about the relation between messageable and the messages: is it read?, is it trashed?, etc.

#alfa gets the last conversation (chronologically, the first in the inbox)
conversation = alfa.mailbox.inbox.first

#alfa gets it receipts chronologically ordered.
receipts = conversation.receipts_for alfa

#using the receipts (i.e. in the view)
receipts.each do |receipt|
  ...
  message = receipt.message
  read = receipt.is_unread? #or message.is_unread?(alfa)
  ...
end

How can I reply to a message?

#alfa wants to reply to all in a conversation
#using a receipt
alfa.reply_to_all(receipt, "Reply body")

#using a conversation
alfa.reply_to_conversation(conversation, "Reply body")
#alfa wants to reply to the sender of a message (and ONLY the sender)
#using a receipt
alfa.reply_to_sender(receipt, "Reply body")

How can I delete a message from trash?

#delete conversations forever for one receipt (still in database)
receipt.mark_as_deleted

#you can mark conversation as deleted for one participant
conversation.mark_as_deleted participant

#Mark the object as deleted for messageable
#Object can be:
  #* A Receipt
  #* A Conversation
  #* A Notification
  #* A Message
  #* An array with any of them
alfa.mark_as_deleted conversation

# get available message for specific user
conversation.messages_for(alfa)

How can I retrieve my conversations?

#alfa wants to retrieve all his conversations
alfa.mailbox.conversations

#A wants to retrieve his inbox
alfa.mailbox.inbox

#A wants to retrieve his sent conversations
alfa.mailbox.sentbox

#alfa wants to retrieve his trashed conversations
alfa.mailbox.trash

How can I paginate conversations?

You can use Kaminari to paginate the conversations as normal. Please, make sure you use the last version as mailboxer uses select('DISTINCT conversations.*') which was not respected before Kaminari 0.12.4 according to its changelog. Working correctly on Kaminari 0.13.0.

#Paginating all conversations using :page parameter and 9 per page
conversations = alfa.mailbox.conversations.page(params[:page]).per(9)

#Paginating received conversations using :page parameter and 9 per page
conversations = alfa.mailbox.inbox.page(params[:page]).per(9)

#Paginating sent conversations using :page parameter and 9 per page
conversations = alfa.mailbox.sentbox.page(params[:page]).per(9)

#Paginating trashed conversations using :page parameter and 9 per page
conversations = alfa.mailbox.trash.page(params[:page]).per(9)

You can take a look at the full documentation for Mailboxer in rubydoc.info.

Do you want to test Mailboxer?

Thanks to Roman Kushnir (@RKushnir) you can test Mailboxer with this sample app.

I need a GUI!

If you need a GUI you should take a look at these links:

Contributors

mailboxer's People

Contributors

ahmadhussain avatar alexbrinkman avatar amaierhofer avatar apneadiving avatar asselstine avatar atd avatar bennick avatar davidstosik avatar edwinwills avatar fabianoalmeida avatar jasdeepsingh avatar jcoyne avatar mhdaljuboori avatar mikesnare avatar naveda89 avatar rafaelgg avatar rjst avatar rkushnir avatar roendal avatar romanbsd avatar rposborne avatar ryannielson avatar seankay avatar soyellupi avatar supremebeing7 avatar t27duck avatar tonydewan avatar trappist avatar uysim avatar yonahforst avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mailboxer's Issues

ArgumentError: wrong number of arguments (0 for 1)

I just installed mailboxer yesterday and was in an attempting to get it running, so I may be completely off base here.

Here is my code:

u1 = User.where(login:'u1').first
u2 = User.where(login:'u2').first
recipt = u1.send_message(u2, "log", "Audit Run")

User model contains the lines

include Mailboxer::Models::Messageable
class User < ActiveRecord::Base

set this up as a messageable object

acts_as_messageable

#method needed for messaging
def name
read_attribute :login
end

#method needed for messaging
def mailboxer_email
return nil
end
...
end

When I send a message I get the following error:

ArgumentError: wrong number of arguments (0 for 1)
from /home/carolyn/.rvm/gems/ruby-1.9.3-p125@scholarsphere/gems/mailboxer-0.6.5/lib/mailboxer/models/messageable.rb:103:in read' from /home/carolyn/.rvm/gems/ruby-1.9.3-p125@scholarsphere/gems/activemodel-3.2.3/lib/active_model/dirty.rb:146:inattribute_change'
from /home/carolyn/.rvm/gems/ruby-1.9.3-p125@scholarsphere/gems/activemodel-3.2.3/lib/active_model/dirty.rb:117:in block in changes' from /home/carolyn/.rvm/gems/ruby-1.9.3-p125@scholarsphere/gems/activemodel-3.2.3/lib/active_model/dirty.rb:117:inmap'
from /home/carolyn/.rvm/gems/ruby-1.9.3-p125@scholarsphere/gems/activemodel-3.2.3/lib/active_model/dirty.rb:117:in changes' from /home/carolyn/.rvm/gems/ruby-1.9.3-p125@scholarsphere/gems/activerecord-3.2.3/lib/active_record/attribute_methods/dirty.rb:34:inblock in save!'
from /home/carolyn/.rvm/gems/ruby-1.9.3-p125@scholarsphere/gems/activerecord-3.2.3/lib/active_record/attribute_methods/dirty.rb:33:in tap' from /home/carolyn/.rvm/gems/ruby-1.9.3-p125@scholarsphere/gems/activerecord-3.2.3/lib/active_record/attribute_methods/dirty.rb:33:insave!'
from /home/carolyn/.rvm/gems/ruby-1.9.3-p125@scholarsphere/gems/activerecord-3.2.3/lib/active_record/transactions.rb:246:in block in save!' from /home/carolyn/.rvm/gems/ruby-1.9.3-p125@scholarsphere/gems/activerecord-3.2.3/lib/active_record/transactions.rb:295:inblock in with_transaction_returning_status'
from /home/carolyn/.rvm/gems/ruby-1.9.3-p125@scholarsphere/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in transaction' from /home/carolyn/.rvm/gems/ruby-1.9.3-p125@scholarsphere/gems/activerecord-3.2.3/lib/active_record/transactions.rb:208:intransaction'
from /home/carolyn/.rvm/gems/ruby-1.9.3-p125@scholarsphere/gems/activerecord-3.2.3/lib/active_record/transactions.rb:293:in with_transaction_returning_status' from /home/carolyn/.rvm/gems/ruby-1.9.3-p125@scholarsphere/gems/activerecord-3.2.3/lib/active_record/transactions.rb:246:insave!'
from /home/carolyn/.rvm/gems/ruby-1.9.3-p125@scholarsphere/gems/mailboxer-0.6.5/app/models/message.rb:54:in block in deliver' from /home/carolyn/.rvm/gems/ruby-1.9.3-p125@scholarsphere/gems/mailboxer-0.6.5/app/models/message.rb:52:ineach'
from /home/carolyn/.rvm/gems/ruby-1.9.3-p125@scholarsphere/gems/mailboxer-0.6.5/app/models/message.rb:52:in deliver' from /home/carolyn/.rvm/gems/ruby-1.9.3-p125@scholarsphere/gems/mailboxer-0.6.5/lib/mailboxer/models/messageable.rb:59:insend_message'
from (irb):5
from /home/carolyn/.rvm/gems/ruby-1.9.3-p125@scholarsphere/gems/railties-3.2.3/lib/rails/commands/console.rb:47:in start' from /home/carolyn/.rvm/gems/ruby-1.9.3-p125@scholarsphere/gems/railties-3.2.3/lib/rails/commands/console.rb:8:instart'
from /home/carolyn/.rvm/gems/ruby-1.9.3-p125@scholarsphere/gems/railties-3.2.3/lib/rails/commands.rb:41:in <top (required)>' from script/rails:6:inrequire'

I tracked the error down to the fact the read method in mailboxer-0.6.5/lib/mailboxer/models/messageable.rb was getting called with no arguments by the send method in dirty.

I modified line 103
from
def read(obj)
to
def read(obj=nil)

This allowed the above code to complete successfully. I have no idea what the repercussions are, I was just looking to get the code running.

It seems like the read attribute of the Recipt and the read method of Messageble are getting confused by Active Record and that the wrong one is getting called during the active record save.

I am including some debug output below so you can see what values are being sent. I added some debug here and there to determine where the error was occuring and those are also in this stream.

1.9.3p125 :005 > recipt = u1.send_message(u1, "log", "Audit Run")
!!!!!!!!!!!!!!!!!!!! before conversation
!!!!!!!!!!!!!!!!!!!! after conversation #<Conversation id: nil, subject: "Audit Run", created_at: nil, updated_at: nil>
!!!!!!!!!!!!!!!!!!!! after message #<Message id: nil, type: "Message", body: "log", subject: "Audit Run", sender_id: 6, sender_type: "User", conversation_id: nil, draft: false, updated_at: nil, created_at: nil, notified_object_id: nil, notified_object_type: nil, notification_code: nil, attachment: nil>
Before send #<Message id: nil, type: "Message", body: "log", subject: "Audit Run", sender_id: 6, sender_type: "User", conversation_id: nil, draft: false, updated_at: nil, created_at: nil, notified_object_id: nil, notified_object_type: nil, notification_code: nil, attachment: nil>

 message recipt = #<Receipt id: nil, receiver_id: 6, receiver_type: "User", notification_id: nil, read: false, trashed: false, deleted: false, mailbox_type: "inbox", created_at: nil, updated_at: nil>
 sender recipt = #<Receipt id: nil, receiver_id: 6, receiver_type: "User", notification_id: nil, read: true, trashed: false, deleted: false, mailbox_type: "sentbox", created_at: nil, updated_at: nil>
~~~~~~~~~~~~~~~~~~~~ dilver 2
~~~~~~~~~~~~~~~~~~~~ dilver3 
~~~~~~~~~~~~~~~~~~~~ dilver4 
#<Receipt id: nil, receiver_id: 6, receiver_type: "User", notification_id: nil, read: false, trashed: false, deleted: false, mailbox_type: "inbox", created_at: nil, updated_at: nil>
  SQL (0.2ms)  BEGIN
  SQL (10.5ms)  INSERT INTO `conversations` (`created_at`, `subject`, `updated_at`) VALUES (?, ?, ?)  [["created_at", Fri, 18 May 2012 11:30:25 UTC +00:00], ["subject", "Audit Run"], ["updated_at", Fri, 18 May 2012 11:30:25 UTC +00:00]]
^^^^^^^ attr= "subject"
^^^^^^^ attr= "created_at"
^^^^^^^ attr= "updated_at"
^^^^^^^ attr= "id"
  SQL (1.0ms)  INSERT INTO `notifications` (`attachment`, `body`, `conversation_id`, `created_at`, `draft`, `notification_code`, `notified_object_id`, `notified_object_type`, `sender_id`, `sender_type`, `subject`, `type`, `updated_at`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)  [["attachment", nil], ["body", "log"], ["conversation_id", 28], ["created_at", Fri, 18 May 2012 11:30:25 UTC +00:00], ["draft", false], ["notification_code", nil], ["notified_object_id", nil], ["notified_object_type", nil], ["sender_id", 6], ["sender_type", "User"], ["subject", "Audit Run"], ["type", "Message"], ["updated_at", Fri, 18 May 2012 11:30:25 UTC +00:00]]
^^^^^^^ attr= "type"
^^^^^^^ attr= "sender_id"
^^^^^^^ attr= "sender_type"
^^^^^^^ attr= "body"
^^^^^^^ attr= "subject"
^^^^^^^ attr= "attachment"
^^^^^^^ attr= "conversation_id"
^^^^^^^ attr= "created_at"
^^^^^^^ attr= "updated_at"
^^^^^^^ attr= "id"
  SQL (1.6ms)  INSERT INTO `receipts` (`created_at`, `deleted`, `mailbox_type`, `notification_id`, `read`, `receiver_id`, `receiver_type`, `trashed`, `updated_at`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)  [["created_at", Fri, 18 May 2012 11:30:25 UTC +00:00], ["deleted", false], ["mailbox_type", "inbox"], ["notification_id", 28], ["read", false], ["receiver_id", 6], ["receiver_type", "User"], ["trashed", false], ["updated_at", Fri, 18 May 2012 11:30:25 UTC +00:00]]
^^^^^^^ attr= "receiver_id"
^^^^^^^ attr= "receiver_type"
^^^^^^^ attr= "mailbox_type"
^^^^^^^ attr= "notification_id"
^^^^^^^ attr= "created_at"
^^^^^^^ attr= "updated_at"
^^^^^^^ attr= "id"
   (4.3ms)  COMMIT
#<Receipt id: nil, receiver_id: 6, receiver_type: "User", notification_id: nil, read: true, trashed: false, deleted: false, mailbox_type: "sentbox", created_at: nil, updated_at: nil>
  SQL (1.8ms)  BEGIN
  SQL (1.1ms)  INSERT INTO `receipts` (`created_at`, `deleted`, `mailbox_type`, `notification_id`, `read`, `receiver_id`, `receiver_type`, `trashed`, `updated_at`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)  [["created_at", Fri, 18 May 2012 11:30:25 UTC +00:00], ["deleted", false], ["mailbox_type", "sentbox"], ["notification_id", 28], ["read", true], ["receiver_id", 6], ["receiver_type", "User"], ["trashed", false], ["updated_at", Fri, 18 May 2012 11:30:25 UTC +00:00]]
^^^^^^^ attr= "read"
   (1.6ms)  ROLLBACK

Emails subjects should be customizables

Right now Mailboxer adds "You have a new message:" and "You have a new notification:" that may not be wanted.

If done with I18n it will be customizable for each application.

Multiple queries to get participants

Hi,

This gem appears to do most of the things I would expect for messaging which is great, however, a common feature of message inboxes is to get the participants along with subject and date.

I have the following code:

  def inbox
    response = []
    current_user.mailbox.inbox.each do |i|
      response << MessagePresenter.new(i, current_user)
    end
    #...snip...
  end

And my presenter looks like this:

  def as_json(*)
    participants = @message.participants
   # ...snip...
  end

The issue here is the number of queries this does: (output from a call that retrieves 4 messages)

User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
Conversation Load (0.2ms) SELECT DISTINCT conversations.* FROM "conversations" INNER JOIN "notifications" ON "notifications"."conversation_id" = "conversations"."id" AND "notifications"."type" IN ('Message') INNER JOIN "receipts" ON "receipts"."notification_id" = "notifications"."id" WHERE "notifications"."type" = 'Message' AND "receipts"."receiver_id" = 1 AND "receipts"."receiver_type" = 'User' AND "receipts"."mailbox_type" = 'inbox' AND "receipts"."trashed" = 'f' ORDER BY conversations.updated_at DESC
Message Load (0.2ms) SELECT "notifications".* FROM "notifications" WHERE "notifications"."type" IN ('Message') AND "notifications"."conversation_id" = 5 ORDER BY created_at DESC LIMIT 1
Receipt Load (0.1ms) SELECT "receipts".* FROM "receipts" WHERE "receipts"."notification_id" = 6
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = 2 LIMIT 1
Message Load (0.1ms) SELECT "notifications".* FROM "notifications" WHERE "notifications"."type" IN ('Message') AND "notifications"."conversation_id" = 4 ORDER BY created_at DESC LIMIT 1
Receipt Load (0.1ms) SELECT "receipts".* FROM "receipts" WHERE "receipts"."notification_id" = 5
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = 2 LIMIT 1
Message Load (0.1ms) SELECT "notifications".* FROM "notifications" WHERE "notifications"."type" IN ('Message') AND "notifications"."conversation_id" = 3 ORDER BY created_at DESC LIMIT 1
Receipt Load (0.1ms) SELECT "receipts".* FROM "receipts" WHERE "receipts"."notification_id" = 4
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = 2 LIMIT 1
Message Load (0.1ms) SELECT "notifications".* FROM "notifications" WHERE "notifications"."type" IN ('Message') AND "notifications"."conversation_id" = 2 ORDER BY created_at DESC LIMIT 1
Receipt Load (0.1ms) SELECT "receipts".* FROM "receipts" WHERE "receipts"."notification_id" = 3
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = 2 LIMIT 1

Since this is such a common thing, shouldn't the sender be included with the request? If not, how can I reduce this to fewer queries?

Regards,
Gazler.

How to count unread messages

I fetch all the messages in inbox by coding this @messages = current_user.mailbox.inbox
How can I get the number of unread message out of this??

Mass-assignment issue

When using the latest Rails in a brand new app one needs to set

config.active_record.whitelist_attributes = false

to avoid getting the exception about mass-assignment. I suggest to specify the necessary attr_accessible in the models (Conversation etc.) to fix this.

Search engines

From a comment in other issue:

Jeff added a search engine to the Message model. As I am using another search engine (sphinx) I will be changing the way it behaves. I will make it configurable and, of course, delete the strong dependency on sunspot_rails. Is it causing major problems or may I leave it this way until I have quality time for it? (Right now we are working heavily on social_stream.)

Mailboxer should be able to work with sunspot, sphinx or none of them depending on which gems are present.

mark_as_read and read(obj)

I just installed mailboxer yesterday so perhaps I'm missing something, but no matter what I do, I can't successfully mark a conversation as read. What I've tried:

read(conversation)

=>undefined method `read' for #<ConversationsController:0x7a244f0>

conversation.mark_as_read(self)

=>undefined method `id' for #<ConversationsController:0x47cee60>

conversation.mark_as_read(conversation)

=>success . . . kind of. . . .

This last method doesn't throw any errors, but it'll only mark the final receipts in a conversation as read. The first receipt (original message) remains false. Even if I manually set the first receipt as read like so:

receipt.read=true

It will reset itself to false the next time I load the page. My code contains no other references to "read" or "unread," so I'm not sure why this is happening.

rough howto

So I installed this gem and I know you are busy with other stuff, but maybe you can give me a 5 step simple howto, I seem to need to have a message model or something setup besides running the setup. I can deliver email or not?
A little bit more documentation is needed, I would then surely provide my project as a sample.
It just needs for me user, messages but even that simple documentation I cannot find.

generator for email views

This is nicety, but something that would be imminently helpful. I ended up opening the gem source and copying the files into my app. Devise offers similar functionality.

I'd be happy to add this functionality and do a pull request, if you'd like.

Lack of documentation

The gem promise very cool feature, and seriously seems working pretty well, the only problem is the very poor documentation, and the lack of simple examples that allow to use the gem without becoming crazy in understanding everything.

I try to be more clear, obviously, looking as an example the social_stream gem, the way in which the mailboxer gem is used can be very time consuming, especially because, before understanding the implementation, you need to look up all the connections in that huge gem. Moreover the fact that the implementation consider actors, and different objects just put so much stuff in the middle that you practically need to dedicate a very good slack of your time to understand what is going on, instead of just taking the gem, and kick the hell out of it in your own project. The problem with the full package of social_stream, is that is full of functionality that maybe an user just doesn't need, and just need a simple mailboxer.

You did and are doing an amazing job, but sincerely, the lack of documentation and some simple application example, just create so much trouble that probably will delete the adoption of such awesome gem.

Especially for what concern the GUI and the potentially views. I believe that also a very basic example, without using js,or complex scss module, can do the job. The example made by frodefi is very good, but also that is heavy in additional js and tools, and let lose the specific focus on the pure functionality of the mailboxer gem.

The idea of using gems in a rails project, is based on the simple concept that you need to focus on your project, and not reinvent the wheel, if some other one did...Take for example the gem devise, not only is an amazing and awesome gem, but their documentation is very exhaustive and complete, you take that gem, install it, and just use it (obvy you will have some problems in adapting perfectly it to your application architecture, but are local and simple problems, instead with your amazing work you just need to dig so deep, just to let it move on).

Do you think that I am so wrong? Do you have some basic example or some more detailed documentation on how to use your gem?

Get all notifications to a messageable

I have look up the documentation at http://rubydoc.info/gems/mailboxer/frames but I can't find a method to get all notification sent to a messageable.
I find one way to do it is finding all receipts with mailbox_type = nil. Is there a better way to do this ?

Moreover, could you please provide me an ERD about the relationships between models in mailboxer ? This would provide an overview of mailboxer functionality.

Notification to more than one recipient?

Is it possible to send a notification to more than just one recipient?

E.g.

user.friends.notify("New Image","A friend just uploaded an image")

Or do I really have to loop over all friends?

And is there a way to get all notifications an Conversations in one recordset?

E.g.

user.mailbox.conversations_and_notifications

"attachment_will_change!" with social_stream

I am using social_stream (Just base and linker)

gem 'social_stream-base','0.18.0' #, :path => "vendor/gems/social_stream/base"
gem 'social_stream-linkser','0.8.0' #, :path => "vendor/gems/social_stream/linkser"

I can't send a message, i think the problem come from carrierwave, but i can't find how.

ruby-1.9.2-p180 :065 > User.first.actor.send_message(User.last.actor,"Test","Test")
  User Load (0.3ms)  SELECT `users`.* FROM `users` LIMIT 1
  Actor Load (0.2ms)  SELECT `actors`.* FROM `actors` WHERE `actors`.`id` = 1 LIMIT 1
  User Load (0.2ms)  SELECT `users`.* FROM `users` ORDER BY `users`.`id` DESC LIMIT 1
  Actor Load (0.2ms)  SELECT `actors`.* FROM `actors` WHERE `actors`.`id` = 67 LIMIT 1
NoMethodError: undefined method `attachment_will_change!' for #<Message:0x00000006fab760>
    from /home/pierre/.rvm/gems/ruby-1.9.2-p180/gems/activemodel-3.2.1/lib/active_model/attribute_methods.rb:407:in `method_missing'
    from /home/pierre/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.2.1/lib/active_record/attribute_methods.rb:126:in `method_missing'
    from /home/pierre/.rvm/gems/ruby-1.9.2-p180@global/gems/carrierwave-0.5.8/lib/carrierwave/orm/activerecord.rb:36:in `attachment='

Do you know how to resolve this issue ?

Broken specs

The Factory Girl 3.x series supports Ruby 1.9.x.

For older versions of Ruby, please use the Factory Girl 2.x series.

Link to frode's gui?

Frode and I worked on a gui for mailboxer that runs as a rails or refinerycms engine. It seems that people are using it with some success. It's certainly not something I think that should be in the main mailboxer gem, but it is useful.

@Roendal, @frodefi Do you guys have any ideas? Maybe just as simple as linking to the project in the README

Message validation

Hi,
currently when you use send_message there's no way to get the list of errors if it fails. I would like to tell user that he forgot to specify the recipient, for example. Maybe, it's better to split this function to allow the following:

@message = user.compose_message(params)
if @message.deliver
  redirect_to :sentbox
else
  render :new
end

Giving credit to the contributors

A section should be added to the readme to give credit to anyone who has helped directly or indirectly in the development of mailboxer.

New Feature: Data Attatchments

Hey all!

I'm currently in a position where I need to extend mailboxer to handle what I'm currently calling "data attachments" to messages. Data attatchments are basically just serializable objects or models that are associated with a given Message. Here's an example:

m = Message.new(subject: "Hi!", body: "Be my friend!", data: { profile_id: 123, preview_image: "/some/path/to/file.png" })
m.recipients = params[:to]
m.deliver(false,true) # Sends message to recipient's inbox

And now that we have our new message:

m = Message.last
m.data # => { profile_id: 123, preview_image: "/some/path/to/file.png" }

I'm currently just letting Rails handle the serialization of arbitrary hashes and using this data to do things like render user profiles inline with message notification emails.

Would anybody be interested in me submitting this as a patch/pull request to mailboxer? Is this a feature that would be useful or desirable to you?

Specifying date of a message

Hi,

I'm using mailboxer, and so far it looks very nice :)

However, one thing I noticed is that it's not possible to specify the date of a message. Does the API not have that feature or did I miss it ? The reason we stumbled on this is we're working on migrating a an app that has a built in messaging system, and we're migrating legacy messages.

For now we're just changing the created_at and updated_at timestamps for messages, notifications and receipts, but it doesn't feel like a way to do it.

thanks,
Ricardo

undefined method `conversation=' for #<Message:0x103393768>

Hi,

Not sure if this is a mailboxer's issue, but have encountered it after following wiki's steps
and calling the send_message method.

I have not instanciated any conversation or defined any conversation model, and I am
working with latest version of the mailboxer's code.

It is running under Rails 3.0.7

Below the stack trace:

app/models/message.rb:14:in send' app/models/message.rb:14:ininitialize'
app/models/message.rb:13:in each' app/models/message.rb:13:ininitialize'
mailboxer (0.6.5) lib/mailboxer/models/messageable.rb:52:in new' mailboxer (0.6.5) lib/mailboxer/models/messageable.rb:52:insend_message'
app/controllers/users_controller.rb:61:in send_message' actionpack (3.0.7) lib/action_controller/metal/implicit_render.rb:5:insend_action'
actionpack (3.0.7) lib/action_controller/metal/implicit_render.rb:5:in `send_action'

Please let me know if some more information can be useful to you.

Labeling

Would be nice to isolate the table names to mailboxes (ie: mailboxer_receipts, mailboxer_conversations...) so that it is "separate" from my schema and readable to new developers working on my project knowing this belongs to this specific project.

pagination

Do you have any guidance on paginating conversations? Is there any reason kaminari or will_paginate won't work?

Ability to reply to the message via email

I've seen this feature here on Github. If I get direct message or a new message in the issue discussion, I can just reply to email (which is sent from a special address, like [email protected]) instead of going to my inbox and manually replying.

Seems to me that some simple integration with MailMan would take care of this. Any plans to include something like this in the gem in the future?

Deliver status

Delivering methods should inform corretly about the deliver status.

Rescue only NameError

name, email, etc. methods in messageable should only rescue NameError exceptions, so they do not mask other type of error (database related, for example)

Database Pagination

I've already read #17, but after reading it I got the impression that you're talking about array pagination, after obtaining all of the messages from the database.

I have a migration scenario where some users have hundreds of thousands of messages, and so that approach doesn't work. We tried doing it with standard Rails scopes, but the way the queries and indexes are structured results in about 1 minute per query (even with limit scope), which can't be used to paginate (at least on Postgres).

Do you know if such a scenario has ever been tested ?

Sending messages without a subject

Hey guys!

First off, thanks for mailboxer. Great piece of work!

That being said, is there any particular reason why a subject is required to send a message? I have a requirement to send messages without requiring a subject and ended up overriding the default send_message method like so:

# Override's Mailboxer's #send_message such that subjects are not required.
# @see https://github.com/ging/mailboxer/blob/56987403939d6077ddb72bc708df90ab6e672ab6/lib/mailboxer/models/messageable.rb#L48-57
# @param [Hash] opts An options hash used to configure and send a message
# @option [User, Array<User>] :to Users to send a message to
# @option [String] :subject An optional subject for this message (nil)
# @option [File] :attatchment An optional attatchment to include with this message (nil)
# @options [Boolean] :sanitize Weather or not to sanetize input (true)
def send_message(opts = {})
  recipients = opts.delete(:to)
  subject    = opts.delete(:subject) || ""
  body       = opts.delete(:body)
  attachment = opts.delete(:attatchment)
  sanitize   = opts.delete(:sanitize) || true

  convo = Conversation.new(subject: subject)

  message = messages.new(body: body, subject: subject, attachment: attachment)
  message.conversation = convo
  message.recipients = recipients.is_a?(Array) ? recipients : [recipients]
  message.recipients = message.recipients.uniq

  message.deliver(false, sanitize)
end

Here's what I'm wondering:

  1. Will this cause any issues with Mailboxer's data model?
  2. Are there any implications to making a subject optional that I should consider or be aware of?
  3. If everything here checks out, would you guys be open to me submitting this as a patch to send_message?

Sanitize options

Right now Message and Notification bodies get sanitizes when delivering. No possible configuration about that.

uninitialized constant Mailboxer (NameError)

I use mailboxer in my project, and it works well in my development environment. But it raised an error when I deployed to production. The error message is uninitialized constant Mailboxer (NameError). So weird.

My mailboxer.rb in initializers folder is

Mailboxer.setup do |config|

  #Configures if you applications uses or no the email sending for Notifications and Messages
  config.uses_emails = true

  #Configures the default from for the email sent for Messages and Notifications of Mailboxer
  config.default_from = "[email protected]"

  #Configures the methods needed by mailboxer
  config.email_method = :mailboxer_email
  config.name_method = :name

  #Configures if you use or not a search engine and wich one are you using
  #Supported enignes: [:solr,:sphinx] 
  config.search_enabled = false
  config.search_engine = :solr
end

I use capistrano. Thanks

No solution to fetch the records constrained with search keyword

@messages = current_user.search_messages(@search) This fetches all the messages that relates to current user. But what if you'd like to narrow down to only the messages in inbox? sentbox messages? or trashed messages? I spent so much time to find the way to do this but nowhere. Is there anyway?

user_messages_path

Hi,

When I tried to go to some view I found the next error:

undefined method `user_messages_path' for #<#Class:0xa0b58d8:0xa0943a4>

Where should I define that method?

Thanks a lot
Alberto

Rails 3.0 support

Hi,

I just noticed that mailboxer depends on rails 3.1. Is the gemspec wrong or does it really depend on rails 3.1 ? Can it be changed to support rails 3.0 ?

thanks,
Ricardo

How can I judge if a message is trashed when I'm logged in.

At show page I'm showing these info

subject:
<%= @messages.subject %>
body:
<%= @messages.body %>

If @messages is already trashed, I'd like to show

This message is trashed

if not, I'd like to show
This message is un-trashed

So I tried this, but it didn't work.

<% if @messages.is_trashed %>

This message is trashed
<% else %>
This message is un-trashed
<% end %>

undefined local variable or method `acts_as_messageable'

I followed the docs, but am getting an error stating "undefined local variable or method `acts_as_messageable'" when I try to run my app or bring up the Rails console.

If it matters, my User model is a "standard" Devise user, and here's the relevant code.

class User < ActiveRecord::Base
  acts_as_messageable

  has_one :project_professional
  has_many :projects
  has_many :bids
  has_many :ratings, through: :reviews

  after_create :mark_approved

  ROLES = %w[admin client project_professional moderator]
  # Include default devise modules. Others available are:
  # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable, :omniauthable,
         :recoverable, :rememberable, :trackable, :validatable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :name, :email, :password, :password_confirmation, :remember_me, :roles, :user_type
...
end

Using the default Mailboxer initializer:

Mailboxer.setup do |config|

  #Configures if you applications uses or no the email sending for Notifications and Messages
  config.uses_emails = true

  #Configures the default from for the email sent for Messages and Notifications of Mailboxer
  config.default_from = "[email protected]"

  #Configures the methods needed by mailboxer
  config.email_method = :mailboxer_email
  config.name_method = :name

  #Configures if you use or not a search engine and wich one are you using
  #Supported enignes: [:solr,:sphinx] 
  config.search_enabled = false
  config.search_engine = :solr
end

And the relevant bits of my Gemfile

gem 'rails', '3.2.2'
gem 'haml'
gem 'devise', '~> 2.0.0'
gem "omniauth-facebook"
gem 'rails_admin', :git => 'git://github.com/sferik/rails_admin.git'
gem 'cancan'
gem 'paperclip', '~> 2.5.1'
gem 'acts-as-taggable-on'
gem 'forem', :git => "git://github.com/radar/forem.git"
gem 'redcarpet'
gem 'best_in_place'
gem 'simple_form'
gem 'gmaps4rails'
gem "kaminari"
gem "will_paginate"

gem 'mailboxer', git: 'git://github.com/ging/mailboxer.git'

Is my issue Rails 3.2.2? Any tips on how to resolve this would be greatly appreciated. Looks like a great gem.

sunspot dependency?

Perhaps I was on an earlier version, but this dependency on sunspot_rails seems new. Is it necessary? It seems like a bad idea to take such a strong opinion about the search tool someone should use. Or should it just be a development dependency, for the dummy app?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.