Skip to content

Commit

Permalink
Implement feature #231 Display Top tweets instead of latest when sear…
Browse files Browse the repository at this point in the history
…ching hashtag.
  • Loading branch information
j-fbriere committed Feb 28, 2024
1 parent 9858d93 commit e1988f1
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 34 deletions.
1 change: 1 addition & 0 deletions fastlane/metadata/android/en-US/changelogs/41.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Implement feature #231 Display Top tweets instead of latest when searching hashtag.
15 changes: 1 addition & 14 deletions fastlane/metadata/android/en-US/changelogs/default.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1 @@
* Fix issue #226 App does not open, showing a black screen. Some db records have unexpected null fields.
* Implement feature #218 Share tweet as image.
* Implement feature #232 Allow unauthenticated access like with a browser.
What is possible to do with unauthenticated access:
- view specific tweets (but not their threads);
- view profiles;
- view what is trending;
- import subscriptions.
What is not possible to do with unauthenticated access:
- view search results;
- view feed/groups timelines;
- view tweet threads.
* Implement feature #203 View profile picture and banner.
* Implement feature #234 Ability to import specific subscriptions.
* Implement feature #231 Display Top tweets instead of latest when searching hashtag.
4 changes: 2 additions & 2 deletions lib/client/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -415,11 +415,11 @@ class Twitter {
return TweetStatus(chains: chains, cursorBottom: cursorBottom, cursorTop: cursorTop);
}

static Future<TweetStatus> searchTweetsGraphql(String query, bool includeReplies, {int limit = 25, String? cursor, bool leanerFeeds = false, RateFetchContext? fetchContext}) async {
static Future<TweetStatus> searchTweetsGraphql(String query, bool includeReplies, {int limit = 25, String? cursor, bool leanerFeeds = false, bool trending = false, RateFetchContext? fetchContext}) async {
var variables = {
"rawQuery": query,
"count": limit.toString(),
"product": 'Latest',
"product": trending ? 'Top' : 'Latest',
"withDownvotePerspective": false,
"withReactionsMetadata": false,
"withReactionsPerspective": false
Expand Down
18 changes: 11 additions & 7 deletions lib/search/search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class _SearchScreenState extends State<_SearchScreen> with SingleTickerProviderS
void initState() {
super.initState();

_tabController = TabController(length: 2, vsync: this, initialIndex: widget.initialTab);
_tabController = TabController(length: 3, vsync: this, initialIndex: widget.initialTab);
_bothControllers = CombinedChangeNotifier(_tabController, _queryController);

if (widget.focusInputOnOpen) {
Expand Down Expand Up @@ -141,6 +141,7 @@ class _SearchScreenState extends State<_SearchScreen> with SingleTickerProviderS
tabs: const [
Tab(icon: Icon(Icons.person_rounded)),
Tab(icon: Icon(Icons.comment_rounded)),
Tab(icon: Icon(Icons.trending_up)),
],
labelColor: Theme.of(context).appBarTheme.foregroundColor,
indicatorColor: Theme.of(context).appBarTheme.foregroundColor,
Expand All @@ -154,19 +155,22 @@ class _SearchScreenState extends State<_SearchScreen> with SingleTickerProviderS
create: (_) => VideoContextState(prefs.get(optionMediaDefaultMute))),
],
child: Expanded(
child: TabBarView(controller: _tabController, children: [
TweetSearchResultList<SearchUsersModel, UserWithExtra>(
child: TabBarView(controller: _tabController, children: [
TweetSearchResultList<SearchUsersModel, UserWithExtra>(
queryController: _queryController,
store: context.read<SearchUsersModel>(),
searchFunction: (q) => context.read<SearchUsersModel>().searchUsers(q, PrefService.of(context).get(optionEnhancedSearches)),
itemBuilder: (context, user) => UserTile(user: UserSubscription.fromUser(user))),
TweetSearchResultList<SearchTweetsModel, TweetWithCard>(
TweetSearchResultList<SearchTweetsModel, TweetWithCard>(
queryController: _queryController,
store: context.read<SearchTweetsModel>(),
searchFunction: (q) => context.read<SearchTweetsModel>().searchTweets(q, PrefService.of(context).get(optionEnhancedSearches)),
itemBuilder: (context, item) {
return TweetTile(tweet: item, clickable: true);
})
itemBuilder: (context, item) => TweetTile(tweet: item, clickable: true)),
TweetSearchResultList<SearchTweetsModel, TweetWithCard>(
queryController: _queryController,
store: context.read<SearchTweetsModel>(),
searchFunction: (q) => context.read<SearchTweetsModel>().searchTweets(q, PrefService.of(context).get(optionEnhancedSearches), trending: true),
itemBuilder: (context, item) => TweetTile(tweet: item, clickable: true))
])),
)
],
Expand Down
20 changes: 10 additions & 10 deletions lib/search/search_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ import 'package:squawker/user.dart';
class SearchTweetsModel extends Store<List<TweetWithCard>> {
SearchTweetsModel() : super([]);

Future<void> searchTweets(String query, bool enhanced) async {
Future<void> searchTweets(String query, bool enhanced, {bool trending = false}) async {
await execute(() async {
if (query.isEmpty) {
return [];
} else {
if (enhanced) {
return (await Twitter.searchTweetsGraphql(query, true))
.chains
.map((e) => e.tweets)
.expand((element) => element)
.toList();
return (await Twitter.searchTweetsGraphql(query, true, trending: trending))
.chains
.map((e) => e.tweets)
.expand((element) => element)
.toList();
}
else {
return (await Twitter.searchTweets(query, true))
.chains
.map((e) => e.tweets)
.expand((element) => element)
.toList();
.chains
.map((e) => e.tweets)
.expand((element) => element)
.toList();
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html

version: 3.7.6+40
version: 3.7.7+41

environment:
sdk: ">=2.18.0 <3.0.0"
Expand Down

0 comments on commit e1988f1

Please sign in to comment.