Skip to content

Commit

Permalink
Per-status control for unlisted mode, also federation for unlisted mode
Browse files Browse the repository at this point in the history
Fix #233, fix #268
  • Loading branch information
Gargron committed Nov 30, 2016
1 parent 1b447c1 commit 14bd469
Show file tree
Hide file tree
Showing 31 changed files with 175 additions and 82 deletions.
12 changes: 6 additions & 6 deletions Gemfile.lock
@@ -1,6 +1,6 @@
GIT
remote: https://github.com/rails/rails.git
revision: ecb394a31420f6fd1d0ab692c79f2dd44176e2c9
revision: c7a716aa5a692cae301d56b345faa5d79cbfc320
branch: 5-0-stable
specs:
actioncable (5.0.0.1)
Expand Down Expand Up @@ -110,7 +110,7 @@ GEM
coffee-script-source (1.10.0)
colorize (0.8.1)
concurrent-ruby (1.0.2)
connection_pool (2.2.0)
connection_pool (2.2.1)
crack (0.4.3)
safe_yaml (~> 1.0.0)
debug_inspector (0.0.2)
Expand Down Expand Up @@ -287,7 +287,7 @@ GEM
execjs
railties (>= 3.2)
tilt
redis (3.3.1)
redis (3.3.2)
redis-actionpack (5.0.0)
actionpack (>= 4.0.0, < 6)
redis-rack (~> 2.0.0.pre)
Expand Down Expand Up @@ -348,10 +348,10 @@ GEM
sdoc (0.4.1)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
sidekiq (4.2.1)
sidekiq (4.2.7)
concurrent-ruby (~> 1.0)
connection_pool (~> 2.2, >= 2.2.0)
rack-protection (~> 1.5)
rack-protection (>= 1.5.0)
redis (~> 3.2, >= 3.2.1)
simple_form (3.2.1)
actionpack (> 4, < 5.1)
Expand All @@ -374,7 +374,7 @@ GEM
tins (~> 1.0)
terminal-table (1.7.0)
unicode-display_width (~> 1.1)
thor (0.19.1)
thor (0.19.4)
thread (0.2.2)
thread_safe (0.3.5)
tilt (2.0.5)
Expand Down
11 changes: 10 additions & 1 deletion app/assets/javascripts/components/actions/compose.jsx
Expand Up @@ -23,6 +23,7 @@ export const COMPOSE_MOUNT = 'COMPOSE_MOUNT';
export const COMPOSE_UNMOUNT = 'COMPOSE_UNMOUNT';

export const COMPOSE_SENSITIVITY_CHANGE = 'COMPOSE_SENSITIVITY_CHANGE';
export const COMPOSE_VISIBILITY_CHANGE = 'COMPOSE_VISIBILITY_CHANGE';

