removeSearchSuggestions method
Remove search suggestion from the user search history.
suggestions
The Map obtained from getSearchSuggestions (withdetailedRuns
=true
).indices
Optional. The indices of the suggestions to be removed. (Default: remove all suggestions).
Returns true
if the operation was successful, false
otherwise.
Implementation
Future<bool> removeSearchSuggestions(
List<JsonMap> suggestions, {
List<int>? indices,
}) async {
if (!suggestions.any((run) => run['fromHistory'] == true)) {
throw YTMusicUserError(
'No search result from history provided. '
'Please run getSearchSuggestions first to retrieve suggestions.',
);
}
indices ??= List.generate(suggestions.length, (i) => i);
if (indices.any((index) => index >= suggestions.length)) {
throw YTMusicUserError(
'Index out of range. Index must be smaller than the length of suggestions',
);
}
// filter null tokens
final feedbackTokens =
indices
.map((i) => suggestions[i]['feedbackToken'])
.where((t) => t != null)
.toList();
if (feedbackTokens.isEmpty) return false;
final body = {'feedbackTokens': feedbackTokens};
const endpoint = 'feedback';
final response = await sendRequest(endpoint, body);
return nav(response, [
'feedbackResponses',
0,
'isProcessed',
], nullIfAbsent: true) ==
true;
}