mirror of
https://github.com/stoatchat/javascript-client-sdk.git
synced 2026-07-20 20:16:06 -04:00
feat: bring up to spec
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "revolt.js",
|
||||
"version": "6.0.9",
|
||||
"version": "6.0.10",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"module": "esm/index.js",
|
||||
|
||||
+14
-3
@@ -10,7 +10,7 @@ import type { File } from "revolt-api";
|
||||
import { makeAutoObservable, runInAction, action, computed } from "mobx";
|
||||
import isEqual from "lodash.isequal";
|
||||
|
||||
import { Nullable, toNullable } from "../util/null";
|
||||
import { Nullable, toNullable, toNullableDate } from "../util/null";
|
||||
import Collection from "./Collection";
|
||||
import { Channel, Client, FileArgs, Server } from "..";
|
||||
import { bitwiseAndEq, calculatePermission } from "../permissions/calculator";
|
||||
@@ -20,10 +20,12 @@ export class Member {
|
||||
client: Client;
|
||||
|
||||
_id: MemberCompositeKey;
|
||||
joined_at: Date;
|
||||
|
||||
nickname: Nullable<string> = null;
|
||||
avatar: Nullable<File> = null;
|
||||
roles: Nullable<string[]> = null;
|
||||
timeout: Nullable<Date> = null;
|
||||
|
||||
/**
|
||||
* Associated user.
|
||||
@@ -50,23 +52,25 @@ export class Member {
|
||||
* Whether the client can kick this user.
|
||||
*/
|
||||
get kickable() {
|
||||
return this.server?.havePermission('KickMembers') && this.inferior;
|
||||
return this.server?.havePermission("KickMembers") && this.inferior;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the client can ban this user.
|
||||
*/
|
||||
get bannable() {
|
||||
return this.server?.havePermission('BanMembers') && this.inferior;
|
||||
return this.server?.havePermission("BanMembers") && this.inferior;
|
||||
}
|
||||
|
||||
constructor(client: Client, data: MemberI) {
|
||||
this.client = client;
|
||||
this._id = data._id;
|
||||
this.joined_at = new Date(data.joined_at);
|
||||
|
||||
this.nickname = toNullable(data.nickname);
|
||||
this.avatar = toNullable(data.avatar);
|
||||
this.roles = toNullable(data.roles);
|
||||
this.timeout = toNullableDate(data.timeout);
|
||||
|
||||
makeAutoObservable(this, {
|
||||
_id: false,
|
||||
@@ -96,12 +100,19 @@ export class Member {
|
||||
case "Avatar":
|
||||
this.avatar = null;
|
||||
break;
|
||||
case "Roles":
|
||||
this.roles = [];
|
||||
break;
|
||||
case "Timeout":
|
||||
this.timeout = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
apply("nickname");
|
||||
apply("avatar");
|
||||
apply("roles");
|
||||
apply("timeout");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,8 +33,8 @@ export class Message {
|
||||
mention_ids: Nullable<string[]>;
|
||||
reply_ids: Nullable<string[]>;
|
||||
masquerade: Nullable<Masquerade>;
|
||||
// reactions: Record<string, Set<string>>;
|
||||
// interactions: Nullable<Interactions>;
|
||||
reactions: Record<string, string[]>;
|
||||
interactions: Nullable<Interactions>;
|
||||
|
||||
get channel() {
|
||||
return this.client.channels.get(this.channel_id);
|
||||
@@ -132,6 +132,8 @@ export class Message {
|
||||
this.mention_ids = toNullable(data.mentions);
|
||||
this.reply_ids = toNullable(data.replies);
|
||||
this.masquerade = toNullable(data.masquerade);
|
||||
this.reactions = data.reactions ?? {};
|
||||
this.interactions = toNullable(data.interactions);
|
||||
|
||||
makeAutoObservable(this, {
|
||||
_id: false,
|
||||
@@ -166,6 +168,9 @@ export class Message {
|
||||
apply("edited", undefined, toNullableDate as (obj: unknown) => unknown);
|
||||
apply("embeds");
|
||||
apply("mentions", "mention_ids");
|
||||
apply("masquerade");
|
||||
apply("reactions");
|
||||
apply("interactions");
|
||||
}
|
||||
|
||||
@action append({ embeds }: Pick<Partial<MessageI>, "embeds">) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import Long from "long";
|
||||
import { Channel, Server, Member } from "..";
|
||||
import {
|
||||
ALLOW_IN_TIMEOUT,
|
||||
DEFAULT_PERMISSION_DIRECT_MESSAGE,
|
||||
DEFAULT_PERMISSION_VIEW_ONLY,
|
||||
Permission,
|
||||
@@ -46,7 +47,7 @@ export function calculatePermission(
|
||||
target.client.members.getKey({
|
||||
user: user!._id,
|
||||
server: target._id,
|
||||
}) ?? { roles: null };
|
||||
}) ?? { roles: null, timeout: null };
|
||||
|
||||
if (!member) return 0;
|
||||
|
||||
@@ -67,6 +68,11 @@ export function calculatePermission(
|
||||
}
|
||||
}
|
||||
|
||||
// 5. Revoke permissions if member is timed out.
|
||||
if (member.timeout && member.timeout > new Date()) {
|
||||
perm = perm.and(ALLOW_IN_TIMEOUT);
|
||||
}
|
||||
|
||||
return perm.toNumber();
|
||||
}
|
||||
} else {
|
||||
@@ -111,7 +117,7 @@ export function calculatePermission(
|
||||
target.client.members.getKey({
|
||||
user: user!._id,
|
||||
server: server._id,
|
||||
}) ?? { roles: null };
|
||||
}) ?? { roles: null, timeout: null };
|
||||
|
||||
if (!member) return 0;
|
||||
|
||||
@@ -150,6 +156,11 @@ export function calculatePermission(
|
||||
}
|
||||
}
|
||||
|
||||
// 8. Revoke permissions if member is timed out.
|
||||
if (member.timeout && member.timeout > new Date()) {
|
||||
perm = perm.and(ALLOW_IN_TIMEOUT);
|
||||
}
|
||||
|
||||
return perm.toNumber();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ export const Permission = {
|
||||
/// Manage roles on server
|
||||
ManageRole: 2 ** 3,
|
||||
/// Manage server customisation (includes emoji)
|
||||
ManageCustomisation: 2**4,
|
||||
ManageCustomisation: 2 ** 4,
|
||||
|
||||
// % 1 bits reserved
|
||||
|
||||
@@ -65,8 +65,8 @@ export const Permission = {
|
||||
UploadFiles: 2 ** 27,
|
||||
/// Masquerade messages using custom nickname and avatar
|
||||
Masquerade: 2 ** 28,
|
||||
|
||||
// % 1 bits reserved
|
||||
/// React to messages with emoji
|
||||
React: 2 ** 29,
|
||||
|
||||
// * Voice permissions
|
||||
/// Connect to a voice channel
|
||||
@@ -96,6 +96,12 @@ export const Permission = {
|
||||
*/
|
||||
export const U32_MAX = 2 ** 32 - 1; // 4294967295
|
||||
|
||||
/**
|
||||
* Permissions allowed for a user while in timeout
|
||||
*/
|
||||
export const ALLOW_IN_TIMEOUT =
|
||||
Permission.ViewChannel + Permission.ReadMessageHistory;
|
||||
|
||||
/**
|
||||
* Default permissions if we can only view
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user