sforkowany z mirror/soapbox
Porównaj commity
7 Commity
develop
...
quote-repl
Autor | SHA1 | Data |
---|---|---|
Alex Gleason | 3863988ff2 | |
Alex Gleason | 2b0811a51c | |
marcin mikołajczak | 8917f47d70 | |
marcin mikołajczak | 1f5e925581 | |
marcin mikołajczak | 3c765b7fdd | |
marcin mikołajczak | 3b7cbc5a68 | |
marcin mikołajczak | b2b157384d |
|
@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
## [Unreleased]
|
||||
|
||||
### Added
|
||||
- Composer: ability to quote posts by adding link to a post.
|
||||
|
||||
### Changed
|
||||
|
||||
|
|
|
@ -11,13 +11,14 @@ import { isLoggedIn } from 'soapbox/utils/auth';
|
|||
import { getFeatures, parseVersion } from 'soapbox/utils/features';
|
||||
import { formatBytes, getVideoDuration } from 'soapbox/utils/media';
|
||||
import resizeImage from 'soapbox/utils/resize-image';
|
||||
import { getStatusIdsFromLinksInContent } from 'soapbox/utils/status';
|
||||
|
||||
import { useEmoji } from './emojis';
|
||||
import { importFetchedAccounts } from './importer';
|
||||
import { uploadMedia, fetchMedia, updateMedia } from './media';
|
||||
import { openModal, closeModal } from './modals';
|
||||
import { getSettings } from './settings';
|
||||
import { createStatus } from './statuses';
|
||||
import { createStatus, fetchStatus } from './statuses';
|
||||
|
||||
import type { History } from 'history';
|
||||
import type { Emoji } from 'soapbox/components/autosuggest-emoji';
|
||||
|
@ -235,9 +236,11 @@ const validateSchedule = (state: RootState, composeId: string) => {
|
|||
};
|
||||
|
||||
const submitCompose = (composeId: string, routerHistory?: History, force = false) =>
|
||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||
async (dispatch: AppDispatch, getState: () => RootState) => {
|
||||
if (!isLoggedIn(getState)) return;
|
||||
const state = getState();
|
||||
const instance = state.instance;
|
||||
const { quotePosts } = getFeatures(instance);
|
||||
|
||||
const compose = state.compose.get(composeId)!;
|
||||
|
||||
|
@ -245,6 +248,7 @@ const submitCompose = (composeId: string, routerHistory?: History, force = false
|
|||
const media = compose.media_attachments;
|
||||
const statusId = compose.id;
|
||||
let to = compose.to;
|
||||
let quoteId = compose.quote;
|
||||
|
||||
if (!validateSchedule(state, composeId)) {
|
||||
toast.error(messages.scheduleError);
|
||||
|
@ -271,6 +275,24 @@ const submitCompose = (composeId: string, routerHistory?: History, force = false
|
|||
to = to.union(mentions.map(mention => mention.trim().slice(1)));
|
||||
}
|
||||
|
||||
if (!quoteId && quotePosts) {
|
||||
const ids = getStatusIdsFromLinksInContent(status);
|
||||
|
||||
for (const id of ids) {
|
||||
if (state.statuses.get(id)) {
|
||||
quoteId = id;
|
||||
break;
|
||||
}
|
||||
|
||||
const status: APIEntity = await dispatch(fetchStatus(id));
|
||||
|
||||
if (status) {
|
||||
quoteId = status.id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dispatch(submitComposeRequest(composeId));
|
||||
dispatch(closeModal());
|
||||
|
||||
|
@ -279,7 +301,7 @@ const submitCompose = (composeId: string, routerHistory?: History, force = false
|
|||
const params = {
|
||||
status,
|
||||
in_reply_to_id: compose.in_reply_to,
|
||||
quote_id: compose.quote,
|
||||
quote_id: quoteId,
|
||||
media_ids: media.map(item => item.id),
|
||||
sensitive: compose.sensitive,
|
||||
spoiler_text: compose.spoiler_text,
|
||||
|
|
|
@ -78,3 +78,13 @@ export const getActualStatus: {
|
|||
return status;
|
||||
}
|
||||
};
|
||||
|
||||
export const getStatusIdsFromLinksInContent = (content: string): string[] => {
|
||||
const urls = content.match(RegExp(`${window.location.origin}/@([a-z\\d_-]+(?:@[^@\\s]+)?)/posts/[a-z0-9]+(?!\\S)`, 'gi'));
|
||||
|
||||
if (!urls) return [];
|
||||
|
||||
return Array.from(new Set(urls
|
||||
.map(url => url.split('/').at(-1) as string)
|
||||
.filter(url => url)));
|
||||
};
|
||||
|
|
Ładowanie…
Reference in New Issue