request blocked users with passport

This commit is contained in:
HF 2020-11-19 20:18:45 +01:00
parent cce2ad1f80
commit 389f447b5b
4 changed files with 19 additions and 1 deletions

View File

@ -61,6 +61,7 @@ const UserContextMenu = ({
tabIndex={0} tabIndex={0}
onClick={() => { onClick={() => {
dm(uid); dm(uid);
// TODO if DM Channel with user already exist, just switch
close(); close();
}} }}
style={{ borderBottom: 'thin solid' }} style={{ borderBottom: 'thin solid' }}

View File

@ -41,6 +41,11 @@ const include = [{
'id', 'id',
'name', 'name',
], ],
}, {
model: RegUser,
as: 'blocked',
through: UserBlock,
foreignKey: 'uid',
}], }],
}, { }, {
model: RegUser, model: RegUser,

View File

@ -30,6 +30,7 @@ class User {
this.ip = ip; this.ip = ip;
this.channels = []; this.channels = [];
this.channelIds = []; this.channelIds = [];
this.blocked = [];
this.ipSub = getIPv6Subnet(ip); this.ipSub = getIPv6Subnet(ip);
this.wait = null; this.wait = null;
// following gets populated by passport // 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() { getName() {
@ -194,6 +204,7 @@ class User {
mailreg: !!(regUser.password), mailreg: !!(regUser.password),
userlvl: this.isAdmin() ? 1 : 0, userlvl: this.isAdmin() ? 1 : 0,
channels: this.channels, channels: this.channels,
blocked: this.blocked,
}; };
} }
} }

View File

@ -34,7 +34,7 @@ async function startDm(req: Request, res: Response) {
errors.push('You are not logged in'); errors.push('You are not logged in');
} }
if (user && userId && user.id === userId) { 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) { if (errors.length) {
res.status(400); res.status(400);
@ -118,6 +118,7 @@ async function startDm(req: Request, res: Response) {
]; ];
await Promise.all(promises); await Promise.all(promises);
// TODO: inform websocket to add channelId to user
res.json({ res.json({
channel: [ channel: [
ChannelId, ChannelId,