export function changeCompose(text) {
return {
Expand Down Expand Up @@ -65,7 +66,8 @@ export function submitCompose() {
status: getState().getIn(['compose', 'text'], ''),
in_reply_to_id: getState().getIn(['compose', 'in_reply_to'], null),
media_ids: getState().getIn(['compose', 'media_attachments']).map(item => item.get('id')),
sensitive: getState().getIn(['compose', 'sensitive'])
sensitive: getState().getIn(['compose', 'sensitive']),
unlisted: getState().getIn(['compose', 'unlisted'])
}).then(function (response) {
dispatch(submitComposeSuccess(response.data));
dispatch(updateTimeline('home', response.data));
Expand Down Expand Up @@ -207,3 +209,10 @@ export function changeComposeSensitivity(checked) {
checked
};
};

export function changeComposeVisibility(checked) {
return {
type: COMPOSE_VISIBILITY_CHANGE,
checked
};
};
Expand Up @@ -70,6 +70,7 @@ const ComposeForm = React.createClass({
suggestion_token: React.PropTypes.string,
suggestions: React.PropTypes.array,
sensitive: React.PropTypes.bool,
unlisted: React.PropTypes.bool,
is_submitting: React.PropTypes.bool,
is_uploading: React.PropTypes.bool,
in_reply_to: ImmutablePropTypes.map,
Expand All @@ -79,7 +80,8 @@ const ComposeForm = React.createClass({
onClearSuggestions: React.PropTypes.func.isRequired,
onFetchSuggestions: React.PropTypes.func.isRequired,
onSuggestionSelected: React.PropTypes.func.isRequired,
onChangeSensitivity: React.PropTypes.func.isRequired
onChangeSensitivity: React.PropTypes.func.isRequired,
onChangeVisibility: React.PropTypes.func.isRequired
},

mixins: [PureRenderMixin],
Expand Down Expand Up @@ -147,6 +149,10 @@ const ComposeForm = React.createClass({
this.props.onChangeSensitivity(e.target.checked);
},

handleChangeVisibility (e) {
this.props.onChangeVisibility(e.target.checked);
},

render () {
const { intl } = this.props;
let replyArea = '';
Expand Down Expand Up @@ -187,7 +193,12 @@ const ComposeForm = React.createClass({
<UploadButtonContainer style={{ paddingTop: '4px' }} />
</div>

<label style={{ display: 'block', lineHeight: '24px', verticalAlign: 'middle', marginTop: '10px', borderTop: '1px solid #616b86', paddingTop: '10px' }}>
<label style={{ display: 'block', lineHeight: '24px', verticalAlign: 'middle', marginTop: '10px', borderTop: '1px solid #282c37', paddingTop: '10px' }}>
<Toggle checked={this.props.unlisted} onChange={this.handleChangeVisibility} />
<span style={{ display: 'inline-block', verticalAlign: 'middle', marginBottom: '14px', marginLeft: '8px', color: '#9baec8' }}><FormattedMessage id='compose_form.unlisted' defaultMessage='Unlisted mode' /></span>
</label>

<label style={{ display: 'block', lineHeight: '24px', verticalAlign: 'middle' }}>
<Toggle checked={this.props.sensitive} onChange={this.handleChangeSensitivity} />
<span style={{ display: 'inline-block', verticalAlign: 'middle', marginBottom: '14px', marginLeft: '8px', color: '#9baec8' }}><FormattedMessage id='compose_form.sensitive' defaultMessage='Mark content as sensitive' /></span>
</label>
Expand Down
Expand Up @@ -7,7 +7,8 @@ import {
clearComposeSuggestions,
fetchComposeSuggestions,
selectComposeSuggestion,
changeComposeSensitivity
changeComposeSensitivity,
changeComposeVisibility
} from '../../../actions/compose';
import { makeGetStatus } from '../../../selectors';

Expand All @@ -20,6 +21,7 @@ const makeMapStateToProps = () => {
suggestion_token: state.getIn(['compose', 'suggestion_token']),
suggestions: state.getIn(['compose', 'suggestions']).toJS(),
sensitive: state.getIn(['compose', 'sensitive']),
unlisted: state.getIn(['compose', 'unlisted']),
is_submitting: state.getIn(['compose', 'is_submitting']),
is_uploading: state.getIn(['compose', 'is_uploading']),
in_reply_to: getStatus(state, state.getIn(['compose', 'in_reply_to']))
Expand Down Expand Up @@ -57,6 +59,10 @@ const mapDispatchToProps = function (dispatch) {

onChangeSensitivity (checked) {
dispatch(changeComposeSensitivity(checked));
},

onChangeVisibility (checked) {
dispatch(changeComposeVisibility(checked));
}
}
};
Expand Down
2 changes: 2 additions & 0 deletions app/assets/javascripts/components/locales/de.jsx
Expand Up @@ -34,6 +34,8 @@ const en = {
"tabs_bar.notifications": "Mitteilungen",
"compose_form.placeholder": "Worüber möchstest du schreiben?",
"compose_form.publish": "Veröffentlichen",
"compose_form.sensitive": "Medien als sensitiv markieren",
"compose_form.unlisted": "Öffentlich nicht auflisten",
"navigation_bar.settings": "Einstellungen",
"navigation_bar.public_timeline": "Öffentlich",
"navigation_bar.logout": "Abmelden",
Expand Down
1 change: 1 addition & 0 deletions app/assets/javascripts/components/locales/en.jsx
Expand Up @@ -38,6 +38,7 @@ const en = {
"compose_form.placeholder": "What is on your mind?",
"compose_form.publish": "Toot",
"compose_form.sensitive": "Mark content as sensitive",
"compose_form.unlisted": "Unlisted mode",
"navigation_bar.settings": "Settings",
"navigation_bar.public_timeline": "Public timeline",
"navigation_bar.logout": "Logout",
Expand Down
2 changes: 2 additions & 0 deletions app/assets/javascripts/components/locales/es.jsx
Expand Up @@ -35,6 +35,8 @@ const es = {
"tabs_bar.notifications": "Notificaciones",
"compose_form.placeholder": "¿En qué estás pensando?",
"compose_form.publish": "Publicar",
"compose_form.sensitive": null,
"compose_form.unlisted": "No listado",
"navigation_bar.settings": "Ajustes",
"navigation_bar.public_timeline": "Público",
"navigation_bar.logout": "Cerrar sesión",
Expand Down
3 changes: 2 additions & 1 deletion app/assets/javascripts/components/locales/fr.jsx
Expand Up @@ -36,7 +36,8 @@ const fr = {
"tabs_bar.notifications": "Notifications",
"compose_form.placeholder": "Qu’avez-vous en tête ?",
"compose_form.publish": "Pouet",
"compose_form.sensitive": "Marquer le contenu comme délicat",
"compose_form.sensitive": "Marquer le contenu comme délicat",
"compose_form.unlisted": "Ne pas apparaître dans le fil public",
"navigation_bar.settings": "Paramètres",
"navigation_bar.public_timeline": "Public",
"navigation_bar.logout": "Déconnexion",
Expand Down
1 change: 1 addition & 0 deletions app/assets/javascripts/components/locales/hu.jsx
Expand Up @@ -37,6 +37,7 @@ const hu = {
"compose_form.placeholder": "Mire gondolsz?",
"compose_form.publish": "Tülk!",
"compose_form.sensitive": "Tartalom érzékenynek jelölése",
"compose_form.unlisted": "Listázatlan mód",
"navigation_bar.settings": "Beállítások",
"navigation_bar.public_timeline": "Nyilvános időfolyam",
"navigation_bar.logout": "Kijelentkezés",
Expand Down
2 changes: 2 additions & 0 deletions app/assets/javascripts/components/locales/pt.jsx
Expand Up @@ -33,6 +33,8 @@ const pt = {
"tabs_bar.public": "Público",
"compose_form.placeholder": "Que estás pensando?",
"compose_form.publish": "Publicar",
"compose_form.sensitive": null,
"compose_form.unlisted": null,
"navigation_bar.settings": "Configurações",
"navigation_bar.public_timeline": "Timeline Pública",
"navigation_bar.logout": "Logout",
Expand Down
6 changes: 5 additions & 1 deletion app/assets/javascripts/components/reducers/compose.jsx
Expand Up @@ -16,7 +16,8 @@ import {
COMPOSE_SUGGESTIONS_CLEAR,
COMPOSE_SUGGESTIONS_READY,
COMPOSE_SUGGESTION_SELECT,
COMPOSE_SENSITIVITY_CHANGE
COMPOSE_SENSITIVITY_CHANGE,
COMPOSE_VISIBILITY_CHANGE
} from '../actions/compose';
import { TIMELINE_DELETE } from '../actions/timelines';
import { ACCOUNT_SET_SELF } from '../actions/accounts';
Expand All @@ -25,6 +26,7 @@ import Immutable from 'immutable';
const initialState = Immutable.Map({
mounted: false,
sensitive: false,
unlisted: false,
text: '',
in_reply_to: null,
is_submitting: false,
Expand Down Expand Up @@ -91,6 +93,8 @@ export default function compose(state = initialState, action) {
return state.set('mounted', false);
case COMPOSE_SENSITIVITY_CHANGE:
return state.set('sensitive', action.checked);
case COMPOSE_VISIBILITY_CHANGE:
return state.set('unlisted', action.checked);
case COMPOSE_CHANGE:
return state.set('text', action.text);
case COMPOSE_REPLY:
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/api/v1/statuses_controller.rb
Expand Up @@ -52,7 +52,7 @@ def favourited_by
end

def create
@status = PostStatusService.new.call(current_user.account, params[:status], params[:in_reply_to_id].blank? ? nil : Status.find(params[:in_reply_to_id]), media_ids: params[:media_ids], sensitive: params[:sensitive])
@status = PostStatusService.new.call(current_user.account, params[:status], params[:in_reply_to_id].blank? ? nil : Status.find(params[:in_reply_to_id]), media_ids: params[:media_ids], sensitive: params[:sensitive], unlisted: params[:unlisted])
render action: :show
end

Expand All @@ -73,7 +73,7 @@ def unreblog
@reblogged_map = { @status.id => false }

RemovalWorker.perform_async(reblog.id)

render action: :show
end

Expand Down
@@ -1,3 +1,4 @@
# frozen_string_literal: true
module ObfuscateFilename
extend ActiveSupport::Concern

Expand All @@ -11,6 +12,6 @@ def obfuscate_filename(path)
file = params.dig(*path)
return if file.nil?

file.original_filename = "media" + File.extname(file.original_filename)
file.original_filename = 'media' + File.extname(file.original_filename)
end
end
2 changes: 1 addition & 1 deletion app/controllers/settings/profiles_controller.rb
Expand Up @@ -24,7 +24,7 @@ def update
private

def account_params
params.require(:account).permit(:display_name, :note, :avatar, :header, :silenced)
params.require(:account).permit(:display_name, :note, :avatar, :header)
end

def set_account
Expand Down
38 changes: 27 additions & 11 deletions app/helpers/atom_builder_helper.rb
Expand Up @@ -38,7 +38,7 @@ def updated_at(xml, date)
end

def verb(xml, verb)
xml['activity'].send('verb', "http://activitystrea.ms/schema/1.0/#{verb}")
xml['activity'].send('verb', TagManager::VERBS[verb])
end

def content(xml, content)
Expand All @@ -62,7 +62,7 @@ def target(xml, &block)
end

def object_type(xml, type)
xml['activity'].send('object-type', "http://activitystrea.ms/schema/1.0/#{type}")
xml['activity'].send('object-type', TagManager::TYPES[type])
end

def uri(xml, uri)
Expand Down Expand Up @@ -108,7 +108,7 @@ def in_reply_to(xml, uri, url)
end

def link_mention(xml, account)
xml.link(rel: 'mentioned', href: TagManager.instance.uri_for(account))
xml.link(:rel => 'mentioned', :href => TagManager.instance.uri_for(account), 'ostatus:object-type' => TagManager::TYPES[:person])
end

def link_enclosure(xml, media)
Expand Down Expand Up @@ -139,6 +139,11 @@ def conditionally_formatted(activity)
end
end

def link_visibility(xml, item)
return unless item.respond_to?(:visibility) && item.public_visibility?
xml.link(:rel => 'mentioned', :href => TagManager::COLLECTIONS[:public], 'ostatus:object-type' => TagManager::TYPES[:collection])
end

def include_author(xml, account)
object_type xml, :person
uri xml, TagManager.instance.uri_for(account)
Expand Down Expand Up @@ -189,6 +194,8 @@ def include_entry(xml, stream_entry)
include_author xml, stream_entry.target.account
end

link_visibility xml, stream_entry.target

stream_entry.target.mentions.each do |mention|
link_mention xml, mention.account
end
Expand All @@ -204,25 +211,34 @@ def include_entry(xml, stream_entry)
end
end

link_visibility xml, stream_entry.activity

stream_entry.mentions.each do |mentioned|
link_mention xml, mentioned
end

if stream_entry.activity.is_a?(Status)
stream_entry.activity.media_attachments.each do |media|
link_enclosure xml, media
end
return unless stream_entry.activity.is_a?(Status)

stream_entry.activity.tags.each do |tag|
category xml, tag
end
stream_entry.activity.media_attachments.each do |media|
link_enclosure xml, media
end

stream_entry.activity.tags.each do |tag|
category xml, tag
end
end

private

def root_tag(xml, tag, &block)
xml.send(tag, { :xmlns => 'http://www.w3.org/2005/Atom', 'xmlns:thr' => 'http://purl.org/syndication/thread/1.0', 'xmlns:activity' => 'http://activitystrea.ms/spec/1.0/', 'xmlns:poco' => 'http://portablecontacts.net/spec/1.0', 'xmlns:media' => 'http://purl.org/syndication/atommedia' }, &block)
xml.send(tag, {
'xmlns' => TagManager::XMLNS,
'xmlns:thr' => TagManager::THR_XMLNS,
'xmlns:activity' => TagManager::AS_XMLNS,
'xmlns:poco' => TagManager::POCO_XMLNS,
'xmlns:media' => TagManager::MEDIA_XMLNS,
'xmlns:ostatus' => TagManager::OS_XMLNS,
}, &block)
end

def single_link_avatar(xml, account, size, px)
Expand Down
31 changes: 31 additions & 0 deletions app/lib/tag_manager.rb
Expand Up @@ -6,6 +6,37 @@ class TagManager
include Singleton
include RoutingHelper

VERBS = {
post: 'http://activitystrea.ms/schema/1.0/post',
share: 'http://activitystrea.ms/schema/1.0/share',
favorite: 'http://activitystrea.ms/schema/1.0/favorite',
unfavorite: 'http://activitystrea.ms/schema/1.0/unfavorite',
delete: 'delete',
follow: 'http://activitystrea.ms/schema/1.0/follow',
unfollow: 'http://ostatus.org/schema/1.0/unfollow',
}.freeze

TYPES = {
activity: 'http://activitystrea.ms/schema/1.0/activity',
note: 'http://activitystrea.ms/schema/1.0/note',
comment: 'http://activitystrea.ms/schema/1.0/comment',
person: 'http://activitystrea.ms/schema/1.0/person',
collection: 'http://activitystrea.ms/schema/1.0/collection',
group: 'http://activitystrea.ms/schema/1.0/group',
}.freeze

COLLECTIONS = {
public: 'http://activityschema.org/collection/public',
}.freeze

XMLNS = 'http://www.w3.org/2005/Atom'
MEDIA_XMLNS = 'http://purl.org/syndication/atommedia'
AS_XMLNS = 'http://activitystrea.ms/spec/1.0/'
THR_XMLNS = 'http://purl.org/syndication/thread/1.0'
POCO_XMLNS = 'http://portablecontacts.net/spec/1.0'
DFRN_XMLNS = 'http://purl.org/macgirvin/dfrn/1.0'
OS_XMLNS = 'http://ostatus.org/schema/1.0'

def unique_tag(date, id, type)
"tag:#{Rails.configuration.x.local_domain},#{date.strftime('%Y-%m-%d')}:objectId=#{id}:objectType=#{type}"
end
Expand Down

0 comments on commit 14bd469

Please sign in to comment.