@@ -30,6 +30,7 @@ import {AutonomousMonoforumThreadList} from '@components/autonomousDialogList/mo
3030import Scrollable from '@components/scrollable' ;
3131import SortedDialogList from '@components/sortedDialogList' ;
3232import rootScope from '@lib/rootScope' ;
33+ import apiManagerProxy from '@lib/apiManagerProxy' ;
3334
3435type PopupPickUserOptions = Modify < ConstructorParameters < typeof AppSelectPeers > [ 0 ] , {
3536 multiSelect ?: never ,
@@ -77,6 +78,29 @@ async function wrapTopicRow({
7778 return row . container ;
7879}
7980
81+ function wrapAllMessagesRow ( {
82+ onClick
83+ } : {
84+ onClick : ( ) => void
85+ } ) {
86+ const row = new Row ( {
87+ title : i18n ( 'AllMessages' ) ,
88+ clickable : onClick
89+ } ) ;
90+ row . container . classList . add ( 'selector-forum-topic' ) ;
91+ const media = row . createMedia ( 'abitbigger' ) ;
92+ media . append ( wrapEmojiText ( '💬' ) ) ;
93+ return row . container ;
94+ }
95+
96+ type OnSelectOptions = {
97+ threadId ?: number ;
98+ monoforumThreadId ?: PeerId ;
99+ done ?: boolean ;
100+ } ;
101+
102+ type LocalOnSelectCallback = ( peerId : PeerId , options ?: OnSelectOptions ) => void ;
103+
80104export default class PopupPickUser extends PopupElement {
81105 public selector : AppSelectPeers ;
82106 public forumSelector : AppSelectPeers ;
@@ -110,13 +134,15 @@ export default class PopupPickUser extends PopupElement {
110134 const headerSearch = options . headerSearch ?? isMultiSelect ;
111135
112136 let ignoreOnSelect : boolean ;
113- const onSelect = async ( peerId : PeerId | PeerId [ ] , threadId ?: number , monoforumThreadId ?: PeerId ) => {
137+
138+ const onSelect = async ( peerId : PeerId | PeerId [ ] , { threadId, monoforumThreadId, done} : OnSelectOptions = { } ) => {
114139 if ( ignoreOnSelect ) {
115140 return ;
116141 }
117142
118143 if (
119144 options . useTopics &&
145+ ! done &&
120146 ! Array . isArray ( peerId ) &&
121147 ! threadId && ! monoforumThreadId &&
122148 ( await this . managers . appPeersManager . isForum ( peerId ) || await this . managers . appPeersManager . isBotforum ( peerId ) )
@@ -134,6 +160,7 @@ export default class PopupPickUser extends PopupElement {
134160
135161 if (
136162 ! Array . isArray ( peerId ) &&
163+ ! done &&
137164 ! threadId && ! monoforumThreadId &&
138165 await this . managers . appPeersManager . canManageDirectMessages ( peerId ) &&
139166 await this . managers . appPeersManager . isMonoforum ( peerId )
@@ -263,7 +290,7 @@ export default class PopupPickUser extends PopupElement {
263290 tabsContainer : HTMLElement ,
264291 peerId : PeerId ,
265292 placeholder : LangPackKey ,
266- onSelect : ( peerId : PeerId , threadId : number ) => any
293+ onSelect : LocalOnSelectCallback
267294 } ) {
268295 const middlewareHelper = this . middlewareHelper . get ( ) . create ( ) ;
269296 const middleware = middlewareHelper . get ( ) ;
@@ -313,7 +340,7 @@ export default class PopupPickUser extends PopupElement {
313340 forumSelector . list [ ! append ? 'append' : 'prepend' ] ( ...elements ) ;
314341 } ,
315342 onSelect : ( topicId ) => {
316- onSelect ( peerId , topicId ) ;
343+ onSelect ( peerId , { threadId : topicId } ) ;
317344 } ,
318345 placeholderSizes : {
319346 avatarSize : 32 ,
@@ -329,7 +356,14 @@ export default class PopupPickUser extends PopupElement {
329356 } ,
330357 onFirstRender : ( ) => {
331358 deferred . resolve ( ) ;
332- }
359+ } ,
360+ topSectionContentElements : apiManagerProxy . isBotforum ( peerId ) && ! apiManagerProxy . canManageBotforumTopics ( peerId ) ? [
361+ wrapAllMessagesRow ( {
362+ onClick : ( ) => {
363+ onSelect ( peerId , { done : true } ) ;
364+ }
365+ } )
366+ ] : undefined
333367 } ) ;
334368
335369 forumSelector . container . classList . add ( 'tabs-tab' ) ;
@@ -363,7 +397,7 @@ export default class PopupPickUser extends PopupElement {
363397 peerId : PeerId ,
364398 tabsContainer : HTMLElement ,
365399 placeholder : LangPackKey ,
366- onSelect : PopupPickUserOptions [ 'onSelect' ]
400+ onSelect : LocalOnSelectCallback
367401 } ) {
368402 const middlewareHelper = this . middlewareHelper . get ( ) . create ( ) ;
369403 const middleware = middlewareHelper . get ( ) ;
@@ -404,7 +438,7 @@ export default class PopupPickUser extends PopupElement {
404438 const peerId = target . dataset . peerId ?. toPeerId ?.( ) ;
405439 if ( ! peerId ) return ;
406440
407- onSelect ?.( parentPeerId , undefined , peerId ) ;
441+ onSelect ?.( parentPeerId , { monoforumThreadId : peerId } ) ;
408442 } ) ;
409443
410444 const container = document . createElement ( 'div' ) ;
0 commit comments