Skip to content

Commit 9884629

Browse files
Merge pull request #189 from jesseplusplus/account-timeline-markers
Add account timeline markers
2 parents db1816f + eaa554d commit 9884629

File tree

5 files changed

+51
-2
lines changed

5 files changed

+51
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ An opinionated fork of mastodon with the following modifications:
1616

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

19+
* timeline markers for accounts' feed of updates - [jesseplusplus/decodon#189](https://github.com/jesseplusplus/decodon/pull/189)
20+
1921
* more control over logo and branding in email templates [jesseplusplus/decodon#10](https://github.com/jesseplusplus/decodon/pull/10)
2022

2123
* updated heroku deployment configs

app/controllers/api/v1/markers_controller.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ def serialize_map(map)
4242
end
4343

4444
def resource_params
45-
params.slice(*Marker::TIMELINES).permit(*Marker::TIMELINES.map { |timeline| { timeline.to_sym => [:last_read_id] } })
45+
timeline_params = params.slice(*Marker::TIMELINES).permit!.to_h
46+
account_params = params.select { |key, _| key.start_with?('account:') && key.split(':', 2)[1].match?(/\A\d+\z/) }.permit!.to_h
47+
48+
merged_params = timeline_params.merge(account_params)
49+
params = ActionController::Parameters.new(merged_params)
50+
51+
params.permit(
52+
*Marker::TIMELINES.map { |timeline| { timeline.to_sym => [:last_read_id] } },
53+
*account_params.keys.map { |key| { key.to_sym => [:last_read_id] } }
54+
)
4655
end
4756
end

app/models/marker.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,18 @@ class Marker < ApplicationRecord
1919
belongs_to :user
2020

2121
validates :timeline, :last_read_id, presence: true
22-
validates :timeline, inclusion: { in: TIMELINES }
22+
validate :timeline_format_valid
23+
24+
def self.for_account(account_id)
25+
"account:#{account_id}"
26+
end
27+
28+
private
29+
30+
def timeline_format_valid
31+
return if TIMELINES.include?(timeline)
32+
return if timeline.start_with?('account:') && timeline.split(':', 2)[1].match?(/\A\d+\z/)
33+
34+
errors.add(:timeline, 'must be a valid timeline type')
35+
end
2336
end
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# frozen_string_literal: true
2+
3+
require 'rails_helper'
4+
5+
RSpec.describe Api::V1::MarkersController do
6+
let(:user) { Fabricate(:user) }
7+
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'write:statuses') }
8+
9+
before do
10+
allow(controller).to receive(:doorkeeper_token) { token }
11+
end
12+
13+
describe 'POST #create' do
14+
it 'creates markers for account-based timelines' do
15+
post :create, params: {
16+
'account:123': { last_read_id: '456' },
17+
}
18+
19+
expect(response).to have_http_status(200)
20+
json = JSON.parse(response.body)
21+
expect(json['account:123']).to include('last_read_id' => '456')
22+
end
23+
end
24+
end

spec/rails_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
require 'paperclip/matchers'
4343
require 'capybara/rspec'
4444
require 'chewy/rspec'
45+
require 'email_spec'
4546
require 'email_spec/rspec'
4647
require 'pundit/rspec'
4748
require 'test_prof/recipes/rspec/before_all'

0 commit comments

Comments
 (0)