🐛 fix channel events + message send

This commit is contained in:
Flam3rboy 2021-09-13 00:17:56 +02:00
parent e32bb24fa8
commit 6b21e107dd
3 changed files with 17 additions and 13 deletions

View File

@ -11,7 +11,8 @@
"build:api": "cd ../api/ && npm run build", "build:api": "cd ../api/ && npm run build",
"build:cdn": "cd ../cdn/ && npm run build", "build:cdn": "cd ../cdn/ && npm run build",
"build:gateway": "cd ../gateway/ && npm run build", "build:gateway": "cd ../gateway/ && npm run build",
"start": "npm run build && node -r ./tsconfig-paths-bootstrap.js dist/start.js", "start": "npm run build && npm run start:bundle",
"start:bundle": "node -r ./tsconfig-paths-bootstrap.js dist/start.js",
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
"repository": { "repository": {

View File

@ -26,16 +26,16 @@ import { Recipient } from "@fosscord/util";
// TODO: use already queried guilds/channels of Identify and don't fetch them again // TODO: use already queried guilds/channels of Identify and don't fetch them again
export async function setupListener(this: WebSocket) { export async function setupListener(this: WebSocket) {
const members = await Member.find({ id: this.user_id }); const members = await Member.find({
const guild_ids = members.map((x) => x.guild_id); where: { id: this.user_id },
const user = await User.findOneOrFail({ id: this.user_id }); relations: ["guild", "guild.channels"],
});
const guilds = members.map((x) => x.guild);
const recipients = await Recipient.find({ const recipients = await Recipient.find({
where: { user_id: this.user_id }, where: { user_id: this.user_id },
relations: ["channel"], relations: ["channel"],
}); });
const channels = await Channel.find({ guild_id: In(guild_ids) });
const dm_channels = recipients.map((x) => x.channel); const dm_channels = recipients.map((x) => x.channel);
const guild_channels = channels.filter((x) => x.guild_id);
const opts: { acknowledge: boolean; channel?: AMQChannel } = { const opts: { acknowledge: boolean; channel?: AMQChannel } = {
acknowledge: true, acknowledge: true,
@ -54,18 +54,20 @@ export async function setupListener(this: WebSocket) {
this.events[channel.id] = await listenEvent(channel.id, consumer, opts); this.events[channel.id] = await listenEvent(channel.id, consumer, opts);
} }
for (const guild of guild_ids) { for (const guild of guilds) {
// contains guild and dm channels // contains guild and dm channels
getPermission(this.user_id, guild) getPermission(this.user_id, guild.id)
.then(async (x) => { .then(async (x) => {
this.permissions[guild] = x; this.permissions[guild.id] = x;
this.listeners; this.listeners;
this.events[guild] = await listenEvent(guild, consumer, opts); this.events[guild.id] = await listenEvent(
guild.id,
consumer,
opts
);
for (const channel of guild_channels.filter( for (const channel of guild.channels) {
(c) => c.guild_id === guild
)) {
if ( if (
x x
.overwriteChannel(channel.permission_overwrites) .overwriteChannel(channel.permission_overwrites)

View File

@ -61,6 +61,7 @@ export class Channel extends BaseClass {
@ManyToOne(() => Channel) @ManyToOne(() => Channel)
parent?: Channel; parent?: Channel;
// only for group dms
@Column({ nullable: true }) @Column({ nullable: true })
@RelationId((channel: Channel) => channel.owner) @RelationId((channel: Channel) => channel.owner)
owner_id: string; owner_id: string;