1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-14 06:32:36 +01:00

🚧 read state

This commit is contained in:
Flam3rboy 2021-05-21 21:59:04 +02:00
parent 6af753f4e0
commit 350b932ef6
2 changed files with 54 additions and 24 deletions

View File

@ -0,0 +1,29 @@
import { getPermission } from "@fosscord/server-util";
import { MessageModel } from "@fosscord/server-util";
import { Event } from "@fosscord/server-util";
import { ChannelModel } from "@fosscord/server-util";
import { Request, Response, Router } from "express";
import { HTTPError } from "lambert-server";
import { emitEvent } from "../../../../../util/Event";
const router = Router();
// router.pot("/", async (req: Request, res: Response) => {
// const { channel_id, message_id } = req.params;
// const permission = await getPermission(req.user_id, channel?.guild_id, channel_id, { channel });
// permission.hasThrow("MANAGE_MESSAGES");
// await emitEvent({
// event: "MESSAGE_ACK",
// channel_id,
// data: {
// channel_id,
// message_id
// }
// } as MessageAckEvent);
// res.sendStatus(204);
// });
export default router;

View File

@ -10,7 +10,7 @@ import {
RoleModel, RoleModel,
toObject, toObject,
UserModel, UserModel,
GuildDocument, GuildDocument
} from "@fosscord/server-util"; } from "@fosscord/server-util";
import { HTTPError } from "lambert-server"; import { HTTPError } from "lambert-server";
@ -27,7 +27,7 @@ export const PublicMemberProjection = {
pending: true, pending: true,
deaf: true, deaf: true,
mute: true, mute: true,
premium_since: true, premium_since: true
}; };
export async function isMember(user_id: string, guild_id: string) { export async function isMember(user_id: string, guild_id: string) {
@ -59,12 +59,13 @@ export async function addMember(user_id: string, guild_id: string, cache?: { gui
premium_since: undefined, premium_since: undefined,
deaf: false, deaf: false,
mute: false, mute: false,
pending: false, pending: false
}; };
await Promise.all([ await Promise.all([
new MemberModel({ new MemberModel({
...member, ...member,
read_state: {},
settings: { settings: {
channel_overrides: [], channel_overrides: [],
message_notifications: 0, message_notifications: 0,
@ -73,8 +74,8 @@ export async function addMember(user_id: string, guild_id: string, cache?: { gui
muted: false, muted: false,
suppress_everyone: false, suppress_everyone: false,
suppress_roles: false, suppress_roles: false,
version: 0, version: 0
}, }
}).save(), }).save(),
UserModel.updateOne({ id: user_id }, { $push: { guilds: guild_id } }).exec(), UserModel.updateOne({ id: user_id }, { $push: { guilds: guild_id } }).exec(),
@ -85,10 +86,10 @@ export async function addMember(user_id: string, guild_id: string, cache?: { gui
data: { data: {
...member, ...member,
user, user,
guild_id: guild_id, guild_id: guild_id
}, },
guild_id: guild_id, guild_id: guild_id
} as GuildMemberAddEvent), } as GuildMemberAddEvent)
]); ]);
await emitEvent({ await emitEvent({
@ -99,7 +100,7 @@ export async function addMember(user_id: string, guild_id: string, cache?: { gui
.populate({ path: "joined_at", match: { id: user.id } }) .populate({ path: "joined_at", match: { id: user.id } })
.execPopulate() .execPopulate()
), ),
user_id, user_id
} as GuildCreateEvent); } as GuildCreateEvent);
} }
@ -115,7 +116,7 @@ export async function removeMember(user_id: string, guild_id: string) {
return Promise.all([ return Promise.all([
MemberModel.deleteOne({ MemberModel.deleteOne({
id: user_id, id: user_id,
guild_id: guild_id, guild_id: guild_id
}).exec(), }).exec(),
UserModel.updateOne({ id: user.id }, { $pull: { guilds: guild_id } }).exec(), UserModel.updateOne({ id: user.id }, { $pull: { guilds: guild_id } }).exec(),
GuildModel.updateOne({ id: guild_id }, { $inc: { member_count: -1 } }).exec(), GuildModel.updateOne({ id: guild_id }, { $inc: { member_count: -1 } }).exec(),
@ -123,18 +124,18 @@ export async function removeMember(user_id: string, guild_id: string) {
emitEvent({ emitEvent({
event: "GUILD_DELETE", event: "GUILD_DELETE",
data: { data: {
id: guild_id, id: guild_id
}, },
user_id: user_id, user_id: user_id
} as GuildDeleteEvent), } as GuildDeleteEvent),
emitEvent({ emitEvent({
event: "GUILD_MEMBER_REMOVE", event: "GUILD_MEMBER_REMOVE",
data: { data: {
guild_id: guild_id, guild_id: guild_id,
user: user, user: user
}, },
guild_id: guild_id, guild_id: guild_id
} as GuildMemberRemoveEvent), } as GuildMemberRemoveEvent)
]); ]);
} }
@ -147,7 +148,7 @@ export async function addRole(user_id: string, guild_id: string, role_id: string
var memberObj = await MemberModel.findOneAndUpdate( var memberObj = await MemberModel.findOneAndUpdate(
{ {
id: user_id, id: user_id,
guild_id: guild_id, guild_id: guild_id
}, },
{ $push: { roles: role_id } } { $push: { roles: role_id } }
).exec(); ).exec();
@ -159,9 +160,9 @@ export async function addRole(user_id: string, guild_id: string, role_id: string
data: { data: {
guild_id: guild_id, guild_id: guild_id,
user: user, user: user,
roles: memberObj.roles, roles: memberObj.roles
}, },
guild_id: guild_id, guild_id: guild_id
} as GuildMemberUpdateEvent); } as GuildMemberUpdateEvent);
} }
@ -174,7 +175,7 @@ export async function removeRole(user_id: string, guild_id: string, role_id: str
var memberObj = await MemberModel.findOneAndUpdate( var memberObj = await MemberModel.findOneAndUpdate(
{ {
id: user_id, id: user_id,
guild_id: guild_id, guild_id: guild_id
}, },
{ $pull: { roles: role_id } } { $pull: { roles: role_id } }
).exec(); ).exec();
@ -186,9 +187,9 @@ export async function removeRole(user_id: string, guild_id: string, role_id: str
data: { data: {
guild_id: guild_id, guild_id: guild_id,
user: user, user: user,
roles: memberObj.roles, roles: memberObj.roles
}, },
guild_id: guild_id, guild_id: guild_id
} as GuildMemberUpdateEvent); } as GuildMemberUpdateEvent);
} }
@ -198,7 +199,7 @@ export async function changeNickname(user_id: string, guild_id: string, nickname
var memberObj = await MemberModel.findOneAndUpdate( var memberObj = await MemberModel.findOneAndUpdate(
{ {
id: user_id, id: user_id,
guild_id: guild_id, guild_id: guild_id
}, },
{ nick: nickname } { nick: nickname }
).exec(); ).exec();
@ -210,8 +211,8 @@ export async function changeNickname(user_id: string, guild_id: string, nickname
data: { data: {
guild_id: guild_id, guild_id: guild_id,
user: user, user: user,
nick: nickname, nick: nickname
}, },
guild_id: guild_id, guild_id: guild_id
} as GuildMemberUpdateEvent); } as GuildMemberUpdateEvent);
} }