From 0345cd5a0f434a43ea988a2b50ab6f8597bcf58e Mon Sep 17 00:00:00 2001 From: ThibG Date: Tue, 29 May 2018 16:25:05 +0200 Subject: Fix error when unmuting a domain without listing muted domains first (#7670) --- app/javascript/mastodon/reducers/domain_lists.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/javascript/mastodon/reducers/domain_lists.js b/app/javascript/mastodon/reducers/domain_lists.js index a9e3519f3..eff97fbd6 100644 --- a/app/javascript/mastodon/reducers/domain_lists.js +++ b/app/javascript/mastodon/reducers/domain_lists.js @@ -6,7 +6,9 @@ import { import { Map as ImmutableMap, OrderedSet as ImmutableOrderedSet } from 'immutable'; const initialState = ImmutableMap({ - blocks: ImmutableMap(), + blocks: ImmutableMap({ + items: ImmutableOrderedSet(), + }), }); export default function domainLists(state = initialState, action) { -- cgit From 7706ed038f1a16d232635d564a28e6f90e53e0fd Mon Sep 17 00:00:00 2001 From: unarist Date: Wed, 30 May 2018 00:42:29 +0900 Subject: Fix context building in the reducer (#7671) This fixes below bugs: * addReply() had used native compare operator for string ids => descendants may appears at wrong position * CONTEXT_FETCH_SUCCESS had added the focused status as the reply of the *first* status in ancestors, not last status. => descendants may also appears wrong position as well as correct position * TIMELINE_UPDATE had added the status to replies of *itself* instead of replied status => browser will hangs if you open the status due to a circular reference --- app/javascript/mastodon/reducers/contexts.js | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/app/javascript/mastodon/reducers/contexts.js b/app/javascript/mastodon/reducers/contexts.js index 53e70b58e..4c2d6cc8a 100644 --- a/app/javascript/mastodon/reducers/contexts.js +++ b/app/javascript/mastodon/reducers/contexts.js @@ -5,6 +5,7 @@ import { import { CONTEXT_FETCH_SUCCESS } from '../actions/statuses'; import { TIMELINE_DELETE, TIMELINE_UPDATE } from '../actions/timelines'; import { Map as ImmutableMap, List as ImmutableList } from 'immutable'; +import compareId from '../compare_id'; const initialState = ImmutableMap({ inReplyTos: ImmutableMap(), @@ -15,27 +16,27 @@ const normalizeContext = (immutableState, id, ancestors, descendants) => immutab state.update('inReplyTos', immutableAncestors => immutableAncestors.withMutations(inReplyTos => { state.update('replies', immutableDescendants => immutableDescendants.withMutations(replies => { function addReply({ id, in_reply_to_id }) { - if (in_reply_to_id) { - const siblings = replies.get(in_reply_to_id, ImmutableList()); + if (in_reply_to_id && !inReplyTos.has(id)) { - if (!siblings.includes(id)) { - const index = siblings.findLastIndex(sibling => sibling.id < id); - replies.set(in_reply_to_id, siblings.insert(index + 1, id)); - } + replies.update(in_reply_to_id, ImmutableList(), siblings => { + const index = siblings.findLastIndex(sibling => compareId(sibling, id) < 0); + return siblings.insert(index + 1, id); + }); inReplyTos.set(id, in_reply_to_id); } } - if (ancestors[0]) { - addReply({ id, in_reply_to_id: ancestors[0].id }); - } + // We know in_reply_to_id of statuses but `id` itself. + // So we assume that the status of the id replies to last ancestors. - if (descendants[0]) { - addReply({ id: descendants[0].id, in_reply_to_id: id }); + ancestors.forEach(addReply); + + if (ancestors[0]) { + addReply({ id, in_reply_to_id: ancestors[ancestors.length - 1].id }); } - [ancestors, descendants].forEach(statuses => statuses.forEach(addReply)); + descendants.forEach(addReply); })); })); }); @@ -80,7 +81,7 @@ const updateContext = (state, status) => { mutable.setIn(['inReplyTos', status.id], status.in_reply_to_id); if (!replies.includes(status.id)) { - mutable.setIn(['replies', status.id], replies.push(status.id)); + mutable.setIn(['replies', status.in_reply_to_id], replies.push(status.id)); } }); } -- cgit From 461542784b555237316f3dd5e32ea224cd3ab8ef Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Tue, 29 May 2018 22:55:33 +0200 Subject: Reduce wasted work in RemoveStatusService due to inactive followers (#7672) --- app/models/concerns/account_interactions.rb | 11 +++++++++++ app/services/batched_remove_status_service.rb | 4 ++-- app/services/fan_out_on_write_service.rb | 4 ++-- app/services/remove_status_service.rb | 4 ++-- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/app/models/concerns/account_interactions.rb b/app/models/concerns/account_interactions.rb index ae43711be..ef59f5d15 100644 --- a/app/models/concerns/account_interactions.rb +++ b/app/models/concerns/account_interactions.rb @@ -183,4 +183,15 @@ module AccountInteractions def pinned?(status) status_pins.where(status: status).exists? end + + def followers_for_local_distribution + followers.local + .joins(:user) + .where('users.current_sign_in_at > ?', User::ACTIVE_DURATION.ago) + end + + def lists_for_local_distribution + lists.joins(account: :user) + .where('users.current_sign_in_at > ?', User::ACTIVE_DURATION.ago) + end end diff --git a/app/services/batched_remove_status_service.rb b/app/services/batched_remove_status_service.rb index ace51a1fc..dab1c4794 100644 --- a/app/services/batched_remove_status_service.rb +++ b/app/services/batched_remove_status_service.rb @@ -53,7 +53,7 @@ class BatchedRemoveStatusService < BaseService end def unpush_from_home_timelines(account, statuses) - recipients = account.followers.local.to_a + recipients = account.followers_for_local_distribution.to_a recipients << account if account.local? @@ -65,7 +65,7 @@ class BatchedRemoveStatusService < BaseService end def unpush_from_list_timelines(account, statuses) - account.lists.select(:id, :account_id).each do |list| + account.lists_for_local_distribution.select(:id, :account_id).each do |list| statuses.each do |status| FeedManager.instance.unpush_from_list(list, status) end diff --git a/app/services/fan_out_on_write_service.rb b/app/services/fan_out_on_write_service.rb index 8b3630229..5efd3edb2 100644 --- a/app/services/fan_out_on_write_service.rb +++ b/app/services/fan_out_on_write_service.rb @@ -38,7 +38,7 @@ class FanOutOnWriteService < BaseService def deliver_to_followers(status) Rails.logger.debug "Delivering status #{status.id} to followers" - status.account.followers.where(domain: nil).joins(:user).where('users.current_sign_in_at > ?', User::ACTIVE_DURATION.ago).select(:id).reorder(nil).find_in_batches do |followers| + status.account.followers_for_local_distribution.select(:id).reorder(nil).find_in_batches do |followers| FeedInsertWorker.push_bulk(followers) do |follower| [status.id, follower.id, :home] end @@ -48,7 +48,7 @@ class FanOutOnWriteService < BaseService def deliver_to_lists(status) Rails.logger.debug "Delivering status #{status.id} to lists" - status.account.lists.joins(account: :user).where('users.current_sign_in_at > ?', User::ACTIVE_DURATION.ago).select(:id).reorder(nil).find_in_batches do |lists| + status.account.lists_for_local_distribution.select(:id).reorder(nil).find_in_batches do |lists| FeedInsertWorker.push_bulk(lists) do |list| [status.id, list.id, :list] end diff --git a/app/services/remove_status_service.rb b/app/services/remove_status_service.rb index 8c3e18444..b9631077c 100644 --- a/app/services/remove_status_service.rb +++ b/app/services/remove_status_service.rb @@ -43,13 +43,13 @@ class RemoveStatusService < BaseService end def remove_from_followers - @account.followers.local.find_each do |follower| + @account.followers_for_local_distribution.find_each do |follower| FeedManager.instance.unpush_from_home(follower, @status) end end def remove_from_lists - @account.lists.select(:id, :account_id).find_each do |list| + @account.lists_for_local_distribution.select(:id, :account_id).find_each do |list| FeedManager.instance.unpush_from_list(list, @status) end end -- cgit From a7d726c3836a87006cedcdc4bd186f8aff89d093 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Wed, 30 May 2018 02:50:23 +0200 Subject: Improve counter caches on Status and Account (#7644) Do not touch statuses_count on accounts table when mass-destroying statuses to reduce load when removing accounts, same for reblogs_count and favourites_count Do not count statuses with direct visibility in statuses_count Fix #828 --- app/models/favourite.rb | 25 ++++++++++++- app/models/status.rb | 51 +++++++++++++++++++++++++-- app/services/batched_remove_status_service.rb | 5 ++- app/services/suspend_account_service.rb | 7 ++-- spec/models/account_spec.rb | 31 ++++++++++++++++ spec/models/status_spec.rb | 14 ++++++++ 6 files changed, 126 insertions(+), 7 deletions(-) diff --git a/app/models/favourite.rb b/app/models/favourite.rb index c998a67eb..0fce82f6f 100644 --- a/app/models/favourite.rb +++ b/app/models/favourite.rb @@ -16,7 +16,7 @@ class Favourite < ApplicationRecord update_index('statuses#status', :status) if Chewy.enabled? belongs_to :account, inverse_of: :favourites - belongs_to :status, inverse_of: :favourites, counter_cache: true + belongs_to :status, inverse_of: :favourites has_one :notification, as: :activity, dependent: :destroy @@ -25,4 +25,27 @@ class Favourite < ApplicationRecord before_validation do self.status = status.reblog if status&.reblog? end + + after_create :increment_cache_counters + after_destroy :decrement_cache_counters + + private + + def increment_cache_counters + if association(:status).loaded? + status.update_attribute(:favourites_count, status.favourites_count + 1) + else + Status.where(id: status_id).update_all('favourites_count = COALESCE(favourites_count, 0) + 1') + end + end + + def decrement_cache_counters + return if association(:status).loaded? && (status.marked_for_destruction? || status.marked_for_mass_destruction?) + + if association(:status).loaded? + status.update_attribute(:favourites_count, [status.favourites_count - 1, 0].max) + else + Status.where(id: status_id).update_all('favourites_count = GREATEST(COALESCE(favourites_count, 0) - 1, 0)') + end + end end diff --git a/app/models/status.rb b/app/models/status.rb index 54f3f68f5..08ec36f38 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -41,12 +41,12 @@ class Status < ApplicationRecord belongs_to :application, class_name: 'Doorkeeper::Application', optional: true - belongs_to :account, inverse_of: :statuses, counter_cache: true + belongs_to :account, inverse_of: :statuses belongs_to :in_reply_to_account, foreign_key: 'in_reply_to_account_id', class_name: 'Account', optional: true belongs_to :conversation, optional: true belongs_to :thread, foreign_key: 'in_reply_to_id', class_name: 'Status', inverse_of: :replies, optional: true - belongs_to :reblog, foreign_key: 'reblog_of_id', class_name: 'Status', inverse_of: :reblogs, counter_cache: :reblogs_count, optional: true + belongs_to :reblog, foreign_key: 'reblog_of_id', class_name: 'Status', inverse_of: :reblogs, optional: true has_many :favourites, inverse_of: :status, dependent: :destroy has_many :reblogs, foreign_key: 'reblog_of_id', class_name: 'Status', inverse_of: :reblog, dependent: :destroy @@ -167,6 +167,17 @@ class Status < ApplicationRecord @emojis ||= CustomEmoji.from_text([spoiler_text, text].join(' '), account.domain) end + def mark_for_mass_destruction! + @marked_for_mass_destruction = true + end + + def marked_for_mass_destruction? + @marked_for_mass_destruction + end + + after_create :increment_counter_caches + after_destroy :decrement_counter_caches + after_create_commit :store_uri, if: :local? after_create_commit :update_statistics, if: :local? @@ -388,4 +399,40 @@ class Status < ApplicationRecord return unless public_visibility? || unlisted_visibility? ActivityTracker.increment('activity:statuses:local') end + + def increment_counter_caches + return if direct_visibility? + + if association(:account).loaded? + account.update_attribute(:statuses_count, account.statuses_count + 1) + else + Account.where(id: account_id).update_all('statuses_count = COALESCE(statuses_count, 0) + 1') + end + + return unless reblog? + + if association(:reblog).loaded? + reblog.update_attribute(:reblogs_count, reblog.reblogs_count + 1) + else + Status.where(id: reblog_of_id).update_all('reblogs_count = COALESCE(reblogs_count, 0) + 1') + end + end + + def decrement_counter_caches + return if direct_visibility? || marked_for_mass_destruction? + + if association(:account).loaded? + account.update_attribute(:statuses_count, [account.statuses_count - 1, 0].max) + else + Account.where(id: account_id).update_all('statuses_count = GREATEST(COALESCE(statuses_count, 0) - 1, 0)') + end + + return unless reblog? + + if association(:reblog).loaded? + reblog.update_attribute(:reblogs_count, [reblog.reblogs_count - 1, 0].max) + else + Status.where(id: reblog_of_id).update_all('reblogs_count = GREATEST(COALESCE(reblogs_count, 0) - 1, 0)') + end + end end diff --git a/app/services/batched_remove_status_service.rb b/app/services/batched_remove_status_service.rb index dab1c4794..ebb4034aa 100644 --- a/app/services/batched_remove_status_service.rb +++ b/app/services/batched_remove_status_service.rb @@ -21,7 +21,10 @@ class BatchedRemoveStatusService < BaseService @activity_xml = {} # Ensure that rendered XML reflects destroyed state - statuses.each(&:destroy) + statuses.each do |status| + status.mark_for_mass_destruction! + status.destroy + end # Batch by source account statuses.group_by(&:account_id).each_value do |account_statuses| diff --git a/app/services/suspend_account_service.rb b/app/services/suspend_account_service.rb index 56fa2d8dd..708d15e37 100644 --- a/app/services/suspend_account_service.rb +++ b/app/services/suspend_account_service.rb @@ -41,9 +41,10 @@ class SuspendAccountService < BaseService end def purge_profile! - @account.suspended = true - @account.display_name = '' - @account.note = '' + @account.suspended = true + @account.display_name = '' + @account.note = '' + @account.statuses_count = 0 @account.avatar.destroy @account.header.destroy @account.save! diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index 3aaaa55eb..cce659a8a 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -525,6 +525,37 @@ RSpec.describe Account, type: :model do end end + describe '#statuses_count' do + subject { Fabricate(:account) } + + it 'counts statuses' do + Fabricate(:status, account: subject) + Fabricate(:status, account: subject) + expect(subject.statuses_count).to eq 2 + end + + it 'does not count direct statuses' do + Fabricate(:status, account: subject, visibility: :direct) + expect(subject.statuses_count).to eq 0 + end + + it 'is decremented when status is removed' do + status = Fabricate(:status, account: subject) + expect(subject.statuses_count).to eq 1 + status.destroy + expect(subject.statuses_count).to eq 0 + end + + it 'is decremented when status is removed when account is not preloaded' do + status = Fabricate(:status, account: subject) + expect(subject.reload.statuses_count).to eq 1 + clean_status = Status.find(status.id) + expect(clean_status.association(:account).loaded?).to be false + clean_status.destroy + expect(subject.reload.statuses_count).to eq 0 + end + end + describe '.following_map' do it 'returns an hash' do expect(Account.following_map([], 1)).to be_a Hash diff --git a/spec/models/status_spec.rb b/spec/models/status_spec.rb index aee4f49b4..5113b652f 100644 --- a/spec/models/status_spec.rb +++ b/spec/models/status_spec.rb @@ -175,6 +175,13 @@ RSpec.describe Status, type: :model do expect(subject.reblogs_count).to eq 2 end + + it 'is decremented when reblog is removed' do + reblog = Fabricate(:status, account: bob, reblog: subject) + expect(subject.reblogs_count).to eq 1 + reblog.destroy + expect(subject.reblogs_count).to eq 0 + end end describe '#favourites_count' do @@ -184,6 +191,13 @@ RSpec.describe Status, type: :model do expect(subject.favourites_count).to eq 2 end + + it 'is decremented when favourite is removed' do + favourite = Fabricate(:favourite, account: bob, status: subject) + expect(subject.favourites_count).to eq 1 + favourite.destroy + expect(subject.favourites_count).to eq 0 + end end describe '#proper' do -- cgit From a16e06bbf584412c5a0f812da37fcd6e2c479d1a Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Wed, 30 May 2018 02:51:26 +0200 Subject: Deduplicate accounts and make unique username/domain index case-insensitive (#7658) Fix #6937 Fix #6837 Fix #6667 --- .../20180528141303_fix_accounts_unique_index.rb | 84 ++++++++++++++++++++++ db/schema.rb | 5 +- 2 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20180528141303_fix_accounts_unique_index.rb diff --git a/db/migrate/20180528141303_fix_accounts_unique_index.rb b/db/migrate/20180528141303_fix_accounts_unique_index.rb new file mode 100644 index 000000000..2e5eca814 --- /dev/null +++ b/db/migrate/20180528141303_fix_accounts_unique_index.rb @@ -0,0 +1,84 @@ +class FixAccountsUniqueIndex < ActiveRecord::Migration[5.2] + disable_ddl_transaction! + + def up + say '' + say 'WARNING: This migration may take a *long* time for large instances' + say 'It will *not* lock tables for any significant time, but it may run' + say 'for a very long time. We will pause for 10 seconds to allow you to' + say 'interrupt this migration if you are not ready.' + say '' + say 'This migration will irreversibly delete user accounts with duplicate' + say 'usernames. You may use the `rake mastodon:maintenance:find_duplicate_usernames`' + say 'task to manually deal with such accounts before running this migration.' + + 10.downto(1) do |i| + say "Continuing in #{i} second#{i == 1 ? '' : 's'}...", true + sleep 1 + end + + duplicates = Account.connection.select_all('SELECT string_agg(id::text, \',\') AS ids FROM accounts GROUP BY lower(username), lower(domain) HAVING count(*) > 1').to_hash + + duplicates.each do |row| + deduplicate_account!(row['ids'].split(',')) + end + + remove_index :accounts, name: 'index_accounts_on_username_and_domain_lower' if index_name_exists?(:accounts, 'index_accounts_on_username_and_domain_lower') + safety_assured { execute 'CREATE UNIQUE INDEX CONCURRENTLY index_accounts_on_username_and_domain_lower ON accounts (lower(username), lower(domain))' } + remove_index :accounts, name: 'index_accounts_on_username_and_domain' if index_name_exists?(:accounts, 'index_accounts_on_username_and_domain') + end + + def down + raise ActiveRecord::IrreversibleMigration + end + + private + + def deduplicate_account!(account_ids) + accounts = Account.where(id: account_ids).to_a + accounts = account.first.local? ? accounts.sort_by(&:created_at) : accounts.sort_by(&:updated_at).reverse + reference_account = accounts.shift + + accounts.each do |other_account| + if other_account.public_key == reference_account.public_key + # The accounts definitely point to the same resource, so + # it's safe to re-attribute content and relationships + merge_accounts!(reference_account, other_account) + elsif other_account.local? + # Since domain is in the GROUP BY clause, both accounts + # are always either going to be local or not local, so only + # one check is needed. Since we cannot support two users with + # the same username locally, one has to go. 😢 + other_account.user.destroy + end + + other_account.destroy + end + end + + def merge_accounts!(main_account, duplicate_account) + [Status, Favourite, Mention, StatusPin, StreamEntry].each do |klass| + klass.where(account_id: duplicate_account.id).update_all(account_id: main_account.id) + end + + # Since it's the same remote resource, the remote resource likely + # already believes we are following/blocking, so it's safe to + # re-attribute the relationships too. However, during the presence + # of the index bug users could have *also* followed the reference + # account already, therefore mass update will not work and we need + # to check for (and skip past) uniqueness errors + [Follow, FollowRequest, Block, Mute].each do |klass| + klass.where(account_id: duplicate_account.id).find_each do |record| + record.update(account_id: main_account.id) + rescue ActiveRecord::RecordNotUnique + next + end + + klass.where(target_account_id: duplicate_account.id).find_each do |record| + record.update(target_account_id: main_account.id) + rescue ActiveRecord::RecordNotUnique + next + end + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 7435b6cc9..c9d4e0fe7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_05_14_140000) do +ActiveRecord::Schema.define(version: 2018_05_28_141303) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -77,10 +77,9 @@ ActiveRecord::Schema.define(version: 2018_05_14_140000) do t.jsonb "fields" t.string "actor_type" t.index "(((setweight(to_tsvector('simple'::regconfig, (display_name)::text), 'A'::\"char\") || setweight(to_tsvector('simple'::regconfig, (username)::text), 'B'::\"char\")) || setweight(to_tsvector('simple'::regconfig, (COALESCE(domain, ''::character varying))::text), 'C'::\"char\")))", name: "search_index", using: :gin - t.index "lower((username)::text), lower((domain)::text)", name: "index_accounts_on_username_and_domain_lower" + t.index "lower((username)::text), lower((domain)::text)", name: "index_accounts_on_username_and_domain_lower", unique: true t.index ["uri"], name: "index_accounts_on_uri" t.index ["url"], name: "index_accounts_on_url" - t.index ["username", "domain"], name: "index_accounts_on_username_and_domain", unique: true end create_table "admin_action_logs", force: :cascade do |t| -- cgit From 9130b3cda9cd460aa137e399a8b50880aba3bb63 Mon Sep 17 00:00:00 2001 From: Yamagishi Kazutoshi Date: Wed, 30 May 2018 16:39:52 +0900 Subject: Fix broken migrate (regression from #7658) (#7674) --- db/migrate/20180528141303_fix_accounts_unique_index.rb | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/db/migrate/20180528141303_fix_accounts_unique_index.rb b/db/migrate/20180528141303_fix_accounts_unique_index.rb index 2e5eca814..92e490f9e 100644 --- a/db/migrate/20180528141303_fix_accounts_unique_index.rb +++ b/db/migrate/20180528141303_fix_accounts_unique_index.rb @@ -36,7 +36,7 @@ class FixAccountsUniqueIndex < ActiveRecord::Migration[5.2] def deduplicate_account!(account_ids) accounts = Account.where(id: account_ids).to_a - accounts = account.first.local? ? accounts.sort_by(&:created_at) : accounts.sort_by(&:updated_at).reverse + accounts = accounts.first.local? ? accounts.sort_by(&:created_at) : accounts.sort_by(&:updated_at).reverse reference_account = accounts.shift accounts.each do |other_account| @@ -69,15 +69,19 @@ class FixAccountsUniqueIndex < ActiveRecord::Migration[5.2] # to check for (and skip past) uniqueness errors [Follow, FollowRequest, Block, Mute].each do |klass| klass.where(account_id: duplicate_account.id).find_each do |record| - record.update(account_id: main_account.id) - rescue ActiveRecord::RecordNotUnique - next + begin + record.update(account_id: main_account.id) + rescue ActiveRecord::RecordNotUnique + next + end end klass.where(target_account_id: duplicate_account.id).find_each do |record| - record.update(target_account_id: main_account.id) - rescue ActiveRecord::RecordNotUnique - next + begin + record.update(target_account_id: main_account.id) + rescue ActiveRecord::RecordNotUnique + next + end end end end -- cgit From 1a7a74ff76a129031a3fd6d73688ab9409899002 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Wed, 30 May 2018 18:41:47 +0200 Subject: Improve getting started column (#7676) * Adjust footer of getting started column - Improved style - Moved hotkeys, about this instance and logout to footer - Removed FAQ, User Guide, Apps links - Use hamburger icon for the column * Add edit profile action button to profile and more to dropdown * Add "Trending now" to getting started column * Add preferences/security links on mobile layout --- app/javascript/mastodon/components/hashtag.js | 41 ++++++++ .../features/account/components/action_bar.js | 28 +++++- .../mastodon/features/account/components/header.js | 11 +++ .../features/compose/components/search_results.js | 39 +------- app/javascript/mastodon/features/compose/index.js | 2 +- .../mastodon/features/domain_blocks/index.js | 2 +- .../mastodon/features/getting_started/index.js | 109 ++++++++++++--------- app/javascript/mastodon/locales/en.json | 2 +- app/javascript/styles/mastodon/components.scss | 71 +++++++++----- 9 files changed, 197 insertions(+), 108 deletions(-) create mode 100644 app/javascript/mastodon/components/hashtag.js diff --git a/app/javascript/mastodon/components/hashtag.js b/app/javascript/mastodon/components/hashtag.js new file mode 100644 index 000000000..cc37a91e2 --- /dev/null +++ b/app/javascript/mastodon/components/hashtag.js @@ -0,0 +1,41 @@ +import React from 'react'; +import { Sparklines, SparklinesCurve } from 'react-sparklines'; +import { Link } from 'react-router-dom'; +import { FormattedMessage, FormattedNumber } from 'react-intl'; +import ImmutablePropTypes from 'react-immutable-proptypes'; + +const shortNumberFormat = number => { + if (number < 1000) { + return ; + } else { + return K; + } +}; + +const Hashtag = ({ hashtag }) => ( +
+
+ + #{hashtag.get('name')} + + + {shortNumberFormat(hashtag.getIn(['history', 0, 'accounts']))} }} /> +
+ +
+ {shortNumberFormat(hashtag.getIn(['history', 0, 'uses']))} +
+ +
+ day.get('uses')).toArray()}> + + +
+
+); + +Hashtag.propTypes = { + hashtag: ImmutablePropTypes.map.isRequired, +}; + +export default Hashtag; diff --git a/app/javascript/mastodon/features/account/components/action_bar.js b/app/javascript/mastodon/features/account/components/action_bar.js index 23dbf32bc..3a1f92811 100644 --- a/app/javascript/mastodon/features/account/components/action_bar.js +++ b/app/javascript/mastodon/features/account/components/action_bar.js @@ -23,6 +23,14 @@ const messages = defineMessages({ unblockDomain: { id: 'account.unblock_domain', defaultMessage: 'Unhide {domain}' }, hideReblogs: { id: 'account.hide_reblogs', defaultMessage: 'Hide boosts from @{name}' }, showReblogs: { id: 'account.show_reblogs', defaultMessage: 'Show boosts from @{name}' }, + pins: { id: 'navigation_bar.pins', defaultMessage: 'Pinned toots' }, + preferences: { id: 'navigation_bar.preferences', defaultMessage: 'Preferences' }, + follow_requests: { id: 'navigation_bar.follow_requests', defaultMessage: 'Follow requests' }, + favourites: { id: 'navigation_bar.favourites', defaultMessage: 'Favourites' }, + lists: { id: 'navigation_bar.lists', defaultMessage: 'Lists' }, + blocks: { id: 'navigation_bar.blocks', defaultMessage: 'Blocked users' }, + domain_blocks: { id: 'navigation_bar.domain_blocks', defaultMessage: 'Hidden domains' }, + mutes: { id: 'navigation_bar.mutes', defaultMessage: 'Muted users' }, }); @injectIntl @@ -54,17 +62,29 @@ export default class ActionBar extends React.PureComponent { let menu = []; let extraInfo = ''; - menu.push({ text: intl.formatMessage(messages.mention, { name: account.get('username') }), action: this.props.onMention }); - menu.push({ text: intl.formatMessage(messages.direct, { name: account.get('username') }), action: this.props.onDirect }); + if (account.get('id') !== me) { + menu.push({ text: intl.formatMessage(messages.mention, { name: account.get('username') }), action: this.props.onMention }); + menu.push({ text: intl.formatMessage(messages.direct, { name: account.get('username') }), action: this.props.onDirect }); + menu.push(null); + } if ('share' in navigator) { menu.push({ text: intl.formatMessage(messages.share, { name: account.get('username') }), action: this.handleShare }); + menu.push(null); } - menu.push(null); - if (account.get('id') === me) { menu.push({ text: intl.formatMessage(messages.edit_profile), href: '/settings/profile' }); + menu.push({ text: intl.formatMessage(messages.preferences), href: '/settings/preferences' }); + menu.push({ text: intl.formatMessage(messages.pins), to: '/pinned' }); + menu.push(null); + menu.push({ text: intl.formatMessage(messages.follow_requests), to: '/follow_requests' }); + menu.push({ text: intl.formatMessage(messages.favourites), to: '/favourites' }); + menu.push({ text: intl.formatMessage(messages.lists), to: '/lists' }); + menu.push(null); + menu.push({ text: intl.formatMessage(messages.mutes), to: '/mutes' }); + menu.push({ text: intl.formatMessage(messages.blocks), to: '/blocks' }); + menu.push({ text: intl.formatMessage(messages.domain_blocks), to: '/domain_blocks' }); } else { if (account.getIn(['relationship', 'following'])) { if (account.getIn(['relationship', 'showing_reblogs'])) { diff --git a/app/javascript/mastodon/features/account/components/header.js b/app/javascript/mastodon/features/account/components/header.js index 7358053da..dd2cd406b 100644 --- a/app/javascript/mastodon/features/account/components/header.js +++ b/app/javascript/mastodon/features/account/components/header.js @@ -14,6 +14,7 @@ const messages = defineMessages({ follow: { id: 'account.follow', defaultMessage: 'Follow' }, requested: { id: 'account.requested', defaultMessage: 'Awaiting approval. Click to cancel follow request' }, unblock: { id: 'account.unblock', defaultMessage: 'Unblock @{name}' }, + edit_profile: { id: 'account.edit_profile', defaultMessage: 'Edit profile' }, }); class Avatar extends ImmutablePureComponent { @@ -74,6 +75,10 @@ export default class Header extends ImmutablePureComponent { intl: PropTypes.object.isRequired, }; + openEditProfile = () => { + window.open('/settings/profile', '_blank'); + } + render () { const { account, intl } = this.props; @@ -118,6 +123,12 @@ export default class Header extends ImmutablePureComponent { ); } + } else { + actionBtn = ( +
+ +
+ ); } if (account.get('moved') && !account.getIn(['relationship', 'following'])) { diff --git a/app/javascript/mastodon/features/compose/components/search_results.js b/app/javascript/mastodon/features/compose/components/search_results.js index 445bf27bb..cf022362e 100644 --- a/app/javascript/mastodon/features/compose/components/search_results.js +++ b/app/javascript/mastodon/features/compose/components/search_results.js @@ -1,42 +1,11 @@ import React from 'react'; import PropTypes from 'prop-types'; import ImmutablePropTypes from 'react-immutable-proptypes'; -import { FormattedMessage, FormattedNumber } from 'react-intl'; +import { FormattedMessage } from 'react-intl'; import AccountContainer from '../../../containers/account_container'; import StatusContainer from '../../../containers/status_container'; -import { Link } from 'react-router-dom'; import ImmutablePureComponent from 'react-immutable-pure-component'; -import { Sparklines, SparklinesCurve } from 'react-sparklines'; - -const shortNumberFormat = number => { - if (number < 1000) { - return ; - } else { - return K; - } -}; - -const renderHashtag = hashtag => ( -
-
- - #{hashtag.get('name')} - - - {shortNumberFormat(hashtag.getIn(['history', 0, 'accounts']))} }} /> -
- -
- {shortNumberFormat(hashtag.getIn(['history', 0, 'uses']))} -
- -
- day.get('uses')).toArray()}> - - -
-
-); +import Hashtag from '../../../components/hashtag'; export default class SearchResults extends ImmutablePureComponent { @@ -66,7 +35,7 @@ export default class SearchResults extends ImmutablePureComponent { - {trends && trends.map(hashtag => renderHashtag(hashtag))} + {trends && trends.map(hashtag => )} ); @@ -100,7 +69,7 @@ export default class SearchResults extends ImmutablePureComponent {
- {results.get('hashtags').map(hashtag => renderHashtag(hashtag))} + {results.get('hashtags').map(hashtag => )}
); } diff --git a/app/javascript/mastodon/features/compose/index.js b/app/javascript/mastodon/features/compose/index.js index d8e9ad9ee..df1ec4915 100644 --- a/app/javascript/mastodon/features/compose/index.js +++ b/app/javascript/mastodon/features/compose/index.js @@ -75,7 +75,7 @@ export default class Compose extends React.PureComponent { const { columns } = this.props; header = (