mirror of
https://iceshrimp.dev/crimekillz/trashposs
synced 2024-11-22 08:53:48 +01:00
[mastodon-client] Implement note editing, resolves #158
This commit is contained in:
parent
de3c75689e
commit
74941f35e4
@ -159,7 +159,7 @@ export const paramDef = {
|
|||||||
type: "object",
|
type: "object",
|
||||||
properties: {
|
properties: {
|
||||||
editId: { type: "string", format: "misskey:id" },
|
editId: { type: "string", format: "misskey:id" },
|
||||||
visibility: { type: "string", enum: noteVisibilities, default: "public" },
|
visibility: { type: "string", enum: noteVisibilities, nullable: true },
|
||||||
visibleUserIds: {
|
visibleUserIds: {
|
||||||
type: "array",
|
type: "array",
|
||||||
uniqueItems: true,
|
uniqueItems: true,
|
||||||
@ -334,6 +334,11 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// keep visibility on edit if not specified
|
||||||
|
if (ps.visibility == null) {
|
||||||
|
ps.visibility = note.visibility;
|
||||||
|
}
|
||||||
|
|
||||||
// enforce silent clients on server
|
// enforce silent clients on server
|
||||||
if (user.isSilenced && ps.visibility === "public" && ps.channelId == null) {
|
if (user.isSilenced && ps.visibility === "public" && ps.channelId == null) {
|
||||||
ps.visibility = "home";
|
ps.visibility = "home";
|
||||||
|
@ -96,6 +96,56 @@ export function apiStatusMastodon(router: Router): void {
|
|||||||
ctx.body = e.response.data;
|
ctx.body = e.response.data;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
router.put("/v1/statuses/:id", async (ctx) => {
|
||||||
|
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
|
||||||
|
const accessTokens = ctx.headers.authorization;
|
||||||
|
const client = getClient(BASE_URL, accessTokens);
|
||||||
|
try {
|
||||||
|
ctx.params.id = convertId(ctx.params.id, IdType.IceshrimpId);
|
||||||
|
let body: any = ctx.request.body;
|
||||||
|
if (
|
||||||
|
(!body.poll && body["poll[options][]"]) ||
|
||||||
|
(!body.media_ids && body["media_ids[]"])
|
||||||
|
) {
|
||||||
|
body = normalizeQuery(body);
|
||||||
|
}
|
||||||
|
if (!body.media_ids) body.media_ids = undefined;
|
||||||
|
if (body.media_ids && !body.media_ids.length) body.media_ids = undefined;
|
||||||
|
if (body.media_ids) {
|
||||||
|
body.media_ids = (body.media_ids as string[]).map((p) =>
|
||||||
|
convertId(p, IdType.IceshrimpId),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const { sensitive } = body;
|
||||||
|
body.sensitive =
|
||||||
|
typeof sensitive === "string" ? sensitive === "true" : sensitive;
|
||||||
|
|
||||||
|
if (body.poll) {
|
||||||
|
if (
|
||||||
|
body.poll.expires_in != null &&
|
||||||
|
typeof body.poll.expires_in === "string"
|
||||||
|
)
|
||||||
|
body.poll.expires_in = parseInt(body.poll.expires_in);
|
||||||
|
if (
|
||||||
|
body.poll.multiple != null &&
|
||||||
|
typeof body.poll.multiple === "string"
|
||||||
|
)
|
||||||
|
body.poll.multiple = body.poll.multiple == "true";
|
||||||
|
if (
|
||||||
|
body.poll.hide_totals != null &&
|
||||||
|
typeof body.poll.hide_totals === "string"
|
||||||
|
)
|
||||||
|
body.poll.hide_totals = body.poll.hide_totals == "true";
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await client.editStatus(ctx.params.id, body);
|
||||||
|
ctx.body = convertStatus(data.data);
|
||||||
|
} catch (e: any) {
|
||||||
|
console.error(e);
|
||||||
|
ctx.status = ctx.status == 404 ? 404 : 401;
|
||||||
|
ctx.body = e.response.data;
|
||||||
|
}
|
||||||
|
});
|
||||||
router.get<{ Params: { id: string } }>("/v1/statuses/:id", async (ctx) => {
|
router.get<{ Params: { id: string } }>("/v1/statuses/:id", async (ctx) => {
|
||||||
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
|
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
|
||||||
const accessTokens = ctx.headers.authorization;
|
const accessTokens = ctx.headers.authorization;
|
||||||
|
@ -1632,24 +1632,68 @@ export default class Misskey implements MegalodonInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async editStatus(
|
public async editStatus(
|
||||||
_id: string,
|
id: string,
|
||||||
_options: {
|
options: {
|
||||||
status?: string;
|
status?: string;
|
||||||
spoiler_text?: string;
|
spoiler_text?: string;
|
||||||
sensitive?: boolean;
|
sensitive?: boolean;
|
||||||
media_ids?: Array<string>;
|
media_ids?: Array<string>;
|
||||||
poll?: {
|
poll?: {
|
||||||
options?: Array<string>;
|
options: Array<string>;
|
||||||
expires_in?: number;
|
expires_in: number;
|
||||||
multiple?: boolean;
|
multiple?: boolean;
|
||||||
hide_totals?: boolean;
|
hide_totals?: boolean;
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
): Promise<Response<Entity.Status>> {
|
): Promise<Response<Entity.Status>> {
|
||||||
return new Promise((_, reject) => {
|
let params = {
|
||||||
const err = new NoImplementedError("misskey does not support");
|
editId: id,
|
||||||
reject(err);
|
};
|
||||||
});
|
if (options) {
|
||||||
|
params = Object.assign(params, {
|
||||||
|
text: options.status,
|
||||||
|
});
|
||||||
|
if (options.media_ids) {
|
||||||
|
params = Object.assign(params, {
|
||||||
|
fileIds: options.media_ids,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (options.poll) {
|
||||||
|
let pollParam = {
|
||||||
|
choices: options.poll.options,
|
||||||
|
expiresAt: null,
|
||||||
|
expiredAfter: options.poll.expires_in * 1000,
|
||||||
|
};
|
||||||
|
if (options.poll.multiple !== undefined) {
|
||||||
|
pollParam = Object.assign(pollParam, {
|
||||||
|
multiple: options.poll.multiple,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
params = Object.assign(params, {
|
||||||
|
poll: pollParam,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (options.sensitive) {
|
||||||
|
params = Object.assign(params, {
|
||||||
|
cw: "",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (options.spoiler_text) {
|
||||||
|
params = Object.assign(params, {
|
||||||
|
cw: options.spoiler_text,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this.client
|
||||||
|
.post<MisskeyAPI.Entity.CreatedNote>("/api/notes/edit", params)
|
||||||
|
.then(async (res) => ({
|
||||||
|
...res,
|
||||||
|
data: await this.noteWithDetails(
|
||||||
|
res.data.createdNote,
|
||||||
|
this.baseUrlToHost(this.baseUrl),
|
||||||
|
this.getFreshAccountCache(),
|
||||||
|
),
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user