revolt.js
Advanced tools
Comparing version 6.0.10 to 6.0.11
import type { DataEditMessage, DataMessageSend, Embed, Interactions, Masquerade, Message as MessageI, SystemMessage } from "revolt-api"; | ||
import type { File } from "revolt-api"; | ||
import { ObservableMap, ObservableSet } from "mobx"; | ||
import { Nullable } from "../util/null"; | ||
@@ -20,3 +21,3 @@ import Collection from "./Collection"; | ||
masquerade: Nullable<Masquerade>; | ||
reactions: Record<string, string[]>; | ||
reactions: ObservableMap<string, ObservableSet<string>>; | ||
interactions: Nullable<Interactions>; | ||
@@ -291,2 +292,16 @@ get channel(): import("./Channels").Channel | undefined; | ||
}), mention?: boolean): Promise<Message> | undefined; | ||
/** | ||
* Clear all reactions from this message | ||
*/ | ||
clearReactions(): Promise<undefined>; | ||
/** | ||
* React to a message | ||
* @param emoji Unicode or emoji ID | ||
*/ | ||
react(emoji: string): Promise<undefined>; | ||
/** | ||
* Unreact from a message | ||
* @param emoji Unicode or emoji ID | ||
*/ | ||
unreact(emoji: string): Promise<undefined>; | ||
} | ||
@@ -293,0 +308,0 @@ export default class Messages extends Collection<string, Message> { |
@@ -43,4 +43,7 @@ "use strict"; | ||
this.masquerade = (0, null_1.toNullable)(data.masquerade); | ||
this.reactions = (_b = data.reactions) !== null && _b !== void 0 ? _b : {}; | ||
this.interactions = (0, null_1.toNullable)(data.interactions); | ||
this.reactions = new mobx_1.ObservableMap(); | ||
for (const reaction of Object.keys((_b = data.reactions) !== null && _b !== void 0 ? _b : {})) { | ||
this.reactions.set(reaction, new mobx_1.ObservableSet(data.reactions[reaction])); | ||
} | ||
(0, mobx_1.makeAutoObservable)(this, { | ||
@@ -189,2 +192,28 @@ _id: false, | ||
} | ||
/** | ||
* Clear all reactions from this message | ||
*/ | ||
clearReactions() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield this.client.api.delete(`/channels/${this.channel_id}/messages/${this._id}/reactions`); | ||
}); | ||
} | ||
/** | ||
* React to a message | ||
* @param emoji Unicode or emoji ID | ||
*/ | ||
react(emoji) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield this.client.api.put(`/channels/${this.channel_id}/messages/${this._id}/reactions/${emoji}`); | ||
}); | ||
} | ||
/** | ||
* Unreact from a message | ||
* @param emoji Unicode or emoji ID | ||
*/ | ||
unreact(emoji) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield this.client.api.delete(`/channels/${this.channel_id}/messages/${this._id}/reactions/${emoji}`); | ||
}); | ||
} | ||
} | ||
@@ -191,0 +220,0 @@ __decorate([ |
@@ -96,3 +96,3 @@ "use strict"; | ||
const process = (packet) => __awaiter(this, void 0, void 0, function* () { | ||
var _a, _b, _c, _d, _e, _f, _g, _h; | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j; | ||
this.client.emit("packet", packet); | ||
@@ -243,2 +243,26 @@ try { | ||
} | ||
case "MessageReact": { | ||
const msg = this.client.messages.get(packet.id); | ||
if (msg) { | ||
if (msg.reactions.has(packet.emoji_id)) { | ||
msg.reactions | ||
.get(packet.emoji_id) | ||
.add(packet.user_id); | ||
} | ||
else { | ||
msg.reactions.set(packet.emoji_id, new mobx_1.ObservableSet([packet.user_id])); | ||
} | ||
} | ||
break; | ||
} | ||
case "MessageUnreact": { | ||
const msg = this.client.messages.get(packet.id); | ||
(_b = msg === null || msg === void 0 ? void 0 : msg.reactions.get(packet.emoji_id)) === null || _b === void 0 ? void 0 : _b.delete(packet.user_id); | ||
break; | ||
} | ||
case "MessageRemoveReaction": { | ||
const msg = this.client.messages.get(packet.id); | ||
msg === null || msg === void 0 ? void 0 : msg.reactions.delete(packet.emoji_id); | ||
break; | ||
} | ||
case "BulkMessageDelete": { | ||
@@ -282,4 +306,4 @@ (0, mobx_1.runInAction)(() => { | ||
case "ChannelGroupJoin": { | ||
(_b = this.client.channels | ||
.get(packet.id)) === null || _b === void 0 ? void 0 : _b.updateGroupJoin(packet.user); | ||
(_c = this.client.channels | ||
.get(packet.id)) === null || _c === void 0 ? void 0 : _c.updateGroupJoin(packet.user); | ||
break; | ||
@@ -290,3 +314,3 @@ } | ||
if (channel) { | ||
if (packet.user === ((_c = this.client.user) === null || _c === void 0 ? void 0 : _c._id)) { | ||
if (packet.user === ((_d = this.client.user) === null || _d === void 0 ? void 0 : _d._id)) { | ||
channel.delete(true); | ||
@@ -376,3 +400,3 @@ } | ||
if (server) { | ||
const role = Object.assign(Object.assign({}, (_d = server.roles) === null || _d === void 0 ? void 0 : _d[packet.role_id]), packet.data); | ||
const role = Object.assign(Object.assign({}, (_e = server.roles) === null || _e === void 0 ? void 0 : _e[packet.role_id]), packet.data); | ||
server.roles = Object.assign(Object.assign({}, server.roles), { [packet.role_id]: role }); | ||
@@ -386,3 +410,3 @@ this.client.emit("role/update", packet.role_id, role, packet.id); | ||
if (server) { | ||
const _j = (_e = server.roles) !== null && _e !== void 0 ? _e : {}, _k = packet.role_id, _ = _j[_k], roles = __rest(_j, [typeof _k === "symbol" ? _k : _k + ""]); | ||
const _k = (_f = server.roles) !== null && _f !== void 0 ? _f : {}, _l = packet.role_id, _ = _k[_l], roles = __rest(_k, [typeof _l === "symbol" ? _l : _l + ""]); | ||
server.roles = roles; | ||
@@ -394,4 +418,4 @@ this.client.emit("role/delete", packet.role_id, packet.id); | ||
case "UserUpdate": { | ||
(_f = this.client.users | ||
.get(packet.id)) === null || _f === void 0 ? void 0 : _f.update(packet.data, packet.clear); | ||
(_g = this.client.users | ||
.get(packet.id)) === null || _g === void 0 ? void 0 : _g.update(packet.data, packet.clear); | ||
break; | ||
@@ -422,4 +446,4 @@ } | ||
case "ChannelStopTyping": { | ||
(_g = this.client.channels | ||
.get(packet.id)) === null || _g === void 0 ? void 0 : _g.updateStopTyping(packet.user); | ||
(_h = this.client.channels | ||
.get(packet.id)) === null || _h === void 0 ? void 0 : _h.updateStopTyping(packet.user); | ||
clearInterval(timeouts[packet.id + packet.user]); | ||
@@ -429,3 +453,3 @@ break; | ||
case "ChannelAck": { | ||
(_h = this.client.unreads) === null || _h === void 0 ? void 0 : _h.markRead(packet.id, packet.message_id); | ||
(_j = this.client.unreads) === null || _j === void 0 ? void 0 : _j.markRead(packet.id, packet.message_id); | ||
break; | ||
@@ -432,0 +456,0 @@ } |
@@ -64,2 +64,19 @@ import type { Emoji, FieldsChannel, FieldsMember, FieldsServer, FieldsUser } from "revolt-api"; | ||
} | { | ||
type: "MessageReact"; | ||
id: string; | ||
channel_id: string; | ||
user_id: string; | ||
emoji_id: string; | ||
} | { | ||
type: "MessageUnreact"; | ||
id: string; | ||
channel_id: string; | ||
user_id: string; | ||
emoji_id: string; | ||
} | { | ||
type: "MessageRemoveReaction"; | ||
id: string; | ||
channel_id: string; | ||
emoji_id: string; | ||
} | { | ||
type: "BulkMessageDelete"; | ||
@@ -66,0 +83,0 @@ channel: string; |
import type { DataEditMessage, DataMessageSend, Embed, Interactions, Masquerade, Message as MessageI, SystemMessage } from "revolt-api"; | ||
import type { File } from "revolt-api"; | ||
import { ObservableMap, ObservableSet } from "mobx"; | ||
import { Nullable } from "../util/null"; | ||
@@ -20,3 +21,3 @@ import Collection from "./Collection"; | ||
masquerade: Nullable<Masquerade>; | ||
reactions: Record<string, string[]>; | ||
reactions: ObservableMap<string, ObservableSet<string>>; | ||
interactions: Nullable<Interactions>; | ||
@@ -291,2 +292,16 @@ get channel(): import("./Channels").Channel | undefined; | ||
}), mention?: boolean): Promise<Message> | undefined; | ||
/** | ||
* Clear all reactions from this message | ||
*/ | ||
clearReactions(): Promise<undefined>; | ||
/** | ||
* React to a message | ||
* @param emoji Unicode or emoji ID | ||
*/ | ||
react(emoji: string): Promise<undefined>; | ||
/** | ||
* Unreact from a message | ||
* @param emoji Unicode or emoji ID | ||
*/ | ||
unreact(emoji: string): Promise<undefined>; | ||
} | ||
@@ -293,0 +308,0 @@ export default class Messages extends Collection<string, Message> { |
@@ -16,3 +16,3 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
}; | ||
import { makeAutoObservable, runInAction, action, computed } from "mobx"; | ||
import { makeAutoObservable, runInAction, action, computed, ObservableMap, ObservableSet, } from "mobx"; | ||
import isEqual from "lodash.isequal"; | ||
@@ -38,4 +38,7 @@ import { toNullable, toNullableDate } from "../util/null"; | ||
this.masquerade = toNullable(data.masquerade); | ||
this.reactions = (_b = data.reactions) !== null && _b !== void 0 ? _b : {}; | ||
this.interactions = toNullable(data.interactions); | ||
this.reactions = new ObservableMap(); | ||
for (const reaction of Object.keys((_b = data.reactions) !== null && _b !== void 0 ? _b : {})) { | ||
this.reactions.set(reaction, new ObservableSet(data.reactions[reaction])); | ||
} | ||
makeAutoObservable(this, { | ||
@@ -184,2 +187,28 @@ _id: false, | ||
} | ||
/** | ||
* Clear all reactions from this message | ||
*/ | ||
clearReactions() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield this.client.api.delete(`/channels/${this.channel_id}/messages/${this._id}/reactions`); | ||
}); | ||
} | ||
/** | ||
* React to a message | ||
* @param emoji Unicode or emoji ID | ||
*/ | ||
react(emoji) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield this.client.api.put(`/channels/${this.channel_id}/messages/${this._id}/reactions/${emoji}`); | ||
}); | ||
} | ||
/** | ||
* Unreact from a message | ||
* @param emoji Unicode or emoji ID | ||
*/ | ||
unreact(emoji) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield this.client.api.delete(`/channels/${this.channel_id}/messages/${this._id}/reactions/${emoji}`); | ||
}); | ||
} | ||
} | ||
@@ -186,0 +215,0 @@ __decorate([ |
@@ -23,3 +23,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import WebSocket from "@insertish/isomorphic-ws"; | ||
import { runInAction } from "mobx"; | ||
import { ObservableSet, runInAction } from "mobx"; | ||
export class WebSocketClient { | ||
@@ -91,3 +91,3 @@ constructor(client) { | ||
const process = (packet) => __awaiter(this, void 0, void 0, function* () { | ||
var _a, _b, _c, _d, _e, _f, _g, _h; | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j; | ||
this.client.emit("packet", packet); | ||
@@ -238,2 +238,26 @@ try { | ||
} | ||
case "MessageReact": { | ||
const msg = this.client.messages.get(packet.id); | ||
if (msg) { | ||
if (msg.reactions.has(packet.emoji_id)) { | ||
msg.reactions | ||
.get(packet.emoji_id) | ||
.add(packet.user_id); | ||
} | ||
else { | ||
msg.reactions.set(packet.emoji_id, new ObservableSet([packet.user_id])); | ||
} | ||
} | ||
break; | ||
} | ||
case "MessageUnreact": { | ||
const msg = this.client.messages.get(packet.id); | ||
(_b = msg === null || msg === void 0 ? void 0 : msg.reactions.get(packet.emoji_id)) === null || _b === void 0 ? void 0 : _b.delete(packet.user_id); | ||
break; | ||
} | ||
case "MessageRemoveReaction": { | ||
const msg = this.client.messages.get(packet.id); | ||
msg === null || msg === void 0 ? void 0 : msg.reactions.delete(packet.emoji_id); | ||
break; | ||
} | ||
case "BulkMessageDelete": { | ||
@@ -277,4 +301,4 @@ runInAction(() => { | ||
case "ChannelGroupJoin": { | ||
(_b = this.client.channels | ||
.get(packet.id)) === null || _b === void 0 ? void 0 : _b.updateGroupJoin(packet.user); | ||
(_c = this.client.channels | ||
.get(packet.id)) === null || _c === void 0 ? void 0 : _c.updateGroupJoin(packet.user); | ||
break; | ||
@@ -285,3 +309,3 @@ } | ||
if (channel) { | ||
if (packet.user === ((_c = this.client.user) === null || _c === void 0 ? void 0 : _c._id)) { | ||
if (packet.user === ((_d = this.client.user) === null || _d === void 0 ? void 0 : _d._id)) { | ||
channel.delete(true); | ||
@@ -371,3 +395,3 @@ } | ||
if (server) { | ||
const role = Object.assign(Object.assign({}, (_d = server.roles) === null || _d === void 0 ? void 0 : _d[packet.role_id]), packet.data); | ||
const role = Object.assign(Object.assign({}, (_e = server.roles) === null || _e === void 0 ? void 0 : _e[packet.role_id]), packet.data); | ||
server.roles = Object.assign(Object.assign({}, server.roles), { [packet.role_id]: role }); | ||
@@ -381,3 +405,3 @@ this.client.emit("role/update", packet.role_id, role, packet.id); | ||
if (server) { | ||
const _j = (_e = server.roles) !== null && _e !== void 0 ? _e : {}, _k = packet.role_id, _ = _j[_k], roles = __rest(_j, [typeof _k === "symbol" ? _k : _k + ""]); | ||
const _k = (_f = server.roles) !== null && _f !== void 0 ? _f : {}, _l = packet.role_id, _ = _k[_l], roles = __rest(_k, [typeof _l === "symbol" ? _l : _l + ""]); | ||
server.roles = roles; | ||
@@ -389,4 +413,4 @@ this.client.emit("role/delete", packet.role_id, packet.id); | ||
case "UserUpdate": { | ||
(_f = this.client.users | ||
.get(packet.id)) === null || _f === void 0 ? void 0 : _f.update(packet.data, packet.clear); | ||
(_g = this.client.users | ||
.get(packet.id)) === null || _g === void 0 ? void 0 : _g.update(packet.data, packet.clear); | ||
break; | ||
@@ -417,4 +441,4 @@ } | ||
case "ChannelStopTyping": { | ||
(_g = this.client.channels | ||
.get(packet.id)) === null || _g === void 0 ? void 0 : _g.updateStopTyping(packet.user); | ||
(_h = this.client.channels | ||
.get(packet.id)) === null || _h === void 0 ? void 0 : _h.updateStopTyping(packet.user); | ||
clearInterval(timeouts[packet.id + packet.user]); | ||
@@ -424,3 +448,3 @@ break; | ||
case "ChannelAck": { | ||
(_h = this.client.unreads) === null || _h === void 0 ? void 0 : _h.markRead(packet.id, packet.message_id); | ||
(_j = this.client.unreads) === null || _j === void 0 ? void 0 : _j.markRead(packet.id, packet.message_id); | ||
break; | ||
@@ -427,0 +451,0 @@ } |
@@ -64,2 +64,19 @@ import type { Emoji, FieldsChannel, FieldsMember, FieldsServer, FieldsUser } from "revolt-api"; | ||
} | { | ||
type: "MessageReact"; | ||
id: string; | ||
channel_id: string; | ||
user_id: string; | ||
emoji_id: string; | ||
} | { | ||
type: "MessageUnreact"; | ||
id: string; | ||
channel_id: string; | ||
user_id: string; | ||
emoji_id: string; | ||
} | { | ||
type: "MessageRemoveReaction"; | ||
id: string; | ||
channel_id: string; | ||
emoji_id: string; | ||
} | { | ||
type: "BulkMessageDelete"; | ||
@@ -66,0 +83,0 @@ channel: string; |
{ | ||
"name": "revolt.js", | ||
"version": "6.0.10", | ||
"version": "6.0.11", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "typings": "dist/index.d.ts", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
484978
13478