Start reworking things

This commit is contained in:
June Rhodes 2016-11-27 13:36:10 +11:00
parent fe68151be6
commit abac9c9778
13 changed files with 102 additions and 57 deletions

View File

@ -20,7 +20,7 @@ const NavigationBar = React.createClass({
<div style={{ flex: '1 1 auto', marginLeft: '8px', color: '#9baec8' }}>
<strong style={{ fontWeight: '500', display: 'block', color: '#fff' }}>{this.props.account.get('acct')}</strong>
<a href='/settings/profile' style={{ color: 'inherit', textDecoration: 'none' }}><FormattedMessage id='navigation_bar.settings' defaultMessage='Settings' /></a> · <Link to='/timelines/public' style={{ color: 'inherit', textDecoration: 'none' }}><FormattedMessage id='navigation_bar.public_timeline' defaultMessage='Public timeline' /></Link> · <a href='/auth/sign_out' data-method='delete' style={{ color: 'inherit', textDecoration: 'none' }}><FormattedMessage id='navigation_bar.logout' defaultMessage='Logout' /></a>
<a href='/settings/profile' style={{ color: 'inherit', textDecoration: 'none' }}><FormattedMessage id='navigation_bar.settings' defaultMessage='Settings' /></a> · <Link to='/timelines/public' style={{ color: 'inherit', textDecoration: 'none' }}><FormattedMessage id='navigation_bar.public_timeline' defaultMessage='Public' /></Link> · <Link to='/messages' style={{ color: 'inherit', textDecoration: 'none' }}><FormattedMessage id='navigation_bar.messages' defaultMessage='Messages' /></Link> · <a href='/auth/sign_out' data-method='delete' style={{ color: 'inherit', textDecoration: 'none' }}><FormattedMessage id='navigation_bar.logout' defaultMessage='Logout' /></a>
</div>
</div>
);

View File

@ -0,0 +1,30 @@
# frozen_string_literal: true
class Api::V1::MessagesController < ApiController
before_action -> { doorkeeper_authorize! :read }
before_action -> { doorkeeper_authorize! :write }
before_action :require_user!
respond_to :json
def index
@messages = Message.where(account: current_account).paginate_by_max_id(20, params[:max_id], params[:since_id])
@messages = cache(@messages)
messages = @messages #.select { |n| !n.target_status.nil? }.map(&:target_status)
#set_maps(statuses)
#set_counters_maps(statuses)
#set_account_counters_maps(@notifications.map(&:from_account))
next_path = api_v1_messages_url(max_id: @messages.last.id) if @messages.size == 20
prev_path = api_v1_messages_url(since_id: @messages.first.id) unless @messages.empty?
set_pagination_headers(next_path, prev_path)
end
def create
end
def destroy
end
end

View File

@ -32,6 +32,7 @@ class Account < ApplicationRecord
has_many :favourites, inverse_of: :account, dependent: :destroy
has_many :mentions, inverse_of: :account, dependent: :destroy
has_many :notifications, inverse_of: :account, dependent: :destroy
has_many :messages, inverse_of: :account, dependent: :destroy
# Follow relations
has_many :active_relationships, class_name: 'Follow', foreign_key: 'account_id', dependent: :destroy

16
app/models/message.rb Normal file
View File

@ -0,0 +1,16 @@
# frozen_string_literal: true
class Message < ApplicationRecord
include Paginable
include Streamable
belongs_to :account, inverse_of: :messages
belongs_to :private_recipient, foreign_key: 'private_recipient_id', class_name: 'Account', optional: true
has_one :notification, as: :activity, dependent: :destroy
validates :account, presence: true
validates :private_recipient, presence: true
validates :text, presence: true, length: { maximum: 500 }, if: proc { |s| s.local? && !s.reblog? }
validates :text, presence: true, if: proc { |s| !s.local? && !s.reblog? }
end

View File

@ -16,8 +16,6 @@ class Status < ApplicationRecord
has_many :media_attachments, dependent: :destroy
has_and_belongs_to_many :tags
belongs_to :private_recipient, foreign_key: 'private_recipient_id', class_name: 'Account', optional: true
has_one :notification, as: :activity, dependent: :destroy
validates :account, presence: true
@ -63,10 +61,6 @@ class Status < ApplicationRecord
content
end
def is_private
!private_recipient_id.nil?
end
def reblogs_count
attributes['reblogs_count'] || reblogs.count
end

View File

@ -0,0 +1,2 @@
collection @messages
extends('api/v1/messages/show')

View File

@ -0,0 +1,13 @@
object @message
attributes :id, :created_at
node(:content) { |message| Formatter.instance.format(message) }
child :account do
extends 'api/v1/accounts/show'
end
child :private_recipient do
extends 'api/v1/accounts/show'
end

View File

@ -6,42 +6,6 @@ node(:url) { |status| TagManager.instance.url_for(status) }
node(:reblogs_count) { |status| defined?(@reblogs_counts_map) ? (@reblogs_counts_map[status.id] || 0) : status.reblogs_count }
node(:favourites_count) { |status| defined?(@favourites_counts_map) ? (@favourites_counts_map[status.id] || 0) : status.favourites_count }
node(:current_user_id) { |status|
current_user.id
}
node(:account_id) { |status|
status.account_id
}
node(:private_recipient_id) { |status|
status.private_recipient_id
}
node(:private_content) { |status|
if status.is_private then
if current_user.id == status.account_id || current_user.id == status.private_recipient_id then
Formatter.instance.format(status, true)
else
nil
end
else
nil
end
}
node(:private_recipient) { |status|
if status.is_private then
if current_user.id == status.account_id || current_user.id == status.private_recipient_id then
partial('api/v1/accounts/show', object: status.private_recipient)
else
nil
end
else
nil
end
}
child :account do
extends 'api/v1/accounts/show'
end

View File

@ -6,7 +6,11 @@ default: &default
development:
<<: *default
database: mastodon_development
database: <%= ENV['DB_DEV_NAME'] || 'mastodon_development' %>
username: <%= ENV['DB_USER'] || 'mastodon' %>
password: <%= ENV['DB_PASS'] || '' %>
host: <%= ENV['DB_HOST'] || 'localhost' %>
port: <%= ENV['DB_PORT'] || 5432 %>
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".

View File

@ -76,6 +76,8 @@ Rails.application.routes.draw do
resources :notifications, only: [:index]
resources :messages, only: [:index, :create, :destroy]
resources :accounts, only: [:show] do
collection do
get :relationships

View File

@ -0,0 +1,11 @@
class CreateMessages < ActiveRecord::Migration
def change
create_table :messages do |t|
t.integer :account_id, null: false
t.integer :private_recipient_id, null: false
t.text :text, null: false, default: ''
t.timestamps null: false
end
end
end

View File

@ -10,10 +10,11 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20161123093447) do
ActiveRecord::Schema.define(version: 20161127131100) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
enable_extension "adminpack"
create_table "accounts", force: :cascade do |t|
t.string "username", default: "", null: false
@ -96,6 +97,14 @@ ActiveRecord::Schema.define(version: 20161123093447) do
t.index ["account_id", "status_id"], name: "index_mentions_on_account_id_and_status_id", unique: true, using: :btree
end
create_table "messages", force: :cascade do |t|
t.integer "account_id", null: false
t.integer "private_recipient_id", null: false
t.text "text", default: "", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "notifications", force: :cascade do |t|
t.integer "account_id"
t.integer "activity_id"
@ -155,14 +164,16 @@ ActiveRecord::Schema.define(version: 20161123093447) do
create_table "statuses", force: :cascade do |t|
t.string "uri"
t.integer "account_id", null: false
t.text "text", default: "", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "account_id", null: false
t.text "text", default: "", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "in_reply_to_id"
t.integer "reblog_of_id"
t.string "url"
t.boolean "sensitive", default: false
t.integer "private_recipient_id"
t.text "private_text", default: "", null: false
t.boolean "sensitive", default: false
t.index ["account_id"], name: "index_statuses_on_account_id", using: :btree
t.index ["in_reply_to_id"], name: "index_statuses_on_in_reply_to_id", using: :btree
t.index ["reblog_of_id"], name: "index_statuses_on_reblog_of_id", using: :btree

View File

@ -7,11 +7,9 @@ export REDIS_HOST=localhost
export REDIS_PORT=6379
export DB_HOST=localhost
export DB_USER=postgres
export DB_NAME=postgres
export DB_DEV_NAME=postgres
export DB_PASS=postgres
export DB_PORT=5432
export NEO4J_HOST=localhost
export NEO4J_PORT=7474
# Federation
export LOCAL_DOMAIN=localhost
@ -34,9 +32,8 @@ export SMTP_LOGIN=
export SMTP_PASSWORD=
export SMTP_FROM_ADDRESS=notifications@example.com
# Set us in production mode so that the configuration uses
# the DB_HOST variables.
export RAILS_ENV=production
# Set the rails environment to development.
export RAILS_ENV=development
# Install dependencies
#bundle install
@ -45,7 +42,7 @@ export RAILS_ENV=production
rails db:migrate
# Compile assets
rails assets:precompile
#rails assets:precompile
# Run web server
rails server