Fix chown, add remove parameter to user flags
This commit is contained in:
parent
9d84c5f81b
commit
e1937aea02
|
@ -234,7 +234,8 @@ declare interface ServerEvents {
|
||||||
m: "user_flag";
|
m: "user_flag";
|
||||||
_id: string;
|
_id: string;
|
||||||
key: keyof UserFlags;
|
key: keyof UserFlags;
|
||||||
value: UserFlags[keyof UserFlags];
|
value?: UserFlags[keyof UserFlags];
|
||||||
|
remove?: true;
|
||||||
};
|
};
|
||||||
|
|
||||||
clear_chat: {
|
clear_chat: {
|
||||||
|
|
|
@ -1,14 +1,19 @@
|
||||||
import { readUser, updateUser } from "../../../../data/user";
|
import { readUser, updateUser } from "../../../../data/user";
|
||||||
|
import { Logger } from "../../../../util/Logger";
|
||||||
import { ServerEventListener } from "../../../../util/types";
|
import { ServerEventListener } from "../../../../util/types";
|
||||||
import { findSocketsByUserID } from "../../../Socket";
|
import { findSocketsByUserID } from "../../../Socket";
|
||||||
|
|
||||||
|
const logger = new Logger("User flag handler");
|
||||||
|
|
||||||
export const user_flag: ServerEventListener<"user_flag"> = {
|
export const user_flag: ServerEventListener<"user_flag"> = {
|
||||||
id: "user_flag",
|
id: "user_flag",
|
||||||
callback: async (msg, socket) => {
|
callback: async (msg, socket) => {
|
||||||
// User flag modification (changing some real specific shit)
|
// User flag modification (changing some real specific shit)
|
||||||
if (typeof msg._id !== "string") return;
|
if (typeof msg._id !== "string") return;
|
||||||
if (typeof msg.key !== "string") return;
|
if (typeof msg.key !== "string") return;
|
||||||
if (typeof msg.value == "undefined") return;
|
if (typeof msg.remove !== "boolean" && typeof msg.value == "undefined") {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// socket.getCurrentChannel()?.logger.debug(msg);
|
// socket.getCurrentChannel()?.logger.debug(msg);
|
||||||
|
|
||||||
|
@ -18,7 +23,11 @@ export const user_flag: ServerEventListener<"user_flag"> = {
|
||||||
|
|
||||||
// Set the flag
|
// Set the flag
|
||||||
const flags = JSON.parse(user.flags);
|
const flags = JSON.parse(user.flags);
|
||||||
flags[msg.key] = msg.value;
|
if (msg.remove === true) {
|
||||||
|
delete flags[msg.key];
|
||||||
|
} else {
|
||||||
|
flags[msg.key] = msg.value;
|
||||||
|
}
|
||||||
user.flags = JSON.stringify(flags);
|
user.flags = JSON.stringify(flags);
|
||||||
|
|
||||||
// Save the user data
|
// Save the user data
|
||||||
|
|
|
@ -7,22 +7,18 @@ export const chown: ServerEventListener<"chown"> = {
|
||||||
id: "chown",
|
id: "chown",
|
||||||
callback: (msg, socket) => {
|
callback: (msg, socket) => {
|
||||||
// Change channel ownership
|
// Change channel ownership
|
||||||
if (typeof msg.id == "undefined") return;
|
|
||||||
|
|
||||||
|
|
||||||
const ch = socket.getCurrentChannel();
|
const ch = socket.getCurrentChannel();
|
||||||
if (!ch) return;
|
if (!ch) return;
|
||||||
|
|
||||||
if (!socket.isOwner()) return;
|
|
||||||
|
|
||||||
if (!ch.crown) {
|
if (!ch.crown) {
|
||||||
// TODO Crown admin stuff
|
// TODO Crown admin stuff
|
||||||
} else {
|
} else {
|
||||||
if (!ch.crown.canBeSetBy(socket)) return;
|
if (!ch.crown.canBeSetBy(socket)) return;
|
||||||
|
|
||||||
const heir = ch.getParticipantList().find(p => p.id == msg.id);
|
// This user may not always exist,
|
||||||
if (!heir) return;
|
// but sometimes we don't provide a user
|
||||||
|
// to drop the crown
|
||||||
|
let heir = ch.getParticipantList().find(p => p.id == msg.id);
|
||||||
ch.chown(heir);
|
ch.chown(heir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue