Skip to content

Commit a278f70

Browse files
committed
Fixed HMS token registration
1 parent f1d00de commit a278f70

File tree

13 files changed

+67
-44
lines changed

13 files changed

+67
-44
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [3.1.4] - Sep 24, 2021
2+
* Fixed HMS push token registration
3+
* Improved stability
4+
15
## [3.1.3] - Sep 3, 2021
26
* Added metaData related filters for `GroupChannelListQuery` and `PublicGroupChannelListQuery`
37
* Fixed behavior when app life cylce state has changed

README.md

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
# [Sendbird](https://sendbird.com) Chat SDK for Flutter
22

33
[![Platform](https://img.shields.io/badge/platform-flutter-blue)](https://flutter.dev/)
4+
[![Language](https://img.shields.io/badge/language-dart-blue)](https://dart.dev/)
5+
46

57
## Table of contents
68

79
1. [Introduction](#introduction)
8-
1. [Before getting started](#before-getting-started)
10+
1. [Requirements](#requirements)
911
1. [Getting started](#getting-started)
1012
1. [Sending your first message](#sending-your-first-message)
13+
1. [Getting help](#getting-help)
14+
1. [Hiring](#we-are-hiring)
1115

1216
<br />
1317

@@ -17,19 +21,16 @@ Through Chat SDK for flutter, you can efficiently integrate real-time chat into
1721

1822
### How it works
1923

20-
It is simple to implement chat in your client app with Sendbird Chat SDK for Flutter: a user logs in, sees a list of channels, selects or creates an [open channel](https://sendbird.com/docs/chat/v3/flutter/guides/open-channel) or a [group channel](https://sendbird.com/docs/chat/v3/flutter/guides/group-channel), and, through the use of the [channel event handler](https://sendbird.com/docs/chat/v3/flutter/guides/event-handler), sends messages to the channel, while also receiving them from other users within the channel.
21-
22-
### More about Sendbird Chat SDK for flutter
24+
1. A user logs in
25+
2. User sees a list of channels
26+
3. Select or create an [open channel](https://sendbird.com/docs/chat/v3/flutter/guides/open-channel?&utm_source=github&utm_medium=referral&utm_campaign=repo&utm_content=sendbird-chat-flutter-sdk) or a [group channel](https://sendbird.com/docs/chat/v3/flutter/guides/group-channel?&utm_source=github&utm_medium=referral&utm_campaign=repo&utm_content=sendbird-chat-flutter-sdk)
27+
4. Through the use of the [channel event handler](https://sendbird.com/docs/chat/v3/flutter/guides/event-handler?&utm_source=github&utm_medium=referral&utm_campaign=repo&utm_content=sendbird-chat-flutter-sdk), sends and receives messages to other users in that channel.
2328

24-
Find out more about Sendbird Chat for Flutter at [Sendbird Docs](https://sendbird.com/docs/chat/v3/flutter/getting-started/about-chat-sdk). If you have any comments or questions regarding bugs and feature requests, visit [Sendbird community](https://community.sendbird.com).
2529

2630
<br />
2731

28-
## Before getting started
2932

30-
This section shows you the prerequisites you need to check for using Sendbird Chat SDK for Flutter.
31-
32-
### Requirements
33+
## Requirements
3334

3435
The minimum requirements for Chat SDK for Flutter are:
3536

@@ -51,7 +52,7 @@ The fastest way to test Sendbird Chat SDK for Flutter is to build your chat app
5152

5253
A Sendbird application comprises everything required in a chat service including users, message, and channels. To create an application:
5354

54-
1. Go to the [Sendbird Dashboard](https://dashboard.sendbird.com/auth/signup) and enter your email and password, and create a new account. You can also sign up with a Google account.
55+
1. Go to the [Sendbird Dashboard](https://dashboard.sendbird.com/auth/signup?&utm_source=github&utm_medium=referral&utm_campaign=repo&utm_content=sendbird-chat-flutter-sdk) and enter your email and password, and create a new account. You can also sign up with a Google account.
5556
2. When prompted by the setup wizard, enter your organization information to manage Sendbird applications.
5657
3. Lastly, when your dashboard home appears after completing setup, click **Create +** at the top-right corner.
5758

@@ -116,9 +117,9 @@ try {
116117

117118
#### B. Using a unique user ID and an access token
118119

119-
By using Chat Platform API, you can [create a user](https://sendbird.com/docs/chat/v3/platform-api/guides/user#2-create-a-user) and issue a unique access token to each user, or [issue an access token](https://sendbird.com/docs/chat/v3/platform-api/guides/user#2-update-a-user) for an existing user. Once an access token is issued, a user is required to provide the access token to log in to your Sendbird application.
120+
By using Chat Platform API, you can [create a user](https://sendbird.com/docs/chat/v3/platform-api/guides/user#2-create-a-user) and issue a unique access token to each user, or [issue an access token](https://sendbird.com/docs/chat/v3/platform-api/guides/user#2-update-a-user?&utm_source=github&utm_medium=referral&utm_campaign=repo&utm_content=sendbird-chat-flutter-sdk) for an existing user. Once an access token is issued, a user is required to provide the access token to log in to your Sendbird application.
120121

121-
1. Using the [Chat Platform API](https://sendbird.com/docs/chat/v3/platform-api/guides/user#2-create-a-user), create a Sendbird user account with the information submitted when a user signs up or signs in to your service.
122+
1. Using the [Chat Platform API](https://sendbird.com/docs/chat/v3/platform-api/guides/user#2-create-a-user?&utm_source=github&utm_medium=referral&utm_campaign=repo&utm_content=sendbird-chat-flutter-sdk), create a Sendbird user account with the information submitted when a user signs up or signs in to your service.
122123
2. Save the user ID along with the issued access token to your securely managed persistent storage.
123124
3. When a user attempts to log in to the application, load the user ID and access token from the storage, and then pass them to `connect()` method.
124125
4. Periodically replacing the user's access token is recommended for account security.
@@ -135,11 +136,11 @@ try {
135136

136137
To manage user access to your Sendbird application, go to **Settings** > **Application** > **Security** > **Access token permission** setting on your Sendbird dashboard. You can change settings to prevent the users without an access token from logging in to your application or restrict their access to read and write messages.
137138

138-
For security reasons, you can also use a session token when a user logs in to Sendbird server instead of an access token. Learn more about [Access token vs. Session token](https://sendbird.com/docs/chat/v3/platform-api/guides/user#2-create-a-user-3-access-token-vs-session-token) from the Chat Platform API guide.
139+
For security reasons, you can also use a session token when a user logs in to Sendbird server instead of an access token. Learn more about [Access token vs. Session token](https://sendbird.com/docs/chat/v3/platform-api/guides/user#2-create-a-user-3-access-token-vs-session-token?&utm_source=github&utm_medium=referral&utm_campaign=repo&utm_content=sendbird-chat-flutter-sdk) from the Chat Platform API guide.
139140

140141
### Step 3: Create a new open channel
141142

142-
Create an [open channel](https://sendbird.com/docs/chat/v3/flutter/guides/open-channel#2-create-a-channel). Once created, all users in your Sendbird application can easily participate in the channel.
143+
Create an [open channel](https://sendbird.com/docs/chat/v3/flutter/guides/open-channel#2-create-a-channel?&utm_source=github&utm_medium=referral&utm_campaign=repo&utm_content=sendbird-chat-flutter-sdk). Once created, all users in your Sendbird application can easily participate in the channel.
143144

144145
```dart
145146
try {
@@ -149,7 +150,7 @@ try {
149150
}
150151
```
151152

152-
You can also create a [group channel](https://sendbird.com/docs/chat/v3/flutter/guides/group-channel#2-create-a-channel) by [inviting users as new members](https://sendbird.com/docs/chat/v3/flutter/guides/group-channel#2-invite-users-as-members) to the channel.
153+
You can also create a [group channel](https://sendbird.com/docs/chat/v3/flutter/guides/group-channel#2-create-a-channel?&utm_source=github&utm_medium=referral&utm_campaign=repo&utm_content=sendbird-chat-flutter-sdk) by [inviting users as new members](https://sendbird.com/docs/chat/v3/flutter/guides/group-channel#2-invite-users-as-members?&utm_source=github&utm_medium=referral&utm_campaign=repo&utm_content=sendbird-chat-flutter-sdk) to the channel.
153154

154155
> Note: The majority of the methods used in the following steps are all asynchronous. This means, with asynchronous methods, your client app must receive a result via `await` or `then()` callbacks from Sendbird server through completion handlers before moving on to the next step.
155156

@@ -168,11 +169,12 @@ try {
168169

169170
### Step 5: Send a message to the channel
170171

171-
Finally, send a message to the channel. There are three types of [messages](https://sendbird.com/docs/chat/v3/platform-api/guides/messages#-3-resource-representation): a user message in a plain text, a file message in a binary file, such as an image or PDF, and an admin message in a plain text sent through the [dashboard](https://dashboard.sendbird.com/auth/signin) or [Chat Platform API](https://sendbird.com/docs/chat/v3/platform-api/guides/messages#2-send-a-message).
172+
Finally, send a message to the channel. There are three types of [messages](https://sendbird.com/docs/chat/v3/platform-api/guides/messages#-3-resource-representation?&utm_source=github&utm_medium=referral&utm_campaign=repo&utm_content=sendbird-chat-flutter-sdk): a user message in a plain text, a file message in a binary file, such as an image or PDF, and an admin message in a plain text sent through the [dashboard](https://dashboard.sendbird.com/auth/signin?&utm_source=github&utm_medium=referral&utm_campaign=repo&utm_content=sendbird-chat-flutter-sdk) or [Chat Platform API](https://sendbird.com/docs/chat/v3/platform-api/guides/messages#2-send-a-message?&utm_source=github&utm_medium=referral&utm_campaign=repo&utm_content=sendbird-chat-flutter-sdk).
172173

173174
```dart
174175
try {
175-
final params = UserMessageParams(message: MESSAGE)
176+
final params = UserMessageParams()
177+
..message = MESSAGE
176178
..data = DATA
177179
..customType = CUSTOM_TYPE;
178180
@@ -188,3 +190,12 @@ try {
188190
// error
189191
}
190192
```
193+
194+
195+
## Getting Help
196+
Check out the Official Sendbird [Flutter docs](https://sendbird.com/docs/chat/v3/flutter/quickstart/send-first-message?&utm_source=github&utm_medium=referral&utm_campaign=repo&utm_content=sendbird-chat-flutter-sdk) and Sendbird's [Developer Portal](https://sendbird.com/developer?&utm_source=github&utm_medium=referral&utm_campaign=repo&utm_content=sendbird-chat-flutter-sdk) for tutorials and videos. If you need any help in resolving any issues or have questions, visit our [community forums](https://community.sendbird.com?&utm_source=github&utm_medium=referral&utm_campaign=repo&utm_content=sendbird-chat-flutter-sdk).
197+
198+
<br />
199+
200+
## We are Hiring!
201+
Sendbird is made up of a diverse group of humble, friendly, and hardworking individuals united by a shared purpose to build the next generation of mobile & social technologies. Join our team remotely or at one of our locations in San Mateo, Seoul, New York, London, and Singapore. More information on a [careers page](https://sendbird.com/careers?&utm_source=github&utm_medium=referral&utm_campaign=repo&utm_content=sendbird-chat-flutter-sdk).

lib/constant/enums.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,19 @@ enum PushTokenRegistrationStatus { success, pending, error }
368368
/// Represents push token type
369369
enum PushTokenType { none, hms, fcm, apns }
370370

371+
String? pushTokenToString(PushTokenType type) {
372+
switch (type) {
373+
case PushTokenType.apns:
374+
return 'apns';
375+
case PushTokenType.fcm:
376+
return 'gcm';
377+
case PushTokenType.hms:
378+
return 'huawei';
379+
default:
380+
return null;
381+
}
382+
}
383+
371384
/// Represents unread item key filter
372385
enum UnreadItemKey {
373386
@JsonValue('non_super_group_channel_unread_message_count')

lib/events/login_event.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ class LoginEvent extends SessionEvent {
3131

3232
LoginEvent({
3333
String? ekey,
34-
int? expiresIn,
3534
String? newKey,
3635
String? key,
3736
required this.loginTimestamp,
@@ -43,7 +42,6 @@ class LoginEvent extends SessionEvent {
4342
ekey: ekey,
4443
newKey: newKey,
4544
key: key,
46-
expiresIn: expiresIn,
4745
);
4846

4947
factory LoginEvent.fromJson(Map<String, dynamic> json) {

lib/events/login_event.g.dart

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/events/session_event.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ part 'session_event.g.dart';
77
@JsonSerializable(createToJson: false)
88
class SessionEvent extends BaseEvent {
99
@JsonKey(defaultValue: 0)
10-
final int? expiresIn;
10+
final int? expiresAt;
1111

1212
final String? newKey;
1313

@@ -17,7 +17,7 @@ class SessionEvent extends BaseEvent {
1717

1818
String get sessionKey => key ?? newKey ?? '';
1919

20-
SessionEvent({this.expiresIn, this.newKey, this.ekey, this.key});
20+
SessionEvent({this.expiresAt, this.newKey, this.ekey, this.key});
2121

2222
factory SessionEvent.fromJson(Map<String, dynamic> json) =>
2323
_$SessionEventFromJson(json);

lib/events/session_event.g.dart

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/managers/command_manager.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,7 @@ class CommandManager with SdkAccessor {
271271
sdk.sessionManager
272272
..setUserId(user.userId)
273273
..setEKey(event.ekey)
274-
..setSessionKey(event.sessionKey)
275-
..setSessionExpiresIn(event.expiresIn);
274+
..setSessionKey(event.sessionKey);
276275

277276
if (wasReconnecting) {
278277
eventManager.notifyReconnectionSucceeded();
@@ -528,7 +527,7 @@ class CommandManager with SdkAccessor {
528527
Future<void> _processSessionRefresh(Command cmd) async {
529528
final event = SessionEvent.fromJson(cmd.payload);
530529
sdk.sessionManager.setSessionKey(event.sessionKey);
531-
sdk.sessionManager.setSessionExpiresIn(event.expiresIn);
530+
sdk.sessionManager.setSessionExpiresAt(event.expiresAt);
532531
}
533532

534533
Future<void> _processError(Command cmd) async {

lib/managers/session_manager.dart

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class SessionManager with SdkAccessor {
1919
String? _accessToken;
2020
late String _sessionKeyPath;
2121
late String _userIdKeyPath;
22-
int _sessionExpiresIn = 0;
22+
int _sessionExpiresAt = 0;
2323

2424
bool isRefreshingKey = false;
2525

@@ -52,11 +52,11 @@ class SessionManager with SdkAccessor {
5252
_userIdKeyPath = path;
5353
}
5454

55-
void setSessionExpiresIn(int? timestamp) {
56-
_sessionExpiresIn = timestamp ?? 0;
55+
void setSessionExpiresAt(int? timestamp) {
56+
_sessionExpiresAt = timestamp ?? 0;
5757
}
5858

59-
int get sessionExpiresIn => _sessionExpiresIn;
59+
int get sessionExpiresAt => _sessionExpiresAt;
6060

6161
/// Set a `sessionKey` that will be used for SDK globally
6262
///
@@ -202,14 +202,12 @@ class SessionManager with SdkAccessor {
202202
setSessionKey(payload['new_key']);
203203
}
204204

205-
final reconnect = sessionExpiresIn <= 0;
206-
207-
if (payload['expires_in'] != null) {
208-
setSessionExpiresIn(payload['expires_in']);
205+
if (payload['expires_at'] != null) {
206+
setSessionExpiresAt(payload['expires_at']);
209207
}
210208

211209
eventManager.notifySessionRefreshed();
212-
if (reconnect) sdk.reconnect(reset: true);
210+
sdk.reconnect(reset: true);
213211
}
214212

215213
// Handler for refresh session success case
@@ -231,7 +229,7 @@ class SessionManager with SdkAccessor {
231229

232230
// Resets session manager
233231
void cleanUp() {
234-
_sessionExpiresIn = 0;
232+
_sessionExpiresAt = 0;
235233
_eKey = null;
236234
_sessionKey = null;
237235
}

lib/params/file_message_params.dart

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,8 @@ class FileMessageParams extends BaseMessageParams {
2222
),
2323
super.withMessage(fileMessage, deepCopy: deepCopy);
2424

25-
FileMessageParams.withFile(
26-
File file, {
27-
String? name,
28-
FileMessage? fileMessage,
29-
}) : uploadFile = FileInfo.fromData(
25+
FileMessageParams.withFile(File file, {String? name})
26+
: uploadFile = FileInfo.fromData(
3027
name: name ?? 'my_file',
3128
file: file,
3229
mimeType: lookupMimeType(file.path),

0 commit comments

Comments
 (0)