Fixed 267U.pre2
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
import { Brackets } from "typeorm";
|
||||
import { MessagingMessages, Mutings, UserGroupJoinings } from "../../../../models/index.js";
|
||||
import define from "../../define.js";
|
||||
export const meta = {
|
||||
tags: [
|
||||
"messaging"
|
||||
],
|
||||
requireCredential: true,
|
||||
kind: "read:messaging",
|
||||
res: {
|
||||
type: "array",
|
||||
optional: false,
|
||||
nullable: false,
|
||||
items: {
|
||||
type: "object",
|
||||
optional: false,
|
||||
nullable: false,
|
||||
ref: "MessagingMessage"
|
||||
}
|
||||
}
|
||||
};
|
||||
export const paramDef = {
|
||||
type: "object",
|
||||
properties: {
|
||||
limit: {
|
||||
type: "integer",
|
||||
minimum: 1,
|
||||
maximum: 100,
|
||||
default: 10
|
||||
},
|
||||
group: {
|
||||
type: "boolean",
|
||||
default: false
|
||||
}
|
||||
},
|
||||
required: []
|
||||
};
|
||||
export default define(meta, paramDef, async (ps, user)=>{
|
||||
const mute = await Mutings.findBy({
|
||||
muterId: user.id
|
||||
});
|
||||
const groups = ps.group ? await UserGroupJoinings.findBy({
|
||||
userId: user.id
|
||||
}).then((xs)=>xs.map((x)=>x.userGroupId)) : [];
|
||||
if (ps.group && groups.length === 0) {
|
||||
return [];
|
||||
}
|
||||
const history = [];
|
||||
for(let i = 0; i < ps.limit; i++){
|
||||
const found = ps.group ? history.map((m)=>m.groupId) : history.map((m)=>m.userId === user.id ? m.recipientId : m.userId);
|
||||
const query = MessagingMessages.createQueryBuilder("message").orderBy("message.createdAt", "DESC");
|
||||
if (ps.group) {
|
||||
query.where("message.groupId IN (:...groups)", {
|
||||
groups: groups
|
||||
});
|
||||
if (found.length > 0) {
|
||||
query.andWhere("message.groupId NOT IN (:...found)", {
|
||||
found: found
|
||||
});
|
||||
}
|
||||
} else {
|
||||
query.where(new Brackets((qb)=>{
|
||||
qb.where("message.userId = :userId", {
|
||||
userId: user.id
|
||||
}).orWhere("message.recipientId = :userId", {
|
||||
userId: user.id
|
||||
});
|
||||
}));
|
||||
query.andWhere("message.groupId IS NULL");
|
||||
if (found.length > 0) {
|
||||
query.andWhere("message.userId NOT IN (:...found)", {
|
||||
found: found
|
||||
});
|
||||
query.andWhere("message.recipientId NOT IN (:...found)", {
|
||||
found: found
|
||||
});
|
||||
}
|
||||
if (mute.length > 0) {
|
||||
query.andWhere("message.userId NOT IN (:...mute)", {
|
||||
mute: mute.map((m)=>m.muteeId)
|
||||
});
|
||||
query.andWhere("message.recipientId NOT IN (:...mute)", {
|
||||
mute: mute.map((m)=>m.muteeId)
|
||||
});
|
||||
}
|
||||
}
|
||||
const message = await query.getOne();
|
||||
if (message) {
|
||||
history.push(message);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return await Promise.all(history.map((h)=>MessagingMessages.pack(h.id, user)));
|
||||
});
|
||||
@@ -0,0 +1,144 @@
|
||||
import define from "../../define.js";
|
||||
import { ApiError } from "../../error.js";
|
||||
import { getUser } from "../../common/getters.js";
|
||||
import { MessagingMessages, UserGroups, UserGroupJoinings, Users } from "../../../../models/index.js";
|
||||
import { makePaginationQuery } from "../../common/make-pagination-query.js";
|
||||
import { Brackets } from "typeorm";
|
||||
import { readUserMessagingMessage, readGroupMessagingMessage, deliverReadActivity } from "../../common/read-messaging-message.js";
|
||||
export const meta = {
|
||||
tags: [
|
||||
"messaging"
|
||||
],
|
||||
requireCredential: true,
|
||||
kind: "read:messaging",
|
||||
res: {
|
||||
type: "array",
|
||||
optional: false,
|
||||
nullable: false,
|
||||
items: {
|
||||
type: "object",
|
||||
optional: false,
|
||||
nullable: false,
|
||||
ref: "MessagingMessage"
|
||||
}
|
||||
},
|
||||
errors: {
|
||||
noSuchUser: {
|
||||
message: "No such user.",
|
||||
code: "NO_SUCH_USER",
|
||||
id: "11795c64-40ea-4198-b06e-3c873ed9039d"
|
||||
},
|
||||
noSuchGroup: {
|
||||
message: "No such group.",
|
||||
code: "NO_SUCH_GROUP",
|
||||
id: "c4d9f88c-9270-4632-b032-6ed8cee36f7f"
|
||||
},
|
||||
groupAccessDenied: {
|
||||
message: "You can not read messages of groups that you have not joined.",
|
||||
code: "GROUP_ACCESS_DENIED",
|
||||
id: "a053a8dd-a491-4718-8f87-50775aad9284"
|
||||
}
|
||||
}
|
||||
};
|
||||
export const paramDef = {
|
||||
type: "object",
|
||||
properties: {
|
||||
limit: {
|
||||
type: "integer",
|
||||
minimum: 1,
|
||||
maximum: 100,
|
||||
default: 10
|
||||
},
|
||||
sinceId: {
|
||||
type: "string",
|
||||
format: "misskey:id"
|
||||
},
|
||||
untilId: {
|
||||
type: "string",
|
||||
format: "misskey:id"
|
||||
},
|
||||
markAsRead: {
|
||||
type: "boolean",
|
||||
default: true
|
||||
}
|
||||
},
|
||||
anyOf: [
|
||||
{
|
||||
properties: {
|
||||
userId: {
|
||||
type: "string",
|
||||
format: "misskey:id"
|
||||
}
|
||||
},
|
||||
required: [
|
||||
"userId"
|
||||
]
|
||||
},
|
||||
{
|
||||
properties: {
|
||||
groupId: {
|
||||
type: "string",
|
||||
format: "misskey:id"
|
||||
}
|
||||
},
|
||||
required: [
|
||||
"groupId"
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
export default define(meta, paramDef, async (ps, user)=>{
|
||||
if (ps.userId != null) {
|
||||
// Fetch recipient (user)
|
||||
const recipient = await getUser(ps.userId).catch((e)=>{
|
||||
if (e.id === "15348ddd-432d-49c2-8a5a-8069753becff") throw new ApiError(meta.errors.noSuchUser);
|
||||
throw e;
|
||||
});
|
||||
const query = makePaginationQuery(MessagingMessages.createQueryBuilder("message"), ps.sinceId, ps.untilId).andWhere(new Brackets((qb)=>{
|
||||
qb.where(new Brackets((qb)=>{
|
||||
qb.where("message.userId = :meId").andWhere("message.recipientId = :recipientId");
|
||||
})).orWhere(new Brackets((qb)=>{
|
||||
qb.where("message.userId = :recipientId").andWhere("message.recipientId = :meId");
|
||||
}));
|
||||
})).setParameter("meId", user.id).setParameter("recipientId", recipient.id);
|
||||
const messages = await query.take(ps.limit).getMany();
|
||||
// Mark all as read
|
||||
if (ps.markAsRead) {
|
||||
readUserMessagingMessage(user.id, recipient.id, messages.filter((m)=>m.recipientId === user.id).map((x)=>x.id));
|
||||
// リモートユーザーとのメッセージだったら既読配信
|
||||
if (Users.isLocalUser(user) && Users.isRemoteUser(recipient)) {
|
||||
deliverReadActivity(user, recipient, messages);
|
||||
}
|
||||
}
|
||||
return await Promise.all(messages.map((message)=>MessagingMessages.pack(message, user, {
|
||||
populateRecipient: false
|
||||
})));
|
||||
} else if (ps.groupId != null) {
|
||||
// Fetch recipient (group)
|
||||
const recipientGroup = await UserGroups.findOneBy({
|
||||
id: ps.groupId
|
||||
});
|
||||
if (recipientGroup == null) {
|
||||
throw new ApiError(meta.errors.noSuchGroup);
|
||||
}
|
||||
// check joined
|
||||
const joining = await UserGroupJoinings.findOneBy({
|
||||
userId: user.id,
|
||||
userGroupId: recipientGroup.id
|
||||
});
|
||||
if (joining == null) {
|
||||
throw new ApiError(meta.errors.groupAccessDenied);
|
||||
}
|
||||
const query = makePaginationQuery(MessagingMessages.createQueryBuilder("message"), ps.sinceId, ps.untilId).andWhere("message.groupId = :groupId", {
|
||||
groupId: recipientGroup.id
|
||||
});
|
||||
const messages = await query.take(ps.limit).getMany();
|
||||
// Mark all as read
|
||||
if (ps.markAsRead) {
|
||||
readGroupMessagingMessage(user.id, recipientGroup.id, messages.map((x)=>x.id));
|
||||
}
|
||||
return await Promise.all(messages.map((message)=>MessagingMessages.pack(message, user, {
|
||||
populateGroup: false
|
||||
})));
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,147 @@
|
||||
import define from "../../../define.js";
|
||||
import { ApiError } from "../../../error.js";
|
||||
import { getUser } from "../../../common/getters.js";
|
||||
import { DriveFiles, UserGroups, UserGroupJoinings, Blockings } from "../../../../../models/index.js";
|
||||
import { createMessage } from "../../../../../services/messages/create.js";
|
||||
export const meta = {
|
||||
tags: [
|
||||
"messaging"
|
||||
],
|
||||
requireCredential: true,
|
||||
kind: "write:messaging",
|
||||
res: {
|
||||
type: "object",
|
||||
optional: false,
|
||||
nullable: false,
|
||||
ref: "MessagingMessage"
|
||||
},
|
||||
errors: {
|
||||
recipientIsYourself: {
|
||||
message: "You can not send a message to yourself.",
|
||||
code: "RECIPIENT_IS_YOURSELF",
|
||||
id: "17e2ba79-e22a-4cbc-bf91-d327643f4a7e"
|
||||
},
|
||||
noSuchUser: {
|
||||
message: "No such user.",
|
||||
code: "NO_SUCH_USER",
|
||||
id: "11795c64-40ea-4198-b06e-3c873ed9039d"
|
||||
},
|
||||
noSuchGroup: {
|
||||
message: "No such group.",
|
||||
code: "NO_SUCH_GROUP",
|
||||
id: "c94e2a5d-06aa-4914-8fa6-6a42e73d6537"
|
||||
},
|
||||
groupAccessDenied: {
|
||||
message: "You can not send messages to groups that you have not joined.",
|
||||
code: "GROUP_ACCESS_DENIED",
|
||||
id: "d96b3cca-5ad1-438b-ad8b-02f931308fbd"
|
||||
},
|
||||
noSuchFile: {
|
||||
message: "No such file.",
|
||||
code: "NO_SUCH_FILE",
|
||||
id: "4372b8e2-185d-4146-8749-2f68864a3e5f"
|
||||
},
|
||||
contentRequired: {
|
||||
message: "Content required. You need to set text or fileId.",
|
||||
code: "CONTENT_REQUIRED",
|
||||
id: "25587321-b0e6-449c-9239-f8925092942c"
|
||||
},
|
||||
youHaveBeenBlocked: {
|
||||
message: "You cannot send a message because you have been blocked by this user.",
|
||||
code: "YOU_HAVE_BEEN_BLOCKED",
|
||||
id: "c15a5199-7422-4968-941a-2a462c478f7d"
|
||||
}
|
||||
}
|
||||
};
|
||||
export const paramDef = {
|
||||
type: "object",
|
||||
properties: {
|
||||
text: {
|
||||
type: "string",
|
||||
nullable: true,
|
||||
maxLength: 3000
|
||||
},
|
||||
fileId: {
|
||||
type: "string",
|
||||
format: "misskey:id"
|
||||
}
|
||||
},
|
||||
anyOf: [
|
||||
{
|
||||
properties: {
|
||||
userId: {
|
||||
type: "string",
|
||||
format: "misskey:id"
|
||||
}
|
||||
},
|
||||
required: [
|
||||
"userId"
|
||||
]
|
||||
},
|
||||
{
|
||||
properties: {
|
||||
groupId: {
|
||||
type: "string",
|
||||
format: "misskey:id"
|
||||
}
|
||||
},
|
||||
required: [
|
||||
"groupId"
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
export default define(meta, paramDef, async (ps, user)=>{
|
||||
let recipientUser;
|
||||
let recipientGroup;
|
||||
if (ps.userId != null) {
|
||||
// Myself
|
||||
if (ps.userId === user.id) {
|
||||
throw new ApiError(meta.errors.recipientIsYourself);
|
||||
}
|
||||
// Fetch recipient (user)
|
||||
recipientUser = await getUser(ps.userId).catch((e)=>{
|
||||
if (e.id === "15348ddd-432d-49c2-8a5a-8069753becff") throw new ApiError(meta.errors.noSuchUser);
|
||||
throw e;
|
||||
});
|
||||
// Check blocking
|
||||
const block = await Blockings.findOneBy({
|
||||
blockerId: recipientUser.id,
|
||||
blockeeId: user.id
|
||||
});
|
||||
if (block) {
|
||||
throw new ApiError(meta.errors.youHaveBeenBlocked);
|
||||
}
|
||||
} else if (ps.groupId != null) {
|
||||
// Fetch recipient (group)
|
||||
recipientGroup = await UserGroups.findOneBy({
|
||||
id: ps.groupId
|
||||
});
|
||||
if (recipientGroup == null) {
|
||||
throw new ApiError(meta.errors.noSuchGroup);
|
||||
}
|
||||
// check joined
|
||||
const joining = await UserGroupJoinings.findOneBy({
|
||||
userId: user.id,
|
||||
userGroupId: recipientGroup.id
|
||||
});
|
||||
if (joining == null) {
|
||||
throw new ApiError(meta.errors.groupAccessDenied);
|
||||
}
|
||||
}
|
||||
let file = null;
|
||||
if (ps.fileId != null) {
|
||||
file = await DriveFiles.findOneBy({
|
||||
id: ps.fileId,
|
||||
userId: user.id
|
||||
});
|
||||
if (file == null) {
|
||||
throw new ApiError(meta.errors.noSuchFile);
|
||||
}
|
||||
}
|
||||
// テキストが無いかつ添付ファイルも無かったらエラー
|
||||
if ((ps.text == null || ps.text.trim() === "") && file == null) {
|
||||
throw new ApiError(meta.errors.contentRequired);
|
||||
}
|
||||
return await createMessage(user, recipientUser, recipientGroup, ps.text, file);
|
||||
});
|
||||
@@ -0,0 +1,46 @@
|
||||
import define from "../../../define.js";
|
||||
import { ApiError } from "../../../error.js";
|
||||
import { MessagingMessages } from "../../../../../models/index.js";
|
||||
import { deleteMessage } from "../../../../../services/messages/delete.js";
|
||||
import { SECOND, HOUR } from "../../../../../const.js";
|
||||
export const meta = {
|
||||
tags: [
|
||||
"messaging"
|
||||
],
|
||||
requireCredential: true,
|
||||
kind: "write:messaging",
|
||||
limit: {
|
||||
duration: HOUR,
|
||||
max: 300,
|
||||
minInterval: SECOND
|
||||
},
|
||||
errors: {
|
||||
noSuchMessage: {
|
||||
message: "No such message.",
|
||||
code: "NO_SUCH_MESSAGE",
|
||||
id: "54b5b326-7925-42cf-8019-130fda8b56af"
|
||||
}
|
||||
}
|
||||
};
|
||||
export const paramDef = {
|
||||
type: "object",
|
||||
properties: {
|
||||
messageId: {
|
||||
type: "string",
|
||||
format: "misskey:id"
|
||||
}
|
||||
},
|
||||
required: [
|
||||
"messageId"
|
||||
]
|
||||
};
|
||||
export default define(meta, paramDef, async (ps, user)=>{
|
||||
const message = await MessagingMessages.findOneBy({
|
||||
id: ps.messageId,
|
||||
userId: user.id
|
||||
});
|
||||
if (message == null) {
|
||||
throw new ApiError(meta.errors.noSuchMessage);
|
||||
}
|
||||
await deleteMessage(message);
|
||||
});
|
||||
@@ -0,0 +1,53 @@
|
||||
import define from "../../../define.js";
|
||||
import { ApiError } from "../../../error.js";
|
||||
import { MessagingMessages } from "../../../../../models/index.js";
|
||||
import { readUserMessagingMessage, readGroupMessagingMessage } from "../../../common/read-messaging-message.js";
|
||||
export const meta = {
|
||||
tags: [
|
||||
"messaging"
|
||||
],
|
||||
requireCredential: true,
|
||||
kind: "write:messaging",
|
||||
errors: {
|
||||
noSuchMessage: {
|
||||
message: "No such message.",
|
||||
code: "NO_SUCH_MESSAGE",
|
||||
id: "86d56a2f-a9c3-4afb-b13c-3e9bfef9aa14"
|
||||
}
|
||||
}
|
||||
};
|
||||
export const paramDef = {
|
||||
type: "object",
|
||||
properties: {
|
||||
messageId: {
|
||||
type: "string",
|
||||
format: "misskey:id"
|
||||
}
|
||||
},
|
||||
required: [
|
||||
"messageId"
|
||||
]
|
||||
};
|
||||
export default define(meta, paramDef, async (ps, user)=>{
|
||||
const message = await MessagingMessages.findOneBy({
|
||||
id: ps.messageId
|
||||
});
|
||||
if (message == null) {
|
||||
throw new ApiError(meta.errors.noSuchMessage);
|
||||
}
|
||||
if (message.recipientId) {
|
||||
await readUserMessagingMessage(user.id, message.userId, [
|
||||
message.id
|
||||
]).catch((e)=>{
|
||||
if (e.id === "e140a4bf-49ce-4fb6-b67c-b78dadf6b52f") throw new ApiError(meta.errors.noSuchMessage);
|
||||
throw e;
|
||||
});
|
||||
} else if (message.groupId) {
|
||||
await readGroupMessagingMessage(user.id, message.groupId, [
|
||||
message.id
|
||||
]).catch((e)=>{
|
||||
if (e.id === "930a270c-714a-46b2-b776-ad27276dc569") throw new ApiError(meta.errors.noSuchMessage);
|
||||
throw e;
|
||||
});
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user