GithubHelp home page GithubHelp logo

discuss's Introduction

Discuss

We have a table discuss users that will be used to populate the recipients field. We are not creating new users via recipients since the user need to exist and be logged in in order to view her messages.

If for example we have two users: Batman and Robin and Batman sends a message to Robin. What will be created are two objects:

  1. A Message object where(discuss_user: Batman, sent_at: Time.zone.now)
  2. A second MEssage object where(dicuss_user: Robin, received_at: Time.zone.now)

When Robin logs in, she can view this message in her inbox. The inbox view user Mailbox.new(Robin).inbox

Batman's sent messages view will use a similar query: Mailbox.new(user).outbox

If no recipients are entered, the message will be saved as draft. Messages by default are sent as draft until they are delivered

Setup

add the gem to your Gemfile.

  gem 'discuss'

get the migrations

  rake discuss:install:migrations

Api

  @mailbox = Mailbox.new(user)
  @mailbox.inbox
  @mailbox.outbox
  @mailbox.drafts
  @mailbox.trash

  @mailbox.empty_trash! # => deletes all messages that are already trashed

  @message = User.message.create(body: 'lorem ipsum', recipients: [@user1, @user2]) # => creates a draft
  @message.send! # delivers a message

  @message.trash!   # => moves the message to the trash
  @message.delete!  # => removes message from all views

  @message.reply!(body: 'awesome', subject: 'adjusted subject') # => replies to sender. only :body is really needed

  # With conversation:
  @conversation = Discuss::Conversation.new(@message, user) # => user defaults to message.owner if not passed through
  @conversation.all # => shows all the messages, owned or not by the user
  @conversation.for_user # => shows only the messages the user owns
  @conversation.trash_conversation! # => trashes messages in the conversation that the user owns

Override current user

The gem uses a current_user helper method that is usally provided with most authentication systems. If you wish to use your own class, override our current_discuss_user method to use your own class.

  class ApplicationController < ActionController::Base

    private
    def current_user
      # Your own implementation
    end
  end

Running the tests

  rake db:create && rake db:migrate
  rake db:migrate RAILS_ENV=test
  rake test

TODO

  • Views
  • Markdown styling for message body
  • Display conversations
  • Mailers
  • Config options to disbale or enable mailers
  • Move message delivery and mailers to a background job
  • Generator to copy views to parent project for customisation

This project rocks and uses MIT-LICENSE.

discuss's People

Contributors

gogogarrett avatar delitescere avatar

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.