@@ -54,7 +54,6 @@ public function broadcastWithProgress(
5454 array $ allUsers ,
5555 array $ messages ,
5656 $ chatId ,
57- string $ filterType = 'users ' ,
5857 bool $ pin = false ,
5958 int $ concurrency = 20
6059 ): array {
@@ -68,36 +67,12 @@ public function broadcastWithProgress(
6867 ]);
6968 $ statusId = $ api ->extractMessageId ($ status );
7069
71- /* ===== FILTER TARGETS ===== */
72- $ allowedTypes = [
73- 'all ' => ['user ' ,'bot ' ,'chat ' ,'supergroup ' ,'channel ' ],
74- 'users ' => ['user ' ,'bot ' ],
75- 'groups ' => ['chat ' ,'supergroup ' ],
76- 'channels ' => ['channel ' ],
77- ];
78-
79- $ targets = [];
80- $ failedCount = 0 ;
81-
82- foreach ($ allUsers as $ peer ) {
83- try {
84- $ info = $ api ->getInfo ($ peer );
85- $ type = $ info ['type ' ] ?? 'user ' ;
86- if (in_array ($ type , $ allowedTypes [$ filterType ] ?? ['user ' ,'bot ' ], true )) {
87- $ targets [] = (string )$ peer ;
88- }
89- } catch (\Throwable ) {
90- if ($ filterType === 'all ' ) $ targets [] = (string )$ peer ;
91- else $ failedCount ++;
92- }
93- }
94-
95- $ total = count ($ targets );
70+ $ total = count ($ allUsers );
9671
9772 /* ===== STATE ===== */
9873 $ state = [
9974 'sent ' => 0 ,
100- 'failed ' => $ failedCount ,
75+ 'failed ' => 0 ,
10176 'queue ' => new \SplQueue (),
10277 'inFlight ' => [],
10378 'lastMessageIds ' => [],
@@ -110,7 +85,7 @@ public function broadcastWithProgress(
11085/* ===== SET CURRENT BROADCAST STATE FOR PAUSE/CANCEL ===== */
11186 $ this ->currentBroadcastState = &$ state ;
11287
113- foreach ($ targets as $ peer ) {
88+ foreach ($ allUsers as $ peer ) {
11489 $ state ['queue ' ]->enqueue ([
11590 'peer ' => $ peer ,
11691 'attempts ' => 0 ,
@@ -711,7 +686,6 @@ public function deleteAllBroadcastsForAll(
711686 public function unpinAllMessagesForAll (
712687 array $ allUsers ,
713688 $ chatId ,
714- string $ filterType = 'users ' ,
715689 int $ concurrency = 20
716690 ): array {
717691 $ api = $ this ->api ;
@@ -724,37 +698,12 @@ public function unpinAllMessagesForAll(
724698 ]);
725699 $ statusId = $ api ->extractMessageId ($ status );
726700
727- /* ===== FILTER TARGETS ===== */
728- $ allowedTypesByFilter = [
729- 'all ' => ['user ' ,'bot ' ,'chat ' ,'supergroup ' ,'channel ' ],
730- 'users ' => ['user ' ,'bot ' ],
731- 'groups ' => ['chat ' ,'supergroup ' ],
732- 'channels ' => ['channel ' ],
733- ];
734-
735- $ targets = [];
736- $ failedCount = 0 ;
737-
738- foreach ($ allUsers as $ peer ) {
739- try {
740- $ info = $ api ->getInfo ($ peer );
741- $ type = $ info ['type ' ] ?? 'user ' ;
742-
743- if (in_array ($ type , $ allowedTypesByFilter [$ filterType ] ?? ['user ' ,'bot ' ], true )) {
744- $ targets [] = (string )$ peer ;
745- }
746- } catch (\Throwable ) {
747- if ($ filterType === 'all ' ) $ targets [] = (string )$ peer ;
748- else $ failedCount ++;
749- }
750- }
751-
752- $ total = count ($ targets );
701+ $ total = count ($ allUsers );
753702
754703 /* ===== STATE ===== */
755704 $ state = [
756705 'unpin ' => 0 ,
757- 'failed ' => $ failedCount ,
706+ 'failed ' => 0 ,
758707 'flood ' => 0 ,
759708 'queue ' => new \SplQueue (),
760709 'inFlight ' => [],
@@ -763,7 +712,7 @@ public function unpinAllMessagesForAll(
763712 'startedAt ' => microtime (true ),
764713 ];
765714
766- foreach ($ targets as $ peer ) {
715+ foreach ($ allUsers as $ peer ) {
767716 $ state ['queue ' ]->enqueue ([
768717 'peer ' => $ peer ,
769718 'attempts ' => 0 ,
@@ -953,6 +902,7 @@ public function resume(): void {
953902 public function cancel (): void {
954903 if ($ this ->currentBroadcastState ) {
955904 $ this ->currentBroadcastState ['cancel ' ] = true ;
905+ $ this ->currentBroadcastState ['inFlight ' ] = [];
956906 }
957907 }
958908
@@ -1034,4 +984,44 @@ public function lastBroadcastData(): string|false {
1034984return \Amp \File \read ($ path );
1035985 }
1036986
987+ /**
988+ * Filter peers
989+ */
990+ public function filterPeers (
991+ array $ allUsers ,
992+ string $ filterType = 'users '
993+ ): array {
994+
995+ $ api = $ this ->api ;
996+
997+ $ allowedTypes = [
998+ 'all ' => ['user ' ,'chat ' ,'supergroup ' ,'channel ' ],
999+ 'users ' => ['user ' ],
1000+ 'groups ' => ['chat ' ,'supergroup ' ],
1001+ 'channels ' => ['channel ' ],
1002+ ];
1003+
1004+ $ targets = [];
1005+ $ failedCount = 0 ;
1006+
1007+ foreach ($ allUsers as $ peer ) {
1008+ try {
1009+ $ info = $ api ->getInfo ($ peer );
1010+ $ type = $ info ['type ' ] ?? 'user ' ;
1011+ if (in_array ($ type , $ allowedTypes [$ filterType ] ?? ['user ' ], true )) {
1012+ $ targets [] = (string )$ peer ;
1013+ }
1014+ } catch (\Throwable ) {
1015+ if ($ filterType === 'all ' ) $ targets [] = (string )$ peer ;
1016+ else $ failedCount ++;
1017+ }
1018+ }
1019+
1020+ return [
1021+ 'targets ' => $ targets ,
1022+ 'failed ' => $ failedCount ,
1023+ 'total ' => count ($ targets )
1024+ ];
1025+
1026+ }
10371027}
0 commit comments