Skip to content

Commit

Permalink
replies now work when loading status directly from remote instance
Browse files Browse the repository at this point in the history
  • Loading branch information
ghobs91 committed Feb 21, 2024
1 parent 1247f54 commit 5aeb7fc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 19 deletions.
56 changes: 40 additions & 16 deletions src/components/compose.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import db from '../utils/db';
import emojifyText from '../utils/emojify-text';
import localeMatch from '../utils/locale-match';
import openCompose from '../utils/open-compose';
import states, { saveStatus } from '../utils/states';
import states, { saveStatus, statusKey } from '../utils/states';
import store from '../utils/store';
import {
getCurrentAccount,
Expand Down Expand Up @@ -112,6 +112,9 @@ function Compose({
}) {
console.warn('RENDER COMPOSER');
const { masto, instance } = api();
const {
masto: currentMasto
} = api();
const [uiState, setUIState] = useState('default');
const UID = useRef(draftStatus?.uid || uid());
console.log('Compose UID', UID.current);
Expand Down Expand Up @@ -811,29 +814,50 @@ function Compose({
} else if (!editStatus) {
params.visibility = visibility;
// params.inReplyToId = replyToStatus?.id || undefined;
params.in_reply_to_id = replyToStatus?.id || undefined;
// params.in_reply_to_id = replyToStatus?.id || undefined;
}
params = removeNullUndefined(params);
console.log('POST', params);

let newStatus;
if (editStatus) {
newStatus = await masto.v1.statuses
.$select(editStatus.id)
.update(params);
saveStatus(newStatus, instance, {
skipThreading: true,
});
} else {
try {
newStatus = await masto.v1.statuses.create(params, {
idempotencyKey: UID.current,
let sKey = statusKey(replyToStatus?.id, instance);
const results = await currentMasto?.v2.search.fetch({
q: replyToStatus.url,
type: 'statuses',
resolve: true,
limit: 1,
});

if (results.statuses.length) {
const status = results.statuses[0];
params.in_reply_to_id = status?.id || undefined;
// states.statuses[sKey] = {
// ...status,
// reblogged: !reblogged,
// reblogsCount: reblogsCount + (reblogged ? -1 : 1),
// favouritesCount: favouritesCount,
// repliesCount: repliesCount,
// };
if (editStatus) {
// newStatus = await masto.v1.statuses
newStatus = await instance.v1.statuses
.$select(editStatus.id)
.update(params);
saveStatus(newStatus, instance, {
skipThreading: true,
});
} catch (_) {
// If idempotency key fails, try again without it
newStatus = await masto.v1.statuses.create(params);
} else {
try {
newStatus = await currentMasto.v1.statuses.create(params, {
idempotencyKey: UID.current,
});
} catch (_) {
// If idempotency key fails, try again without it
newStatus = await currentMasto.v1.statuses.create(params);
}
}
}

setUIState('default');

// Close
Expand Down
6 changes: 3 additions & 3 deletions src/components/status.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,9 @@ function Status({
}

const replyStatus = () => {
if (!sameInstance || !authenticated) {
return alert(unauthInteractionErrorMessage);
}
// if (!sameInstance || !authenticated) {
// return alert(unauthInteractionErrorMessage);
// }
states.showCompose = {
replyToStatus: status,
};
Expand Down

0 comments on commit 5aeb7fc

Please sign in to comment.