Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ An opinionated fork of mastodon with the following modifications:

* default "inner circle" for all accounts to get them started - [jesseplusplus/decodon#14](https://github.com/jesseplusplus/decodon/pull/14)

* timeline markers for accounts' feed of updates - [jesseplusplus/decodon#189](https://github.com/jesseplusplus/decodon/pull/189)

* more control over logo and branding in email templates [jesseplusplus/decodon#10](https://github.com/jesseplusplus/decodon/pull/10)

* updated heroku deployment configs
Expand Down
11 changes: 10 additions & 1 deletion app/controllers/api/v1/markers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ def serialize_map(map)
end

def resource_params
params.slice(*Marker::TIMELINES).permit(*Marker::TIMELINES.map { |timeline| { timeline.to_sym => [:last_read_id] } })
timeline_params = params.slice(*Marker::TIMELINES).permit!.to_h
account_params = params.select { |key, _| key.start_with?('account:') && key.split(':', 2)[1].match?(/\A\d+\z/) }.permit!.to_h

merged_params = timeline_params.merge(account_params)
params = ActionController::Parameters.new(merged_params)

params.permit(
*Marker::TIMELINES.map { |timeline| { timeline.to_sym => [:last_read_id] } },
*account_params.keys.map { |key| { key.to_sym => [:last_read_id] } }
)
end
end
15 changes: 14 additions & 1 deletion app/models/marker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,18 @@ class Marker < ApplicationRecord
belongs_to :user

validates :timeline, :last_read_id, presence: true
validates :timeline, inclusion: { in: TIMELINES }
validate :timeline_format_valid

def self.for_account(account_id)
"account:#{account_id}"
end

private

def timeline_format_valid
return if TIMELINES.include?(timeline)
return if timeline.start_with?('account:') && timeline.split(':', 2)[1].match?(/\A\d+\z/)

errors.add(:timeline, 'must be a valid timeline type')
end
end
24 changes: 24 additions & 0 deletions spec/controllers/api/v1/markers_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe Api::V1::MarkersController do
let(:user) { Fabricate(:user) }
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'write:statuses') }

before do
allow(controller).to receive(:doorkeeper_token) { token }
end

describe 'POST #create' do
it 'creates markers for account-based timelines' do
post :create, params: {
'account:123': { last_read_id: '456' },
}

expect(response).to have_http_status(200)
json = JSON.parse(response.body)
expect(json['account:123']).to include('last_read_id' => '456')
end
end
end
1 change: 1 addition & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
require 'paperclip/matchers'
require 'capybara/rspec'
require 'chewy/rspec'
require 'email_spec'
require 'email_spec/rspec'
require 'pundit/rspec'
require 'test_prof/recipes/rspec/before_all'
Expand Down