Skip to content

Commit

Permalink
Merge pull request #337 from GetStream/release/1.5.0
Browse files Browse the repository at this point in the history
Release/1.5.0
  • Loading branch information
imtoori authored Mar 16, 2021
2 parents db85929 + b9defc9 commit a3519ac
Show file tree
Hide file tree
Showing 58 changed files with 1,473 additions and 1,025 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pana.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ jobs:
TOTAL_MAX: ${{ steps.analysis.outputs.total_max }}
run: |
PERCENTAGE=$(( $TOTAL * 100 / $TOTAL_MAX ))
if (( $PERCENTAGE < 90 ))
if (( $PERCENTAGE < 80 ))
then
echo Score too low!
exit 1
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/pr_title.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
- opened
- edited
- synchronize
branches:
- develop

jobs:
main:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scripts/install-tools.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

flutter pub global activate melos 0.4.0+1
flutter pub global activate melos
echo "::add-path::$HOME/.pub-cache/bin"
echo "::add-path::$GITHUB_WORKSPACE/_flutter/.pub-cache/bin"
echo "::add-path::$GITHUB_WORKSPACE/_flutter/bin/cache/dart-sdk/bin"
61 changes: 28 additions & 33 deletions .github/workflows/stream_flutter_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ on:

jobs:
analyze:
if: github.base_ref == 'master'
timeout-minutes: 15
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -48,28 +47,15 @@ jobs:
- name: 'Install Tools'
run: |
./.github/workflows/scripts/install-tools.sh
curl -sL https://github.com/google/google-java-format/releases/download/google-java-format-1.3/google-java-format-1.3-all-deps.jar -o $HOME/google-java-format.jar
- name: 'Bootstrap Workspace'
run: melos bootstrap
- name: 'Dart'
run: |
melos exec -c 1 -- \
flutter format .
./.github/workflows/scripts/validate-formatting.sh
- name: 'Objective-C'
if: ${{ success() || failure() }}
run: |
melos exec -c 4 --ignore="*platform_interface*" --ignore="*web*" -- \
find . -maxdepth 3 -name "*.h" -o -name "*.m" -print0 \| xargs -0 clang-format -i --style=Google --verbose
./.github/workflows/scripts/validate-formatting.sh
- name: 'Java'
if: ${{ success() || failure() }}
run: |
melos exec -c 4 --ignore="*platform_interface*" --ignore="*web*" -- \
find . -maxdepth 12 -name "*.java" -print0 \| xargs -0 java -jar $HOME/google-java-format.jar --replace
./.github/workflows/scripts/validate-formatting.sh
test_dart:
test:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
Expand All @@ -79,26 +65,35 @@ jobs:
- name: 'Install Flutter'
run: ./.github/workflows/scripts/install-flutter.sh stable
- name: 'Install Tools'
run: ./.github/workflows/scripts/install-tools.sh
- name: 'Bootstrap Workspace'
run: melos bootstrap
- name: 'Flutter Test'
run: cd packages/stream_chat && flutter pub run test

