-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c343e84
commit 7f78c22
Showing
9 changed files
with
214 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 58 additions & 60 deletions
118
lib/src/internal/network/http/http_client/request/main/message_search_request.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,58 @@ | ||
// // Copyright (c) 2023 Sendbird, Inc. All rights reserved. | ||
// | ||
// import 'package:sendbird_chat_sdk/src/internal/main/chat/chat.dart'; | ||
// import 'package:sendbird_chat_sdk/src/internal/network/http/http_client/http_client.dart'; | ||
// import 'package:sendbird_chat_sdk/src/internal/network/http/http_client/request/api_request.dart'; | ||
// import 'package:sendbird_chat_sdk/src/internal/network/http/http_client/response/responses.dart'; | ||
// | ||
// class MessageSearchRequest extends ApiRequest { | ||
// @override | ||
// HttpMethod get method => HttpMethod.get; | ||
// | ||
// MessageSearchRequest( | ||
// Chat chat, { | ||
// required int limit, | ||
// required String keyword, | ||
// String? channelUrl, | ||
// String? channelCustomType, | ||
// String? beforeToken, | ||
// String? afterToken, | ||
// String? token, | ||
// int? startAt, | ||
// int? endAt, | ||
// String? sortField, | ||
// bool? reverse, | ||
// bool? exactMatch, | ||
// bool? advancedQuery, | ||
// List<String>? targetFields, | ||
// }) : super(chat: chat) { | ||
// url = 'search/messages'; | ||
// queryParams = { | ||
// // 'user_id': userId, // TODO: Check (MessageSearchQuery) | ||
// 'limit': limit, | ||
// 'query': keyword, | ||
// 'channel_url': channelUrl, | ||
// 'custom_type': channelCustomType, | ||
// 'before': beforeToken, | ||
// 'after': afterToken, | ||
// 'token': token, | ||
// 'message_ts_from': startAt, | ||
// 'message_ts_to': endAt, | ||
// 'sort_field': sortField, | ||
// 'reverse': reverse, | ||
// 'exact_match': exactMatch, | ||
// 'advanced_query': advancedQuery, | ||
// 'target_fields': targetFields, | ||
// // 'include_operators': true, // TODO: Check (MessageSearchQuery) | ||
// }; | ||
// | ||
// queryParams.removeWhere((key, value) => value == null); | ||
// } | ||
// | ||
// @override | ||
// Future<MessageSearchQueryResponse> response(Map<String, dynamic> res) async { | ||
// final response = MessageSearchQueryResponse.fromJson(res); | ||
// for (final element in response.results) { | ||
// element.set(chat); | ||
// } | ||
// return response; | ||
// } | ||
// } | ||
// Copyright (c) 2023 Sendbird, Inc. All rights reserved. | ||
|
||
import 'package:sendbird_chat_sdk/src/internal/main/chat/chat.dart'; | ||
import 'package:sendbird_chat_sdk/src/internal/network/http/http_client/http_client.dart'; | ||
import 'package:sendbird_chat_sdk/src/internal/network/http/http_client/request/api_request.dart'; | ||
import 'package:sendbird_chat_sdk/src/internal/network/http/http_client/response/responses.dart'; | ||
|
||
class MessageSearchRequest extends ApiRequest { | ||
@override | ||
HttpMethod get method => HttpMethod.get; | ||
|
||
MessageSearchRequest( | ||
Chat chat, { | ||
required int limit, | ||
required String keyword, | ||
String? channelUrl, | ||
String? channelCustomType, | ||
String? beforeToken, | ||
String? afterToken, | ||
String? token, | ||
int? startAt, | ||
int? endAt, | ||
String? sortField, | ||
bool? reverse, | ||
bool? exactMatch, | ||
bool? advancedQuery, | ||
List<String>? targetFields, | ||
}) : super(chat: chat) { | ||
url = 'search/messages'; | ||
queryParams = { | ||
'limit': limit, | ||
'query': keyword, | ||
'channel_url': channelUrl, | ||
'custom_type': channelCustomType, | ||
'before': beforeToken, | ||
'after': afterToken, | ||
'token': token, | ||
'message_ts_from': startAt, | ||
'message_ts_to': endAt, | ||
'sort_field': sortField, | ||
'reverse': reverse, | ||
'exact_match': exactMatch, | ||
'advanced_query': advancedQuery, | ||
'target_fields': targetFields, | ||
}; | ||
|
||
queryParams.removeWhere((key, value) => value == null); | ||
} | ||
|
||
@override | ||
Future<MessageSearchQueryResponse> response(Map<String, dynamic> res) async { | ||
final response = MessageSearchQueryResponse.fromJson(res); | ||
for (final element in response.results) { | ||
element.set(chat); | ||
} | ||
return response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
200 changes: 109 additions & 91 deletions
200
lib/src/public/main/query/message/message_search_query.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,109 @@ | ||
// // Copyright (c) 2023 Sendbird, Inc. All rights reserved. | ||
// | ||
// import 'package:sendbird_chat_sdk/src/internal/main/chat/chat.dart'; | ||
// import 'package:sendbird_chat_sdk/src/internal/main/logger/sendbird_logger.dart'; | ||
// import 'package:sendbird_chat_sdk/src/internal/network/http/http_client/request/main/message_search_request.dart'; | ||
// import 'package:sendbird_chat_sdk/src/internal/network/http/http_client/response/responses.dart'; | ||
// import 'package:sendbird_chat_sdk/src/public/core/message/base_message.dart'; | ||
// import 'package:sendbird_chat_sdk/src/public/main/chat/sendbird_chat_sdk.dart'; | ||
// import 'package:sendbird_chat_sdk/src/public/main/define/enums.dart'; | ||
// import 'package:sendbird_chat_sdk/src/public/main/define/exceptions.dart'; | ||
// import 'package:sendbird_chat_sdk/src/public/main/query/base_query.dart'; | ||
// | ||
// /// A class representing query to retrieve list of [BaseMessage]s that matches a given query | ||
// /// with given filters. | ||
// class MessageSearchQuery extends BaseQuery { | ||
// /// The keyword to search for. | ||
// String keyword; | ||
// | ||
// /// The channel url to set as the search scope. | ||
// String? channelUrl; | ||
// | ||
// /// The custom type of channel to set as the search scope. | ||
// String? channelCustomType; | ||
// | ||
// /// Whether the search result is set to be reversed or not. | ||
// bool reverse = false; | ||
// | ||
// /// Whether the search query should be an exact match or not. | ||
// bool exactMatch = false; | ||
// | ||
// /// The start message timestamp set as the search range. | ||
// int? messageTimestampFrom; | ||
// | ||
// /// The end message timestamp set as the search range. | ||
// int? messageTimestampTo; | ||
// | ||
// /// Whether the search query should be an advanced query or not. | ||
// bool advancedQuery = false; | ||
// | ||
// /// Target fields of the query to set as the search scope. | ||
// List<String> targetFields = []; | ||
// | ||
// /// The [MessageSearchQueryOrder] of the search. | ||
// MessageSearchQueryOrder order = MessageSearchQueryOrder.score; | ||
// | ||
// final messageSearchQueryOrderEnumMap = <MessageSearchQueryOrder, String>{ | ||
// MessageSearchQueryOrder.score: 'score', | ||
// MessageSearchQueryOrder.timestamp: 'ts', | ||
// }; | ||
// | ||
// MessageSearchQuery({ | ||
// required this.keyword, | ||
// Chat? chat, | ||
// }) : super(chat: chat ?? SendbirdChat().chat); | ||
// | ||
// /// Gets the list of next items. | ||
// @override | ||
// Future<List<BaseMessage>> next() async { | ||
// sbLog.i(StackTrace.current); | ||
// | ||
// if (isLoading) throw QueryInProgressException(); | ||
// if (!hasNext) return []; | ||
// | ||
// isLoading = true; | ||
// | ||
// final res = await chat.apiClient.send<MessageSearchQueryResponse>( | ||
// MessageSearchRequest( | ||
// chat, | ||
// limit: limit, | ||
// keyword: keyword, | ||
// channelUrl: channelUrl, | ||
// channelCustomType: channelCustomType, | ||
// beforeToken: null, | ||
// afterToken: token, | ||
// token: null, | ||
// startAt: messageTimestampFrom, | ||
// endAt: messageTimestampTo, | ||
// sortField: messageSearchQueryOrderEnumMap[order], | ||
// reverse: reverse, | ||
// exactMatch: exactMatch, | ||
// advancedQuery: advancedQuery, | ||
// targetFields: targetFields, | ||
// ), | ||
// ); | ||
// | ||
// isLoading = false; | ||
// token = res.next; | ||
// hasNext = res.hasNext; | ||
// return res.results; | ||
// } | ||
// } | ||
// Copyright (c) 2023 Sendbird, Inc. All rights reserved. | ||
|
||
import 'package:sendbird_chat_sdk/src/internal/main/chat/chat.dart'; | ||
import 'package:sendbird_chat_sdk/src/internal/main/logger/sendbird_logger.dart'; | ||
import 'package:sendbird_chat_sdk/src/internal/network/http/http_client/request/main/message_search_request.dart'; | ||
import 'package:sendbird_chat_sdk/src/internal/network/http/http_client/response/responses.dart'; | ||
import 'package:sendbird_chat_sdk/src/public/core/message/base_message.dart'; | ||
import 'package:sendbird_chat_sdk/src/public/main/chat/sendbird_chat.dart'; | ||
import 'package:sendbird_chat_sdk/src/public/main/define/enums.dart'; | ||
import 'package:sendbird_chat_sdk/src/public/main/define/exceptions.dart'; | ||
import 'package:sendbird_chat_sdk/src/public/main/query/base_query.dart'; | ||
|
||
/// A class representing query to retrieve list of [BaseMessage]s that matches a given query | ||
/// with given filters. | ||
/// @since 4.0.13 | ||
class MessageSearchQuery extends BaseQuery { | ||
/// The keyword to search for. | ||
/// @since 4.0.13 | ||
String keyword; | ||
|
||
/// The channel url to set as the search scope. | ||
/// @since 4.0.13 | ||
String? channelUrl; | ||
|
||
/// The custom type of channel to set as the search scope. | ||
/// @since 4.0.13 | ||
String? channelCustomType; | ||
|
||
/// Whether the search result is set to be reversed or not. | ||
/// @since 4.0.13 | ||
bool reverse = false; | ||
|
||
/// Whether the search query should be an exact match or not. | ||
/// @since 4.0.13 | ||
bool exactMatch = false; | ||
|
||
/// The start message timestamp set as the search range. | ||
/// @since 4.0.13 | ||
int? messageTimestampFrom; | ||
|
||
/// The end message timestamp set as the search range. | ||
/// @since 4.0.13 | ||
int? messageTimestampTo; | ||
|
||
/// Whether the search query should be an advanced query or not. | ||
/// @since 4.0.13 | ||
bool advancedQuery = false; | ||
|
||
/// Target fields of the query to set as the search scope. | ||
/// @since 4.0.13 | ||
List<String> targetFields = []; | ||
|
||
/// The [MessageSearchQueryOrder] of the search. | ||
/// @since 4.0.13 | ||
MessageSearchQueryOrder order = MessageSearchQueryOrder.score; | ||
|
||
final _messageSearchQueryOrderEnumMap = <MessageSearchQueryOrder, String>{ | ||
MessageSearchQueryOrder.score: 'score', | ||
MessageSearchQueryOrder.timestamp: 'ts', | ||
}; | ||
|
||
/// The total count of results that matches the given search. | ||
/// @since 4.0.13 | ||
int totalCount = -1; | ||
|
||
MessageSearchQuery({ | ||
required this.keyword, | ||
Chat? chat, | ||
}) : super(chat: chat ?? SendbirdChat().chat); | ||
|
||
/// Gets the list of next items. | ||
/// @since 4.0.13 | ||
@override | ||
Future<List<BaseMessage>> next() async { | ||
sbLog.i(StackTrace.current); | ||
|
||
if (isLoading) throw QueryInProgressException(); | ||
if (!hasNext) return []; | ||
|
||
isLoading = true; | ||
|
||
final res = await chat.apiClient.send<MessageSearchQueryResponse>( | ||
MessageSearchRequest( | ||
chat, | ||
limit: limit, | ||
keyword: keyword, | ||
channelUrl: channelUrl, | ||
channelCustomType: channelCustomType, | ||
beforeToken: null, | ||
afterToken: token, | ||
token: null, | ||
startAt: messageTimestampFrom, | ||
endAt: messageTimestampTo, | ||
sortField: _messageSearchQueryOrderEnumMap[order], | ||
reverse: reverse, | ||
exactMatch: exactMatch, | ||
advancedQuery: advancedQuery, | ||
targetFields: targetFields, | ||
), | ||
); | ||
|
||
isLoading = false; | ||
|
||
hasNext = res.hasNext; | ||
totalCount = res.totalCount; | ||
token = res.next; | ||
return res.results; | ||
} | ||
} |
Oops, something went wrong.