Handle all packets.

This commit is contained in:
Paul 2021-07-29 20:39:58 +01:00
parent d5cd45196e
commit b06729d0b3

View file

@ -79,6 +79,10 @@ export class User {
apply("relationship"); apply("relationship");
apply("online"); apply("online");
} }
@action setRelationship(relationship: Users.Relationship) {
this.relationship = relationship;
}
} }
export class Channel { export class Channel {
@ -180,6 +184,16 @@ export class Channel {
apply("recipients"); apply("recipients");
apply("last_message"); apply("last_message");
} }
@action groupJoin(user: string) {
this.recipients?.push(user);
}
@action groupLeave(user: string) {
this.recipients = toNullable(
this.recipients?.filter((x) => x !== user),
);
}
} }
export class Server { export class Server {
@ -320,10 +334,59 @@ export class DataStore {
break; break;
} }
case "ChannelCreate": {
this.channels.set(packet._id, new Channel(packet));
break;
}
case "ChannelUpdate": {
this.channels.get(packet.id)?.update(packet.data, packet.clear);
break;
}
case "ChannelDelete": {
this.channels.delete(packet.id);
break;
}
case "ChannelGroupJoin": {
this.channels.get(packet.id)?.groupJoin(packet.user);
break;
}
case "ChannelGroupLeave": {
this.channels.get(packet.id)?.groupJoin(packet.user);
break;
}
case "UserUpdate": { case "UserUpdate": {
this.users.get(packet.id)?.update(packet.data, packet.clear); this.users.get(packet.id)?.update(packet.data, packet.clear);
break; break;
} }
case "UserRelationship": {
if (!this.users.has(packet.user._id)) {
this.users.set(packet.user._id, new User(packet.user));
}
this.users.get(packet.user._id)?.setRelationship(packet.status);
break;
}
case "ServerUpdate": {
this.servers.get(packet.id)?.update(packet.data, packet.clear);
break;
}
case "ServerDelete": {
this.servers.delete(packet.id);
break;
}
case "ServerMemberUpdate": {
this.members.get(packet.id)?.update(packet.data, packet.clear);
break;
}
case "ServerMemberJoin": {
const _id = { server: packet.id, user: packet.user };
this.members.set(_id, new Member({ _id }));
break;
}
case "ServerMemberLeave": {
this.members.delete({ server: packet.id, user: packet.user });
break;
}
} }
} }
} }