test_flutter:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: 'Install Flutter'
run: ./.github/workflows/scripts/install-flutter.sh stable
- name: 'Install Tools'
run: ./.github/workflows/scripts/install-tools.sh
run: |
./.github/workflows/scripts/install-tools.sh
flutter pub global activate coverage
- name: 'Bootstrap Workspace'
run: melos bootstrap
- name: 'Dart Test'
run: |
cd packages/stream_chat
flutter pub run test --coverage coverage/
format_coverage --lcov --in=coverage/ --out=lcov.info --packages=.packages --report-on=lib
- name: 'Flutter Test'
run: |
melos exec -c 3 --flutter --dir-exists=test --ignore="*example*" --ignore="*web*" -- \
flutter test
flutter test --coverage
- name: CodeCov
run: bash <(curl -s https://codecov.io/bash) -t ${{ secrets.CODECOV_TOKEN }}
- uses: VeryGoodOpenSource/[email protected]
with:
path: packages/stream_chat/lcov.info
min_coverage: 50
- uses: VeryGoodOpenSource/[email protected]
with:
path: packages/stream_chat_persistence/coverage/lcov.info
min_coverage: 0.2
- uses: VeryGoodOpenSource/[email protected]
with:
path: packages/stream_chat_flutter_core/coverage/lcov.info
min_coverage: 4.5
- uses: VeryGoodOpenSource/[email protected]
with:
path: packages/stream_chat_flutter/coverage/lcov.info
min_coverage: 16
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
.atom/
.idea/
.vscode/

**/lcov.info
coverage
.packages
.pub/
.dart_tool/
Expand Down
4 changes: 4 additions & 0 deletions packages/stream_chat/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.5.0

- Minor fixes and improvements

## 1.4.0-beta

- Improved attachment uploading
Expand Down
1 change: 0 additions & 1 deletion packages/stream_chat/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ linter:
- avoid_private_typedef_functions
- avoid_redundant_argument_values
- avoid_return_types_on_setters
- avoid_returning_null
- avoid_returning_null_for_void
- avoid_shadowing_type_parameters
- avoid_single_cascade_in_expression_statements
Expand Down
19 changes: 13 additions & 6 deletions packages/stream_chat/lib/src/api/channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import 'package:logging/logging.dart';
import 'package:rxdart/rxdart.dart';
import 'package:stream_chat/src/api/retry_queue.dart';
import 'package:stream_chat/src/event_type.dart';
import 'package:stream_chat/src/extensions/rate_limit.dart';
import 'package:stream_chat/src/models/attachment_file.dart';
import 'package:stream_chat/src/models/channel_state.dart';
import 'package:stream_chat/src/models/user.dart';
import 'package:stream_chat/stream_chat.dart';
import 'package:stream_chat/src/extensions/rate_limit.dart';

/// This a the class that manages a specific channel.
class Channel {
Expand Down Expand Up @@ -1209,9 +1209,10 @@ class ChannelClientState {
ChannelClientState(
this._channel,
ChannelState channelState,
) : _debouncedUpdatePersistenceChannelState = _channel
?._client?.chatPersistenceClient?.updateChannelState
?.debounced(const Duration(seconds: 1)) {
//ignore: unnecessary_parenthesis
) : _debouncedUpdatePersistenceChannelState = ((ChannelState state) {
_channel?._client?.chatPersistenceClient?.updateChannelState(state);
}).debounced(const Duration(seconds: 1)) {
retryQueue = RetryQueue(
channel: _channel,
logger: Logger('RETRY QUEUE ${_channel.cid}'),
Expand Down Expand Up @@ -1463,10 +1464,16 @@ class ChannelClientState {
void addMessage(Message message) {
if (message.parentId == null || message.showInChannel == true) {
final newMessages = List<Message>.from(_channelState.messages);

final oldIndex = newMessages.indexWhere((m) => m.id == message.id);
if (oldIndex != -1) {
newMessages[oldIndex] = message;
Message m;
if (message.quotedMessageId != null && message.quotedMessage == null) {
final oldMessage = newMessages[oldIndex];
m = message.copyWith(
quotedMessage: oldMessage.quotedMessage,
);
}
newMessages[oldIndex] = m ?? message;
} else {
newMessages.add(message);
}
Expand Down
82 changes: 47 additions & 35 deletions packages/stream_chat/lib/src/client.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// ignore_for_file: unnecessary_getters_setters

import 'dart:async';
import 'dart:convert';
import 'package:stream_chat/src/extensions/map_extension.dart';

import 'package:dio/dio.dart';
import 'package:logging/logging.dart';
Expand All @@ -16,6 +17,7 @@ import 'package:stream_chat/src/attachment_file_uploader.dart';
import 'package:stream_chat/src/db/chat_persistence_client.dart';
import 'package:stream_chat/src/event_type.dart';
import 'package:stream_chat/src/exceptions.dart';
import 'package:stream_chat/src/extensions/map_extension.dart';
import 'package:stream_chat/src/models/attachment_file.dart';
import 'package:stream_chat/src/models/channel_model.dart';
import 'package:stream_chat/src/models/channel_state.dart';
Expand Down Expand Up @@ -106,14 +108,22 @@ class StreamChatClient {
logger.info('instantiating new client');
}

set chatPersistenceClient(ChatPersistenceClient value) {
_originalChatPersistenceClient = value;
}

ChatPersistenceClient _originalChatPersistenceClient;

/// Chat persistence client
ChatPersistenceClient chatPersistenceClient;
ChatPersistenceClient get chatPersistenceClient => _chatPersistenceClient;

ChatPersistenceClient _chatPersistenceClient;

/// Attachment uploader
AttachmentFileUploader attachmentFileUploader;

/// Whether the chat persistence is available or not
bool get persistenceEnabled => chatPersistenceClient != null;
bool get persistenceEnabled => _chatPersistenceClient != null;

RetryPolicy _retryPolicy;

Expand Down Expand Up @@ -357,7 +367,7 @@ class StreamChatClient {

/// Call this function to dispose the client
void dispose() async {
await chatPersistenceClient?.disconnect();
await _chatPersistenceClient?.disconnect();
await _disconnect();
httpClient.close();
await _controller.close();
Expand Down Expand Up @@ -446,8 +456,8 @@ class StreamChatClient {

if (!event.isLocal) {
if (_synced && event.createdAt != null) {
await chatPersistenceClient?.updateConnectionInfo(event);
await chatPersistenceClient?.updateLastSyncAt(event.createdAt);
await _chatPersistenceClient?.updateConnectionInfo(event);
await _chatPersistenceClient?.updateLastSyncAt(event.createdAt);
}
}

Expand Down Expand Up @@ -478,8 +488,9 @@ class StreamChatClient {

_wsConnectionStatus = ConnectionStatus.connecting;

if (persistenceEnabled) {
await chatPersistenceClient.connect(state.user.id);
if (_originalChatPersistenceClient != null) {
_chatPersistenceClient = _originalChatPersistenceClient;
await _chatPersistenceClient.connect(state.user.id);
}

_ws = WebSocket(
Expand Down Expand Up @@ -508,34 +519,35 @@ class StreamChatClient {
),
);

if (status == ConnectionStatus.connected &&
state.channels?.isNotEmpty == true) {
// ignore: unawaited_futures
queryChannelsOnline(filter: {
'cid': {
'\$in': state.channels.keys.toList(),
},
}).then(
(_) async {
await resync();
handleEvent(Event(
type: EventType.connectionRecovered,
online: true,
));
},
);
} else {
_synced = false;
if (status == ConnectionStatus.connected) {
handleEvent(Event(
type: EventType.connectionRecovered,
online: true,
));
if (state.channels?.isNotEmpty == true) {
// ignore: unawaited_futures
queryChannelsOnline(filter: {
'cid': {
'\$in': state.channels.keys.toList(),
},
}).then(
(_) async {
await resync();
},
);
} else {
_synced = false;
}
}
};

_connectionStatusSubscription =
_ws.connectionStatusStream.listen(_connectionStatusHandler);

var event = await chatPersistenceClient?.getConnectionInfo();
var event = await _chatPersistenceClient?.getConnectionInfo();

await _ws.connect().then((e) async {
await chatPersistenceClient?.updateConnectionInfo(e);
await _chatPersistenceClient?.updateConnectionInfo(e);
event = e;
await resync();
}).catchError((err, stacktrace) {
Expand All @@ -551,14 +563,14 @@ class StreamChatClient {

/// Get the events missed while offline to sync the offline storage
Future<void> resync([List<String> cids]) async {
final lastSyncAt = await chatPersistenceClient?.getLastSyncAt();
final lastSyncAt = await _chatPersistenceClient?.getLastSyncAt();

if (lastSyncAt == null) {
_synced = true;
return;
}

cids ??= await chatPersistenceClient?.getChannelCids();
cids ??= await _chatPersistenceClient?.getChannelCids();

if (cids?.isEmpty == true) {
return;
Expand Down Expand Up @@ -586,7 +598,7 @@ class StreamChatClient {

res.events.forEach(handleEvent);

await chatPersistenceClient?.updateLastSyncAt(DateTime.now());
await _chatPersistenceClient?.updateLastSyncAt(DateTime.now());
_synced = true;
} catch (error) {
logger.severe('Error during resync $error');
Expand Down Expand Up @@ -723,7 +735,7 @@ class StreamChatClient {

final updateData = _mapChannelStateToChannel(channels);

await chatPersistenceClient?.updateChannelQueries(
await _chatPersistenceClient?.updateChannelQueries(
filter,
channels.map((c) => c.channel.cid).toList(),
paginationParams?.offset == null || paginationParams.offset == 0,
Expand All @@ -739,7 +751,7 @@ class StreamChatClient {
@required List<SortOption<ChannelModel>> sort,
PaginationParams paginationParams = const PaginationParams(),
}) async {
final offlineChannels = await chatPersistenceClient?.getChannelStates(
final offlineChannels = await _chatPersistenceClient?.getChannelStates(
filter: filter,
sort: sort,
paginationParams: paginationParams,
Expand Down Expand Up @@ -960,8 +972,8 @@ class StreamChatClient {
logger.info('Disconnecting flushOfflineStorage: $flushChatPersistence; '
'clearUser: $clearUser');

await chatPersistenceClient?.disconnect(flush: flushChatPersistence);
chatPersistenceClient = null;
await _chatPersistenceClient?.disconnect(flush: flushChatPersistence);
_chatPersistenceClient = null;

_connectCompleter = null;

Expand Down
2 changes: 1 addition & 1 deletion packages/stream_chat/lib/version.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ import 'package:stream_chat/src/client.dart';
/// Current package version
/// Used in [StreamChatClient] to build the `x-stream-client` header
// ignore: constant_identifier_names
const PACKAGE_VERSION = '1.4.0-beta';
const PACKAGE_VERSION = '1.5.0';
2 changes: 1 addition & 1 deletion packages/stream_chat/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: stream_chat
homepage: https://getstream.io/
description: The official Dart client for Stream Chat, a service for building chat applications.
version: 1.4.0-beta
version: 1.5.0
repository: https://github.com/GetStream/stream-chat-flutter
issue_tracker: https://github.com/GetStream/stream-chat-flutter/issues

Expand Down
Loading

0 comments on commit a3519ac

Please sign in to comment.