From e79003d8d7cc5fed5dad7fec11a1e7a6284d1a7d Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Sat, 3 Mar 2018 10:11:32 -0800 Subject: [PATCH] separate uploaded media by instance/realm --- routes/_actions/instances.js | 5 +- routes/_actions/media.js | 15 +++-- routes/_components/compose/ComposeAuthor.html | 3 + routes/_components/compose/ComposeBox.html | 8 +-- routes/_components/compose/ComposeInput.html | 56 ++++++++++++------- routes/_components/compose/ComposeMedia.html | 11 ++-- .../_components/compose/ComposeToolbar.html | 9 ++- routes/_store/instanceComputations.js | 7 ++- routes/_store/store.js | 3 +- routes/index.html | 2 +- tests/spec/12-compose.js | 2 +- 11 files changed, 80 insertions(+), 41 deletions(-) diff --git a/routes/_actions/instances.js b/routes/_actions/instances.js index 640e9775..f4e269db 100644 --- a/routes/_actions/instances.js +++ b/routes/_actions/instances.js @@ -34,6 +34,7 @@ export async function logOutOfInstance (instanceName) { let instanceThemes = store.get('instanceThemes') let loggedInInstancesInOrder = store.get('loggedInInstancesInOrder') let composeText = store.get('composeText') + let uploadedMedia = store.get('uploadedMedia') let currentInstance = store.get('currentInstance') loggedInInstancesInOrder.splice(loggedInInstancesInOrder.indexOf(instanceName), 1) let newInstance = instanceName === currentInstance @@ -42,6 +43,7 @@ export async function logOutOfInstance (instanceName) { delete loggedInInstances[instanceName] delete instanceThemes[instanceName] delete composeText[instanceName] + delete uploadedMedia[instanceName] store.set({ loggedInInstances: loggedInInstances, instanceThemes: instanceThemes, @@ -50,7 +52,8 @@ export async function logOutOfInstance (instanceName) { searchResults: null, queryInSearch: '', rawComposeText: '', - composeText: composeText + composeText: composeText, + uploadedMedia: uploadedMedia }) store.save() toast.say(`Logged out of ${instanceName}`) diff --git a/routes/_actions/media.js b/routes/_actions/media.js index 4cdb84aa..e6ac67e5 100644 --- a/routes/_actions/media.js +++ b/routes/_actions/media.js @@ -2,14 +2,16 @@ import { store } from '../_store/store' import { uploadMedia } from '../_api/media' import { toast } from '../_utils/toast' -export async function doMediaUpload (file) { +export async function doMediaUpload (realm, file) { let instanceName = store.get('currentInstance') let accessToken = store.get('accessToken') store.set({uploadingMedia: true}) try { let response = await uploadMedia(instanceName, accessToken, file) - let uploadedMedia = store.get('uploadedMedia') || [] - uploadedMedia.push({ + let uploadedMedia = store.get('uploadedMedia') + uploadedMedia[instanceName] = uploadedMedia[instanceName] || {} + uploadedMedia[instanceName][realm] = uploadedMedia[instanceName][realm] || [] + uploadedMedia[instanceName][realm].push({ data: response, file: file }) @@ -22,8 +24,11 @@ export async function doMediaUpload (file) { } } -export function deleteMedia (i) { +export function deleteMedia (realm, i) { let uploadedMedia = store.get('uploadedMedia') - uploadedMedia.splice(i, 1) + let instanceName = store.get('currentInstance') + let uploadedMediaArray = uploadedMedia[instanceName][realm] + + uploadedMediaArray.splice(i, 1) store.set({uploadedMedia}) } diff --git a/routes/_components/compose/ComposeAuthor.html b/routes/_components/compose/ComposeAuthor.html index ee963f35..253a02be 100644 --- a/routes/_components/compose/ComposeAuthor.html +++ b/routes/_components/compose/ComposeAuthor.html @@ -49,6 +49,9 @@ export default { components: { Avatar + }, + computed: { + verifyCredentials: ($currentVerifyCredentials) => $currentVerifyCredentials } } \ No newline at end of file diff --git a/routes/_components/compose/ComposeBox.html b/routes/_components/compose/ComposeBox.html index 938d76ac..da45ecfe 100644 --- a/routes/_components/compose/ComposeBox.html +++ b/routes/_components/compose/ComposeBox.html @@ -1,10 +1,10 @@
- - + + - + - +