Skip to content

Commit

Permalink
Appiled lint
Browse files Browse the repository at this point in the history
  • Loading branch information
intoxicated committed Apr 22, 2021
1 parent ddcfd68 commit 77b997f
Show file tree
Hide file tree
Showing 63 changed files with 349 additions and 270 deletions.
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ Through Chat SDK for flutter, you can efficiently integrate real-time chat into

### How it works

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/ios/guides/open-channel) or a [group channel](https://sendbird.com/docs/chat/v3/ios/guides/group-channel), and, through the use of the [channel event handler](https://sendbird.com/docs/chat/v3/ios/guides/event-delegate), sends messages to the channel, while also receiving them from other users within the channel.
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.

### More about Sendbird Chat SDK for flutter

Find out more about Sendbird Chat for Flutter at [Sendbird Docs](). If you have any comments or questions regarding bugs and feature requests, visit [Sendbird community](https://community.sendbird.com).
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).

<br />

Expand All @@ -35,9 +35,7 @@ The minimum requirements for Chat SDK for Flutter are:

- Xcode or Android studio
- Dart 2.10.4
- Flutter 1.22.x

>__Note__: Flutter 2.0.x aren't compatible yet.
- Flutter 1.22.x or higher

## Getting started

Expand Down Expand Up @@ -146,7 +144,7 @@ For security reasons, you can also use a session token when a user logs in to Se

### Step 3: Create a new open channel

Create an [open channel](https://sendbird.com/docs/chat/v3/ios/guides/open-channel#2-create-a-channel). Once created, all users in your Sendbird application can easily participate in the channel.
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.

```dart
try {
Expand All @@ -156,7 +154,7 @@ try {
}
```

You can also create a [group channel](https://sendbird.com/docs/chat/v3/ios/guides/group-channel#2-create-a-channel) by [inviting users as new members](https://sendbird.com/docs/chat/v3/ios/guides/group-channel#2-invite-users-as-members) to the channel.
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.

> 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.

Expand Down
17 changes: 17 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Defines a default set of lint rules enforced for
# projects at Google. For details and rationale,
# see https://github.com/dart-lang/pedantic#enabled-lints.
include: package:pedantic/analysis_options.yaml

# For lint rules and documentation, see http://dart-lang.github.io/linter/lints.
# Uncomment to specify additional rules.
linter:
rules:
prefer_final_fields: false
unawaited_futures: false

analyzer:
exclude:
- example
- lib/**/*.g.dart
- lib/params/message_change_logs_params.g.dart
29 changes: 29 additions & 0 deletions example/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import 'package:sendbird_sdk/sendbird_sdk.dart';

void main(List<String> arguments) async {
// This example uses the Google Books API to search for books about http.
// https://developers.google.com/books/docs/overview

final sendbird = SendbirdSdk(appId: 'YOUR-APP-ID');

try {
final user = await sendbird.connect('UNIQUE-USER-ID');
final params = GroupChannelParams()
..userIds = [user.userId]
..operatorUserIds = [user.userId]
..name = 'YOUR_GROUP_NAME'
..customType = 'CUSTOM_TYPE'
..isPublic = true;

// create group channel
final channel = await GroupChannel.createChannel(params);

channel.sendUserMessageWithText('Hello World',
onCompleted: (message, error) {
// message has been sent successfully
print('${message.message} has been sent!');
});
} catch (e) {
// handle error
}
}
19 changes: 9 additions & 10 deletions lib/constant/enums.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ extension ChannelTypeExtension on ChannelType {
String get urlString {
switch (this) {
case ChannelType.group:
return "group_channels";
return 'group_channels';
case ChannelType.open:
return "open_channels";
return 'open_channels';
default:
return null;
}
Expand Down Expand Up @@ -52,7 +52,7 @@ enum Role {
none,

/// Operator
@JsonValue("operator")
@JsonValue('operator')
chat_operator
}

Expand Down Expand Up @@ -499,13 +499,12 @@ enum ChannelQueryIncludeOption {

extension IncludeOptionList on List<ChannelQueryIncludeOption> {
Map<String, bool> toJson() {
final hasEmpty = this.contains(ChannelQueryIncludeOption.emptyChannel);
final hasMember = this.contains(ChannelQueryIncludeOption.memberList);
final hasFrozen = this.contains(ChannelQueryIncludeOption.frozenChannel);
final hasRead = this.contains(ChannelQueryIncludeOption.readReceipt);
final hasDelivery =
this.contains(ChannelQueryIncludeOption.deliveryReceipt);
final hasMeta = this.contains(ChannelQueryIncludeOption.metaData);
final hasEmpty = contains(ChannelQueryIncludeOption.emptyChannel);
final hasMember = contains(ChannelQueryIncludeOption.memberList);
final hasFrozen = contains(ChannelQueryIncludeOption.frozenChannel);
final hasRead = contains(ChannelQueryIncludeOption.readReceipt);
final hasDelivery = contains(ChannelQueryIncludeOption.deliveryReceipt);
final hasMeta = contains(ChannelQueryIncludeOption.metaData);

return {
if (hasEmpty) 'show_empty': true,
Expand Down
9 changes: 5 additions & 4 deletions lib/constant/types.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import 'package:sendbird_sdk/core/message/base_message.dart';
import 'package:sendbird_sdk/core/message/file_message.dart';
import 'package:sendbird_sdk/core/message/user_message.dart';

typedef void OnUploadProgressCallback(int sentBytes, int totalBytes);
typedef void OnMessageCallback(BaseMessage message, Error error);
typedef void OnFileMessageCallback(FileMessage message, Error error);
typedef void OnUserMessageCallback(FileMessage message, Error error);
typedef OnUploadProgressCallback = void Function(int sentBytes, int totalBytes);
typedef OnMessageCallback = void Function(BaseMessage message, Error error);
typedef OnFileMessageCallback = void Function(FileMessage message, Error error);
typedef OnUserMessageCallback = void Function(UserMessage message, Error error);
3 changes: 2 additions & 1 deletion lib/core/channel/base/base_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ class BaseChannel implements Cacheable {
bool fromCache = false;

@JsonKey(ignore: true)
bool dirty = false;
@override
bool dirty;

/// **WARNING:** Do not use default constructor to initialize manually
BaseChannel({
Expand Down
19 changes: 11 additions & 8 deletions lib/core/channel/base/base_channel_messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ extension Messages on BaseChannel {
/// on all other members' end.
UserMessage sendUserMessageWithText(
String text, {
OnMessageCallback onCompleted,
OnUserMessageCallback onCompleted,
}) {
final params = UserMessageParams()..message = text;
return sendUserMessage(
Expand All @@ -27,7 +27,7 @@ extension Messages on BaseChannel {
/// on all other members' end.
UserMessage sendUserMessage(
UserMessageParams params, {
OnMessageCallback onCompleted,
OnUserMessageCallback onCompleted,
}) {
if (params.message == null || params.message.isEmpty) {
throw InvalidParameterError();
Expand Down Expand Up @@ -77,7 +77,7 @@ extension Messages on BaseChannel {
/// on all other members' end.
UserMessage resendUserMessage(
UserMessage message, {
OnMessageCallback onCompleted,
OnUserMessageCallback onCompleted,
}) {
if (message == null ||
message.sendingStatus != MessageSendingStatus.failed) {
Expand Down Expand Up @@ -118,7 +118,7 @@ extension Messages on BaseChannel {
final msg = BaseMessage.msgFromJson<UserMessage>(res.payload);
return msg;
} catch (e) {
throw e;
rethrow;
}
}

Expand Down Expand Up @@ -162,14 +162,15 @@ extension Messages on BaseChannel {
Duration(seconds: _sdk.options.fileTransferTimeout),
onTimeout: () {
logger.e('upload timeout');
if (onCompleted != null)
if (onCompleted != null) {
onCompleted(
pending..sendingStatus = MessageSendingStatus.failed,
SBError(
message: 'upload timeout',
code: ErrorCode.fileUploadTimeout,
),
);
}
return;
},
);
Expand Down Expand Up @@ -272,7 +273,7 @@ extension Messages on BaseChannel {
final msg = BaseMessage.msgFromJson<FileMessage>(res.payload);
return msg;
} catch (e) {
throw e;
rethrow;
}
}

Expand Down Expand Up @@ -364,8 +365,9 @@ extension Messages on BaseChannel {
throw InvalidParameterError();
}

if (channelType == ChannelType.group)
if (channelType == ChannelType.group) {
params.showSubChannelMessagesOnly = false;
}

return _sdk.api.getMessages(
channelType: channelType,
Expand All @@ -387,8 +389,9 @@ extension Messages on BaseChannel {
throw InvalidParameterError();
}

if (channelType == ChannelType.group)
if (channelType == ChannelType.group) {
params.showSubChannelMessagesOnly = false;
}

return _sdk.api.getMessages(
channelType: channelType,
Expand Down
6 changes: 3 additions & 3 deletions lib/core/channel/base/base_channel_meta.dart
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ extension Meta on BaseChannel {
throw InvalidParameterError();
}

if (metaArrays == null || metaArrays.length == 0) {
if (metaArrays == null || metaArrays.isEmpty) {
throw InvalidParameterError();
}

Expand All @@ -330,7 +330,7 @@ extension Meta on BaseChannel {
throw InvalidParameterError();
}

if (keys == null || keys.length <= 0) {
if (keys == null || keys.isEmpty) {
throw InvalidParameterError();
}

Expand All @@ -353,7 +353,7 @@ extension Meta on BaseChannel {
throw InvalidParameterError();
}

if (metaArrays == null || metaArrays.length == 0) {
if (metaArrays == null || metaArrays.isEmpty) {
throw InvalidParameterError();
}

Expand Down
6 changes: 4 additions & 2 deletions lib/core/channel/group/features/delivery_status.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ part 'delivery_status.g.dart';
class DeliveryStatus implements Cacheable {
final String channelUrl;

@JsonKey(name: "updated")
@JsonKey(name: 'updated')
Map<String, int> updatedDeliveryReceipt;

@JsonKey(ignore: true)
@override
bool dirty = false;

DeliveryStatus({
Expand All @@ -30,7 +31,8 @@ class DeliveryStatus implements Cacheable {

@override
void copyWith(dynamic others) {
if (others is DeliveryStatus)
if (others is DeliveryStatus) {
updatedDeliveryReceipt.addAll(others.updatedDeliveryReceipt);
}
}
}
1 change: 1 addition & 0 deletions lib/core/channel/group/features/read_status.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class ReadStatus implements Cacheable {
int timestamp;

@JsonKey(ignore: true)
@override
bool dirty = false;

ReadStatus({
Expand Down
1 change: 1 addition & 0 deletions lib/core/channel/group/features/typing_status.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class TypingStatus implements Cacheable {
User user;
int timestamp;

@override
bool dirty = false;

TypingStatus({
Expand Down
5 changes: 2 additions & 3 deletions lib/core/channel/group/group_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,8 @@ class GroupChannel extends BaseChannel {
if (params == null) {
throw InvalidParameterError();
}
if (params.channelUrl == null) {
params.channelUrl = channelUrl;
}
params.channelUrl ??= channelUrl;

if (params.channelUrl != channelUrl) {
throw InvalidParameterError();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/core/channel/group/group_channel_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extension GroupChannelConfiguration on GroupChannel {
);

if (offset != null) messageOffsetTimestamp = offset;
if (hidePreviousMessage) this.clearUnreadCount();
if (hidePreviousMessage) clearUnreadCount();

isHidden = true;
hiddenState = allowAutoUnhide
Expand Down
4 changes: 2 additions & 2 deletions lib/core/channel/group/group_channel_internal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ extension GroupChannelInternal on GroupChannel {
members.sort((a, b) => a.nickname.compareTo(b.nickname));

final ts = DateTime.now().millisecondsSinceEpoch;
DeliveryStatus delivery = DeliveryStatus(
final delivery = DeliveryStatus(
channelUrl: channelUrl,
updatedDeliveryReceipt: {newMember.userId: ts},
);
ReadStatus read = ReadStatus(
final read = ReadStatus(
channelType: channelType,
channelUrl: channelUrl,
timestamp: ts,
Expand Down
2 changes: 1 addition & 1 deletion lib/core/channel/group/group_channel_typing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extension GroupChannelTyping on GroupChannel {
bool get isTyping {
final typingStatuses =
_sdk.cache.findAll<TypingStatus>(channelKey: channelUrl);
return typingStatuses != null && typingStatuses.length > 0;
return typingStatuses != null && typingStatuses.isNotEmpty;
}

/// Returns a list of [User] who are currently typing.
Expand Down
4 changes: 1 addition & 3 deletions lib/core/channel/open/open_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,7 @@ class OpenChannel extends BaseChannel {
if (params == null) {
throw InvalidParameterError();
}
if (params.channelUrl == null) {
params.channelUrl = channelUrl;
}
params.channelUrl ??= channelUrl;
if (params.channelUrl != channelUrl) {
throw InvalidParameterError();
}
Expand Down
1 change: 1 addition & 0 deletions lib/core/message/admin_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,6 @@ class AdminMessage extends BaseMessage {
factory AdminMessage.fromJson(Map<String, dynamic> json) =>
_$AdminMessageFromJson(json);

@override
Map<String, dynamic> toJson() => _$AdminMessageToJson(this);
}
Loading

0 comments on commit 77b997f

Please sign in to comment.