🚧 dm channels
This commit is contained in:
		
							parent
							
								
									711dc1c4d4
								
							
						
					
					
						commit
						536900d255
					
				
							
								
								
									
										90
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										90
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							| @ -9,7 +9,7 @@ | ||||
| 			"version": "1.0.0", | ||||
| 			"license": "ISC", | ||||
| 			"dependencies": { | ||||
| 				"@fosscord/server-util": "^1.3.14", | ||||
| 				"@fosscord/server-util": "^1.3.15", | ||||
| 				"@types/jest": "^26.0.22", | ||||
| 				"@types/json-schema": "^7.0.7", | ||||
| 				"ajv": "^8.4.0", | ||||
| @ -29,7 +29,7 @@ | ||||
| 				"i18next-http-middleware": "^3.1.3", | ||||
| 				"i18next-node-fs-backend": "^2.1.3", | ||||
| 				"jsonwebtoken": "^8.5.1", | ||||
| 				"lambert-server": "^1.2.3", | ||||
| 				"lambert-server": "^1.2.4", | ||||
| 				"missing-native-js-functions": "^1.2.6", | ||||
| 				"mongoose": "^5.12.3", | ||||
| 				"mongoose-autopopulate": "^0.12.3", | ||||
| @ -520,9 +520,9 @@ | ||||
| 			} | ||||
| 		}, | ||||
| 		"node_modules/@fosscord/server-util": { | ||||
| 			"version": "1.3.14", | ||||
| 			"resolved": "https://registry.npmjs.org/@fosscord/server-util/-/server-util-1.3.14.tgz", | ||||
| 			"integrity": "sha512-P9qQ8bc01SjhRFFjw1WF3Q4rpwb4Sn8fDwwO+jeodAzhGFD1PjhBkG2xAO1UbA8LkF8+cJ8NgLFBUGzNXJTZJQ==", | ||||
| 			"version": "1.3.15", | ||||
| 			"resolved": "https://registry.npmjs.org/@fosscord/server-util/-/server-util-1.3.15.tgz", | ||||
| 			"integrity": "sha512-PCSOYOUiEzpdcUoyBSCHqOB72b+xdNuYStEuvvxLJt6MV6id4GA18DvD79Hw7F38F4gm/PIK6di+GnHWMd3Prw==", | ||||
| 			"dependencies": { | ||||
| 				"@types/jsonwebtoken": "^8.5.0", | ||||
| 				"@types/mongoose-autopopulate": "^0.10.1", | ||||
| @ -2701,22 +2701,26 @@ | ||||
| 			} | ||||
| 		}, | ||||
| 		"node_modules/browserslist": { | ||||
| 			"version": "4.16.3", | ||||
| 			"resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.16.3.tgz", | ||||
| 			"integrity": "sha512-vIyhWmIkULaq04Gt93txdh+j02yX/JzlyhLYbV3YQCn/zvES3JnY7TifHHvvr1w5hTDluNKMkV05cs4vy8Q7sw==", | ||||
| 			"version": "4.16.6", | ||||
| 			"resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.16.6.tgz", | ||||
| 			"integrity": "sha512-Wspk/PqO+4W9qp5iUTJsa1B/QrYn1keNCcEP5OvP7WBwT4KaDly0uONYmC6Xa3Z5IqnUgS0KcgLYu1l74x0ZXQ==", | ||||
| 			"dev": true, | ||||
| 			"dependencies": { | ||||
| 				"caniuse-lite": "^1.0.30001181", | ||||
| 				"colorette": "^1.2.1", | ||||
| 				"electron-to-chromium": "^1.3.649", | ||||
| 				"caniuse-lite": "^1.0.30001219", | ||||
| 				"colorette": "^1.2.2", | ||||
| 				"electron-to-chromium": "^1.3.723", | ||||
| 				"escalade": "^3.1.1", | ||||
| 				"node-releases": "^1.1.70" | ||||
| 				"node-releases": "^1.1.71" | ||||
| 			}, | ||||
| 			"bin": { | ||||
| 				"browserslist": "cli.js" | ||||
| 			}, | ||||
| 			"engines": { | ||||
| 				"node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7" | ||||
| 			}, | ||||
| 			"funding": { | ||||
| 				"type": "opencollective", | ||||
| 				"url": "https://opencollective.com/browserslist" | ||||
| 			} | ||||
| 		}, | ||||
| 		"node_modules/bser": { | ||||
| @ -2876,10 +2880,14 @@ | ||||
| 			} | ||||
| 		}, | ||||
| 		"node_modules/caniuse-lite": { | ||||
| 			"version": "1.0.30001204", | ||||
| 			"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001204.tgz", | ||||
| 			"integrity": "sha512-JUdjWpcxfJ9IPamy2f5JaRDCaqJOxDzOSKtbdx4rH9VivMd1vIzoPumsJa9LoMIi4Fx2BV2KZOxWhNkBjaYivQ==", | ||||
| 			"dev": true | ||||
| 			"version": "1.0.30001230", | ||||
| 			"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001230.tgz", | ||||
| 			"integrity": "sha512-5yBd5nWCBS+jWKTcHOzXwo5xzcj4ePE/yjtkZyUV1BTUmrBaA9MRGC+e7mxnqXSA90CmCA8L3eKLaSUkt099IQ==", | ||||
| 			"dev": true, | ||||
| 			"funding": { | ||||
| 				"type": "opencollective", | ||||
| 				"url": "https://opencollective.com/browserslist" | ||||
| 			} | ||||
| 		}, | ||||
| 		"node_modules/capture-exit": { | ||||
| 			"version": "2.0.0", | ||||
| @ -4163,9 +4171,9 @@ | ||||
| 			"integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" | ||||
| 		}, | ||||
| 		"node_modules/electron-to-chromium": { | ||||
| 			"version": "1.3.702", | ||||
| 			"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.702.tgz", | ||||
| 			"integrity": "sha512-qJVUKFWQnF6wP7MmTngDkmm8/KPzaiTXNFOAg5j7DSa6J7kPou7mTBqC8jpUOxauQWwHR3pn4dMRdV8IE1xdtA==", | ||||
| 			"version": "1.3.742", | ||||
| 			"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.742.tgz", | ||||
| 			"integrity": "sha512-ihL14knI9FikJmH2XUIDdZFWJxvr14rPSdOhJ7PpS27xbz8qmaRwCwyg/bmFwjWKmWK9QyamiCZVCvXm5CH//Q==", | ||||
| 			"dev": true | ||||
| 		}, | ||||
| 		"node_modules/elliptic": { | ||||
| @ -7924,9 +7932,9 @@ | ||||
| 			} | ||||
| 		}, | ||||
| 		"node_modules/lambert-server": { | ||||
| 			"version": "1.2.3", | ||||
| 			"resolved": "https://registry.npmjs.org/lambert-server/-/lambert-server-1.2.3.tgz", | ||||
| 			"integrity": "sha512-tBcxVH5Hj6ts/hk11e5ABc1ihxH9aIrXJth/9ivkfeqWjZEEzGrxvEmtnPULwGGy+k6lvUoZw725LDgVxoYGKQ==", | ||||
| 			"version": "1.2.4", | ||||
| 			"resolved": "https://registry.npmjs.org/lambert-server/-/lambert-server-1.2.4.tgz", | ||||
| 			"integrity": "sha512-7dDX4ZtK5Z8bDVoKIN7y/7h+4g3bW5UUTbPMViJGOiMhE39b8MytPByTZsEE+Re/SZaGmEEwBheE9HG0Qjd5yQ==", | ||||
| 			"dependencies": { | ||||
| 				"body-parser": "^1.19.0", | ||||
| 				"express": "^4.17.1", | ||||
| @ -12856,9 +12864,9 @@ | ||||
| 			} | ||||
| 		}, | ||||
| 		"@fosscord/server-util": { | ||||
| 			"version": "1.3.14", | ||||
| 			"resolved": "https://registry.npmjs.org/@fosscord/server-util/-/server-util-1.3.14.tgz", | ||||
| 			"integrity": "sha512-P9qQ8bc01SjhRFFjw1WF3Q4rpwb4Sn8fDwwO+jeodAzhGFD1PjhBkG2xAO1UbA8LkF8+cJ8NgLFBUGzNXJTZJQ==", | ||||
| 			"version": "1.3.15", | ||||
| 			"resolved": "https://registry.npmjs.org/@fosscord/server-util/-/server-util-1.3.15.tgz", | ||||
| 			"integrity": "sha512-PCSOYOUiEzpdcUoyBSCHqOB72b+xdNuYStEuvvxLJt6MV6id4GA18DvD79Hw7F38F4gm/PIK6di+GnHWMd3Prw==", | ||||
| 			"requires": { | ||||
| 				"@types/jsonwebtoken": "^8.5.0", | ||||
| 				"@types/mongoose-autopopulate": "^0.10.1", | ||||
| @ -14703,16 +14711,16 @@ | ||||
| 			} | ||||
| 		}, | ||||
| 		"browserslist": { | ||||
| 			"version": "4.16.3", | ||||
| 			"resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.16.3.tgz", | ||||
| 			"integrity": "sha512-vIyhWmIkULaq04Gt93txdh+j02yX/JzlyhLYbV3YQCn/zvES3JnY7TifHHvvr1w5hTDluNKMkV05cs4vy8Q7sw==", | ||||
| 			"version": "4.16.6", | ||||
| 			"resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.16.6.tgz", | ||||
| 			"integrity": "sha512-Wspk/PqO+4W9qp5iUTJsa1B/QrYn1keNCcEP5OvP7WBwT4KaDly0uONYmC6Xa3Z5IqnUgS0KcgLYu1l74x0ZXQ==", | ||||
| 			"dev": true, | ||||
| 			"requires": { | ||||
| 				"caniuse-lite": "^1.0.30001181", | ||||
| 				"colorette": "^1.2.1", | ||||
| 				"electron-to-chromium": "^1.3.649", | ||||
| 				"caniuse-lite": "^1.0.30001219", | ||||
| 				"colorette": "^1.2.2", | ||||
| 				"electron-to-chromium": "^1.3.723", | ||||
| 				"escalade": "^3.1.1", | ||||
| 				"node-releases": "^1.1.70" | ||||
| 				"node-releases": "^1.1.71" | ||||
| 			} | ||||
| 		}, | ||||
| 		"bser": { | ||||
| @ -14852,9 +14860,9 @@ | ||||
| 			} | ||||
| 		}, | ||||
| 		"caniuse-lite": { | ||||
| 			"version": "1.0.30001204", | ||||
| 			"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001204.tgz", | ||||
| 			"integrity": "sha512-JUdjWpcxfJ9IPamy2f5JaRDCaqJOxDzOSKtbdx4rH9VivMd1vIzoPumsJa9LoMIi4Fx2BV2KZOxWhNkBjaYivQ==", | ||||
| 			"version": "1.0.30001230", | ||||
| 			"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001230.tgz", | ||||
| 			"integrity": "sha512-5yBd5nWCBS+jWKTcHOzXwo5xzcj4ePE/yjtkZyUV1BTUmrBaA9MRGC+e7mxnqXSA90CmCA8L3eKLaSUkt099IQ==", | ||||
| 			"dev": true | ||||
| 		}, | ||||
| 		"capture-exit": { | ||||
| @ -15936,9 +15944,9 @@ | ||||
| 			"integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" | ||||
| 		}, | ||||
| 		"electron-to-chromium": { | ||||
| 			"version": "1.3.702", | ||||
| 			"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.702.tgz", | ||||
| 			"integrity": "sha512-qJVUKFWQnF6wP7MmTngDkmm8/KPzaiTXNFOAg5j7DSa6J7kPou7mTBqC8jpUOxauQWwHR3pn4dMRdV8IE1xdtA==", | ||||
| 			"version": "1.3.742", | ||||
| 			"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.742.tgz", | ||||
| 			"integrity": "sha512-ihL14knI9FikJmH2XUIDdZFWJxvr14rPSdOhJ7PpS27xbz8qmaRwCwyg/bmFwjWKmWK9QyamiCZVCvXm5CH//Q==", | ||||
| 			"dev": true | ||||
| 		}, | ||||
| 		"elliptic": { | ||||
| @ -18973,9 +18981,9 @@ | ||||
| 			} | ||||
| 		}, | ||||
| 		"lambert-server": { | ||||
| 			"version": "1.2.3", | ||||
| 			"resolved": "https://registry.npmjs.org/lambert-server/-/lambert-server-1.2.3.tgz", | ||||
| 			"integrity": "sha512-tBcxVH5Hj6ts/hk11e5ABc1ihxH9aIrXJth/9ivkfeqWjZEEzGrxvEmtnPULwGGy+k6lvUoZw725LDgVxoYGKQ==", | ||||
| 			"version": "1.2.4", | ||||
| 			"resolved": "https://registry.npmjs.org/lambert-server/-/lambert-server-1.2.4.tgz", | ||||
| 			"integrity": "sha512-7dDX4ZtK5Z8bDVoKIN7y/7h+4g3bW5UUTbPMViJGOiMhE39b8MytPByTZsEE+Re/SZaGmEEwBheE9HG0Qjd5yQ==", | ||||
| 			"requires": { | ||||
| 				"body-parser": "^1.19.0", | ||||
| 				"express": "^4.17.1", | ||||
|  | ||||
| @ -29,7 +29,7 @@ | ||||
| 	}, | ||||
| 	"homepage": "https://github.com/fosscord/fosscord-api#readme", | ||||
| 	"dependencies": { | ||||
| 		"@fosscord/server-util": "^1.3.14", | ||||
| 		"@fosscord/server-util": "^1.3.15", | ||||
| 		"@types/jest": "^26.0.22", | ||||
| 		"@types/json-schema": "^7.0.7", | ||||
| 		"ajv": "^8.4.0", | ||||
| @ -49,7 +49,7 @@ | ||||
| 		"i18next-http-middleware": "^3.1.3", | ||||
| 		"i18next-node-fs-backend": "^2.1.3", | ||||
| 		"jsonwebtoken": "^8.5.1", | ||||
| 		"lambert-server": "^1.2.3", | ||||
| 		"lambert-server": "^1.2.4", | ||||
| 		"missing-native-js-functions": "^1.2.6", | ||||
| 		"mongoose": "^5.12.3", | ||||
| 		"mongoose-autopopulate": "^0.12.3", | ||||
|  | ||||
| @ -2,50 +2,52 @@ import { Router, Request, Response } from "express"; | ||||
| import { | ||||
| 	ChannelModel, | ||||
| 	ChannelCreateEvent, | ||||
| 	DMChannel, | ||||
| 	UserModel, | ||||
| 	toObject, | ||||
| 	ChannelType, | ||||
| 	Snowflake, | ||||
| 	trimSpecial, | ||||
| 	Channel, | ||||
| 	DMChannel, | ||||
| 	UserModel | ||||
| } from "@fosscord/server-util"; | ||||
| import { HTTPError } from "lambert-server"; | ||||
| import { emitEvent } from "../../../util/Event"; | ||||
| import { getPublicUser } from "../../../util/User"; | ||||
| import { DmChannelCreateSchema } from "../../../schema/Channel"; | ||||
| import { check } from "../../../util/instanceOf"; | ||||
| 
 | ||||
| const router: Router = Router(); | ||||
| 
 | ||||
| router.get("/", async (req: Request, res: Response) => { | ||||
| 	var channels = await ChannelModel.find({ | ||||
| 		$or: [ | ||||
| 			{ recipients: req.user_id, type: ChannelType.DM }, | ||||
| 			{ recipients: req.user_id, type: ChannelType.GROUP_DM }, | ||||
| 		], | ||||
| 	}).exec(); | ||||
| 	var channels = await ChannelModel.find({ recipient_ids: req.user_id }).exec(); | ||||
| 
 | ||||
| 	res.json(toObject(channels)); | ||||
| }); | ||||
| 
 | ||||
| router.post("/", check(DmChannelCreateSchema), async (req, res) => { | ||||
| 	const body = req.body as DmChannelCreateSchema; | ||||
| 	if (body.recipients.length === 0) throw new HTTPError("You need to specify at least one recipient"); | ||||
| 
 | ||||
| 	body.recipients = body.recipients.filter((x) => x !== req.user_id).unique(); | ||||
| 
 | ||||
| 	if (!(await Promise.all(body.recipients.map((x) => UserModel.exists({ id: x })))).every((x) => x)) { | ||||
| 		throw new HTTPError("Recipient not found"); | ||||
| 	} | ||||
| 
 | ||||
| 	const type = body.recipients.length === 1 ? ChannelType.DM : ChannelType.GROUP_DM; | ||||
| 	const name = trimSpecial(body.name); | ||||
| 
 | ||||
| 	const channel = { | ||||
| 	const channel = await new ChannelModel({ | ||||
| 		name, | ||||
| 		type, | ||||
| 		owner_id: req.user_id, | ||||
| 		id: Snowflake.generate(), | ||||
| 		created_at: new Date(), | ||||
| 	}; | ||||
| 	await new ChannelModel(channel).save(); | ||||
| 		last_message_id: null, | ||||
| 		recipient_ids: [...body.recipients, req.user_id] | ||||
| 	}).save(); | ||||
| 
 | ||||
| 	/*Event({ event: "CHANNEL_CREATE", data: channel } as ChannelCreateEvent);*/ | ||||
| 	await emitEvent({ event: "CHANNEL_CREATE", data: toObject(channel), user_id: req.user_id } as ChannelCreateEvent); | ||||
| 
 | ||||
| 	res.json(channel); | ||||
| 	res.json(toObject(channel)); | ||||
| }); | ||||
| 
 | ||||
| export default router; | ||||
|  | ||||
| @ -1,5 +1,5 @@ | ||||
| import { Router, Request, Response } from "express"; | ||||
| import { UserModel } from "@fosscord/server-util"; | ||||
| import { GuildModel, MemberModel, UserModel } from "@fosscord/server-util"; | ||||
| import bcrypt from "bcrypt"; | ||||
| const router = Router(); | ||||
| 
 | ||||
| @ -8,7 +8,10 @@ router.post("/", async (req: Request, res: Response) => { | ||||
| 
 | ||||
| 	let correctpass = await bcrypt.compare(req.body.password, user!.user_data.hash); //Not sure if user typed right password :/
 | ||||
| 	if (correctpass) { | ||||
| 		await UserModel.deleteOne({ id: req.user_id }).exec(); //Yeetus user deletus
 | ||||
| 		await Promise.all([ | ||||
| 			UserModel.deleteOne({ id: req.user_id }).exec(), //Yeetus user deletus
 | ||||
| 			MemberModel.deleteMany({ id: req.user_id }).exec() | ||||
| 		]); | ||||
| 
 | ||||
| 		res.sendStatus(204); | ||||
| 	} else { | ||||
|  | ||||
| @ -14,16 +14,16 @@ export const ChannelModifySchema = { | ||||
| 			id: String, | ||||
| 			type: new Length(Number, 0, 1), // either 0 (role) or 1 (member)
 | ||||
| 			allow: BigInt, | ||||
| 			deny: BigInt, | ||||
| 		}, | ||||
| 			deny: BigInt | ||||
| 		} | ||||
| 	], | ||||
| 	$parent_id: String, | ||||
| 	$nsfw: Boolean, | ||||
| 	$nsfw: Boolean | ||||
| }; | ||||
| 
 | ||||
| export const DmChannelCreateSchema = { | ||||
| 	$name: String, | ||||
| 	recipients: [String], | ||||
| 	recipients: new Length([String], 1, 10) | ||||
| }; | ||||
| 
 | ||||
| export interface DmChannelCreateSchema { | ||||
| @ -52,8 +52,8 @@ export interface ChannelModifySchema { | ||||
| export const ChannelGuildPositionUpdateSchema = [ | ||||
| 	{ | ||||
| 		id: String, | ||||
| 		$position: Number, | ||||
| 	}, | ||||
| 		$position: Number | ||||
| 	} | ||||
| ]; | ||||
| 
 | ||||
| export type ChannelGuildPositionUpdateSchema = { | ||||
|  | ||||
| @ -45,7 +45,7 @@ export async function createChannel(channel: Partial<TextChannel | VoiceChannel> | ||||
| 		id: Snowflake.generate(), | ||||
| 		created_at: new Date(), | ||||
| 		// @ts-ignore
 | ||||
| 		recipients: null | ||||
| 		recipient_ids: null | ||||
| 	}).save(); | ||||
| 
 | ||||
| 	await emitEvent({ event: "CHANNEL_CREATE", data: channel, guild_id: channel.guild_id } as ChannelCreateEvent); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Flam3rboy
						Flam3rboy