Skip to content

Commit 304d2fd

Browse files
committed
fix: Use PUT for update for Mastodon-fork compatibility
1 parent 613913e commit 304d2fd

4 files changed

Lines changed: 18 additions & 3 deletions

File tree

src/adapters/action/dispatcher-http-hook-mastodon.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,21 @@ export class HttpActionDispatcherHookMastodon
9999
: action.path + "/" + snakeCase(action.type);
100100
const encoding = inferEncoding(type, path);
101101
const meta: HttpMetaParams<Encoding> = { ...action.meta, encoding };
102+
102103
return { type, path, data: action.data, meta };
103104
}
104105

106+
dispatch(action: AnyAction): false | Promise<unknown> {
107+
if (
108+
action.type === "update" &&
109+
action.path === "/api/v1/accounts/update_credentials"
110+
) {
111+
return this.http.patch(action.path, action.data, action.meta);
112+
}
113+
114+
return false;
115+
}
116+
105117
afterDispatch(action: AnyAction, result: unknown): unknown {
106118
if (action.type === "create" && action.path === "/api/v2/media") {
107119
const media = result as mastodon.v1.MediaAttachment;

src/adapters/action/dispatcher-http.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ export class HttpActionDispatcher implements ActionDispatcher<HttpAction> {
2020
action = this.hook.beforeDispatch(action);
2121
}
2222

23-
let result: T | Promise<T>;
23+
let result = this.hook.dispatch(action) as T | Promise<T> | false;
24+
if (result !== false) {
25+
return result;
26+
}
2427

2528
switch (action.type) {
2629
case "fetch": {
@@ -32,7 +35,7 @@ export class HttpActionDispatcher implements ActionDispatcher<HttpAction> {
3235
break;
3336
}
3437
case "update": {
35-
result = this.http.patch(action.path, action.data, action.meta);
38+
result = this.http.put(action.path, action.data, action.meta);
3639
break;
3740
}
3841
case "remove": {

src/adapters/http/base-http.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ export abstract class BaseHttp implements Http {
4848
}).then((response) => response.data as T);
4949
}
5050

51-
/* istanbul ignore next */
5251
put<T>(
5352
path: string,
5453
data?: unknown,

src/interfaces/action.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ export interface ActionDispatcher<T extends AnyAction> {
1717

1818
export interface ActionDispatcherHook<T extends AnyAction, U = unknown> {
1919
beforeDispatch(action: T): T;
20+
dispatch(action: T): U | Promise<U> | false;
2021
afterDispatch(action: T, result: U | Promise<U>): U;
2122
}

0 commit comments

Comments
 (0)