From 4ec1771165ab8dd40e52804fd087eacfab25290b Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Thu, 28 Sep 2017 15:31:31 +0200 Subject: Add ability to specify alternative text for media attachments (#5123) * Fix #117 - Add ability to specify alternative text for media attachments - POST /api/v1/media accepts `description` straight away - PUT /api/v1/media/:id to update `description` (only for unattached ones) - Serialized as `name` of Document object in ActivityPub - Uploads form adjusted for better performance and description input * Add tests * Change undo button blend mode to difference --- app/models/media_attachment.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'app/models/media_attachment.rb') diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb index e4a974f96..25e41c209 100644 --- a/app/models/media_attachment.rb +++ b/app/models/media_attachment.rb @@ -16,6 +16,7 @@ # shortcode :string # type :integer default("image"), not null # file_meta :json +# description :text # require 'mime/types' @@ -58,6 +59,7 @@ class MediaAttachment < ApplicationRecord validates_attachment_size :file, less_than: 8.megabytes validates :account, presence: true + validates :description, length: { maximum: 140 }, if: :local? scope :attached, -> { where.not(status_id: nil) } scope :unattached, -> { where(status_id: nil) } @@ -78,6 +80,7 @@ class MediaAttachment < ApplicationRecord shortcode end + before_create :prepare_description, unless: :local? before_create :set_shortcode before_post_process :set_type_and_extension before_save :set_meta @@ -136,6 +139,10 @@ class MediaAttachment < ApplicationRecord end end + def prepare_description + self.description = description.strip[0...140] unless description.nil? + end + def set_type_and_extension self.type = VIDEO_MIME_TYPES.include?(file_content_type) ? :video : :image extension = appropriate_extension -- cgit From 887cd94e963f49523af80d845cfe0ea900f7dadf Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Fri, 29 Sep 2017 02:30:00 +0200 Subject: Increase attachment descriptions to 420 characters (#5139) Blaze it --- app/javascript/mastodon/features/compose/components/upload.js | 2 +- app/models/media_attachment.rb | 4 ++-- spec/models/media_attachment_spec.rb | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'app/models/media_attachment.rb') diff --git a/app/javascript/mastodon/features/compose/components/upload.js b/app/javascript/mastodon/features/compose/components/upload.js index c2bf3b72e..cd9e08360 100644 --- a/app/javascript/mastodon/features/compose/components/upload.js +++ b/app/javascript/mastodon/features/compose/components/upload.js @@ -79,7 +79,7 @@ export default class Upload extends ImmutablePureComponent { placeholder={intl.formatMessage(messages.description)} type='text' value={description} - maxLength={140} + maxLength={420} onFocus={this.handleInputFocus} onChange={this.handleInputChange} onBlur={this.handleInputBlur} diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb index 25e41c209..60380198b 100644 --- a/app/models/media_attachment.rb +++ b/app/models/media_attachment.rb @@ -59,7 +59,7 @@ class MediaAttachment < ApplicationRecord validates_attachment_size :file, less_than: 8.megabytes validates :account, presence: true - validates :description, length: { maximum: 140 }, if: :local? + validates :description, length: { maximum: 420 }, if: :local? scope :attached, -> { where.not(status_id: nil) } scope :unattached, -> { where(status_id: nil) } @@ -140,7 +140,7 @@ class MediaAttachment < ApplicationRecord end def prepare_description - self.description = description.strip[0...140] unless description.nil? + self.description = description.strip[0...420] unless description.nil? end def set_type_and_extension diff --git a/spec/models/media_attachment_spec.rb b/spec/models/media_attachment_spec.rb index f20698c45..9fce5bc4f 100644 --- a/spec/models/media_attachment_spec.rb +++ b/spec/models/media_attachment_spec.rb @@ -52,9 +52,9 @@ RSpec.describe MediaAttachment, type: :model do describe 'descriptions for remote attachments' do it 'are cut off at 140 characters' do - media = Fabricate(:media_attachment, description: 'foo' * 100, remote_url: 'http://example.com/blah.jpg') + media = Fabricate(:media_attachment, description: 'foo' * 1000, remote_url: 'http://example.com/blah.jpg') - expect(media.description.size).to be <= 140 + expect(media.description.size).to be <= 420 end end end -- cgit