@@ -18,7 +18,7 @@ import useHeavyAnimationCheck, {getHeavyAnimationPromise} from '../hooks/useHeav
18
18
import I18n , { LangPackKey , i18n , join } from '../lib/langPack' ;
19
19
import findUpClassName from '../helpers/dom/findUpClassName' ;
20
20
import { getMiddleware , Middleware , MiddlewareHelper } from '../helpers/middleware' ;
21
- import { ChannelParticipant , Chat , ChatFull , ChatParticipant , Document , Message , MessageMedia , MessagesChats , Peer , Photo , StoryItem , Update , User , WebPage } from '../layer' ;
21
+ import { ChannelParticipant , Chat , ChatFull , ChatParticipant , Document , Message , MessageMedia , MessagesChats , Peer , Photo , StoryItem , Update , User , UserFull , WebPage } from '../layer' ;
22
22
import SortedUserList from './sortedUserList' ;
23
23
import findUpTag from '../helpers/dom/findUpTag' ;
24
24
import appSidebarRight from './sidebarRight' ;
@@ -93,6 +93,8 @@ import setBlankToAnchor from '../lib/richTextProcessor/setBlankToAnchor';
93
93
import cancelClickOrNextIfNotClick from '../helpers/dom/cancelClickOrNextIfNotClick' ;
94
94
import createElementFromMarkup from '../helpers/createElementFromMarkup' ;
95
95
import numberThousandSplitter from '../helpers/number/numberThousandSplitter' ;
96
+ import { StarGiftsProfileTab } from './sidebarRight/tabs/stargifts' ;
97
+ import { getFirstChild , resolveFirst } from '@solid-primitives/refs' ;
96
98
97
99
// const testScroll = false;
98
100
@@ -112,7 +114,7 @@ export type SearchSuperContext = {
112
114
113
115
export type SearchSuperMediaType = 'stories' | 'members' | 'media' |
114
116
'files' | 'links' | 'music' | 'chats' | 'voice' | 'groups' | 'similar' |
115
- 'savedDialogs' | 'saved' | 'channels' | 'apps' ;
117
+ 'savedDialogs' | 'saved' | 'channels' | 'apps' | 'gifts' ;
116
118
export type SearchSuperMediaTab = {
117
119
inputFilter ?: SearchSuperType ,
118
120
name : LangPackKey ,
@@ -1963,6 +1965,39 @@ export default class AppSearchSuper {
1963
1965
this . loaded [ mediaTab . type ] = true ;
1964
1966
}
1965
1967
1968
+ private _loadedGifts : true
1969
+ private async loadGifts ( { mediaTab} : SearchSuperLoadTypeOptions ) {
1970
+ if ( ! this . _loadedGifts ) {
1971
+ const middleware = this . middleware . get ( ) ;
1972
+ createRoot ( ( dispose ) => {
1973
+ middleware . onClean ( ( ) => dispose ( ) ) ;
1974
+
1975
+ const scrollTarget = this . scrollable . container ;
1976
+
1977
+ const { render : giftsList , loadNext} = StarGiftsProfileTab ( {
1978
+ peerId : this . searchContext . peerId ,
1979
+ scrollParent : scrollTarget ,
1980
+ onCountChange : ( count ) => {
1981
+ this . setCounter ( 'gifts' , count ) ;
1982
+ }
1983
+ } ) ;
1984
+
1985
+ scrollTarget . addEventListener ( 'scroll' , ( ) => {
1986
+ const offset = 400 ;
1987
+ if ( this . mediaTab !== mediaTab ) return ; // There is one scrollable for all tabs
1988
+ if ( scrollTarget . scrollTop + scrollTarget . clientHeight >= scrollTarget . scrollHeight - offset ) {
1989
+ loadNext ( ) ;
1990
+ }
1991
+ } ) ;
1992
+
1993
+ mediaTab . contentTab . append ( getFirstChild ( giftsList , v => v instanceof Element ) as Element ) ;
1994
+ } ) ;
1995
+ this . _loadedGifts = true ;
1996
+ }
1997
+
1998
+ return Promise . resolve ( ) ;
1999
+ }
2000
+
1966
2001
private loadType ( options : SearchSuperLoadTypeOptions ) {
1967
2002
const {
1968
2003
mediaTab,
@@ -1991,6 +2026,8 @@ export default class AppSearchSuper {
1991
2026
promise = this . loadChannels ( options ) ;
1992
2027
} else if ( type === 'apps' ) {
1993
2028
promise = this . loadApps ( options ) ;
2029
+ } else if ( type === 'gifts' ) {
2030
+ promise = this . loadGifts ( options ) ;
1994
2031
}
1995
2032
1996
2033
if ( promise ) {
@@ -2158,15 +2195,17 @@ export default class AppSearchSuper {
2158
2195
canViewMembers ,
2159
2196
canViewGroups ,
2160
2197
canViewStories ,
2161
- canViewSimilar
2198
+ canViewSimilar ,
2199
+ giftsCount
2162
2200
] = await Promise . all ( [
2163
2201
this . managers . appMessagesManager . getSearchCounters ( peerId , filters , undefined , threadId ) ,
2164
2202
this . canViewSavedDialogs ( ) ,
2165
2203
this . canViewSaved ( ) ,
2166
2204
this . canViewMembers ( ) ,
2167
2205
this . canViewGroups ( ) ,
2168
2206
this . canViewStories ( ) ,
2169
- this . canViewSimilar ( )
2207
+ this . canViewSimilar ( ) ,
2208
+ this . getGiftsCount ( )
2170
2209
] ) ;
2171
2210
2172
2211
if ( ! middleware ( ) ) {
@@ -2207,14 +2246,16 @@ export default class AppSearchSuper {
2207
2246
const storiesTab = this . mediaTabsMap . get ( 'stories' ) ;
2208
2247
const groupsTab = this . mediaTabsMap . get ( 'groups' ) ;
2209
2248
const similarTab = this . mediaTabsMap . get ( 'similar' ) ;
2249
+ const giftsTab = this . mediaTabsMap . get ( 'gifts' ) ;
2210
2250
2211
2251
const a : [ SearchSuperMediaTab , boolean ] [ ] = [
2212
2252
[ savedDialogsTab , canViewSavedDialogs ] ,
2213
2253
[ savedTab , canViewSaved ] ,
2214
2254
[ storiesTab , canViewStories ] ,
2215
2255
[ membersTab , canViewMembers ] ,
2216
2256
[ groupsTab , canViewGroups ] ,
2217
- [ similarTab , canViewSimilar ]
2257
+ [ similarTab , canViewSimilar ] ,
2258
+ [ giftsTab , giftsCount !== 0 ]
2218
2259
] ;
2219
2260
2220
2261
a . forEach ( ( [ tab , value ] ) => {
@@ -2229,6 +2270,8 @@ export default class AppSearchSuper {
2229
2270
}
2230
2271
} ) ;
2231
2272
2273
+ this . setCounter ( 'gifts' , giftsCount ) ;
2274
+
2232
2275
if ( canViewStories ) {
2233
2276
firstMediaTab = storiesTab ;
2234
2277
@@ -2441,6 +2484,16 @@ export default class AppSearchSuper {
2441
2484
}
2442
2485
}
2443
2486
2487
+ public async getGiftsCount ( ) {
2488
+ const { peerId} = this . searchContext
2489
+ const full =
2490
+ peerId . isUser ( ) ?
2491
+ await this . managers . appProfileManager . getProfile ( peerId . toUserId ( ) ) :
2492
+ await this . managers . appProfileManager . getChannelFull ( peerId . toChatId ( ) ) ;
2493
+
2494
+ return full . stargifts_count ?? 0 ;
2495
+ }
2496
+
2444
2497
public cleanup ( ) {
2445
2498
this . loadPromises = { } ;
2446
2499
this . loaded = { } ;
0 commit comments