Skip to content

Commit

Permalink
Merge pull request #80 from sendbird/v4.0.11
Browse files Browse the repository at this point in the history
Add 4.0.11.
  • Loading branch information
sf-tyler-jeong authored Sep 12, 2023
2 parents 1deb963 + 4781fe9 commit b7f55ba
Show file tree
Hide file tree
Showing 35 changed files with 95 additions and 53 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## v4.0.11 (Sep 12, 2023)

### Improvements
- Fixed the bug regarding the url encoding of `userId`.

## v4.0.10 (Aug 31, 2023)

### Improvements
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.10
sendbird_chat_sdk: ^4.0.11
```
- 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.10';
const sdkVersion = '4.0.11';

// Internal implementation for main class. Do not directly access this class.
class Chat with WidgetsBindingObserver {
Expand Down
17 changes: 11 additions & 6 deletions lib/src/internal/main/chat_manager/session_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,20 @@ class SessionManager {
throw ConnectionRequiredException();
}

var id = '';
if (userId.length >= 24) {
id = userId.substring(0, 24);
List<int> userId24Data = [];
final userIdData = utf8.encode(userId);
const dataLength = 24;
if (userIdData.length >= dataLength) {
userId24Data.addAll(userIdData.sublist(0, dataLength));
} else {
id = userId + getRandomString(24 - userId.length);
final randomStringData =
utf8.encode(getRandomString(dataLength - userIdData.length));
userId24Data
..addAll(userIdData)
..addAll(randomStringData);
}

final userIdData = utf8.encode(id);
final base64UserId = base64.encode(userIdData);
final base64UserId = base64.encode(userId24Data);
prefs.setString(_userIdKeyPath, base64UserId);

final key = Key.fromUtf8(base64UserId);
Expand Down
6 changes: 6 additions & 0 deletions lib/src/internal/main/utils/string_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import 'dart:math';

import 'package:sendbird_chat_sdk/src/internal/main/chat/chat.dart';

const _chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890';
final _random = Random();

Expand All @@ -13,3 +15,7 @@ String getRandomString(int length) {
String getFileExtension(String fileName) {
return ".${fileName.split('.').last}";
}

String getUrlEncodedUserId(Chat chat, String? userId) {
return Uri.encodeComponent(userId ?? chat.chatContext.currentUserId ?? '');
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import 'package:sendbird_chat_sdk/src/internal/main/chat/chat.dart';
import 'package:sendbird_chat_sdk/src/internal/main/chat_cache/cache_service.dart';
import 'package:sendbird_chat_sdk/src/internal/main/chat_cache/channel/channel_cache_extensions.dart';
import 'package:sendbird_chat_sdk/src/internal/main/utils/string_utils.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/public/main/model/channel/feed_channel_change_logs.dart';
Expand All @@ -20,7 +21,7 @@ class FeedChannelChangeLogsGetRequest extends ApiRequest {
String? userId,
}) : super(chat: chat) {
url =
'users/${userId ?? chat.chatContext.currentUserId}/my_group_channels/changelogs';
'users/${getUrlEncodedUserId(chat, userId)}/my_group_channels/changelogs';
queryParams = params.toJson();
queryParams['show_member'] = true;
queryParams['show_read_receipt'] = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:sendbird_chat_sdk/src/internal/main/chat/chat.dart';
import 'package:sendbird_chat_sdk/src/internal/main/chat_cache/cache_service.dart';
import 'package:sendbird_chat_sdk/src/internal/main/chat_cache/channel/channel_cache_extensions.dart';
import 'package:sendbird_chat_sdk/src/internal/main/extensions/extensions.dart';
import 'package:sendbird_chat_sdk/src/internal/main/utils/string_utils.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';
Expand All @@ -18,7 +19,7 @@ class FeedChannelListRequest extends ApiRequest {
List<ChannelListQueryIncludeOption> options = const [],
String? token,
}) : super(chat: chat) {
url = 'users/${userId ?? chat.chatContext.currentUserId}/my_group_channels';
url = 'users/${getUrlEncodedUserId(chat, userId)}/my_group_channels';

queryParams = {
'limit': limit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import 'package:sendbird_chat_sdk/src/internal/main/chat/chat.dart';
import 'package:sendbird_chat_sdk/src/internal/main/chat_cache/cache_service.dart';
import 'package:sendbird_chat_sdk/src/internal/main/chat_cache/channel/channel_cache_extensions.dart';
import 'package:sendbird_chat_sdk/src/internal/main/utils/string_utils.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/public/main/model/channel/group_channel_change_logs.dart';
Expand All @@ -20,7 +21,7 @@ class GroupChannelChangeLogsGetRequest extends ApiRequest {
String? userId,
}) : super(chat: chat) {
url =
'users/${userId ?? chat.chatContext.currentUserId}/my_group_channels/changelogs';
'users/${getUrlEncodedUserId(chat, userId)}/my_group_channels/changelogs';
queryParams = params.toJson();
queryParams['show_member'] = true;
queryParams['show_read_receipt'] = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:sendbird_chat_sdk/src/internal/main/chat/chat.dart';
import 'package:sendbird_chat_sdk/src/internal/main/chat_cache/cache_service.dart';
import 'package:sendbird_chat_sdk/src/internal/main/chat_cache/channel/channel_cache_extensions.dart';
import 'package:sendbird_chat_sdk/src/internal/main/extensions/extensions.dart';
import 'package:sendbird_chat_sdk/src/internal/main/utils/string_utils.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';
Expand Down Expand Up @@ -37,7 +38,7 @@ class GroupChannelListRequest extends ApiRequest {
required GroupChannelFilter filter,
String? userId,
}) : super(chat: chat, userId: userId) {
url = 'users/${userId ?? chat.chatContext.currentUserId}/my_group_channels';
url = 'users/${getUrlEncodedUserId(chat, userId)}/my_group_channels';

final searchFieldStrings = stringFromSearchFields(searchFields);
queryParams = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 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/utils/string_utils.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';

Expand All @@ -13,7 +14,7 @@ class GroupChannelMarkAsReadRequest extends ApiRequest {
List<String>? channelUrls,
String? userId,
}) : super(chat: chat, userId: userId) {
url = 'users/${userId ?? chat.chatContext.currentUserId}/mark_as_read_all';
url = 'users/${getUrlEncodedUserId(chat, userId)}/mark_as_read_all';
body = {
if (channelUrls != null && channelUrls.isNotEmpty)
'channel_urls': channelUrls,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import 'package:sendbird_chat_sdk/src/internal/main/chat/chat.dart';
import 'package:sendbird_chat_sdk/src/internal/main/extensions/extensions.dart';
import 'package:sendbird_chat_sdk/src/internal/main/utils/string_utils.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/public/main/define/enums.dart';
Expand All @@ -18,7 +19,7 @@ class ChannelMyMuteInfoGetRequest extends ApiRequest {
String? userId,
}) : super(chat: chat, userId: userId) {
url =
'${channelType.urlString}/$channelUrl/mute/${userId ?? chat.chatContext.currentUserId}';
'${channelType.urlString}/$channelUrl/mute/${getUrlEncodedUserId(chat, userId)}';
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import 'package:sendbird_chat_sdk/src/internal/main/chat/chat.dart';
import 'package:sendbird_chat_sdk/src/internal/main/utils/enum_utils.dart';
import 'package:sendbird_chat_sdk/src/internal/main/utils/string_utils.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/public/main/define/enums.dart';
Expand All @@ -24,7 +25,7 @@ class GroupChannelCountReferenceRequest extends ApiRequest {
String? userId,
}) : super(chat: chat, userId: userId) {
url =
'users/${userId ?? chat.chatContext.currentUserId}/count_preference/$channelUrl';
'users/${getUrlEncodedUserId(chat, userId)}/count_preference/$channelUrl';
body = {'count_preference': countPreferenceEnumMap[prefs]};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import 'package:sendbird_chat_sdk/src/internal/main/chat/chat.dart';
import 'package:sendbird_chat_sdk/src/internal/main/utils/enum_utils.dart';
import 'package:sendbird_chat_sdk/src/internal/main/utils/string_utils.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/public/main/define/enums.dart';
Expand All @@ -24,7 +25,7 @@ class GroupChannelPushTriggerOptionGetRequest extends ApiRequest {
String? userId,
}) : super(chat: chat, userId: userId) {
url =
'users/${userId ?? chat.chatContext.currentUserId}/push_preference/$channelUrl';
'users/${getUrlEncodedUserId(chat, userId)}/push_preference/$channelUrl';
}

@override
Expand All @@ -49,7 +50,7 @@ class GroupChannelPushTriggerOptionSetRequest extends ApiRequest {
String? userId,
}) : super(chat: chat, userId: userId) {
url =
'users/${userId ?? chat.chatContext.currentUserId}/push_preference/$channelUrl';
'users/${getUrlEncodedUserId(chat, userId)}/push_preference/$channelUrl';
body = {
'push_trigger_option': _groupChannelPushTriggerOptionEnumMap[option]
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 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/utils/string_utils.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';

Expand All @@ -14,7 +15,7 @@ class ChannelInvitationPreferenceSetRequest extends ApiRequest {
String? userId,
}) : super(chat: chat, userId: userId) {
url =
'users/${userId ?? chat.chatContext.currentUserId}/channel_invitation_preference';
'users/${getUrlEncodedUserId(chat, userId)}/channel_invitation_preference';
body = {'auto_accept': autoAccept};
}
}
Expand All @@ -28,7 +29,7 @@ class ChannelInvitationPreferenceGetRequest extends ApiRequest {
String? userId,
}) : super(chat: chat, userId: userId) {
url =
'users/${userId ?? chat.chatContext.currentUserId}/channel_invitation_preference';
'users/${getUrlEncodedUserId(chat, userId)}/channel_invitation_preference';
}

@override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 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/utils/string_utils.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';

Expand All @@ -14,7 +15,7 @@ class AppSessionKeyUpdateRequest extends ApiRequest {
String? accessToken,
String? userId,
}) : super(chat: chat) {
url = 'users/${userId ?? chat.chatContext.currentUserId}/session_key';
url = 'users/${getUrlEncodedUserId(chat, userId)}/session_key';

headers = {'App-Id': appId};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import 'package:sendbird_chat_sdk/sendbird_chat_sdk.dart';
import 'package:sendbird_chat_sdk/src/internal/main/chat/chat.dart';
import 'package:sendbird_chat_sdk/src/internal/main/utils/string_utils.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';

Expand All @@ -15,7 +16,7 @@ class AuthenticateFeedRequest extends ApiRequest {
String? accessToken,
String? apiHost,
}) : super(chat: chat, userId: userId) {
url = 'users/$userId/login';
url = 'users/${getUrlEncodedUserId(chat, userId)}/login';

isAuthenticateFeed = true; // Check

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 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/utils/string_utils.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/public/core/user/user.dart';
Expand All @@ -14,7 +15,7 @@ class UserBlockRequest extends ApiRequest {
String? userId,
required String targetId,
}) : super(chat: chat, userId: userId) {
url = 'users/${userId ?? chat.chatContext.currentUserId}/block';
url = 'users/${getUrlEncodedUserId(chat, userId)}/block';
body = {'target_id': targetId};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 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/utils/string_utils.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';

Expand All @@ -13,7 +14,7 @@ class UserUnblockRequest extends ApiRequest {
String? userId,
required String targetId,
}) : super(chat: chat, userId: userId) {
url = 'users/${userId ?? chat.chatContext.currentUserId}/block/$targetId';
url = 'users/${getUrlEncodedUserId(chat, userId)}/block/$targetId';
body = {'target_id': targetId};
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 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/utils/string_utils.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/public/main/define/enums.dart';
Expand All @@ -14,8 +15,7 @@ class UserGroupChannelCountGetRequest extends ApiRequest {
MyMemberStateFilter filter, {
String? userId,
}) : super(chat: chat, userId: userId) {
url =
'users/${userId ?? chat.chatContext.currentUserId}/group_channel_count';
url = 'users/${getUrlEncodedUserId(chat, userId)}/group_channel_count';
queryParams = {'state': memberStateFilterEnumForGroupCount(filter)};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import 'package:sendbird_chat_sdk/src/internal/main/chat/chat.dart';
import 'package:sendbird_chat_sdk/src/internal/main/utils/enum_utils.dart';
import 'package:sendbird_chat_sdk/src/internal/main/utils/string_utils.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/public/main/define/enums.dart';
Expand All @@ -16,8 +17,7 @@ class UserTotalUnreadChannelCountGetRequest extends ApiRequest {
GroupChannelTotalUnreadChannelCountParams? params,
String? userId,
}) : super(chat: chat, userId: userId) {
url =
'users/${userId ?? chat.chatContext.currentUserId}/unread_channel_count';
url = 'users/${getUrlEncodedUserId(chat, userId)}/unread_channel_count';
final customTypes = params?.channelCustomTypes ?? [];
final superFilter = params?.superChannelFilter ?? SuperChannelFilter.all;
queryParams = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 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/utils/string_utils.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/public/main/define/enums.dart';
Expand Down Expand Up @@ -35,7 +36,7 @@ class UserUnreadItemCountGetRequest extends ApiRequest {
List<UnreadItemKey> keys, {
String? userId,
}) : super(chat: chat, userId: userId) {
url = 'users/${userId ?? chat.chatContext.currentUserId}/unread_item_count';
url = 'users/${getUrlEncodedUserId(chat, userId)}/unread_item_count';
queryParams = {
'item_keys': keys.map((e) => unreadItemKeyEnumMap[e]).toList()
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import 'package:sendbird_chat_sdk/src/internal/main/chat/chat.dart';
import 'package:sendbird_chat_sdk/src/internal/main/utils/enum_utils.dart';
import 'package:sendbird_chat_sdk/src/internal/main/utils/string_utils.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/public/main/define/enums.dart';
Expand All @@ -17,8 +18,7 @@ class UserTotalUnreadMessageCountGetRequest extends ApiRequest {
GroupChannelTotalUnreadMessageCountParams? params,
String? userId,
}) : super(chat: chat, userId: userId) {
url =
'users/${userId ?? chat.chatContext.currentUserId}/unread_message_count';
url = 'users/${getUrlEncodedUserId(chat, userId)}/unread_message_count';
final customTypes = params?.channelCustomTypes ?? [];
final superFilter = params?.superChannelFilter ?? SuperChannelFilter.all;
queryParams = {
Expand Down
Loading

0 comments on commit b7f55ba

Please sign in to comment.