From 34f6a1ab5b8304ef667fde8deec8b887d8476912 Mon Sep 17 00:00:00 2001 From: mgabdev <> Date: Tue, 22 Dec 2020 12:11:22 -0500 Subject: [PATCH] Progress new MediaAttachment video style :playable for mp4 to make videojs work with multiple files, hiding albums, hiding bookmark collections. may need tweaks on mediaattachment for mov and other formats : todo : --- .../api/v1/album_lists_controller.rb | 65 +++++++++++++++++++ app/controllers/api/v1/albums_controller.rb | 16 ++--- app/javascript/gabsocial/actions/albums.js | 5 +- app/javascript/gabsocial/components/album.js | 30 +++++++-- .../navigation_bar/profile_navigation_bar.js | 3 - .../components/panel/media_gallery_panel.js | 2 +- .../popover/status_options_popover.js | 13 ++-- .../gabsocial/components/profile_header.js | 4 +- .../gabsocial/components/status_check_box.js | 1 + .../gabsocial/components/status_media.js | 1 + app/javascript/gabsocial/components/video.js | 15 +++-- .../gabsocial/features/account_albums.js | 34 +++++----- .../features/account_photo_gallery.js | 11 ++-- .../gabsocial/features/album_create.js | 47 ++++++++++---- .../components/chat_message_compose_form.js | 2 +- app/javascript/gabsocial/features/ui/ui.js | 11 ++-- .../gabsocial/reducers/album_lists.js | 1 + app/javascript/gabsocial/reducers/albums.js | 45 ++++--------- app/javascript/gabsocial/reducers/index.js | 4 +- app/lib/sorting_query_builder.rb | 7 -- app/models/account.rb | 5 -- app/models/chat_conversation_account.rb | 2 - app/models/concerns/account_associations.rb | 1 + app/models/media_attachment.rb | 25 +++++-- app/models/media_attachment_album.rb | 3 + app/serializers/rest/album_serializer.rb | 12 ++++ .../rest/media_attachment_serializer.rb | 14 +++- config/routes.rb | 18 ++--- 28 files changed, 259 insertions(+), 138 deletions(-) create mode 100644 app/controllers/api/v1/album_lists_controller.rb create mode 100644 app/serializers/rest/album_serializer.rb diff --git a/app/controllers/api/v1/album_lists_controller.rb b/app/controllers/api/v1/album_lists_controller.rb new file mode 100644 index 00000000..aa3b3103 --- /dev/null +++ b/app/controllers/api/v1/album_lists_controller.rb @@ -0,0 +1,65 @@ +# frozen_string_literal: true + +class Api::V1::AlbumListsController < Api::BaseController + before_action :require_user! + + before_action :set_account, only: [:show] + after_action :insert_pagination_headers, only: :show + + def show + @albums = load_albums + render json: @albums, each_serializer: REST::AlbumSerializer + end + + private + + def load_albums + paginated_albums + end + + def paginated_albums + @paginated_albums = MediaAttachmentAlbum.where(account: @account) + .paginate_by_max_id( + limit_param(DEFAULT_ACCOUNTS_LIMIT), + params[:max_id], + params[:since_id] + ) + end + + def insert_pagination_headers + set_pagination_headers(next_path, prev_path) + end + + def next_path + if records_continue? + api_v1_album_list_url params[:id], pagination_params(max_id: pagination_max_id) + end + end + + def prev_path + unless paginated_albums.empty? + api_v1_album_list_url params[:id], pagination_params(since_id: pagination_since_id) + end + end + + def pagination_max_id + paginated_albums.last.id + end + + def pagination_since_id + paginated_albums.first.id + end + + def records_continue? + paginated_albums.size == limit_param(DEFAULT_ACCOUNTS_LIMIT) + end + + def pagination_params(core_params) + params.slice(:limit).permit(:limit).merge(core_params) + end + + def set_account + @account = Account.find(params[:id]) + end + +end diff --git a/app/controllers/api/v1/albums_controller.rb b/app/controllers/api/v1/albums_controller.rb index 9376dc63..3b574f28 100644 --- a/app/controllers/api/v1/albums_controller.rb +++ b/app/controllers/api/v1/albums_controller.rb @@ -2,15 +2,11 @@ class Api::V1::AlbumsController < Api::BaseController before_action :require_user! - before_action :set_albums, only: :index + before_action :set_album, only: [:show, :update, :destroy] - def index - render json: @albums, each_serializer: REST::AlbumSerializer - end - def create - @album = "" #current_account.custom_filters.create!(resource_params) + @album = current_account.media_attachment_albums.create!(resource_params) render json: @album, serializer: REST::AlbumSerializer end @@ -30,15 +26,11 @@ class Api::V1::AlbumsController < Api::BaseController private - def set_albums - @albums = "" #current_account.custom_filters - end - def set_album - @album = "" # current_account.custom_filters.find(params[:id]) + @album = current_account.media_attachment_albums.find(params[:id]) end def resource_params - params.permit(:title, :description, :visibility) + params.permit(:title, :description) end end diff --git a/app/javascript/gabsocial/actions/albums.js b/app/javascript/gabsocial/actions/albums.js index e94b114e..bd199be4 100644 --- a/app/javascript/gabsocial/actions/albums.js +++ b/app/javascript/gabsocial/actions/albums.js @@ -47,7 +47,7 @@ export const fetchAlbums = (accountId) => (dispatch, getState) => { dispatch(fetchAlbumsRequest(accountId)) - api(getState).get(`/api/v1/albums/find_by_account/${accountId}`).then((response) => { + api(getState).get(`/api/v1/album_lists/${accountId}`).then((response) => { const next = getLinks(response).refs.find(link => link.rel === 'next') dispatch(fetchAlbumsSuccess(response.data, accountId, next ? next.uri : null)) }).catch((error) => { @@ -119,7 +119,7 @@ const expandAlbumsFail = (accountId, error) => ({ /** * */ -export const createAlbum = (title, description, visibility) => (dispatch, getState) => { +export const createAlbum = (title, description) => (dispatch, getState) => { if (!me || !title) return dispatch(createAlbumRequest()) @@ -127,7 +127,6 @@ export const createAlbum = (title, description, visibility) => (dispatch, getSta api(getState).post('/api/v1/albums', { title, description, - visibility, }).then((response) => { dispatch(createAlbumSuccess(response.data)) }).catch((error) => { diff --git a/app/javascript/gabsocial/components/album.js b/app/javascript/gabsocial/components/album.js index 9d7bfbba..966fea83 100644 --- a/app/javascript/gabsocial/components/album.js +++ b/app/javascript/gabsocial/components/album.js @@ -21,13 +21,17 @@ class Album extends React.PureComponent { render() { const { + account, album, isAddable, } = this.props - - const title = isAddable ? 'New album' : 'Album title' - const subtitle = isAddable ? '' : '10 Items' - const to = isAddable ? undefined : `/photos` + + if (!isAddable && (!album || !account)) return null + + const title = isAddable ? 'New album' : album.get('title') + const subtitle = isAddable ? '' : `${album.get('count')} Items` + const to = isAddable ? undefined : `/${account.get('username')}/albums/${album.get('id')}` + const albumImageUrl = !!album ? album.getIn(['cover', 'preview_url'], null) : null return (