Compare commits

..

1 Commits

Author SHA1 Message Date
David Yip
083f78b8fb Stub out Glitch::ApplyKeywordMutesService. #199.
This service will apply/unapply keyword mutes to home and mentions
timelines.  Maybe other timelines if I find a way to make it work.
2018-06-13 03:32:30 -05:00
13 changed files with 67 additions and 187 deletions

View File

@@ -15,6 +15,7 @@ class Settings::KeywordMutesController < Settings::BaseController
@keyword_mute = keyword_mutes_for_account.create(keyword_mute_params)
if @keyword_mute.persisted?
Glitch::ApplyKeywordMutesWorker.perform_async(current_account.id)
redirect_to settings_keyword_mutes_path, notice: I18n.t('generic.changes_saved_msg')
else
render :new
@@ -23,6 +24,7 @@ class Settings::KeywordMutesController < Settings::BaseController
def update
if @keyword_mute.update(keyword_mute_params)
Glitch::ApplyKeywordMutesWorker.perform_async(current_account.id)
redirect_to settings_keyword_mutes_path, notice: I18n.t('generic.changes_saved_msg')
else
render :edit
@@ -32,12 +34,14 @@ class Settings::KeywordMutesController < Settings::BaseController
def destroy
@keyword_mute.destroy!
Glitch::ApplyKeywordMutesWorker.perform_async(current_account.id)
redirect_to settings_keyword_mutes_path, notice: I18n.t('generic.changes_saved_msg')
end
def destroy_all
keyword_mutes_for_account.delete_all
Glitch::ApplyKeywordMutesWorker.perform_async(current_account.id)
redirect_to settings_keyword_mutes_path, notice: I18n.t('generic.changes_saved_msg')
end

View File

