Skip to content

Commit

Permalink
Add 4.0.13.
Browse files Browse the repository at this point in the history
  • Loading branch information
sf-tyler-jeong committed Sep 27, 2023
1 parent c343e84 commit 7f78c22
Show file tree
Hide file tree
Showing 9 changed files with 214 additions and 166 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
## v4.0.13 (Sep 27, 2023)

### Features
- Added `MessageSearchQuery`
- Added `includeMetaArray`, `includeReactions` and `includeThreadInfo` in `PreviousMessageListQuery`

### Improvements
- Improved stability

## v4.0.12 (Sep 15, 2023)

### Improvements
- Fixed the bug regarding parent FileMessage type
- Fixed the bug regarding parent `FileMessage` type
- Updated regarding statistics

## v4.0.11 (Sep 12, 2023)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Before installing Sendbird Chat SDK, you need to create a Sendbird application o

```yaml
dependencies:
sendbird_chat_sdk: ^4.0.12
sendbird_chat_sdk: ^4.0.13
```
- Run `flutter pub get` command in your project directory.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/internal/main/chat/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ part 'chat_notifications.dart';
part 'chat_push.dart';
part 'chat_user.dart';

const sdkVersion = '4.0.12';
const sdkVersion = '4.0.13';

// Internal implementation for main class. Do not directly access this class.
class Chat with WidgetsBindingObserver {
Expand Down
4 changes: 3 additions & 1 deletion lib/src/internal/main/stats/stat_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@ class StatManager {
UploadStatRequest(_chat, deviceId: deviceId, stats: copiedStats),
);
} catch (e) {
_minStatCount += _intervalCountToTryAgain;
if (copiedStats.length >= _minStatCount) {
_minStatCount += _intervalCountToTryAgain;
}

exception = e;
if (e is SendbirdException && e.code == _errStatUploadNotAllowed) {
Expand Down
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;
}
}
14 changes: 9 additions & 5 deletions lib/src/public/main/define/enums.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) 2023 Sendbird, Inc. All rights reserved.

import 'package:json_annotation/json_annotation.dart';
import 'package:sendbird_chat_sdk/src/public/core/message/base_message.dart';

/// MyConnectionState
enum MyConnectionState {
Expand Down Expand Up @@ -211,11 +212,14 @@ enum GroupChannelListQuerySearchField {
channelName,
}

// /// MessageSearchQueryOrder
// enum MessageSearchQueryOrder {
// score,
// timestamp,
// }
/// The order in which the query result will be based on.
/// [score] query returns the result as by their matching score.
/// [timestamp] query returns the result as by [BaseMessage]'s timestamp.
/// @since 4.0.13
enum MessageSearchQueryOrder {
score,
timestamp,
}

/// PushTokenRegistrationStatus
enum PushTokenRegistrationStatus {
Expand Down
200 changes: 109 additions & 91 deletions lib/src/public/main/query/message/message_search_query.dart
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;
}
}
Loading

0 comments on commit 7f78c22

Please sign in to comment.