summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaindropsSys <contact@minteck.org>2023-07-15 22:51:19 +0200
committerRaindropsSys <contact@minteck.org>2023-07-15 22:51:19 +0200
commit250e9154403aabec467b95538c376fdcd7c9db6e (patch)
treed2ad0c8a4a30aedf2e93b4cc94a838d351925940
parentb00f8d4b4e552dea8ce6740b1606691a23ec0d86 (diff)
downloadsignal.js-250e9154403aabec467b95538c376fdcd7c9db6e.tar.gz
signal.js-250e9154403aabec467b95538c376fdcd7c9db6e.tar.bz2
signal.js-250e9154403aabec467b95538c376fdcd7c9db6e.zip
Update
-rw-r--r--ROADMAP.md10
-rw-r--r--build.js7
-rw-r--r--classes/Client.ts52
-rw-r--r--classes/ClientUser.ts120
-rw-r--r--dist/classes/ClientUser.d.ts51
-rw-r--r--dist/classes/ClientUser.js83
-rw-r--r--dist/classes/ClientUser.js.map1
-rw-r--r--dist/enums/SharedPreference.d.ts9
-rw-r--r--dist/enums/SharedPreference.js14
-rw-r--r--dist/enums/SharedPreference.js.map1
-rw-r--r--enums/SharedPreference.ts9
-rw-r--r--package.json4
12 files changed, 352 insertions, 9 deletions
diff --git a/ROADMAP.md b/ROADMAP.md
index aa68868..81066df 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -38,11 +38,13 @@
* [x] <s>Join (from an invite link)</s>
* [x] <s>Change disappearing messages time</s>
* [ ] Profile
- * [ ] Avatar
- * [ ] Name
- * [ ] Status (emoji + text)
+ * [x] <s>Avatar</s>
+ * [x] <s>Name</s>
+ * [x] <s>Status (emoji + text)</s>
* [ ] Sticker packs
- * [ ] Configuration
+ * [x] <s>User name</s>
+ * [x] <s>Device name</s>
+ * [x] <s>Configuration</s>
* [x] <s>Adding/removing linked devices</s>
* [x] <s>Listings</s>
* [x] <s>Known contacts</s>
diff --git a/build.js b/build.js
index 62ca9f0..75eb334 100644
--- a/build.js
+++ b/build.js
@@ -3,12 +3,13 @@ fs.copyFileSync(__dirname + "/package.json", __dirname + "/package.json.old");
let id = require('child_process').execSync("git rev-parse HEAD", { cwd: __dirname }).toString().trim().substring(0, 7);
-const pkg = require("./package.json");
+const pkg = require(__dirname + "/package.json");
const child_process = require("child_process");
pkg.version = pkg.version.split("-")[0] + "-dev." + Math.round(new Date().getTime() / 1000).toString() + "-" + id + ".0";
-fs.writeFileSync("./package.json", JSON.stringify(pkg, null, 2));
+fs.writeFileSync(__dirname + "/package.json", JSON.stringify(pkg, null, 2));
-child_process.execSync("npx npm-deprecate -n *-dev.* --message \"This version of Signal.js was built automatically and is not the latest version. No support will be provided.\"");
child_process.execSync("npm publish --tag dev", { cwd: __dirname, stdio: "inherit" });
+process.env.NODE_AUTH_TOKEN = fs.readFileSync(__dirname + "/.token").toString().trim();
+child_process.execSync("npx npm-deprecate -p @equestria.dev/signal.js -n *-dev.* --message \"This version of Signal.js was built automatically and is not the latest version. No support will be provided.\"", { cwd: __dirname, stdio: "inherit" });
fs.copyFileSync(__dirname + "/package.json.old", __dirname + "/package.json");
fs.unlinkSync(__dirname + "/package.json.old"); \ No newline at end of file
diff --git a/classes/Client.ts b/classes/Client.ts
index 3190c41..fb830a9 100644
--- a/classes/Client.ts
+++ b/classes/Client.ts
@@ -24,6 +24,8 @@ import {UserProfile} from "./UserProfile";
import {Identity} from "./Identity";
import {StickerPack} from "./StickerPack";
import {Sticker} from "./Sticker";
+import {ClientUser} from "./ClientUser";
+import {SharedPreference} from "../enums/SharedPreference";
export declare interface Client {
/**
@@ -108,6 +110,11 @@ export class Client extends EventEmitter {
public verbose: boolean = false;
/**
+ * The user configuration for this client
+ */
+ public user: ClientUser;
+
+ /**
* @param config - The configuration to use with signal-cli
*/
constructor(config: IConfig) {
@@ -172,6 +179,8 @@ export class Client extends EventEmitter {
if (chunk.toString().trim().startsWith("WARN ")) return;
throw new SignalCLIError(chunk.toString(), command, parameters)
});
+
+ this.user = new ClientUser(this);
}
/**
@@ -281,4 +290,47 @@ export class Client extends EventEmitter {
this.stickerPacks['list'] = list;
return list.map(i => new StickerPack(i, this));
}
+
+ /**
+ * Change a shared Signal preference
+ * @param preference - The name of the preference to change
+ * @param value - The new value of that preference
+ */
+ public async setSharedPreference(preference: SharedPreference, value: boolean) {
+ await CLIDispatcher.dispatch(
+ "updateConfiguration",
+ {
+ [preference]: value
+ },
+ this.process
+ );
+ }
+
+ /**
+ * Change the name of this device on the account
+ * @param name
+ */
+ public async setDeviceName(name: string) {
+ await CLIDispatcher.dispatch(
+ "updateAccount",
+ {
+ deviceName: name
+ },
+ this.process
+ );
+ }
+
+ /**
+ * Set a PIN code to lock account registration
+ * @param pin - The PIN code to set
+ */
+ public async setRegistrationPin(pin: number) {
+ await CLIDispatcher.dispatch(
+ "setPin",
+ {
+ pin
+ },
+ this.process
+ );
+ }
} \ No newline at end of file
diff --git a/classes/ClientUser.ts b/classes/ClientUser.ts
new file mode 100644
index 0000000..2e5e325
--- /dev/null
+++ b/classes/ClientUser.ts
@@ -0,0 +1,120 @@
+import {Client} from "./Client";
+import {CLIDispatcher} from "./CLIDispatcher";
+import {Emoji} from "./Emoji";
+import {AttachmentBuilder} from "./AttachmentBuilder";
+import {IFilePath} from "../types/IFilePath";
+import {IDataURI} from "../types/IDataURI";
+
+/**
+ * A Signal user to associate with a {@link Client}
+ */
+export class ClientUser {
+ public client;
+
+ /**
+ * @internal
+ * @param client
+ */
+ constructor(client: Client) {
+ this.client = client;
+ }
+
+ /**
+ * Remove the currently set username
+ */
+ public async deleteUserName() {
+ await CLIDispatcher.dispatch(
+ "updateAccount",
+ {
+ deleteUsername: true
+ },
+ this.client.process
+ );
+ }
+
+ /**
+ * Change the username used by this account
+ * @param userName - The new username to use
+ */
+ public async setUserName(userName: string) {
+ await CLIDispatcher.dispatch(
+ "updateAccount",
+ {
+ username: userName
+ },
+ this.client.process
+ );
+ }
+
+ /**
+ * Change the user's first name, cannot be empty
+ * @param name - The new first name to use
+ */
+ public async setFirstName(name: string) {
+ await CLIDispatcher.dispatch(
+ "updateProfile",
+ {
+ givenName: name
+ },
+ this.client.process
+ );
+ }
+
+ /**
+ * Change the user's last name, can also be an empty string
+ * @param name - The new last name to use
+ */
+ public async setLastName(name: string) {
+ await CLIDispatcher.dispatch(
+ "updateProfile",
+ {
+ familyName: name
+ },
+ this.client.process
+ );
+ }
+
+ /**
+ * Change the user's MobileCoin address, can also be an empty string
+ * @param address - The new MobileCoin address to use
+ */
+ public async setMobileCoinAddress(address?: string) {
+ await CLIDispatcher.dispatch(
+ "updateProfile",
+ {
+ mobileCoinAddress: address ?? ""
+ },
+ this.client.process
+ );
+ }
+
+ /**
+ * Change the status message for this user, can also be an empty string
+ * @param message - The status message to use
+ * @param emoji - The status emoji to use
+ */
+ public async setStatus(message?: string, emoji?: Emoji) {
+ await CLIDispatcher.dispatch(
+ "updateProfile",
+ {
+ about: message ?? "",
+ aboutEmoji: emoji ?? ""
+ },
+ this.client.process
+ );
+ }
+
+ /**
+ * Change the avatar used by this user
+ * @param url - Either an {@link AttachmentBuilder}, or a path/data URI to a file
+ */
+ public async setAvatar(url: AttachmentBuilder|IFilePath|IDataURI) {
+ await CLIDispatcher.dispatch(
+ "updateProfile",
+ {
+ avatar: url instanceof AttachmentBuilder ? url.uri : url
+ },
+ this.client.process
+ );
+ }
+} \ No newline at end of file
diff --git a/dist/classes/ClientUser.d.ts b/dist/classes/ClientUser.d.ts
new file mode 100644
index 0000000..589ef1e
--- /dev/null
+++ b/dist/classes/ClientUser.d.ts
@@ -0,0 +1,51 @@
+import { Client } from "./Client";
+import { Emoji } from "./Emoji";
+import { AttachmentBuilder } from "./AttachmentBuilder";
+import { IFilePath } from "../types/IFilePath";
+import { IDataURI } from "../types/IDataURI";
+/**
+ * A Signal user to associate with a {@link Client}
+ */
+export declare class ClientUser {
+ client: any;
+ /**
+ * @internal
+ * @param client
+ */
+ constructor(client: Client);
+ /**
+ * Remove the currently set username
+ */
+ deleteUserName(): Promise<void>;
+ /**
+ * Change the username used by this account
+ * @param userName - The new username to use
+ */
+ setUserName(userName: string): Promise<void>;
+ /**
+ * Change the user's first name, cannot be empty
+ * @param name - The new first name to use
+ */
+ setFirstName(name: string): Promise<void>;
+ /**
+ * Change the user's last name, can also be an empty string
+ * @param name - The new last name to use
+ */
+ setLastName(name: string): Promise<void>;
+ /**
+ * Change the user's MobileCoin address, can also be an empty string
+ * @param address - The new MobileCoin address to use
+ */
+ setMobileCoinAddress(address?: string): Promise<void>;
+ /**
+ * Change the status message for this user, can also be an empty string
+ * @param message - The status message to use
+ * @param emoji - The status emoji to use
+ */
+ setStatus(message?: string, emoji?: Emoji): Promise<void>;
+ /**
+ * Change the avatar used by this user
+ * @param url - Either an {@link AttachmentBuilder}, or a path/data URI to a file
+ */
+ setAvatar(url: AttachmentBuilder | IFilePath | IDataURI): Promise<void>;
+}
diff --git a/dist/classes/ClientUser.js b/dist/classes/ClientUser.js
new file mode 100644
index 0000000..040f84e
--- /dev/null
+++ b/dist/classes/ClientUser.js
@@ -0,0 +1,83 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.ClientUser = void 0;
+const CLIDispatcher_1 = require("./CLIDispatcher");
+const AttachmentBuilder_1 = require("./AttachmentBuilder");
+/**
+ * A Signal user to associate with a {@link Client}
+ */
+class ClientUser {
+ /**
+ * @internal
+ * @param client
+ */
+ constructor(client) {
+ this.client = client;
+ }
+ /**
+ * Remove the currently set username
+ */
+ async deleteUserName() {
+ await CLIDispatcher_1.CLIDispatcher.dispatch("updateAccount", {
+ deleteUsername: true
+ }, this.client.process);
+ }
+ /**
+ * Change the username used by this account
+ * @param userName - The new username to use
+ */
+ async setUserName(userName) {
+ await CLIDispatcher_1.CLIDispatcher.dispatch("updateAccount", {
+ username: userName
+ }, this.client.process);
+ }
+ /**
+ * Change the user's first name, cannot be empty
+ * @param name - The new first name to use
+ */
+ async setFirstName(name) {
+ await CLIDispatcher_1.CLIDispatcher.dispatch("updateProfile", {
+ givenName: name
+ }, this.client.process);
+ }
+ /**
+ * Change the user's last name, can also be an empty string
+ * @param name - The new last name to use
+ */
+ async setLastName(name) {
+ await CLIDispatcher_1.CLIDispatcher.dispatch("updateProfile", {
+ familyName: name
+ }, this.client.process);
+ }
+ /**
+ * Change the user's MobileCoin address, can also be an empty string
+ * @param address - The new MobileCoin address to use
+ */
+ async setMobileCoinAddress(address) {
+ await CLIDispatcher_1.CLIDispatcher.dispatch("updateProfile", {
+ mobileCoinAddress: address ?? ""
+ }, this.client.process);
+ }
+ /**
+ * Change the status message for this user, can also be an empty string
+ * @param message - The status message to use
+ * @param emoji - The status emoji to use
+ */
+ async setStatus(message, emoji) {
+ await CLIDispatcher_1.CLIDispatcher.dispatch("updateProfile", {
+ about: message ?? "",
+ aboutEmoji: emoji ?? ""
+ }, this.client.process);
+ }
+ /**
+ * Change the avatar used by this user
+ * @param url - Either an {@link AttachmentBuilder}, or a path/data URI to a file
+ */
+ async setAvatar(url) {
+ await CLIDispatcher_1.CLIDispatcher.dispatch("updateProfile", {
+ avatar: url instanceof AttachmentBuilder_1.AttachmentBuilder ? url.uri : url
+ }, this.client.process);
+ }
+}
+exports.ClientUser = ClientUser;
+//# sourceMappingURL=ClientUser.js.map \ No newline at end of file
diff --git a/dist/classes/ClientUser.js.map b/dist/classes/ClientUser.js.map
new file mode 100644
index 0000000..3824ea4
--- /dev/null
+++ b/dist/classes/ClientUser.js.map
@@ -0,0 +1 @@
+{"version":3,"file":"ClientUser.js","sourceRoot":"","sources":["../../classes/ClientUser.ts"],"names":[],"mappings":";;;AACA,mDAA8C;AAE9C,2DAAsD;AAItD;;GAEG;AACH,MAAa,UAAU;IAGnB;;;OAGG;IACH,YAAY,MAAc;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,cAAc;QACvB,MAAM,6BAAa,CAAC,QAAQ,CACxB,eAAe,EACf;YACI,cAAc,EAAE,IAAI;SACvB,EACD,IAAI,CAAC,MAAM,CAAC,OAAO,CACtB,CAAC;IACN,CAAC;IAED;;;OAGG;I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CACtB,CAAC;IACN,CAAC;CACJ;AA7GD,gCA6GC"} \ No newline at end of file
diff --git a/dist/enums/SharedPreference.d.ts b/dist/enums/SharedPreference.d.ts
new file mode 100644
index 0000000..4d96abc
--- /dev/null
+++ b/dist/enums/SharedPreference.d.ts
@@ -0,0 +1,9 @@
+/**
+ * A preference shared across all devices that are logged into this account
+ */
+export declare enum SharedPreference {
+ SendReadReceipts = "readReceipts",
+ SealedSenderIndicator = "unidentifiedDeliveryIndicators",
+ SendTypingIndicators = "typingIndicators",
+ GenerateLinkPreviews = "linkPreviews"
+}
diff --git a/dist/enums/SharedPreference.js b/dist/enums/SharedPreference.js
new file mode 100644
index 0000000..58099db
--- /dev/null
+++ b/dist/enums/SharedPreference.js
@@ -0,0 +1,14 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.SharedPreference = void 0;
+/**
+ * A preference shared across all devices that are logged into this account
+ */
+var SharedPreference;
+(function (SharedPreference) {
+ SharedPreference["SendReadReceipts"] = "readReceipts";
+ SharedPreference["SealedSenderIndicator"] = "unidentifiedDeliveryIndicators";
+ SharedPreference["SendTypingIndicators"] = "typingIndicators";
+ SharedPreference["GenerateLinkPreviews"] = "linkPreviews";
+})(SharedPreference || (exports.SharedPreference = SharedPreference = {}));
+//# sourceMappingURL=SharedPreference.js.map \ No newline at end of file
diff --git a/dist/enums/SharedPreference.js.map b/dist/enums/SharedPreference.js.map
new file mode 100644
index 0000000..f07cc65
--- /dev/null
+++ b/dist/enums/SharedPreference.js.map
@@ -0,0 +1 @@
+{"version":3,"file":"SharedPreference.js","sourceRoot":"","sources":["../../enums/SharedPreference.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,IAAY,gBAKX;AALD,WAAY,gBAAgB;IACxB,qDAAiC,CAAA;IACjC,4EAAwD,CAAA;IACxD,6DAAyC,CAAA;IACzC,yDAAqC,CAAA;AACzC,CAAC,EALW,gBAAgB,gCAAhB,gBAAgB,QAK3B"} \ No newline at end of file
diff --git a/enums/SharedPreference.ts b/enums/SharedPreference.ts
new file mode 100644
index 0000000..2c312f6
--- /dev/null
+++ b/enums/SharedPreference.ts
@@ -0,0 +1,9 @@
+/**
+ * A preference shared across all devices that are logged into this account
+ */
+export enum SharedPreference {
+ SendReadReceipts = "readReceipts",
+ SealedSenderIndicator = "unidentifiedDeliveryIndicators",
+ SendTypingIndicators = "typingIndicators",
+ GenerateLinkPreviews = "linkPreviews"
+} \ No newline at end of file
diff --git a/package.json b/package.json
index 0342c0c..f8a877b 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "@equestria.dev/signal.js",
- "version": "0.4.0-beta.1",
+ "version": "0.5.0-beta.0",
"description": "An easy-to-use Node.js library for Signal",
"main": "dist/index.js",
"publishConfig": {
@@ -40,4 +40,4 @@
"engines": {
"node": ">=16.9.0"
}
-}
+} \ No newline at end of file