Skip to content

Commit

Permalink
Merge branch 'kb_migration' into kb_development
Browse files Browse the repository at this point in the history
  • Loading branch information
kmycode committed Sep 16, 2023
2 parents 6aaef5c + ae053cc commit 07d2614
Show file tree
Hide file tree
Showing 14 changed files with 156 additions and 64 deletions.
4 changes: 2 additions & 2 deletions app/javascript/mastodon/components/dismissable_banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ export const DismissableBanner: React.FC<PropsWithChildren<Props>> = ({

return (
<div className='dismissable-banner'>
<div className='dismissable-banner__message'>{children}</div>

<div className='dismissable-banner__action'>
<IconButton
icon='times'
title={intl.formatMessage(messages.dismiss)}
onClick={handleDismiss}
/>
</div>

<div className='dismissable-banner__message'>{children}</div>
</div>
);
};
4 changes: 1 addition & 3 deletions app/javascript/styles/mastodon/components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9300,9 +9300,7 @@ noscript {
}

&__action {
position: absolute;
inset-inline-end: 0;
top: 0;
float: right;
padding: 15px 10px;

.icon-button {
Expand Down
7 changes: 7 additions & 0 deletions app/javascript/styles/mastodon/rtl.scss
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,11 @@ body.rtl {
.fa-chevron-right::before {
content: '\F053';
}

.dismissable-banner,
.warning-banner {
&__action {
float: left;
}
}
}
2 changes: 1 addition & 1 deletion app/lib/activitypub/activity/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ def update_status

return if @status.nil?

ActivityPub::ProcessStatusUpdateService.new.call(@status, @object, request_id: @options[:request_id])
ActivityPub::ProcessStatusUpdateService.new.call(@status, @json, @object, request_id: @options[:request_id])
end
end
2 changes: 1 addition & 1 deletion app/models/media_attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,6 @@ def enqueue_processing
end

def reset_parent_cache
Rails.cache.delete("statuses/#{status_id}") if status_id.present?
Rails.cache.delete("v3:statuses/#{status_id}") if status_id.present?
end
end
2 changes: 1 addition & 1 deletion app/models/poll.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def prepare_options
def reset_parent_cache
return if status_id.nil?

Rails.cache.delete("statuses/#{status_id}")
Rails.cache.delete("v3:statuses/#{status_id}")
end

def last_fetched_before_expiration?
Expand Down
8 changes: 0 additions & 8 deletions app/models/status_stat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
class StatusStat < ApplicationRecord
belongs_to :status, inverse_of: :status_stat

after_commit :reset_parent_cache

def replies_count
[attributes['replies_count'], 0].max
end
Expand Down Expand Up @@ -50,10 +48,4 @@ def emoji_reaction_accounts_count
def status_referred_by_count
[attributes['status_referred_by_count'] || 0, 0].max
end

private

def reset_parent_cache
Rails.cache.delete("statuses/#{status_id}")
end
end
2 changes: 1 addition & 1 deletion app/services/activitypub/fetch_remote_poll_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ def call(poll, on_behalf_of = nil)

return unless supported_context?(json)

ActivityPub::ProcessStatusUpdateService.new.call(poll.status, json)
ActivityPub::ProcessStatusUpdateService.new.call(poll.status, json, json)
end
end
7 changes: 4 additions & 3 deletions app/services/activitypub/process_status_update_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ class ActivityPub::ProcessStatusUpdateService < BaseService
include Redisable
include Lockable

def call(status, json, request_id: nil)
def call(status, activity_json, object_json, request_id: nil)
raise ArgumentError, 'Status has unsaved changes' if status.changed?

@json = json
@activity_json = activity_json
@json = object_json
@status_parser = ActivityPub::Parser::StatusParser.new(@json)
@uri = @status_parser.uri
@status = status
Expand Down Expand Up @@ -324,6 +325,6 @@ def forward_activity!
end

def forwarder
@forwarder ||= ActivityPub::Forwarder.new(@account, @json, @status)
@forwarder ||= ActivityPub::Forwarder.new(@account, @activity_json, @status)
end
end
4 changes: 2 additions & 2 deletions app/services/statuses_search_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ def convert_deprecated_options!
end

if @options[:min_id]
timestamp = Mastodon::Snowflake.to_time(@options[:min_id])
timestamp = Mastodon::Snowflake.to_time(@options[:min_id].to_i)
syntax_options << "after:\"#{timestamp.iso8601}\""
end

if @options[:max_id]
timestamp = Mastodon::Snowflake.to_time(@options[:max_id])
timestamp = Mastodon::Snowflake.to_time(@options[:max_id].to_i)
syntax_options << "before:\"#{timestamp.iso8601}\""
end

Expand Down
58 changes: 58 additions & 0 deletions install/setup1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
apt update && apt upgrade -y

apt install -y curl wget gnupg apt-transport-https lsb-release ca-certificates

# nodejs
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
sudo apt-get update && sudo apt-get install nodejs -y

# postgresql
wget -O /usr/share/keyrings/postgresql.asc https://www.postgresql.org/media/keys/ACCC4CF8.asc
echo "deb [signed-by=/usr/share/keyrings/postgresql.asc] http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/postgresql.list

apt update
apt install -y \
imagemagick ffmpeg libpq-dev libxml2-dev libxslt1-dev file git-core \
g++ libprotobuf-dev protobuf-compiler pkg-config nodejs gcc autoconf \
bison build-essential libssl-dev libyaml-dev libreadline6-dev \
zlib1g-dev libncurses5-dev libffi-dev libgdbm-dev \
nginx redis-server redis-tools postgresql postgresql-contrib \
certbot python3-certbot-nginx libidn11-dev libicu-dev libjemalloc-dev

corepack enable
yarn set version classic

adduser --disabled-login mastodon
su - mastodon << EOF
git clone https://github.com/rbenv/rbenv.git /home/mastodon/.rbenv
cd /home/mastodon/.rbenv && src/configure && make -C src
echo 'export PATH="/home/mastodon/.rbenv/bin:$PATH"' >> /home/mastodon/.bashrc
echo 'eval "$(rbenv init -)"' >> /home/mastodon/.bashrc
exec bash
git clone https://github.com/rbenv/ruby-build.git /home/mastodon/.rbenv/plugins/ruby-build
RUBY_CONFIGURE_OPTS=--with-jemalloc rbenv install 3.2.2
rbenv global 3.2.2
gem install bundler --no-document
EOF

sudo -u postgres psql << EOF
CREATE USER mastodon WITH PASSWORD 'ohagi' CREATEDB;
EOF

su - mastodon <<EOF
git clone https://github.com/kmycode/mastodon.git live && cd live
git checkout $(git tag -l | grep -v 'rc[0-9]*$' | sort -V | tail -n 1)
yarn install --pure-lockfile
EOF

cp /home/mastodon/live/dist/nginx.conf /etc/nginx/sites-available/mastodon
ln -s /etc/nginx/sites-available/mastodon /etc/nginx/sites-enabled/mastodon
cp /home/mastodon/live/dist/mastodon-*.service /etc/systemd/system/
systemctl daemon-reload
Empty file added install/setup2.sh
Empty file.
40 changes: 20 additions & 20 deletions spec/services/activitypub/process_status_update_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ def poll_option_json(name, votes)

describe '#call' do
it 'updates text' do
subject.call(status, json)
subject.call(status, json, json)
expect(status.reload.text).to eq 'Hello universe'
end

it 'updates content warning' do
subject.call(status, json)
subject.call(status, json, json)
expect(status.reload.spoiler_text).to eq 'Show more'
end

Expand All @@ -64,7 +64,7 @@ def poll_option_json(name, votes)
end

before do
subject.call(status, json)
subject.call(status, json, json)
end

it 'does not create any edits' do
Expand All @@ -87,7 +87,7 @@ def poll_option_json(name, votes)
end

before do
subject.call(status, json)
subject.call(status, json, json)
end

it 'does not create any edits' do
Expand Down Expand Up @@ -134,7 +134,7 @@ def poll_option_json(name, votes)
end

before do
subject.call(status, json)
subject.call(status, json, json)
end

it 'does not create any edits' do
Expand Down Expand Up @@ -186,7 +186,7 @@ def poll_option_json(name, votes)
end

before do
subject.call(status, json)
subject.call(status, json, json)
end

it 'does not create any edits' do
Expand Down Expand Up @@ -214,11 +214,11 @@ def poll_option_json(name, votes)
end

it 'does not create any edits' do
expect { subject.call(status, json) }.to_not(change { status.reload.edits.pluck(&:id) })
expect { subject.call(status, json, json) }.to_not(change { status.reload.edits.pluck(&:id) })
end

it 'does not update the text, spoiler_text or edited_at' do
expect { subject.call(status, json) }.to_not(change { s = status.reload; [s.text, s.spoiler_text, s.edited_at] })
expect { subject.call(status, json, json) }.to_not(change { s = status.reload; [s.text, s.spoiler_text, s.edited_at] })
end
end

Expand All @@ -233,7 +233,7 @@ def poll_option_json(name, votes)
end

before do
subject.call(status, json)
subject.call(status, json, json)
end

it 'does not create any edits' do
Expand All @@ -257,7 +257,7 @@ def poll_option_json(name, votes)

before do
status.update(ordered_media_attachment_ids: nil)
subject.call(status, json)
subject.call(status, json, json)
end

it 'does not create any edits' do
Expand All @@ -271,7 +271,7 @@ def poll_option_json(name, votes)

context 'when originally without tags' do
before do
subject.call(status, json)
subject.call(status, json, json)
end

it 'updates tags' do
Expand All @@ -297,7 +297,7 @@ def poll_option_json(name, votes)
end

before do
subject.call(status, json)
subject.call(status, json, json)
end

it 'updates tags' do
Expand All @@ -307,7 +307,7 @@ def poll_option_json(name, votes)

context 'when originally without mentions' do
before do
subject.call(status, json)
subject.call(status, json, json)
end

it 'updates mentions' do
Expand All @@ -319,7 +319,7 @@ def poll_option_json(name, votes)
let(:mentions) { [alice, bob] }

before do
subject.call(status, json)
subject.call(status, json, json)
end

it 'updates mentions' do
Expand All @@ -330,7 +330,7 @@ def poll_option_json(name, votes)
context 'when originally without media attachments' do
before do
stub_request(:get, 'https://example.com/foo.png').to_return(body: attachment_fixture('emojo.png'))
subject.call(status, json)
subject.call(status, json, json)
end

let(:payload) do
Expand Down Expand Up @@ -380,7 +380,7 @@ def poll_option_json(name, votes)

before do
allow(RedownloadMediaWorker).to receive(:perform_async)
subject.call(status, json)
subject.call(status, json, json)
end

it 'updates the existing media attachment in-place' do
Expand Down Expand Up @@ -408,7 +408,7 @@ def poll_option_json(name, votes)
before do
poll = Fabricate(:poll, status: status)
status.update(preloadable_poll: poll)
subject.call(status, json)
subject.call(status, json, json)
end

it 'removes poll' do
Expand Down Expand Up @@ -438,7 +438,7 @@ def poll_option_json(name, votes)
end

before do
subject.call(status, json)
subject.call(status, json, json)
end

it 'creates a poll' do
Expand All @@ -454,12 +454,12 @@ def poll_option_json(name, votes)
end

it 'creates edit history' do
subject.call(status, json)
subject.call(status, json, json)
expect(status.edits.reload.map(&:text)).to eq ['Hello world', 'Hello universe']
end

it 'sets edited timestamp' do
subject.call(status, json)
subject.call(status, json, json)
expect(status.reload.edited_at.to_s).to eq '2021-09-08 22:39:25 UTC'
end
end
Expand Down
Loading

0 comments on commit 07d2614

Please sign in to comment.