diff --git a/src/components/UserContextMenu.jsx b/src/components/UserContextMenu.jsx index 4e581a6..cf38f55 100644 --- a/src/components/UserContextMenu.jsx +++ b/src/components/UserContextMenu.jsx @@ -61,6 +61,7 @@ const UserContextMenu = ({ tabIndex={0} onClick={() => { dm(uid); + // TODO if DM Channel with user already exist, just switch close(); }} style={{ borderBottom: 'thin solid' }} diff --git a/src/core/passport.js b/src/core/passport.js index 55444f7..889c8a8 100644 --- a/src/core/passport.js +++ b/src/core/passport.js @@ -41,6 +41,11 @@ const include = [{ 'id', 'name', ], + }, { + model: RegUser, + as: 'blocked', + through: UserBlock, + foreignKey: 'uid', }], }, { model: RegUser, diff --git a/src/data/models/User.js b/src/data/models/User.js index 6120295..07d96dc 100644 --- a/src/data/models/User.js +++ b/src/data/models/User.js @@ -30,6 +30,7 @@ class User { this.ip = ip; this.channels = []; this.channelIds = []; + this.blocked = []; this.ipSub = getIPv6Subnet(ip); this.wait = null; // following gets populated by passport @@ -77,6 +78,15 @@ class User { ]); } } + if (reguser.blocked) { + for (let i = 0; i < reguser.blocked.length; i += 1) { + const { + id, + name, + } = reguser.blocked[i]; + this.blocked.push([id, name]); + } + } } getName() { @@ -194,6 +204,7 @@ class User { mailreg: !!(regUser.password), userlvl: this.isAdmin() ? 1 : 0, channels: this.channels, + blocked: this.blocked, }; } } diff --git a/src/routes/api/startdm.js b/src/routes/api/startdm.js index d46f80c..5f69bec 100644 --- a/src/routes/api/startdm.js +++ b/src/routes/api/startdm.js @@ -34,7 +34,7 @@ async function startDm(req: Request, res: Response) { errors.push('You are not logged in'); } if (user && userId && user.id === userId) { - errors.push('You can not start DM to yourself.'); + errors.push('You can not DM yourself.'); } if (errors.length) { res.status(400); @@ -118,6 +118,7 @@ async function startDm(req: Request, res: Response) { ]; await Promise.all(promises); + // TODO: inform websocket to add channelId to user res.json({ channel: [ ChannelId,