瀏覽代碼

Add showTotal arg to getParticipants

painor 3 年之前
父節點
當前提交
a1df9c4de6
共有 4 個文件被更改,包括 20 次插入12 次删除
  1. 1 1
      gramjs/Version.ts
  2. 16 8
      gramjs/client/chats.ts
  3. 2 2
      package-lock.json
  4. 1 1
      package.json

+ 1 - 1
gramjs/Version.ts

@@ -1 +1 @@
-export const version = "1.8.6";
+export const version = "1.8.7";

+ 16 - 8
gramjs/client/chats.ts

@@ -114,6 +114,7 @@ interface ParticipantsIterInterface {
     entity: EntityLike;
     filter: any;
     search?: string;
+    showTotal?: boolean;
 }
 
 export class _ParticipantsIter extends RequestIter {
@@ -128,6 +129,7 @@ export class _ParticipantsIter extends RequestIter {
         entity,
         filter,
         search,
+        showTotal,
     }: ParticipantsIterInterface): Promise<boolean | void> {
         if (filter && filter.constructor === Function) {
             if (
@@ -167,13 +169,16 @@ export class _ParticipantsIter extends RequestIter {
         // Only used for channels, but we should always set the attribute
         this.requests = [];
         if (ty == helpers._EntityType.CHANNEL) {
-            const channel = await this.client.invoke(
-                new Api.channels.GetFullChannel({
-                    channel: entity,
-                })
-            );
-            if (!(channel.fullChat instanceof Api.ChatFull)) {
-                this.total = channel.fullChat.participantsCount;
+            if (showTotal) {
+                console.log("called me!");
+                const channel = await this.client.invoke(
+                    new Api.channels.GetFullChannel({
+                        channel: entity,
+                    })
+                );
+                if (!(channel.fullChat instanceof Api.ChatFull)) {
+                    this.total = channel.fullChat.participantsCount;
+                }
             }
             if (this.total && this.total <= 0) {
                 return false;
@@ -401,13 +406,15 @@ export interface IterParticipantsParams {
     search?: string;
     /** optional filter to be used. E.g only admins filter or only banned members filter. PS : some filters need more permissions. */
     filter?: Api.TypeChannelParticipantsFilter;
+    /** whether to call an extra request (GetFullChannel) to show the total of users in the group/channel. if set to false total will be 0 */
+    showTotal?: boolean;
 }
 
 /** @hidden */
 export function iterParticipants(
     client: TelegramClient,
     entity: EntityLike,
-    { limit, search, filter }: IterParticipantsParams
+    { limit, search, filter, showTotal = true }: IterParticipantsParams
 ) {
     return new _ParticipantsIter(
         client,
@@ -417,6 +424,7 @@ export function iterParticipants(
             entity: entity,
             filter: filter,
             search: search,
+            showTotal: showTotal,
         }
     );
 }

+ 2 - 2
package-lock.json

@@ -1,12 +1,12 @@
 {
   "name": "telegram",
-  "version": "1.8.6",
+  "version": "1.8.7",
   "lockfileVersion": 2,
   "requires": true,
   "packages": {
     "": {
       "name": "telegram",
-      "version": "1.8.6",
+      "version": "1.8.7",
       "license": "MIT",
       "dependencies": {
         "@cryptography/aes": "^0.1.1",

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "telegram",
-  "version": "1.8.6",
+  "version": "1.8.7",
   "description": "NodeJS MTProto API Telegram client library,",
   "main": "index.js",
   "types": "index.d.ts",