this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Support edit media description for Mastodon v4.1

+67 -20
+21 -20
src/components/compose.jsx
··· 3 3 import '@github/text-expander-element'; 4 4 import equal from 'fast-deep-equal'; 5 5 import { forwardRef } from 'preact/compat'; 6 - import { useEffect, useMemo, useRef, useState } from 'preact/hooks'; 6 + import { useEffect, useRef, useState } from 'preact/hooks'; 7 7 import { useHotkeys } from 'react-hotkeys-hook'; 8 8 import stringLength from 'string-length'; 9 9 import { uid } from 'uid/single'; ··· 18 18 import openCompose from '../utils/open-compose'; 19 19 import states, { saveStatus } from '../utils/states'; 20 20 import store from '../utils/store'; 21 - import { getCurrentAccount, getCurrentAccountNS } from '../utils/store-utils'; 21 + import { 22 + getCurrentAccount, 23 + getCurrentAccountNS, 24 + getCurrentInstance, 25 + } from '../utils/store-utils'; 26 + import supports from '../utils/supports'; 22 27 import useInterval from '../utils/useInterval'; 23 28 import visibilityIconsMap from '../utils/visibility-icons-map'; 24 29 ··· 108 113 const currentAccount = getCurrentAccount(); 109 114 const currentAccountInfo = currentAccount.info; 110 115 111 - const configuration = useMemo(() => { 112 - try { 113 - const instances = store.local.getJSON('instances'); 114 - const currentInstance = currentAccount.instanceURL.toLowerCase(); 115 - const config = instances[currentInstance].configuration; 116 - console.log(config); 117 - return config; 118 - } catch (e) { 119 - console.error(e); 120 - alert('Failed to load instance configuration. Please try again.'); 121 - // Temporary fix for corrupted data 122 - store.local.del('instances'); 123 - location.reload(); 124 - return {}; 125 - } 126 - }, []); 116 + const { configuration } = getCurrentInstance(); 117 + console.log('⚙️ Configuration', configuration); 127 118 128 119 const { 129 120 statuses: { maxCharacters, maxMediaAttachments, charactersReservedPerUrl }, ··· 771 762 // mediaIds: mediaAttachments.map((attachment) => attachment.id), 772 763 media_ids: mediaAttachments.map((attachment) => attachment.id), 773 764 }; 774 - if (!editStatus) { 765 + if (editStatus && supports('@mastodon/edit-media-attributes')) { 766 + params.media_attributes = mediaAttachments.map((attachment) => { 767 + return { 768 + id: attachment.id, 769 + description: attachment.description, 770 + // focus 771 + // thumbnail 772 + }; 773 + }); 774 + } else if (!editStatus) { 775 775 params.visibility = visibility; 776 776 // params.inReplyToId = replyToStatus?.id || undefined; 777 777 params.in_reply_to_id = replyToStatus?.id || undefined; ··· 1279 1279 onDescriptionChange = () => {}, 1280 1280 onRemove = () => {}, 1281 1281 }) { 1282 + const supportsEdit = supports('@mastodon/edit-media-attributes'); 1282 1283 const { url, type, id } = attachment; 1283 1284 console.log({ attachment }); 1284 1285 const [description, setDescription] = useState(attachment.description); ··· 1304 1305 1305 1306 const descTextarea = ( 1306 1307 <> 1307 - {!!id ? ( 1308 + {!!id && !supportsEdit ? ( 1308 1309 <div class="media-desc"> 1309 1310 <span class="tag">Uploaded</span> 1310 1311 <p title={description}>
+3
src/data/features.json
··· 1 + { 2 + "@mastodon/edit-media-attributes": ">=4.1" 3 + }
+18
src/utils/store-utils.js
··· 33 33 store.local.setJSON('accounts', accounts); 34 34 store.session.set('currentAccount', account.info.id); 35 35 } 36 + 37 + let currentInstance = null; 38 + export function getCurrentInstance() { 39 + if (currentInstance) return currentInstance; 40 + try { 41 + const account = getCurrentAccount(); 42 + const instances = store.local.getJSON('instances'); 43 + const instance = account.instanceURL.toLowerCase(); 44 + return (currentInstance = instances[instance]); 45 + } catch (e) { 46 + console.error(e); 47 + alert('Failed to load instance configuration. Please try again.'); 48 + // Temporary fix for corrupted data 49 + store.local.del('instances'); 50 + location.reload(); 51 + return {}; 52 + } 53 + }
+25
src/utils/supports.js
··· 1 + import { satisfies } from 'semver'; 2 + 3 + import features from '../data/features.json'; 4 + 5 + import { getCurrentInstance } from './store-utils'; 6 + 7 + const supportsCache = {}; 8 + 9 + function supports(feature) { 10 + try { 11 + const { version, domain } = getCurrentInstance(); 12 + const key = `${domain}-${feature}`; 13 + if (supportsCache[key]) return supportsCache[key]; 14 + const range = features[feature]; 15 + if (!range) return false; 16 + return (supportsCache[key] = satisfies(version, range, { 17 + includePrerelease: true, 18 + loose: true, 19 + })); 20 + } catch (e) { 21 + return false; 22 + } 23 + } 24 + 25 + export default supports;