Fix gateway not listening for new channels events
This commit is contained in:
parent
5d6fa7697a
commit
97e0c8709b
@ -116,7 +116,7 @@ async function consume(this: WebSocket, opts: EventOpts) {
|
|||||||
.has("VIEW_CHANNEL")
|
.has("VIEW_CHANNEL")
|
||||||
)
|
)
|
||||||
return;
|
return;
|
||||||
break;
|
//No break needed here, we need to call the listenEvent function below
|
||||||
case "GUILD_CREATE":
|
case "GUILD_CREATE":
|
||||||
this.events[id] = await listenEvent(id, consumer, listenOpts);
|
this.events[id] = await listenEvent(id, consumer, listenOpts);
|
||||||
break;
|
break;
|
||||||
@ -193,16 +193,11 @@ async function consume(this: WebSocket, opts: EventOpts) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
let aa = {
|
Send(this, {
|
||||||
op: OPCODES.Dispatch,
|
op: OPCODES.Dispatch,
|
||||||
t: event,
|
t: event,
|
||||||
d: data,
|
d: data,
|
||||||
s: this.sequence++,
|
s: this.sequence++,
|
||||||
}
|
});
|
||||||
|
|
||||||
//TODO remove before PR merge
|
|
||||||
console.log(aa)
|
|
||||||
|
|
||||||
Send(this, aa);
|
|
||||||
opts.acknowledge?.();
|
opts.acknowledge?.();
|
||||||
}
|
}
|
||||||
|
@ -84,27 +84,24 @@ export class ChannelService {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let channel_dto = null;
|
await emitEvent({
|
||||||
|
event: "CHANNEL_DELETE",
|
||||||
|
data: await DmChannelDTO.from(channel, [user_id]),
|
||||||
|
user_id: user_id
|
||||||
|
});
|
||||||
|
|
||||||
//If the owner leave we make the first recipient in the list the new owner
|
//If the owner leave we make the first recipient in the list the new owner
|
||||||
if (channel.owner_id === user_id) {
|
if (channel.owner_id === user_id) {
|
||||||
channel.owner_id = channel.recipients!.find(r => r.user_id !== user_id)!.user_id //Is there a criteria to choose the new owner?
|
channel.owner_id = channel.recipients!.find(r => r.user_id !== user_id)!.user_id //Is there a criteria to choose the new owner?
|
||||||
channel_dto = await DmChannelDTO.from(channel, [user_id])
|
|
||||||
await emitEvent({
|
await emitEvent({
|
||||||
event: "CHANNEL_UPDATE",
|
event: "CHANNEL_UPDATE",
|
||||||
data: channel_dto,
|
data: await DmChannelDTO.from(channel, [user_id]),
|
||||||
channel_id: channel.id
|
channel_id: channel.id
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
await channel.save()
|
await channel.save()
|
||||||
|
|
||||||
await emitEvent({
|
|
||||||
event: "CHANNEL_DELETE",
|
|
||||||
data: channel_dto !== null ? channel_dto : await DmChannelDTO.from(channel, [user_id]),
|
|
||||||
user_id: user_id
|
|
||||||
});
|
|
||||||
|
|
||||||
await emitEvent({
|
await emitEvent({
|
||||||
event: "CHANNEL_RECIPIENT_REMOVE", data: {
|
event: "CHANNEL_RECIPIENT_REMOVE", data: {
|
||||||
channel_id: channel.id,
|
channel_id: channel.id,
|
||||||
|
@ -5,7 +5,6 @@ import { EVENT, Event } from "../interfaces";
|
|||||||
const events = new EventEmitter();
|
const events = new EventEmitter();
|
||||||
|
|
||||||
export async function emitEvent(payload: Omit<Event, "created_at">) {
|
export async function emitEvent(payload: Omit<Event, "created_at">) {
|
||||||
console.log(payload) //TODO remove before merge
|
|
||||||
const id = (payload.channel_id || payload.user_id || payload.guild_id) as string;
|
const id = (payload.channel_id || payload.user_id || payload.guild_id) as string;
|
||||||
if (!id) return console.error("event doesn't contain any id", payload);
|
if (!id) return console.error("event doesn't contain any id", payload);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user