pixelfed/public/js/collections.js

1 line
21 KiB
JavaScript
Raw Normal View History

2024-10-06 06:53:38 +00:00
(self.webpackChunkpixelfed=self.webpackChunkpixelfed||[]).push([[3765],{40902:(t,e,i)=>{"use strict";i.r(e),i.d(e,{default:()=>r});i(58942);var o=i(25100),s=i(74692);function n(t){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},n(t)}function a(t){return function(t){if(Array.isArray(t))return l(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(t){if("string"==typeof t)return l(t,e);var i={}.toString.call(t).slice(8,-1);return"Object"===i&&t.constructor&&(i=t.constructor.name),"Map"===i||"Set"===i?Array.from(t):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?l(t,e):void 0}}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function l(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,o=Array(e);i<e;i++)o[i]=t[i];return o}const r={props:["collection-id","collection-title","collection-description","collection-visibility","profile-id","profile-username"],components:{intersect:o.default},data:function(){return{collection:{},config:window.App.config,loaded:!1,posts:[],ids:[],user:!1,owner:!1,title:this.collectionTitle,description:this.collectionDescription,visibility:this.collectionVisibility,photoId:"",postsList:[],loadingPostList:!1,addingPostToCollection:!1,markedForDeletion:[],canLoadMore:!1,isIntersecting:!1,page:1}},beforeMount:function(){this.fetchCollection()},updated:function(){this.initReadMore()},methods:{enterIntersect:function(){this.isIntersecting||(this.isIntersecting=!0,this.page++,this.fetchItems())},statusUrl:function(t){return"/i/web/post/"+t.id},fetchCollection:function(){var t=this;axios.get("/api/local/collection/"+this.collectionId).then((function(e){t.collection=e.data,t.collection.post_count>9&&(t.canLoadMore=!0),t.fetchCurrentUser()}))},fetchCurrentUser:function(){var t=this;1==document.querySelectorAll("body")[0].classList.contains("loggedIn")?axios.get("/api/pixelfed/v1/accounts/verify_credentials").then((function(e){t.user=e.data,t.owner=t.user.id==t.profileId,window._sharedData.curUser=e.data,window.App.util.navatar(),t.fetchItems()})):this.fetchItems()},fetchItems:function(){var t=this;axios.get("/api/local/collection/items/"+this.collectionId,{params:{page:this.page}}).then((function(e){var i;if(0==e.data.length)return console.log("no items found"),t.loaded=!0,t.isIntersecting=!1,void(t.canLoadMore=!1);var o=e.data.filter((function(e){return-1==t.ids.indexOf(e.id)}));(i=t.posts).push.apply(i,a(o)),t.ids=t.posts.map((function(t){return t.id})),t.loaded=!0,t.isIntersecting=!1,0==o.length&&(t.canLoadMore=!1)}))},previewUrl:function(t){return t&&t.sensitive?"/storage/no-preview.png?v="+(new Date).getTime():t.media_attachments[0].url},previewBackground:function(t){return"background-image: url("+this.previewUrl(t)+");"},addToCollection:function(){var t=this;this.loadingPostList=!0,0==this.postsList.length?axios.get("/api/v1/accounts/"+this.profileId+"/statuses",{params:{min_id:1,limit:40}}).then((function(e){t.postsList=e.data.filter((function(e){return("public"==e.visibility||"unlisted"==e.visibility)&&0==e.sensitive&&-1==t.ids.indexOf(e.id)})),t.loadingPostList=!1,t.$refs.addPhotoModal.show()})).catch((function(e){t.loadingPostList=!1,swal("An Error Occured","We cannot process your request at this time, please try again later.","error")})):(this.$refs.addPhotoModal.show(),this.loadingPostList=!1)},pushId:function(){var t=this,e=this.config.uploader.max_collection_length,i=this;if(this.posts.length>=e)swal("Error","You can only add "+e+" posts per collection","error");else{var o=this.photoId,s=window.location.origin,n=o.split("/");if(o.slice(0,s.length)!==s&&(swal("Invalid URL","You can only add posts from this instance","error"),this.photoId=""),!o.includes("/i/web/post/")&&!o.includes("/p/"))return swal("