@@ -54,13 +54,9 @@ function addCustomToPool(custom, pool) {
index = {};
}
function search(value, { emojisToShowFilter, maxResults, include, exclude, custom } = {}) {
if (custom !== undefined) {
if (customEmojisList !== custom)
addCustomToPool(custom, originalPool);
} else {
custom = [];
}
function search(value, { emojisToShowFilter, maxResults, include, exclude, custom = [] } = {}) {
if (customEmojisList !== custom)
addCustomToPool(custom, originalPool);
maxResults = maxResults || 75;
include = include || [];

View File

@@ -50,14 +50,13 @@ export function normalizeStatus(status, normalOldStatus) {
normalStatus.spoilerHtml = normalOldStatus.get('spoilerHtml');
normalStatus.hidden = normalOldStatus.get('hidden');
} else {
const spoilerText = normalStatus.spoiler_text || '';
const searchContent = [spoilerText, status.content].join('\n\n').replace(/<br\s*\/?>/g, '\n').replace(/<\/p><p>/g, '\n\n');
const emojiMap = makeEmojiMap(normalStatus);
const searchContent = [status.spoiler_text, status.content].join('\n\n').replace(/<br\s*\/?>/g, '\n').replace(/<\/p><p>/g, '\n\n');
const emojiMap = makeEmojiMap(normalStatus);
normalStatus.search_index = domParser.parseFromString(searchContent, 'text/html').documentElement.textContent;
normalStatus.contentHtml = emojify(normalStatus.content, emojiMap);
normalStatus.spoilerHtml = emojify(escapeTextContentForBrowser(spoilerText), emojiMap);
normalStatus.hidden = spoilerText.length > 0 || normalStatus.sensitive;
normalStatus.spoilerHtml = emojify(escapeTextContentForBrowser(normalStatus.spoiler_text || ''), emojiMap);
normalStatus.hidden = normalStatus.sensitive;
}
return normalStatus;

View File

@@ -1,53 +0,0 @@
import React from 'react';
import ImmutablePropTypes from 'react-immutable-proptypes';
import PropTypes from 'prop-types';
import DropdownMenuContainer from '../../../containers/dropdown_menu_container';
import { defineMessages, injectIntl } from 'react-intl';
const messages = defineMessages({
edit_profile: { id: 'account.edit_profile', defaultMessage: 'Edit profile' },
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
export default class ActionBar extends React.PureComponent {
static propTypes = {
account: ImmutablePropTypes.map.isRequired,
intl: PropTypes.object.isRequired,
};
render () {
const { intl } = this.props;
let menu = [];
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' });
return (
<div className='compose__action-bar'>
<div className='compose__action-bar-dropdown'>
<DropdownMenuContainer items={menu} icon='ellipsis-v' size={24} direction='right' />
</div>
</div>
);
}
}

View File

@@ -17,7 +17,6 @@ import { isMobile } from '../../../is_mobile';
import ImmutablePureComponent from 'react-immutable-pure-component';
import { length } from 'stringz';
import { countableText } from '../util/counter';
import { maxChars } from '../../../initial_state';
const allowedAroundShortCode = '><\u0085\u0020\u00a0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029\u0009\u000a\u000b\u000c\u000d';
@@ -81,7 +80,7 @@ export default class ComposeForm extends ImmutablePureComponent {
const { is_submitting, is_uploading, anyMedia } = this.props;
const fulltext = [this.props.spoiler_text, countableText(this.props.text)].join('');
if (is_submitting || is_uploading || length(fulltext) > maxChars || (fulltext.length !== 0 && fulltext.trim().length === 0 && !anyMedia)) {
if (is_submitting || is_uploading || length(fulltext) > 500 || (fulltext.length !== 0 && fulltext.trim().length === 0 && !anyMedia)) {
return;
}
@@ -159,7 +158,7 @@ export default class ComposeForm extends ImmutablePureComponent {
const { intl, onPaste, showSearch, anyMedia } = this.props;
const disabled = this.props.is_submitting;
const text = [this.props.spoiler_text, countableText(this.props.text)].join('');
const disabledButton = disabled || this.props.is_uploading || length(text) > maxChars || (text.length !== 0 && text.trim().length === 0 && !anyMedia);
const disabledButton = disabled || this.props.is_uploading || length(text) > 500 || (text.length !== 0 && text.trim().length === 0 && !anyMedia);
let publishText = '';
if (this.props.privacy === 'private' || this.props.privacy === 'direct') {
@@ -211,7 +210,7 @@ export default class ComposeForm extends ImmutablePureComponent {
<SensitiveButtonContainer />
<SpoilerButtonContainer />
</div>
<div className='character-counter__wrapper'><CharacterCounter max={maxChars} text={text} /></div>
<div className='character-counter__wrapper'><CharacterCounter max={500} text={text} /></div>
</div>
<div className='compose-form__publish'>

View File

@@ -1,10 +1,9 @@
import React from 'react';
import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes';
import ActionBar from './action_bar';
import Avatar from '../../../components/avatar';
import Permalink from '../../../components/permalink';
import IconButton from '../../../components/icon_button';
import Permalink from '../../../components/permalink';
import { FormattedMessage } from 'react-intl';
import ImmutablePureComponent from 'react-immutable-pure-component';
@@ -31,10 +30,7 @@ export default class NavigationBar extends ImmutablePureComponent {
<a href='/settings/profile' className='navigation-bar__profile-edit'><FormattedMessage id='navigation_bar.edit_profile' defaultMessage='Edit profile' /></a>
</div>
<div className='navigation-bar__actions'>
<IconButton className='close' title='' icon='close' onClick={this.props.onClose} />
<ActionBar account={this.props.account} />
</div>
<IconButton title='' icon='close' onClick={this.props.onClose} />
</div>
);
}

View File

@@ -11,6 +11,5 @@ export const boostModal = getMeta('boost_modal');
export const deleteModal = getMeta('delete_modal');
export const me = getMeta('me');
export const searchEnabled = getMeta('search_enabled');
export const maxChars = getMeta('max_toot_chars') || 500;
export default initialState;

View File

@@ -1510,21 +1510,9 @@ a.account__display-name {
text-decoration: none;
}
.navigation-bar__actions {
position: relative;
.icon-button.close {
position: absolute;
pointer-events: none;
transform: scale(0.0, 1.0) translate(-100%, 0);
opacity: 0;
}
.compose__action-bar .icon-button {
pointer-events: auto;
transform: scale(1.0, 1.0) translate(0, 0);
opacity: 1;
}
.icon-button {
pointer-events: none;
opacity: 0;
}
}
@@ -4944,18 +4932,9 @@ noscript {
transition: margin-top $duration $delay;
}
.navigation-bar__actions {
& > .icon-button.close {
will-change: opacity transform;
transition: opacity $duration * 0.5 $delay,
transform $duration $delay;
}
& > .compose__action-bar .icon-button {
will-change: opacity transform;
transition: opacity $duration * 0.5 $delay + $duration * 0.5,
transform $duration $delay;
}
& > .icon-button {
will-change: opacity;
transition: opacity $duration $delay;
}
}
@@ -4982,18 +4961,9 @@ noscript {
margin-top: -50px;
}
.navigation-bar__actions {
.icon-button.close {
pointer-events: auto;
opacity: 1;
transform: scale(1.0, 1.0) translate(0, 0);
}
.compose__action-bar .icon-button {
pointer-events: none;
opacity: 0;
transform: scale(0.0, 1.0) translate(100%, 0);
}
.icon-button {
pointer-events: auto;
opacity: 1;
}
}
}

View File

@@ -0,0 +1,6 @@
module Glitch
class ApplyKeywordMutesService < BaseService
def call(account)
end
end
end

View File

@@ -0,0 +1,13 @@
# frozen_string_literal: true
module Glitch
class ApplyKeywordMutesWorker
include Sidekiq::Worker
sidekiq_options unique: :until_executed
def perform(account_id)
Glitch::ApplyKeywordMutesService.new.call(Account.find(account_id))
end
end
end

View File

@@ -8,45 +8,18 @@ describe FollowerAccountsController do
let(:follower1) { Fabricate(:account) }
describe 'GET #index' do
let!(:follow0) { follower0.follow!(alice) }
let!(:follow1) { follower1.follow!(alice) }
it 'assigns follows' do
follow0 = follower0.follow!(alice)
follow1 = follower1.follow!(alice)
context 'when format is html' do
subject(:response) { get :index, params: { account_username: alice.username, format: :html } }
get :index, params: { account_username: alice.username }
it 'assigns follows' do
expect(response).to have_http_status(200)
assigned = assigns(:follows).to_a
expect(assigned.size).to eq 2
expect(assigned[0]).to eq follow1
expect(assigned[1]).to eq follow0
assigned = assigns(:follows).to_a
expect(assigned.size).to eq 2
expect(assigned[0]).to eq follow1
expect(assigned[1]).to eq follow0
end
end
context 'when format is json' do
subject(:response) { get :index, params: { account_username: alice.username, page: page, format: :json } }
subject(:body) { JSON.parse(response.body) }
context 'with page' do
let(:page) { 1 }
it 'returns followers' do
expect(response).to have_http_status(200)
expect(body['totalItems']).to eq 2
expect(body['partOf']).to be_present
end
end
context 'without page' do
let(:page) { nil }
it 'returns followers' do
expect(response).to have_http_status(200)
expect(body['totalItems']).to eq 2
expect(body['partOf']).to be_blank
end
end
expect(response).to have_http_status(200)
end
end
end

View File

@@ -8,45 +8,18 @@ describe FollowingAccountsController do
let(:followee1) { Fabricate(:account) }
describe 'GET #index' do
let!(:follow0) { alice.follow!(followee0) }
let!(:follow1) { alice.follow!(followee1) }
it 'assigns followees' do
follow0 = alice.follow!(followee0)
follow1 = alice.follow!(followee1)
context 'when format is html' do
subject(:response) { get :index, params: { account_username: alice.username, format: :html } }
get :index, params: { account_username: alice.username }
it 'assigns follows' do
expect(response).to have_http_status(200)
assigned = assigns(:follows).to_a
expect(assigned.size).to eq 2
expect(assigned[0]).to eq follow1
expect(assigned[1]).to eq follow0
assigned = assigns(:follows).to_a
expect(assigned.size).to eq 2
expect(assigned[0]).to eq follow1
expect(assigned[1]).to eq follow0
end
end
context 'when format is json' do
subject(:response) { get :index, params: { account_username: alice.username, page: page, format: :json } }
subject(:body) { JSON.parse(response.body) }
context 'with page' do
let(:page) { 1 }
it 'returns followers' do
expect(response).to have_http_status(200)
expect(body['totalItems']).to eq 2
expect(body['partOf']).to be_present
end
end
context 'without page' do
let(:page) { nil }
it 'returns followers' do
expect(response).to have_http_status(200)
expect(body['totalItems']).to eq 2
expect(body['partOf']).to be_blank
end
end
expect(response).to have_http_status(200)
end
end
end

View File

@@ -0,0 +1,5 @@
require 'rails_helper'
describe Glitch::ApplyKeywordMutesService, type: :service do
end