diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2016-03-21 18:26:47 +0100 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2016-03-21 18:26:47 +0100 |
commit | f14f462eaf8dcf272db54cd513bf7ffe7dc6a6e3 (patch) | |
tree | 2275619996f64b55369e4f35cd228eb52dc48601 /app | |
parent | c28971c70c3d5caf18a5e931ff345534f1e4cece (diff) |
Adding Turbolinks, adding status posting form on homepage
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/application.js | 1 | ||||
-rw-r--r-- | app/assets/javascripts/statuses.coffee | 3 | ||||
-rw-r--r-- | app/assets/stylesheets/dashboard.scss | 9 | ||||
-rw-r--r-- | app/assets/stylesheets/statuses.scss | 3 | ||||
-rw-r--r-- | app/controllers/statuses_controller.rb | 18 | ||||
-rw-r--r-- | app/helpers/statuses_helper.rb | 2 | ||||
-rw-r--r-- | app/models/status.rb | 1 | ||||
-rw-r--r-- | app/services/follow_remote_account_service.rb | 5 | ||||
-rw-r--r-- | app/views/home/index.html.haml | 17 |
9 files changed, 58 insertions, 1 deletions
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 646c5aba4..e07c5a830 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -12,4 +12,5 @@ // //= require jquery //= require jquery_ujs +//= require turbolinks //= require_tree . diff --git a/app/assets/javascripts/statuses.coffee b/app/assets/javascripts/statuses.coffee new file mode 100644 index 000000000..24f83d18b --- /dev/null +++ b/app/assets/javascripts/statuses.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/dashboard.scss b/app/assets/stylesheets/dashboard.scss index afb718c90..d8f26f6c5 100644 --- a/app/assets/stylesheets/dashboard.scss +++ b/app/assets/stylesheets/dashboard.scss @@ -200,6 +200,15 @@ box-shadow: 0 0 15px rgba(0, 0, 0, 0.2); } } + + hr { + clear: both; + border: 0; + padding: 0; + width: 100%; + height: 0; + margin: 30px 0; + } } .dashboard__top-bar { diff --git a/app/assets/stylesheets/statuses.scss b/app/assets/stylesheets/statuses.scss new file mode 100644 index 000000000..bb9365adc --- /dev/null +++ b/app/assets/stylesheets/statuses.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the statuses controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/statuses_controller.rb b/app/controllers/statuses_controller.rb new file mode 100644 index 000000000..a5cb3eae1 --- /dev/null +++ b/app/controllers/statuses_controller.rb @@ -0,0 +1,18 @@ +class StatusesController < ApplicationController + layout 'dashboard' + + before_action :authenticate_user! + + def create + status = PostStatusService.new.(current_user.account, status_params[:text]) + redirect_to root_path + rescue ActiveRecord::RecordInvalid + redirect_to root_path + end + + private + + def status_params + params.require(:status).permit(:text) + end +end diff --git a/app/helpers/statuses_helper.rb b/app/helpers/statuses_helper.rb new file mode 100644 index 000000000..62fedd9b3 --- /dev/null +++ b/app/helpers/statuses_helper.rb @@ -0,0 +1,2 @@ +module StatusesHelper +end diff --git a/app/models/status.rb b/app/models/status.rb index 2fdd8d123..58d25546c 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -13,6 +13,7 @@ class Status < ActiveRecord::Base validates :account, presence: true validates :uri, uniqueness: true, unless: 'local?' + validates :text, presence: true, if: Proc.new { |s| s.local? && !s.reblog? } scope :with_counters, -> { select('statuses.*, (select count(r.id) from statuses as r where r.reblog_of_id = statuses.id) as reblogs_count, (select count(f.id) from favourites as f where f.status_id = statuses.id) as favourites_count') } scope :with_includes, -> { includes(:account, reblog: :account, thread: :account) } diff --git a/app/services/follow_remote_account_service.rb b/app/services/follow_remote_account_service.rb index 2f842e329..01e07e2e9 100644 --- a/app/services/follow_remote_account_service.rb +++ b/app/services/follow_remote_account_service.rb @@ -7,7 +7,10 @@ class FollowRemoteAccountService < BaseService # @return [Account] def call(uri, subscribe = true) username, domain = uri.split('@') - account = Account.where(username: username, domain: domain).first + + return Account.find_local(username) if domain == Rails.configuration.x.local_domain + + account = Account.find_by(username: username, domain: domain) if account.nil? account = Account.new(username: username, domain: domain) diff --git a/app/views/home/index.html.haml b/app/views/home/index.html.haml index a3213a685..70f91d4a3 100644 --- a/app/views/home/index.html.haml +++ b/app/views/home/index.html.haml @@ -1,3 +1,11 @@ += simple_form_for Status.new, url: statuses_path, method: :post do |f| + = f.input :text, required: true, autofocus: true, label: false, placeholder: 'What are you up to?' + + .form-actions + = f.button :submit, 'Post update' + +%hr/ + %h3 OAuth2 %p All API methods require a valid access token. @@ -83,6 +91,15 @@ %samp /api/accounts/:id/unfollow .description Unfollows target account from the user's account. Returns the target account. + %li + .address + %samp.method GET + %samp /api/accounts/lookup + .options + Options: + %samp usernames + .description + Returns accounts for a comma-separated list of usernames %h3 Follows %ul.api-descriptions |