Rebase to current 4.3.0-alpha-glitch-soc, update theming files
This commit is contained in:
1 parent
aeb49bcba0
commit
fff7926498
71 files changed
+30937
-2221
No files matched your search
@@ -0,0 +1,63 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class StatusLengthValidator < ActiveModel::Validator
|
||||
<<<<<<< HEAD
|
||||
MAX_CHARS = (ENV['MAX_TOOT_CHARS'] || 500).to_i
|
||||
=======
|
||||
MAX_CHARS = 1500
|
||||
>>>>>>> 1a7157000 (Theming and such)
|
||||
URL_PLACEHOLDER_CHARS = 23
|
||||
URL_PLACEHOLDER = 'x' * 23
|
||||
|
||||
def validate(status)
|
||||
return unless status.local? && !status.reblog?
|
||||
|
||||
status.errors.add(:text, I18n.t('statuses.over_character_limit', max: MAX_CHARS)) if too_long?(status)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def too_long?(status)
|
||||
countable_length(combined_text(status)) > MAX_CHARS
|
||||
end
|
||||
|
||||
def countable_length(str)
|
||||
str.mb_chars.grapheme_length
|
||||
end
|
||||
|
||||
def combined_text(status)
|
||||
[status.spoiler_text, countable_text(status.text)].join
|
||||
end
|
||||
|
||||
def countable_text(str)
|
||||
return '' if str.blank?
|
||||
|
||||
# To ensure that we only give length concessions to entities that
|
||||
# will be correctly parsed during formatting, we go through full
|
||||
# entity extraction
|
||||
|
||||
entities = Extractor.remove_overlapping_entities(Extractor.extract_urls_with_indices(str, extract_url_without_protocol: false) + Extractor.extract_mentions_or_lists_with_indices(str))
|
||||
|
||||
rewrite_entities(str, entities) do |entity|
|
||||
if entity[:url]
|
||||
URL_PLACEHOLDER
|
||||
elsif entity[:screen_name]
|
||||
"@#{entity[:screen_name].split('@').first}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def rewrite_entities(str, entities)
|
||||
entities.sort_by! { |entity| entity[:indices].first }
|
||||
result = +''
|
||||
|
||||
last_index = entities.reduce(0) do |index, entity|
|
||||
result << str[index...entity[:indices].first]
|
||||
result << yield(entity)
|
||||
entity[:indices].last
|
||||
end
|
||||
|
||||
result << str[last_index..]
|
||||
result
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,60 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class VoteValidator < ActiveModel::Validator
|
||||
def validate(vote)
|
||||
<<<<<<< HEAD
|
||||
vote.errors.add(:base, I18n.t('polls.errors.expired')) if vote.poll_expired?
|
||||
=======
|
||||
vote.errors.add(:base, I18n.t('polls.errors.expired')) if vote.poll.expired?
|
||||
>>>>>>> cca464bce (Fix being able to vote on your own polls (#25015))
|
||||
vote.errors.add(:base, I18n.t('polls.errors.invalid_choice')) if invalid_choice?(vote)
|
||||
vote.errors.add(:base, I18n.t('polls.errors.self_vote')) if self_vote?(vote)
|
||||
|
||||
vote.errors.add(:base, I18n.t('polls.errors.already_voted')) if additional_voting_not_allowed?(vote)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def additional_voting_not_allowed?(vote)
|
||||
poll_multiple_and_already_voted?(vote) || poll_non_multiple_and_already_voted?(vote)
|
||||
end
|
||||
|
||||
def poll_multiple_and_already_voted?(vote)
|
||||
vote.poll_multiple? && already_voted_for_same_choice_on_multiple_poll?(vote)
|
||||
end
|
||||
|
||||
def poll_non_multiple_and_already_voted?(vote)
|
||||
!vote.poll_multiple? && already_voted_on_non_multiple_poll?(vote)
|
||||
end
|
||||
|
||||
def invalid_choice?(vote)
|
||||
vote.choice.negative? || vote.choice >= vote.poll.options.size
|
||||
end
|
||||
|
||||
def self_vote?(vote)
|
||||
vote.account_id == vote.poll.account_id
|
||||
end
|
||||
<<<<<<< HEAD
|
||||
|
||||
def already_voted_for_same_choice_on_multiple_poll?(vote)
|
||||
if vote.persisted?
|
||||
account_votes_on_same_poll(vote).where(choice: vote.choice).where.not(poll_votes: { id: vote }).exists?
|
||||
else
|
||||
account_votes_on_same_poll(vote).where(choice: vote.choice).exists?
|
||||
end
|
||||
end
|
||||
|
||||
def already_voted_on_non_multiple_poll?(vote)
|
||||
if vote.persisted?
|
||||
account_votes_on_same_poll(vote).where.not(poll_votes: { id: vote }).exists?
|
||||
else
|
||||
account_votes_on_same_poll(vote).exists?
|
||||
end
|
||||
end
|
||||
|
||||
def account_votes_on_same_poll(vote)
|
||||
vote.poll.votes.where(account: vote.account)
|
||||
end
|
||||
=======
|
||||
>>>>>>> cca464bce (Fix being able to vote on your own polls (#25015))
|
||||
end
|
||||
Reference in new issue
Block a user