Merge remote-tracking branch 'origin/kb_development' into kb_migration
This commit is contained in:
commit
0071b15fa3
18 changed files with 455 additions and 2 deletions
|
@ -57,6 +57,7 @@ export const COMPOSE_COMPOSING_CHANGE = 'COMPOSE_COMPOSING_CHANGE';
|
||||||
export const COMPOSE_LANGUAGE_CHANGE = 'COMPOSE_LANGUAGE_CHANGE';
|
export const COMPOSE_LANGUAGE_CHANGE = 'COMPOSE_LANGUAGE_CHANGE';
|
||||||
|
|
||||||
export const COMPOSE_EMOJI_INSERT = 'COMPOSE_EMOJI_INSERT';
|
export const COMPOSE_EMOJI_INSERT = 'COMPOSE_EMOJI_INSERT';
|
||||||
|
export const COMPOSE_EXPIRATION_INSERT = 'COMPOSE_EXPIRATION_INSERT';
|
||||||
|
|
||||||
export const COMPOSE_UPLOAD_CHANGE_REQUEST = 'COMPOSE_UPLOAD_UPDATE_REQUEST';
|
export const COMPOSE_UPLOAD_CHANGE_REQUEST = 'COMPOSE_UPLOAD_UPDATE_REQUEST';
|
||||||
export const COMPOSE_UPLOAD_CHANGE_SUCCESS = 'COMPOSE_UPLOAD_UPDATE_SUCCESS';
|
export const COMPOSE_UPLOAD_CHANGE_SUCCESS = 'COMPOSE_UPLOAD_UPDATE_SUCCESS';
|
||||||
|
@ -742,6 +743,14 @@ export function insertEmojiCompose(position, emoji, needsSpace) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function insertExpirationCompose(position, data) {
|
||||||
|
return {
|
||||||
|
type: COMPOSE_EXPIRATION_INSERT,
|
||||||
|
position,
|
||||||
|
data,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function changeComposing(value) {
|
export function changeComposing(value) {
|
||||||
return {
|
return {
|
||||||
type: COMPOSE_COMPOSING_CHANGE,
|
type: COMPOSE_COMPOSING_CHANGE,
|
||||||
|
|
|
@ -44,9 +44,9 @@ class ActionBar extends React.PureComponent {
|
||||||
menu.push({ text: intl.formatMessage(messages.pins), to: '/pinned' });
|
menu.push({ text: intl.formatMessage(messages.pins), to: '/pinned' });
|
||||||
menu.push(null);
|
menu.push(null);
|
||||||
menu.push({ text: intl.formatMessage(messages.follow_requests), to: '/follow_requests' });
|
menu.push({ text: intl.formatMessage(messages.follow_requests), to: '/follow_requests' });
|
||||||
|
menu.push({ text: intl.formatMessage(messages.bookmarks), to: '/bookmarks' });
|
||||||
menu.push({ text: intl.formatMessage(messages.favourites), to: '/favourites' });
|
menu.push({ text: intl.formatMessage(messages.favourites), to: '/favourites' });
|
||||||
menu.push({ text: intl.formatMessage(messages.emoji_reactions), to: '/emoji_reactions' });
|
menu.push({ text: intl.formatMessage(messages.emoji_reactions), to: '/emoji_reactions' });
|
||||||
menu.push({ text: intl.formatMessage(messages.bookmarks), to: '/bookmarks' });
|
|
||||||
menu.push({ text: intl.formatMessage(messages.lists), to: '/lists' });
|
menu.push({ text: intl.formatMessage(messages.lists), to: '/lists' });
|
||||||
menu.push({ text: intl.formatMessage(messages.followed_tags), to: '/followed_tags' });
|
menu.push({ text: intl.formatMessage(messages.followed_tags), to: '/followed_tags' });
|
||||||
menu.push(null);
|
menu.push(null);
|
||||||
|
|
|
@ -11,6 +11,7 @@ import UploadButtonContainer from '../containers/upload_button_container';
|
||||||
import { defineMessages, injectIntl } from 'react-intl';
|
import { defineMessages, injectIntl } from 'react-intl';
|
||||||
import SpoilerButtonContainer from '../containers/spoiler_button_container';
|
import SpoilerButtonContainer from '../containers/spoiler_button_container';
|
||||||
import PrivacyDropdownContainer from '../containers/privacy_dropdown_container';
|
import PrivacyDropdownContainer from '../containers/privacy_dropdown_container';
|
||||||
|
import ExpirationDropdownContainer from '../containers/expiration_dropdown_container';
|
||||||
import EmojiPickerDropdown from '../containers/emoji_picker_dropdown_container';
|
import EmojiPickerDropdown from '../containers/emoji_picker_dropdown_container';
|
||||||
import PollFormContainer from '../containers/poll_form_container';
|
import PollFormContainer from '../containers/poll_form_container';
|
||||||
import UploadFormContainer from '../containers/upload_form_container';
|
import UploadFormContainer from '../containers/upload_form_container';
|
||||||
|
@ -60,6 +61,7 @@ class ComposeForm extends ImmutablePureComponent {
|
||||||
onChangeSpoilerText: PropTypes.func.isRequired,
|
onChangeSpoilerText: PropTypes.func.isRequired,
|
||||||
onPaste: PropTypes.func.isRequired,
|
onPaste: PropTypes.func.isRequired,
|
||||||
onPickEmoji: PropTypes.func.isRequired,
|
onPickEmoji: PropTypes.func.isRequired,
|
||||||
|
onPickExpiration: PropTypes.func.isRequired,
|
||||||
autoFocus: PropTypes.bool,
|
autoFocus: PropTypes.bool,
|
||||||
anyMedia: PropTypes.bool,
|
anyMedia: PropTypes.bool,
|
||||||
isInReply: PropTypes.bool,
|
isInReply: PropTypes.bool,
|
||||||
|
@ -206,6 +208,13 @@ class ComposeForm extends ImmutablePureComponent {
|
||||||
this.props.onPickEmoji(position, data, needsSpace);
|
this.props.onPickEmoji(position, data, needsSpace);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
handleExpirationPick = (data) => {
|
||||||
|
const { text } = this.props;
|
||||||
|
const position = this.autosuggestTextarea.textarea.selectionStart;
|
||||||
|
|
||||||
|
this.props.onPickExpiration(position, data);
|
||||||
|
};
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const { intl, onPaste, autoFocus } = this.props;
|
const { intl, onPaste, autoFocus } = this.props;
|
||||||
const disabled = this.props.isSubmitting;
|
const disabled = this.props.isSubmitting;
|
||||||
|
@ -277,6 +286,7 @@ class ComposeForm extends ImmutablePureComponent {
|
||||||
<PrivacyDropdownContainer disabled={this.props.isEditing} />
|
<PrivacyDropdownContainer disabled={this.props.isEditing} />
|
||||||
<SpoilerButtonContainer />
|
<SpoilerButtonContainer />
|
||||||
<LanguageDropdown />
|
<LanguageDropdown />
|
||||||
|
<ExpirationDropdownContainer onPickExpiration={this.handleExpirationPick} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className='character-counter__wrapper'>
|
<div className='character-counter__wrapper'>
|
||||||
|
|
|
@ -0,0 +1,268 @@
|
||||||
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import { injectIntl, defineMessages } from 'react-intl';
|
||||||
|
import IconButton from '../../../components/icon_button';
|
||||||
|
import Overlay from 'react-overlays/Overlay';
|
||||||
|
import { supportsPassiveEvents } from 'detect-passive-events';
|
||||||
|
import classNames from 'classnames';
|
||||||
|
import Icon from 'mastodon/components/icon';
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
add_expiration: { id: 'status.expiration.add', defaultMessage: 'Set status expiration' },
|
||||||
|
});
|
||||||
|
|
||||||
|
const listenerOptions = supportsPassiveEvents ? { passive: true } : false;
|
||||||
|
|
||||||
|
class ExpirationDropdownMenu extends React.PureComponent {
|
||||||
|
|
||||||
|
static propTypes = {
|
||||||
|
style: PropTypes.object,
|
||||||
|
items: PropTypes.array.isRequired,
|
||||||
|
value: PropTypes.string.isRequired,
|
||||||
|
onClose: PropTypes.func.isRequired,
|
||||||
|
onChange: PropTypes.func.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
handleDocumentClick = e => {
|
||||||
|
if (this.node && !this.node.contains(e.target)) {
|
||||||
|
this.props.onClose();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
handleKeyDown = e => {
|
||||||
|
const { items } = this.props;
|
||||||
|
const value = e.currentTarget.getAttribute('data-index');
|
||||||
|
const index = items.findIndex(item => {
|
||||||
|
return (item.value === value);
|
||||||
|
});
|
||||||
|
let element = null;
|
||||||
|
|
||||||
|
switch(e.key) {
|
||||||
|
case 'Escape':
|
||||||
|
this.props.onClose();
|
||||||
|
break;
|
||||||
|
case 'Enter':
|
||||||
|
this.handleClick(e);
|
||||||
|
break;
|
||||||
|
case 'ArrowDown':
|
||||||
|
element = this.node.childNodes[index + 1] || this.node.firstChild;
|
||||||
|
break;
|
||||||
|
case 'ArrowUp':
|
||||||
|
element = this.node.childNodes[index - 1] || this.node.lastChild;
|
||||||
|
break;
|
||||||
|
case 'Tab':
|
||||||
|
if (e.shiftKey) {
|
||||||
|
element = this.node.childNodes[index - 1] || this.node.lastChild;
|
||||||
|
} else {
|
||||||
|
element = this.node.childNodes[index + 1] || this.node.firstChild;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'Home':
|
||||||
|
element = this.node.firstChild;
|
||||||
|
break;
|
||||||
|
case 'End':
|
||||||
|
element = this.node.lastChild;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (element) {
|
||||||
|
element.focus();
|
||||||
|
this.props.onChange(element.getAttribute('data-index'));
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
handleClick = e => {
|
||||||
|
const value = e.currentTarget.getAttribute('data-index');
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
this.props.onClose();
|
||||||
|
this.props.onChange(value);
|
||||||
|
};
|
||||||
|
|
||||||
|
componentDidMount () {
|
||||||
|
document.addEventListener('click', this.handleDocumentClick, false);
|
||||||
|
document.addEventListener('touchend', this.handleDocumentClick, listenerOptions);
|
||||||
|
if (this.focusedItem) this.focusedItem.focus({ preventScroll: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount () {
|
||||||
|
document.removeEventListener('click', this.handleDocumentClick, false);
|
||||||
|
document.removeEventListener('touchend', this.handleDocumentClick, listenerOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
setRef = c => {
|
||||||
|
this.node = c;
|
||||||
|
};
|
||||||
|
|
||||||
|
setFocusRef = c => {
|
||||||
|
this.focusedItem = c;
|
||||||
|
};
|
||||||
|
|
||||||
|
render () {
|
||||||
|
const { style, items, value } = this.props;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{ ...style }} role='listbox' ref={this.setRef}>
|
||||||
|
{items.map(item => (
|
||||||
|
<div role='option' tabIndex='0' key={item.value} data-index={item.value} onKeyDown={this.handleKeyDown} onClick={this.handleClick} className={classNames('privacy-dropdown__option', { active: item.value === value })} aria-selected={item.value === value} ref={item.value === value ? this.setFocusRef : null}>
|
||||||
|
<div className='privacy-dropdown__option__content'>
|
||||||
|
<strong>{item.text}</strong>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default @injectIntl
|
||||||
|
class ExpirationDropdown extends React.PureComponent {
|
||||||
|
|
||||||
|
static propTypes = {
|
||||||
|
isUserTouching: PropTypes.func,
|
||||||
|
onModalOpen: PropTypes.func,
|
||||||
|
onModalClose: PropTypes.func,
|
||||||
|
value: PropTypes.string.isRequired,
|
||||||
|
onChange: PropTypes.func.isRequired,
|
||||||
|
noDirect: PropTypes.bool,
|
||||||
|
container: PropTypes.func,
|
||||||
|
disabled: PropTypes.bool,
|
||||||
|
intl: PropTypes.object.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
state = {
|
||||||
|
open: false,
|
||||||
|
placement: 'bottom',
|
||||||
|
};
|
||||||
|
|
||||||
|
handleToggle = () => {
|
||||||
|
if (this.props.isUserTouching && this.props.isUserTouching()) {
|
||||||
|
if (this.state.open) {
|
||||||
|
this.props.onModalClose();
|
||||||
|
} else {
|
||||||
|
this.props.onModalOpen({
|
||||||
|
actions: this.options.map(option => ({ ...option, active: option.value === this.props.value })),
|
||||||
|
onClick: this.handleModalActionClick,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (this.state.open && this.activeElement) {
|
||||||
|
this.activeElement.focus({ preventScroll: true });
|
||||||
|
}
|
||||||
|
this.setState({ open: !this.state.open });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
handleModalActionClick = (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
const { value } = this.options[e.currentTarget.getAttribute('data-index')];
|
||||||
|
|
||||||
|
this.props.onModalClose();
|
||||||
|
this.props.onChange(value);
|
||||||
|
};
|
||||||
|
|
||||||
|
handleKeyDown = e => {
|
||||||
|
switch(e.key) {
|
||||||
|
case 'Escape':
|
||||||
|
this.handleClose();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
handleMouseDown = () => {
|
||||||
|
if (!this.state.open) {
|
||||||
|
this.activeElement = document.activeElement;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
handleButtonKeyDown = (e) => {
|
||||||
|
switch(e.key) {
|
||||||
|
case ' ':
|
||||||
|
case 'Enter':
|
||||||
|
this.handleMouseDown();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
handleClose = () => {
|
||||||
|
if (this.state.open && this.activeElement) {
|
||||||
|
this.activeElement.focus({ preventScroll: true });
|
||||||
|
}
|
||||||
|
this.setState({ open: false });
|
||||||
|
};
|
||||||
|
|
||||||
|
handleChange = value => {
|
||||||
|
this.props.onChange(value);
|
||||||
|
};
|
||||||
|
|
||||||
|
componentWillMount () {
|
||||||
|
this.options = [
|
||||||
|
{ value: '#exp5m', text: '#exp5m (5 minutes)' },
|
||||||
|
{ value: '#exp30m', text: '#exp30m (30 minutes)' },
|
||||||
|
{ value: '#exp1h', text: '#exp1h (1 hour)' },
|
||||||
|
{ value: '#exp3h', text: '#exp3h (3 hours)' },
|
||||||
|
{ value: '#exp12h', text: '#exp12h (12 hours)' },
|
||||||
|
{ value: '#exp1d', text: '#exp1d (1 day)' },
|
||||||
|
{ value: '#exp7d', text: '#exp7d (7 days)' },
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
setTargetRef = c => {
|
||||||
|
this.target = c;
|
||||||
|
};
|
||||||
|
|
||||||
|
findTarget = () => {
|
||||||
|
return this.target;
|
||||||
|
};
|
||||||
|
|
||||||
|
handleOverlayEnter = (state) => {
|
||||||
|
this.setState({ placement: state.placement });
|
||||||
|
};
|
||||||
|
|
||||||
|
render () {
|
||||||
|
const { value, container, disabled, intl } = this.props;
|
||||||
|
const { open, placement } = this.state;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={classNames('privacy-dropdown', placement, { active: open })} onKeyDown={this.handleKeyDown}>
|
||||||
|
<div className={classNames('privacy-dropdown__value')} ref={this.setTargetRef}>
|
||||||
|
<IconButton
|
||||||
|
className='privacy-dropdown__value-icon'
|
||||||
|
icon='clock-o'
|
||||||
|
title={intl.formatMessage(messages.add_expiration)}
|
||||||
|
size={18}
|
||||||
|
expanded={open}
|
||||||
|
active={open}
|
||||||
|
inverted
|
||||||
|
onClick={this.handleToggle}
|
||||||
|
onMouseDown={this.handleMouseDown}
|
||||||
|
onKeyDown={this.handleButtonKeyDown}
|
||||||
|
style={{ height: null, lineHeight: '27px' }}
|
||||||
|
disabled={disabled}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Overlay show={open} placement={'bottom'} flip target={this.findTarget} container={container} popperConfig={{ strategy: 'fixed', onFirstUpdate: this.handleOverlayEnter }}>
|
||||||
|
{({ props, placement }) => (
|
||||||
|
<div {...props}>
|
||||||
|
<div className={`dropdown-animation privacy-dropdown__dropdown ${placement}`}>
|
||||||
|
<ExpirationDropdownMenu
|
||||||
|
items={this.options}
|
||||||
|
value={value}
|
||||||
|
onClose={this.handleClose}
|
||||||
|
onChange={this.handleChange}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</Overlay>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -8,6 +8,7 @@ import {
|
||||||
selectComposeSuggestion,
|
selectComposeSuggestion,
|
||||||
changeComposeSpoilerText,
|
changeComposeSpoilerText,
|
||||||
insertEmojiCompose,
|
insertEmojiCompose,
|
||||||
|
insertExpirationCompose,
|
||||||
uploadCompose,
|
uploadCompose,
|
||||||
} from '../../../actions/compose';
|
} from '../../../actions/compose';
|
||||||
|
|
||||||
|
@ -63,6 +64,10 @@ const mapDispatchToProps = (dispatch) => ({
|
||||||
dispatch(insertEmojiCompose(position, data, needsSpace));
|
dispatch(insertEmojiCompose(position, data, needsSpace));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onPickExpiration (position, data) {
|
||||||
|
dispatch(insertExpirationCompose(position, data));
|
||||||
|
},
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(mapStateToProps, mapDispatchToProps)(ComposeForm);
|
export default connect(mapStateToProps, mapDispatchToProps)(ComposeForm);
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
import { connect } from 'react-redux';
|
||||||
|
import ExpirationDropdown from '../components/expiration_dropdown';
|
||||||
|
import { changeComposeVisibility } from '../../../actions/compose';
|
||||||
|
import { openModal, closeModal } from '../../../actions/modal';
|
||||||
|
import { isUserTouching } from '../../../is_mobile';
|
||||||
|
|
||||||
|
const mapStateToProps = state => ({
|
||||||
|
value: state.getIn(['compose', 'privacy']),
|
||||||
|
});
|
||||||
|
|
||||||
|
const mapDispatchToProps = (dispatch, { onPickExpiration }) => ({
|
||||||
|
|
||||||
|
onChange (value) {
|
||||||
|
if (onPickExpiration) {
|
||||||
|
onPickExpiration(value);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
isUserTouching,
|
||||||
|
onModalOpen: props => dispatch(openModal('ACTIONS', props)),
|
||||||
|
onModalClose: () => dispatch(closeModal()),
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
export default connect(mapStateToProps, mapDispatchToProps)(ExpirationDropdown);
|
|
@ -32,6 +32,7 @@ import {
|
||||||
COMPOSE_LANGUAGE_CHANGE,
|
COMPOSE_LANGUAGE_CHANGE,
|
||||||
COMPOSE_COMPOSING_CHANGE,
|
COMPOSE_COMPOSING_CHANGE,
|
||||||
COMPOSE_EMOJI_INSERT,
|
COMPOSE_EMOJI_INSERT,
|
||||||
|
COMPOSE_EXPIRATION_INSERT,
|
||||||
COMPOSE_UPLOAD_CHANGE_REQUEST,
|
COMPOSE_UPLOAD_CHANGE_REQUEST,
|
||||||
COMPOSE_UPLOAD_CHANGE_SUCCESS,
|
COMPOSE_UPLOAD_CHANGE_SUCCESS,
|
||||||
COMPOSE_UPLOAD_CHANGE_FAIL,
|
COMPOSE_UPLOAD_CHANGE_FAIL,
|
||||||
|
@ -217,6 +218,17 @@ const insertEmoji = (state, position, emojiData, needsSpace) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const insertExpiration = (state, position, data) => {
|
||||||
|
const oldText = state.get('text');
|
||||||
|
|
||||||
|
return state.merge({
|
||||||
|
text: `${oldText.slice(0, position)} ${data} ${oldText.slice(position)}`,
|
||||||
|
focusDate: new Date(),
|
||||||
|
caretPosition: position + data.length + 1,
|
||||||
|
idempotencyKey: uuid(),
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const privacyPreference = (a, b) => {
|
const privacyPreference = (a, b) => {
|
||||||
const order = ['public', 'public_unlisted', 'unlisted', 'private', 'direct'];
|
const order = ['public', 'public_unlisted', 'unlisted', 'private', 'direct'];
|
||||||
return order[Math.max(order.indexOf(a), order.indexOf(b), 0)];
|
return order[Math.max(order.indexOf(a), order.indexOf(b), 0)];
|
||||||
|
@ -443,6 +455,8 @@ export default function compose(state = initialState, action) {
|
||||||
}
|
}
|
||||||
case COMPOSE_EMOJI_INSERT:
|
case COMPOSE_EMOJI_INSERT:
|
||||||
return insertEmoji(state, action.position, action.emoji, action.needsSpace);
|
return insertEmoji(state, action.position, action.emoji, action.needsSpace);
|
||||||
|
case COMPOSE_EXPIRATION_INSERT:
|
||||||
|
return insertExpiration(state, action.position, action.data);
|
||||||
case COMPOSE_UPLOAD_CHANGE_SUCCESS:
|
case COMPOSE_UPLOAD_CHANGE_SUCCESS:
|
||||||
return state
|
return state
|
||||||
.set('is_changing_upload', false)
|
.set('is_changing_upload', false)
|
||||||
|
|
|
@ -19,6 +19,7 @@ module AccountAssociations
|
||||||
has_many :notifications, inverse_of: :account, dependent: :destroy
|
has_many :notifications, inverse_of: :account, dependent: :destroy
|
||||||
has_many :conversations, class_name: 'AccountConversation', dependent: :destroy, inverse_of: :account
|
has_many :conversations, class_name: 'AccountConversation', dependent: :destroy, inverse_of: :account
|
||||||
has_many :scheduled_statuses, inverse_of: :account, dependent: :destroy
|
has_many :scheduled_statuses, inverse_of: :account, dependent: :destroy
|
||||||
|
has_many :scheduled_expiration_statuses, inverse_of: :account, dependent: :destroy
|
||||||
|
|
||||||
# Pinned statuses
|
# Pinned statuses
|
||||||
has_many :status_pins, inverse_of: :account, dependent: :destroy
|
has_many :status_pins, inverse_of: :account, dependent: :destroy
|
||||||
|
|
36
app/models/scheduled_expiration_status.rb
Normal file
36
app/models/scheduled_expiration_status.rb
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
# == Schema Information
|
||||||
|
#
|
||||||
|
# Table name: scheduled_expiration_statuses
|
||||||
|
#
|
||||||
|
# id :bigint(8) not null, primary key
|
||||||
|
# account_id :bigint(8)
|
||||||
|
# status_id :bigint(8) not null
|
||||||
|
# scheduled_at :datetime
|
||||||
|
# created_at :datetime not null
|
||||||
|
# updated_at :datetime not null
|
||||||
|
#
|
||||||
|
|
||||||
|
class ScheduledExpirationStatus < ApplicationRecord
|
||||||
|
include Paginable
|
||||||
|
|
||||||
|
TOTAL_LIMIT = 300
|
||||||
|
DAILY_LIMIT = 25
|
||||||
|
|
||||||
|
belongs_to :account, inverse_of: :scheduled_expiration_statuses
|
||||||
|
belongs_to :status, inverse_of: :scheduled_expiration_status
|
||||||
|
|
||||||
|
validate :validate_total_limit
|
||||||
|
validate :validate_daily_limit
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def validate_total_limit
|
||||||
|
errors.add(:base, I18n.t('scheduled_expiration_statuses.over_total_limit', limit: TOTAL_LIMIT)) if account.scheduled_expiration_statuses.count >= TOTAL_LIMIT
|
||||||
|
end
|
||||||
|
|
||||||
|
def validate_daily_limit
|
||||||
|
errors.add(:base, I18n.t('scheduled_expiration_statuses.over_daily_limit', limit: DAILY_LIMIT)) if account.scheduled_expiration_statuses.where('scheduled_at::date = ?::date', scheduled_at).count >= DAILY_LIMIT
|
||||||
|
end
|
||||||
|
end
|
|
@ -81,6 +81,7 @@ class Status < ApplicationRecord
|
||||||
has_one :status_stat, inverse_of: :status
|
has_one :status_stat, inverse_of: :status
|
||||||
has_one :poll, inverse_of: :status, dependent: :destroy
|
has_one :poll, inverse_of: :status, dependent: :destroy
|
||||||
has_one :trend, class_name: 'StatusTrend', inverse_of: :status
|
has_one :trend, class_name: 'StatusTrend', inverse_of: :status
|
||||||
|
has_one :scheduled_expiration_status, inverse_of: :status, dependent: :destroy
|
||||||
|
|
||||||
validates :uri, uniqueness: true, presence: true, unless: :local?
|
validates :uri, uniqueness: true, presence: true, unless: :local?
|
||||||
validates :text, presence: true, unless: -> { with_media? || reblog? }
|
validates :text, presence: true, unless: -> { with_media? || reblog? }
|
||||||
|
|
|
@ -26,6 +26,7 @@ class DeleteAccountService < BaseService
|
||||||
passive_relationships
|
passive_relationships
|
||||||
report_notes
|
report_notes
|
||||||
scheduled_statuses
|
scheduled_statuses
|
||||||
|
scheduled_expiration_statuses
|
||||||
status_pins
|
status_pins
|
||||||
).freeze
|
).freeze
|
||||||
|
|
||||||
|
@ -51,6 +52,7 @@ class DeleteAccountService < BaseService
|
||||||
notifications
|
notifications
|
||||||
owned_lists
|
owned_lists
|
||||||
scheduled_statuses
|
scheduled_statuses
|
||||||
|
scheduled_expiration_statuses
|
||||||
status_pins
|
status_pins
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -76,6 +76,8 @@ class PostStatusService < BaseService
|
||||||
@status = @account.statuses.new(status_attributes)
|
@status = @account.statuses.new(status_attributes)
|
||||||
process_mentions_service.call(@status, save_records: false)
|
process_mentions_service.call(@status, save_records: false)
|
||||||
safeguard_mentions!(@status)
|
safeguard_mentions!(@status)
|
||||||
|
|
||||||
|
UpdateStatusExpirationService.new.call(@status)
|
||||||
|
|
||||||
# The following transaction block is needed to wrap the UPDATEs to
|
# The following transaction block is needed to wrap the UPDATEs to
|
||||||
# the media attachments when the status is created
|
# the media attachments when the status is created
|
||||||
|
|
20
app/services/update_status_expiration_service.rb
Normal file
20
app/services/update_status_expiration_service.rb
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class UpdateStatusExpirationService < BaseService
|
||||||
|
SCAN_EXPIRATION_RE = /#exp((\d{1,4}\.\d{1,2}|\d{1,4}))(d|h|m|s)/
|
||||||
|
|
||||||
|
def call(status)
|
||||||
|
existing_expiration = ScheduledExpirationStatus.find_by(status: status)
|
||||||
|
existing_expiration.destroy! if existing_expiration
|
||||||
|
|
||||||
|
expiration = status.text.scan(SCAN_EXPIRATION_RE).first
|
||||||
|
return if !expiration
|
||||||
|
|
||||||
|
expiration_num = expiration[1].to_f
|
||||||
|
expiration_option = expiration[2]
|
||||||
|
base_time = status.created_at || Time.now.utc
|
||||||
|
|
||||||
|
expired_at = base_time + (expiration_option == 'd' ? expiration_num.days : expiration_option == 'h' ? expiration_num.hours : expiration_option == 's' ? expiration_num.seconds : expiration_num.minutes)
|
||||||
|
ScheduledExpirationStatus.create!(account: status.account, status: status, scheduled_at: expired_at)
|
||||||
|
end
|
||||||
|
end
|
|
@ -117,11 +117,17 @@ class UpdateStatusService < BaseService
|
||||||
|
|
||||||
# We raise here to rollback the entire transaction
|
# We raise here to rollback the entire transaction
|
||||||
raise NoChangesSubmittedError unless significant_changes?
|
raise NoChangesSubmittedError unless significant_changes?
|
||||||
|
|
||||||
|
update_expiration!
|
||||||
|
|
||||||
@status.edited_at = Time.now.utc
|
@status.edited_at = Time.now.utc
|
||||||
@status.save!
|
@status.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update_expiration!
|
||||||
|
UpdateStatusExpirationService.new.call(@status)
|
||||||
|
end
|
||||||
|
|
||||||
def reset_preview_card!
|
def reset_preview_card!
|
||||||
return unless @status.text_previously_changed?
|
return unless @status.text_previously_changed?
|
||||||
|
|
||||||
|
|
16
app/workers/remove_expired_status_worker.rb
Normal file
16
app/workers/remove_expired_status_worker.rb
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class RemoveExpiredStatusWorker
|
||||||
|
include Sidekiq::Worker
|
||||||
|
|
||||||
|
sidekiq_options lock: :until_executed
|
||||||
|
|
||||||
|
def perform(scheduled_expiration_status_id)
|
||||||
|
scheduled_expiration_status = ScheduledExpirationStatus.find(scheduled_expiration_status_id)
|
||||||
|
scheduled_expiration_status.destroy!
|
||||||
|
|
||||||
|
RemoveStatusService.new.call(scheduled_expiration_status.status)
|
||||||
|
rescue ActiveRecord::RecordNotFound, ActiveRecord::RecordInvalid
|
||||||
|
true
|
||||||
|
end
|
||||||
|
end
|
|
@ -7,6 +7,7 @@ class Scheduler::ScheduledStatusesScheduler
|
||||||
|
|
||||||
def perform
|
def perform
|
||||||
publish_scheduled_statuses!
|
publish_scheduled_statuses!
|
||||||
|
unpublish_expired_statuses!
|
||||||
publish_scheduled_announcements!
|
publish_scheduled_announcements!
|
||||||
unpublish_expired_announcements!
|
unpublish_expired_announcements!
|
||||||
end
|
end
|
||||||
|
@ -19,10 +20,20 @@ class Scheduler::ScheduledStatusesScheduler
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def unpublish_expired_statuses!
|
||||||
|
expired_statuses.find_each do |expired_status|
|
||||||
|
RemoveExpiredStatusWorker.perform_at(expired_status.scheduled_at, expired_status.id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def due_statuses
|
def due_statuses
|
||||||
ScheduledStatus.where('scheduled_at <= ?', Time.now.utc + PostStatusService::MIN_SCHEDULE_OFFSET)
|
ScheduledStatus.where('scheduled_at <= ?', Time.now.utc + PostStatusService::MIN_SCHEDULE_OFFSET)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def expired_statuses
|
||||||
|
ScheduledExpirationStatus.where('scheduled_at <= ?', Time.now.utc + PostStatusService::MIN_SCHEDULE_OFFSET)
|
||||||
|
end
|
||||||
|
|
||||||
def publish_scheduled_announcements!
|
def publish_scheduled_announcements!
|
||||||
due_announcements.find_each do |announcement|
|
due_announcements.find_each do |announcement|
|
||||||
PublishScheduledAnnouncementWorker.perform_at(announcement.scheduled_at, announcement.id)
|
PublishScheduledAnnouncementWorker.perform_at(announcement.scheduled_at, announcement.id)
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class CreateScheduledExpirationStatuses < ActiveRecord::Migration[6.1]
|
||||||
|
def change
|
||||||
|
create_table :scheduled_expiration_statuses do |t|
|
||||||
|
t.belongs_to :account, foreign_key: { on_delete: :cascade }
|
||||||
|
t.belongs_to :status, null: false, foreign_key: { on_delete: :cascade }
|
||||||
|
t.datetime :scheduled_at, index: true
|
||||||
|
|
||||||
|
t.datetime :created_at, null: false
|
||||||
|
t.datetime :updated_at, null: false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
15
db/schema.rb
15
db/schema.rb
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 2023_03_14_121142) do
|
ActiveRecord::Schema.define(version: 2023_03_20_234918) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
@ -844,6 +844,17 @@ ActiveRecord::Schema.define(version: 2023_03_14_121142) do
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
create_table "scheduled_expiration_statuses", force: :cascade do |t|
|
||||||
|
t.bigint "account_id"
|
||||||
|
t.bigint "status_id", null: false
|
||||||
|
t.datetime "scheduled_at"
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
t.index ["account_id"], name: "index_scheduled_expiration_statuses_on_account_id"
|
||||||
|
t.index ["scheduled_at"], name: "index_scheduled_expiration_statuses_on_scheduled_at"
|
||||||
|
t.index ["status_id"], name: "index_scheduled_expiration_statuses_on_status_id"
|
||||||
|
end
|
||||||
|
|
||||||
create_table "scheduled_statuses", force: :cascade do |t|
|
create_table "scheduled_statuses", force: :cascade do |t|
|
||||||
t.bigint "account_id"
|
t.bigint "account_id"
|
||||||
t.datetime "scheduled_at"
|
t.datetime "scheduled_at"
|
||||||
|
@ -1222,6 +1233,8 @@ ActiveRecord::Schema.define(version: 2023_03_14_121142) do
|
||||||
add_foreign_key "reports", "accounts", column: "assigned_account_id", on_delete: :nullify
|
add_foreign_key "reports", "accounts", column: "assigned_account_id", on_delete: :nullify
|
||||||
add_foreign_key "reports", "accounts", column: "target_account_id", name: "fk_eb37af34f0", on_delete: :cascade
|
add_foreign_key "reports", "accounts", column: "target_account_id", name: "fk_eb37af34f0", on_delete: :cascade
|
||||||
add_foreign_key "reports", "accounts", name: "fk_4b81f7522c", on_delete: :cascade
|
add_foreign_key "reports", "accounts", name: "fk_4b81f7522c", on_delete: :cascade
|
||||||
|
add_foreign_key "scheduled_expiration_statuses", "accounts", on_delete: :cascade
|
||||||
|
add_foreign_key "scheduled_expiration_statuses", "statuses", on_delete: :cascade
|
||||||
add_foreign_key "scheduled_statuses", "accounts", on_delete: :cascade
|
add_foreign_key "scheduled_statuses", "accounts", on_delete: :cascade
|
||||||
add_foreign_key "session_activations", "oauth_access_tokens", column: "access_token_id", name: "fk_957e5bda89", on_delete: :cascade
|
add_foreign_key "session_activations", "oauth_access_tokens", column: "access_token_id", name: "fk_957e5bda89", on_delete: :cascade
|
||||||
add_foreign_key "session_activations", "users", name: "fk_e5fda67334", on_delete: :cascade
|
add_foreign_key "session_activations", "users", name: "fk_e5fda67334", on_delete: :cascade
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue