Fixing image upload limits, allowing webm, merge/unmerge events trigger
timeline reload in UI, other small fixes
This commit is contained in:
parent
3d566279cb
commit
ce29624c6d
15 changed files with 144 additions and 61 deletions
|
@ -1,6 +1,12 @@
|
|||
export const TIMELINE_SET = 'TIMELINE_SET';
|
||||
export const TIMELINE_UPDATE = 'TIMELINE_UPDATE';
|
||||
export const TIMELINE_DELETE = 'TIMELINE_DELETE';
|
||||
import api from '../api'
|
||||
|
||||
export const TIMELINE_SET = 'TIMELINE_SET';
|
||||
export const TIMELINE_UPDATE = 'TIMELINE_UPDATE';
|
||||
export const TIMELINE_DELETE = 'TIMELINE_DELETE';
|
||||
|
||||
export const TIMELINE_REFRESH_REQUEST = 'TIMELINE_REFRESH_REQUEST';
|
||||
export const TIMELINE_REFRESH_SUCCESS = 'TIMELINE_REFRESH_SUCCESS';
|
||||
export const TIMELINE_REFRESH_FAIL = 'TIMELINE_REFRESH_FAIL';
|
||||
|
||||
export function setTimeline(timeline, statuses) {
|
||||
return {
|
||||
|
@ -24,3 +30,36 @@ export function deleteFromTimelines(id) {
|
|||
id: id
|
||||
};
|
||||
}
|
||||
|
||||
export function refreshTimelineRequest(timeline) {
|
||||
return {
|
||||
type: TIMELINE_REFRESH_REQUEST,
|
||||
timeline: timeline
|
||||
};
|
||||
}
|
||||
|
||||
export function refreshTimeline(timeline) {
|
||||
return function (dispatch, getState) {
|
||||
dispatch(refreshTimelineRequest(timeline));
|
||||
|
||||
api(getState).get(`/api/statuses/${timeline}`).then(function (response) {
|
||||
dispatch(refreshTimelineSuccess(timeline, response.data));
|
||||
}).catch(function (error) {
|
||||
dispatch(refreshTimelineFail(timeline, error));
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export function refreshTimelineSuccess(timeline, statuses) {
|
||||
return function (dispatch) {
|
||||
dispatch(setTimeline(timeline, statuses));
|
||||
};
|
||||
}
|
||||
|
||||
export function refreshTimelineFail(timeline, error) {
|
||||
return {
|
||||
type: TIMELINE_REFRESH_FAIL,
|
||||
timeline: timeline,
|
||||
error: error
|
||||
};
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ const Avatar = React.createClass({
|
|||
|
||||
render () {
|
||||
return (
|
||||
<div style={{ width: `${this.props.size}px`, height: `${this.props.size}px` }}>
|
||||
<div style={{ width: `${this.props.size}px`, height: `${this.props.size}px`, borderRadius: '4px', overflow: 'hidden' }} className='transparent-background'>
|
||||
<img src={this.props.src} width={this.props.size} height={this.props.size} alt='' style={{ display: 'block', borderRadius: '4px' }} />
|
||||
</div>
|
||||
);
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
import { Provider } from 'react-redux';
|
||||
import configureStore from '../store/configureStore';
|
||||
import Frontend from '../components/frontend';
|
||||
import { setTimeline, updateTimeline, deleteFromTimelines } from '../actions/timelines';
|
||||
import { setAccessToken } from '../actions/meta';
|
||||
import PureRenderMixin from 'react-addons-pure-render-mixin';
|
||||
import { Router, Route, createMemoryHistory } from 'react-router';
|
||||
import AccountRoute from '../routes/account_route';
|
||||
import StatusRoute from '../routes/status_route';
|
||||
import { Provider } from 'react-redux';
|
||||
import configureStore from '../store/configureStore';
|
||||
import Frontend from '../components/frontend';
|
||||
import { setTimeline, updateTimeline, deleteFromTimelines, refreshTimeline } from '../actions/timelines';
|
||||
import { setAccessToken } from '../actions/meta';
|
||||
import PureRenderMixin from 'react-addons-pure-render-mixin';
|
||||
import { Router, Route, createMemoryHistory } from 'react-router';
|
||||
import AccountRoute from '../routes/account_route';
|
||||
import StatusRoute from '../routes/status_route';
|
||||
|
||||
const store = configureStore();
|
||||
const history = createMemoryHistory();
|
||||
|
@ -36,10 +36,14 @@ const Root = React.createClass({
|
|||
disconnected: function() {},
|
||||
|
||||
received: function(data) {
|
||||
if (data.type === 'update') {
|
||||
return store.dispatch(updateTimeline(data.timeline, JSON.parse(data.message)));
|
||||
} else if (data.type === 'delete') {
|
||||
return store.dispatch(deleteFromTimelines(data.id));
|
||||
switch(data.type) {
|
||||
case 'update':
|
||||
return store.dispatch(updateTimeline(data.timeline, JSON.parse(data.message)));
|
||||
case 'delete':
|
||||
return store.dispatch(deleteFromTimelines(data.id));
|
||||
case 'merge':
|
||||
case 'unmerge':
|
||||
return store.dispatch(refreshTimeline('home'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -10,7 +10,9 @@ module ApplicationCable
|
|||
protected
|
||||
|
||||
def find_verified_user
|
||||
if verified_user = env['warden'].user
|
||||
verified_user = env['warden'].user
|
||||
|
||||
if verified_user
|
||||
verified_user
|
||||
else
|
||||
reject_unauthorized_connection
|
||||
|
|
|
@ -17,7 +17,11 @@ class FeedManager
|
|||
def push(timeline_type, account, status)
|
||||
redis.zadd(key(timeline_type, account.id), status.id, status.id)
|
||||
trim(timeline_type, account.id)
|
||||
ActionCable.server.broadcast("timeline:#{account.id}", type: 'update', timeline: timeline_type, message: inline_render(account, status))
|
||||
broadcast(account.id, type: 'update', timeline: timeline_type, message: inline_render(account, status))
|
||||
end
|
||||
|
||||
def broadcast(account_id, options = {})
|
||||
ActionCable.server.broadcast("timeline:#{account_id}", options)
|
||||
end
|
||||
|
||||
def trim(type, account_id)
|
||||
|
|
|
@ -35,7 +35,7 @@ class Formatter
|
|||
def link_mentions(html, mentions)
|
||||
html.gsub(Account::MENTION_RE) do |match|
|
||||
acct = Account::MENTION_RE.match(match)[1]
|
||||
mention = mentions.find { |mention| mention.account.acct.eql?(acct) }
|
||||
mention = mentions.find { |item| item.account.acct.eql?(acct) }
|
||||
|
||||
mention.nil? ? match : mention_html(match, mention.account)
|
||||
end
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
class Account < ApplicationRecord
|
||||
include Targetable
|
||||
|
||||
MENTION_RE = /(?:^|\s|\.|>)@([a-z0-9_]+(?:@[a-z0-9\.\-]+)?)/i
|
||||
IMAGE_MIME_TYPES = ['image/jpeg', 'image/png', 'image/gif']
|
||||
|
||||
# Local users
|
||||
has_one :user, inverse_of: :account
|
||||
validates :username, presence: true, format: { with: /\A[a-z0-9_]+\z/i, message: 'only letters, numbers and underscores' }, uniqueness: { scope: :domain, case_sensitive: false }, if: 'local?'
|
||||
|
@ -8,12 +11,12 @@ class Account < ApplicationRecord
|
|||
|
||||
# Avatar upload
|
||||
has_attached_file :avatar, styles: { large: '300x300#', medium: '96x96#', small: '48x48#' }
|
||||
validates_attachment_content_type :avatar, content_type: /\Aimage\/.*\Z/
|
||||
validates_attachment_content_type :avatar, content_type: IMAGE_MIME_TYPES
|
||||
validates_attachment_size :avatar, less_than: 2.megabytes
|
||||
|
||||
# Header upload
|
||||
has_attached_file :header, styles: { medium: '700x335#' }
|
||||
validates_attachment_content_type :header, content_type: /\Aimage\/.*\Z/
|
||||
validates_attachment_content_type :header, content_type: IMAGE_MIME_TYPES
|
||||
validates_attachment_size :header, less_than: 2.megabytes
|
||||
|
||||
# Local user profile validations
|
||||
|
@ -35,8 +38,6 @@ class Account < ApplicationRecord
|
|||
|
||||
has_many :media_attachments, dependent: :destroy
|
||||
|
||||
MENTION_RE = /(?:^|\s|\.|>)@([a-z0-9_]+(?:@[a-z0-9\.\-]+)?)/i
|
||||
|
||||
def follow!(other_account)
|
||||
self.active_relationships.where(target_account: other_account).first_or_create!(target_account: other_account)
|
||||
end
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
class MediaAttachment < ApplicationRecord
|
||||
IMAGE_MIME_TYPES = ['image/jpeg', 'image/png', 'image/gif']
|
||||
VIDEO_MIME_TYPES = ['video/webm']
|
||||
|
||||
belongs_to :account, inverse_of: :media_attachments
|
||||
belongs_to :status, inverse_of: :media_attachments
|
||||
|
||||
has_attached_file :file, styles: { small: '510x680>' }
|
||||
validates_attachment_content_type :file, content_type: /\Aimage\/.*\z/
|
||||
has_attached_file :file, styles: lambda { |f| f.instance.image? ? { small: '510x680>' } : { small: { format: 'webm' } } }, processors: lambda { |f| f.video? ? [:transcoder] : [:thumbnail] }
|
||||
validates_attachment_content_type :file, content_type: IMAGE_MIME_TYPES + VIDEO_MIME_TYPES
|
||||
validates_attachment_size :file, less_than: 4.megabytes
|
||||
|
||||
validates :account, presence: true
|
||||
|
@ -15,4 +18,12 @@ class MediaAttachment < ApplicationRecord
|
|||
def file_remote_url=(url)
|
||||
self.file = URI.parse(url)
|
||||
end
|
||||
|
||||
def image?
|
||||
IMAGE_MIME_TYPES.include? file_content_type
|
||||
end
|
||||
|
||||
def video?
|
||||
VIDEO_MIME_TYPES.include? file_content_type
|
||||
end
|
||||
end
|
||||
|
|
|
@ -30,6 +30,7 @@ class FollowService < BaseService
|
|||
end
|
||||
|
||||
FeedManager.instance.trim(:home, into_account.id)
|
||||
FeedManager.instance.broadcast(into_account.id, type: 'merge')
|
||||
end
|
||||
|
||||
def redis
|
||||
|
|
|
@ -16,6 +16,8 @@ class UnfollowService < BaseService
|
|||
from_account.statuses.find_each do |status|
|
||||
redis.zrem(timeline_key, status.id)
|
||||
end
|
||||
|
||||
FeedManager.instance.broadcast(into_account.id, type: 'unmerge')
|
||||
end
|
||||
|
||||
def redis
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue