Introducing Photon - the Dead Simple Rails messenger service

Photon assumes very basic things about your schema. Right now, there is no config (it’s coming, and the framework is there for it), and no migrations.

It assumes you have the following 4 tables:

Users

Messages, containing: body subject delivery_id sender_id timestamps

MessageThreads, containing: id, timestamps

Deliveries, containing: user_id message_id read message_thread_id timestamps

To setup the proper associations, there are the following model methods:

User: acts_as_sender Delivery: acts_as_deliverable Message: acts_as_message MessageThread: acts_as_threadable

This provides the following methods at this time:

user#send_message(:to => User<object>, :subject => string, :body => string)

Sends a message to a user. It starts a thread.

user#reply_to(Message<object>, :subject => string, :body => string)

Replies to one of the user’s received messages

user#sent_messages

Array of sent messages

user#unread_messages

Array of unread messages

user#read_messages

Array of read messages

user#read(Message<Object>)

Marks the specified message object as read

user#unread(Message<Object>)

Marks the specified message object as unread

Message#find_thread(User<Object>, Message<Object>)

Finds the thread that the message and user belong to.

EXAMPLE USAGE:

user1 = User.create user2 = User.create

user1.send_message(:to => user2, :subject => “Hello!”, :body => “Hello world!”) user1.sent_messages # => [#<Message id: 30, subject: “Hello!”, body: “Hello world!”, sender_id: 1>] unread_messages = user2.unread_messages # => [#<Message id: 30, subject: “Hello!”, body: “Hello world!”, sender_id: 1>] user2.read(unread_messages) user2.read_messages # => [#<Message id: 30, subject: “Hello!”, body: “Hello world!”, sender_id: 1>] user2.reply_to(unread_messages, :subject => “Goodbye!”, :body => “Hello again!”) user1.unread_messages # => [#<Message id: 31, subject: “Goodbye!”, body: “Hello again!”, sender_id: 2>] Message.find_thread(user1, user1.unread_messages) # => [#<Message id: 30, subject: “Hello!”, body: “Hello world!”, sender_id: 1>, #<Message id: 31, subject: “Goodbye!”, body: “Hello again!”, sender_id: 2>]

TODO:

Add configuration files Implement attachment support Make methods chainable - sending and replying should return the delivery object. Support external ActiveRecord databases - involving creating a lookup table on an external database based on current user ids.

An extremely robust Riak version is coming soon.