@@ -76,12 +76,12 @@ public class DialogsSearchAdapter extends RecyclerListView.SelectionAdapter {
76
76
private Runnable searchRunnable ;
77
77
private Runnable searchRunnable2 ;
78
78
private ArrayList <Object > searchResult = new ArrayList <>();
79
- private ArrayList <ContactsController .Contact > searchContacts = new ArrayList <>();
80
- private ArrayList <TLRPC .TL_forumTopic > searchTopics = new ArrayList <>();
79
+ private final ArrayList <ContactsController .Contact > searchContacts = new ArrayList <>();
80
+ private final ArrayList <TLRPC .TL_forumTopic > searchTopics = new ArrayList <>();
81
81
private ArrayList <CharSequence > searchResultNames = new ArrayList <>();
82
- private ArrayList <MessageObject > searchForumResultMessages = new ArrayList <>();
83
- private ArrayList <MessageObject > searchResultMessages = new ArrayList <>();
84
- private ArrayList <String > searchResultHashtags = new ArrayList <>();
82
+ private final ArrayList <MessageObject > searchForumResultMessages = new ArrayList <>();
83
+ private final ArrayList <MessageObject > searchResultMessages = new ArrayList <>();
84
+ private final ArrayList <String > searchResultHashtags = new ArrayList <>();
85
85
private String lastSearchText ;
86
86
private boolean searchWas ;
87
87
private int reqId = 0 ;
@@ -111,12 +111,13 @@ public class DialogsSearchAdapter extends RecyclerListView.SelectionAdapter {
111
111
public View showMoreHeader ;
112
112
private Runnable cancelShowMoreAnimation ;
113
113
private ArrayList <Long > filterDialogIds ;
114
+ private final DialogsActivity dialogsActivity ;
114
115
115
116
private int currentAccount = UserConfig .selectedAccount ;
116
117
117
118
private ArrayList <RecentSearchObject > recentSearchObjects = new ArrayList <>();
118
- private ArrayList <RecentSearchObject > filteredRecentSearchObjects = new ArrayList <>();
119
- private ArrayList <RecentSearchObject > filtered2RecentSearchObjects = new ArrayList <>();
119
+ private final ArrayList <RecentSearchObject > filteredRecentSearchObjects = new ArrayList <>();
120
+ private final ArrayList <RecentSearchObject > filtered2RecentSearchObjects = new ArrayList <>();
120
121
private String filteredRecentQuery = null ;
121
122
private LongSparseArray <RecentSearchObject > recentSearchObjectsById = new LongSparseArray <>();
122
123
private ArrayList <FiltersView .DateData > localTipDates = new ArrayList <>();
@@ -220,9 +221,38 @@ public int getItemCount() {
220
221
}
221
222
}
222
223
223
- public DialogsSearchAdapter (Context context , int messagesSearch , int type , DefaultItemAnimator itemAnimator , boolean allowGlobalSearch ) {
224
+ private boolean filter (Object obj ) {
225
+ if (dialogsType != DialogsActivity .DIALOGS_TYPE_START_ATTACH_BOT ) {
226
+ return true ;
227
+ }
228
+ // add more filters if needed
229
+ if (obj instanceof TLRPC .User ) {
230
+ if (((TLRPC .User ) obj ).bot ) {
231
+ return dialogsActivity .allowBots ;
232
+ }
233
+ return dialogsActivity .allowUsers ;
234
+ } else if (obj instanceof TLRPC .Chat ) {
235
+ TLRPC .Chat chat = (TLRPC .Chat ) obj ;
236
+ if (ChatObject .isChannel (chat )) {
237
+ return dialogsActivity .allowChannels ;
238
+ } else if (ChatObject .isMegagroup (chat )) {
239
+ return dialogsActivity .allowGroups || dialogsActivity .allowMegagroups ;
240
+ } else {
241
+ return dialogsActivity .allowGroups || dialogsActivity .allowLegacyGroups ;
242
+ }
243
+ }
244
+ return false ;
245
+ }
246
+
247
+ public DialogsSearchAdapter (Context context , DialogsActivity dialogsActivity , int messagesSearch , int type , DefaultItemAnimator itemAnimator , boolean allowGlobalSearch ) {
224
248
this .itemAnimator = itemAnimator ;
225
- searchAdapterHelper = new SearchAdapterHelper (false );
249
+ this .dialogsActivity = dialogsActivity ;
250
+ searchAdapterHelper = new SearchAdapterHelper (false ) {
251
+ @ Override
252
+ protected boolean filter (TLObject obj ) {
253
+ return DialogsSearchAdapter .this .filter (obj );
254
+ }
255
+ };
226
256
searchAdapterHelper .setDelegate (new SearchAdapterHelper .SearchAdapterHelperDelegate () {
227
257
@ Override
228
258
public void onDataSetChanged (int searchId ) {
@@ -872,6 +902,12 @@ private void updateSearchResults(final ArrayList<Object> result, final ArrayList
872
902
searchResultMessages .clear ();
873
903
}
874
904
searchWas = true ;
905
+ for (int i = 0 ; i < result .size (); ++i ) {
906
+ if (!filter (result .get (i ))) {
907
+ result .remove (i );
908
+ i --;
909
+ }
910
+ }
875
911
final int recentCount = filtered2RecentSearchObjects .size ();
876
912
for (int a = 0 ; a < result .size (); a ++) {
877
913
Object obj = result .get (a );
@@ -1092,7 +1128,7 @@ public void searchDialogs(String text, int folderId) {
1092
1128
1093
1129
public int getRecentItemsCount () {
1094
1130
ArrayList <RecentSearchObject > recent = searchWas ? filtered2RecentSearchObjects : filteredRecentSearchObjects ;
1095
- return (!recent .isEmpty () ? recent .size () + 1 : 0 ) + (! searchWas && ! MediaDataController . getInstance ( currentAccount ). hints . isEmpty () ? 1 : 0 );
1131
+ return (!recent .isEmpty () ? recent .size () + 1 : 0 ) + (hasHints () ? 1 : 0 );
1096
1132
}
1097
1133
1098
1134
public int getRecentResultsCount () {
@@ -1175,7 +1211,7 @@ public Object getItem(int i) {
1175
1211
}
1176
1212
}
1177
1213
if (isRecentSearchDisplayed ()) {
1178
- int offset = (! searchWas && ! MediaDataController . getInstance ( currentAccount ). hints . isEmpty () ? 1 : 0 );
1214
+ int offset = (hasHints () ? 1 : 0 );
1179
1215
ArrayList <RecentSearchObject > recent = searchWas ? filtered2RecentSearchObjects : filteredRecentSearchObjects ;
1180
1216
if (i > offset && i - 1 - offset < recent .size ()) {
1181
1217
TLObject object = recent .get (i - 1 - offset ).object ;
@@ -1263,7 +1299,7 @@ public boolean isGlobalSearch(int i) {
1263
1299
return false ;
1264
1300
}
1265
1301
if (isRecentSearchDisplayed ()) {
1266
- int offset = (! searchWas && ! MediaDataController . getInstance ( currentAccount ). hints . isEmpty () ? 1 : 0 );
1302
+ int offset = (hasHints () ? 1 : 0 );
1267
1303
ArrayList <RecentSearchObject > recent = searchWas ? filtered2RecentSearchObjects : filteredRecentSearchObjects ;
1268
1304
if (i > offset && i - 1 - offset < recent .size ()) {
1269
1305
return false ;
@@ -1413,6 +1449,10 @@ public boolean supportsPredictiveItemAnimations() {
1413
1449
return new RecyclerListView .Holder (view );
1414
1450
}
1415
1451
1452
+ private boolean hasHints () {
1453
+ return !searchWas && !MediaDataController .getInstance (currentAccount ).hints .isEmpty () && (dialogsType != DialogsActivity .DIALOGS_TYPE_START_ATTACH_BOT || dialogsActivity .allowUsers );
1454
+ }
1455
+
1416
1456
@ Override
1417
1457
public void onBindViewHolder (RecyclerView .ViewHolder holder , int position ) {
1418
1458
switch (holder .getItemViewType ()) {
@@ -1564,7 +1604,7 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
1564
1604
} else {
1565
1605
int rawPosition = position ;
1566
1606
if (isRecentSearchDisplayed () || !searchTopics .isEmpty () || !searchContacts .isEmpty ()) {
1567
- int offset = (! searchWas && ! MediaDataController . getInstance ( currentAccount ). hints . isEmpty () ? 1 : 0 ) ;
1607
+ int offset = hasHints () ? 1 : 0 ;
1568
1608
if (position < offset ) {
1569
1609
cell .setText (LocaleController .getString ("ChatHints" , R .string .ChatHints ));
1570
1610
return ;
@@ -1768,7 +1808,7 @@ public int getItemViewType(int i) {
1768
1808
return i == 0 ? VIEW_TYPE_GRAY_SECTION : VIEW_TYPE_HASHTAG_CELL ;
1769
1809
}
1770
1810
if (isRecentSearchDisplayed ()) {
1771
- int offset = (! searchWas && ! MediaDataController . getInstance ( currentAccount ). hints . isEmpty () ? 1 : 0 ) ;
1811
+ int offset = hasHints () ? 1 : 0 ;
1772
1812
if (i < offset ) {
1773
1813
return VIEW_TYPE_CATEGORY_LIST ;
1774
1814
}
@@ -1889,7 +1929,7 @@ public void filterRecent(String query) {
1889
1929
filteredRecentSearchObjects .clear ();
1890
1930
final int count = recentSearchObjects .size ();
1891
1931
for (int i = 0 ; i < count ; ++i ) {
1892
- if (delegate != null && delegate .getSearchForumDialogId () == recentSearchObjects .get (i ).did ) {
1932
+ if (delegate != null && delegate .getSearchForumDialogId () == recentSearchObjects .get (i ).did || ! filter ( recentSearchObjects . get ( i ). object ) ) {
1893
1933
continue ;
1894
1934
}
1895
1935
filteredRecentSearchObjects .add (recentSearchObjects .get (i ));
@@ -1903,7 +1943,7 @@ public void filterRecent(String query) {
1903
1943
if (obj == null || obj .object == null ) {
1904
1944
continue ;
1905
1945
}
1906
- if (delegate != null && delegate .getSearchForumDialogId () == obj .did ) {
1946
+ if (delegate != null && delegate .getSearchForumDialogId () == obj .did || ! filter ( recentSearchObjects . get ( i ). object ) ) {
1907
1947
continue ;
1908
1948
}
1909
1949
String title = null , username = null ;
0 commit comments