Skip to content

Commit

Permalink
Merge pull request #366 from bobs4462/main
Browse files Browse the repository at this point in the history
Build 2.2.9+3
  • Loading branch information
bmuddha authored Mar 16, 2021
2 parents 3e01d9d + 2b5d382 commit 1e7d93a
Show file tree
Hide file tree
Showing 55 changed files with 441 additions and 489 deletions.
6 changes: 3 additions & 3 deletions android/app/src/main/res/drawable-v21/launch_background.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<item android:drawable="?android:colorBackground" />

<!-- You can insert your own image assets here -->
<!-- <item>
<item>
<bitmap
android:gravity="center"
android:src="@mipmap/launch_image" />
</item> -->
android:src="@drawable/logo" />
</item>
</layer-list>
3 changes: 0 additions & 3 deletions lib/blocs/add_channel_bloc/add_channel_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ class AddChannelBloc extends Bloc<AddChannelEvent, AddChannelState> {
event.type ?? channelRepository.type ?? ChannelType.public;
channelRepository.members =
event.participants ?? channelRepository.members ?? [];
channelRepository.def =
event.automaticallyAddNew ?? channelRepository.def ?? true;

// print('Updated data: ${repository.toJson()}');
final newRepo = AddChannelRepository(
Expand All @@ -49,7 +47,6 @@ class AddChannelBloc extends Bloc<AddChannelEvent, AddChannelState> {
channelGroup: channelRepository.channelGroup,
type: channelRepository.type,
members: channelRepository.members,
def: channelRepository.def,
);
yield Updated(newRepo);
} else if (event is UpdateDirect) {
Expand Down
14 changes: 13 additions & 1 deletion lib/blocs/auth_bloc/auth_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {

AuthBloc(this.repository, this.connectionBloc) : super(AuthInitializing()) {
Api().resetAuthentication = resetAuthentication;
Api().invalidateConfiguration = resetHost;
subscription = connectionBloc.listen((cb.ConnectionState state) async {
if (state is cb.ConnectionLost) {
connectionLost = true;
Expand Down Expand Up @@ -79,7 +80,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
print('WEBVIEW LOAD ERROR: $a, $b, $c');
},
onWebViewCreated: (ctrl) {
// print('CREATED WEBVIEW');
print('CREATED WEBVIEW');
},
);
if (run) runWebView();
Expand Down Expand Up @@ -184,18 +185,25 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
} else if (event is ResetPassword) {
yield PasswordReset('https://console.twake.app/password-recovery');
} else if (event is ValidateHost) {
yield HostValidation(event.host);
Api.host = event.host;
final result = await repository.getAuthMode();
// final host = '${event.host}';
if (result == 'UNKNOWN') {
yield HostInvalid(event.host);
yield HostValidation(event.host);
} else {
if (result == 'CONSOLE') {
setUpWebView();
await runWebView();
}
print('Before yield');
yield HostValidated(event.host);
print('After yield');
}
} else if (event is ResetHost) {
await repository.clean();
yield HostReset();
}
}

Expand All @@ -215,6 +223,10 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
this.add(ResetAuthentication(message: 'Session has expired'));
}

void resetHost() {
this.add(ResetHost());
}

@override
Future<void> close() {
webView.dispose();
Expand Down
14 changes: 14 additions & 0 deletions lib/blocs/auth_bloc/auth_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ class AuthenticationError extends Unauthenticated {
List<Object> get props => [];
}

class HostValidation extends AuthState {
final String host;

const HostValidation(this.host);

@override
List<Object> get props => [host];
}

class HostValidated extends AuthState {
final String host;

Expand All @@ -90,3 +99,8 @@ class HostInvalid extends AuthState {
@override
List<Object> get props => [host];
}

class HostReset extends AuthState {
@override
List<Object> get props => [];
}
2 changes: 1 addition & 1 deletion lib/blocs/base_channel_bloc/base_channel_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ abstract class BaseChannelBloc extends Bloc<ChannelsEvent, ChannelState> {
final ch = await repository.getItemById(event.channelId);
if (ch != null) {
// ch.messagesTotal += event.totalModifier ?? 0;
ch.hasUnread = 1;
ch.hasUnread = event.hasUnread ?? 1;
ch.messagesUnread += event.unreadModifier ?? 0;
ch.lastActivity =
event.timeStamp ?? DateTime.now().millisecondsSinceEpoch;
Expand Down
4 changes: 2 additions & 2 deletions lib/blocs/channels_bloc/channel_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ class ModifyMessageCount extends ChannelsEvent {
final String channelId;
final String workspaceId;
final String companyId;
final int totalModifier;
final int unreadModifier;
final int hasUnread;
final int timeStamp;

ModifyMessageCount({
this.channelId,
this.workspaceId,
this.companyId,
this.totalModifier,
this.unreadModifier,
this.hasUnread,
this.timeStamp,
});

Expand Down
11 changes: 5 additions & 6 deletions lib/blocs/channels_bloc/channels_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ class ChannelsBloc extends BaseChannelBloc {
repository.logger.d('UPDATING CHANNELS\n${event.data.toJson()}');
var item = await repository.getItemById(event.data.channelId) as Channel;
if (item != null) {
item.icon = event.data.icon ?? '👽';
item.name = event.data.name;
item.description = event.data.description;
item.visibility = event.data.visibility;
item.visibility = event.data.visibility;
item.icon = event.data.icon ?? item.icon ?? '👽';
item.name = event.data.name ?? item.name;
item.description = event.data.description ?? item.description;
item.visibility = event.data.visibility ?? item.visibility;
item.lastMessage = event.data.lastMessage ?? item.lastMessage;
} else {
item = Channel.fromJson(event.data.toJson());
}
Expand All @@ -160,7 +160,6 @@ class ChannelsBloc extends BaseChannelBloc {
force: DateTime.now().toString(),
);
} else if (event is LoadSingleChannel) {
// TODO implement single company loading
throw 'Not implemented yet';
} else if (event is RemoveChannel) {
repository.items.removeWhere((i) => i.id == event.channelId);
Expand Down
3 changes: 3 additions & 0 deletions lib/blocs/configuration_cubit/configuration_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ class ConfigurationCubit extends Cubit<ConfigurationState> {
}

Future<void> save(String host) async {
emit(ConfigurationSaving(host: host));
try {
repository.host = host;
await repository.save();
print('Before to emit');
emit(ConfigurationSaved(host: host));
emit(ConfigurationLoaded(host: repository.host));
} on Exception {
emit(ConfigurationError(message: 'Error during the configuration saving'));
}
Expand Down
11 changes: 10 additions & 1 deletion lib/blocs/configuration_cubit/configuration_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import 'package:meta/meta.dart';
import 'package:equatable/equatable.dart';

abstract class ConfigurationState extends Equatable {
const ConfigurationState();
final String host;
const ConfigurationState({@required this.host});
}

class ConfigurationInitial extends ConfigurationState {
Expand All @@ -19,6 +20,14 @@ class ConfigurationLoaded extends ConfigurationState {
List<Object> get props => [host];
}

class ConfigurationSaving extends ConfigurationState {
final String host;

ConfigurationSaving({@required this.host});
@override
List<Object> get props => [host];
}

class ConfigurationSaved extends ConfigurationState {
final String host;

Expand Down
2 changes: 1 addition & 1 deletion lib/blocs/directs_bloc/directs_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ class DirectsBloc extends BaseChannelBloc {
channels: repository.items,
selected: repository.selected,
);
notificationBloc.add(CancelPendingSubscriptions(event.channelId));
} else if (event is LoadSingleChannel) {
// TODO implement single channel loading
throw 'Not implemented yet';
} else if (event is RemoveChannel) {
throw 'Not implemented yet';
Expand Down
8 changes: 5 additions & 3 deletions lib/blocs/messages_bloc/messages_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -197,16 +197,17 @@ class MessagesBloc<T extends BaseChannelBloc>
_makeQueryParams(event),
addToItems: event.channelId == selectedChannel.id,
);
_sortItems();
if (updateParent) {
_updateParentChannel(event.channelId);
}
_sortItems();
final newState = MessagesLoaded(
messages: repository.items,
messageCount: repository.itemsCount,
force: DateTime.now().toString(),
parentChannel: selectedChannel,
);
// repository.logger.w("OLD STATE == NEW STATE: ${newState == this.state}");
yield newState;
} else if (event is ModifyResponsesCount) {
var thread = await repository.updateResponsesCount(event.threadId);
Expand Down Expand Up @@ -287,6 +288,7 @@ class MessagesBloc<T extends BaseChannelBloc>
this.repository.items.add(message);
this.add(FinishLoadingMessages());
this.channelsBloc.add(ChangeSelectedChannel(selectedChannel.id));
_updateParentChannel(selectedChannel.id, 0);
},
);
this.repository.items.add(tempItem);
Expand Down Expand Up @@ -341,12 +343,12 @@ class MessagesBloc<T extends BaseChannelBloc>
return map;
}

void _updateParentChannel([String channelId]) {
void _updateParentChannel(String channelId, [int hasUnread = 1]) {
channelsBloc.add(ModifyMessageCount(
workspaceId: ProfileBloc.selectedWorkspace,
channelId: channelId ?? selectedChannel.id,
companyId: ProfileBloc.selectedCompany,
totalModifier: 1,
hasUnread: hasUnread,
));
}

Expand Down
9 changes: 5 additions & 4 deletions lib/blocs/notification_bloc/notification_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class NotificationBloc extends Bloc<NotificationEvent, NotificationState> {
.setTransports(['websocket']).build(),
);
_authSubscription = authBloc.listen((state) {
if (state is Unauthenticated) {
if (state is Unauthenticated || state is HostReset) {
for (String room in subscriptionRooms.keys) {
unsubscribe(room);
}
Expand Down Expand Up @@ -129,7 +129,7 @@ class NotificationBloc extends Bloc<NotificationEvent, NotificationState> {
handleSocketEvent(data);
});
socket.on(SocketIOEvent.RESOURCE, (data) {
// logger.d('GOT RESOURCE: $data');
logger.d('GOT RESOURCE: $data');
handleSocketResource(data);
});
socket.on(SocketIOEvent.JOIN_ERROR, (data) {
Expand Down Expand Up @@ -361,8 +361,9 @@ class NotificationBloc extends Bloc<NotificationEvent, NotificationState> {
return SocketResourceType.Unknown;
final type = subscriptionRooms[resource['room']]['type'];
if (type == 'CHANNELS_LIST') {
if (resource['type'] == 'channel') {
if (resource['action'] == 'saved') {
if (resource['type'] == 'channel' ||
resource['type'] == 'channel_activity') {
if (resource['action'] == 'saved' || resource['action'] == 'updated') {
return SocketResourceType.ChannelUpdate;
} else if (resource['action'] == 'deleted')
return SocketResourceType.ChannelDelete;
Expand Down
6 changes: 4 additions & 2 deletions lib/blocs/threads_bloc/threads_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ class ThreadsBloc<T extends BaseChannelBloc>
channelId: event.channelId,
threadId: message.threadId,
));
_updateParentChannel(event.channelId, 0);
},
);
this.repository.items.add(tempItem);
Expand Down Expand Up @@ -247,12 +248,13 @@ class ThreadsBloc<T extends BaseChannelBloc>
parentChannel: parentChannel,
);

void _updateParentChannel(String channelId, {int totalModifier: 1}) {
void _updateParentChannel(String channelId, [int hasUnread = 1]) {
print("HAS UNREAD: $hasUnread");
messagesBloc.channelsBloc.add(ModifyMessageCount(
channelId: channelId,
workspaceId: T == DirectsBloc ? "direct" : ProfileBloc.selectedWorkspace,
companyId: ProfileBloc.selectedCompany,
totalModifier: totalModifier,
hasUnread: hasUnread,
));
}
}
5 changes: 4 additions & 1 deletion lib/config/styles_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ class StylesConfig {
color: Colors.transparent,
),
// fontFamily: 'PT',
primaryColorBrightness: SchedulerBinding.instance?.window?.platformBrightness ?? Brightness.light,
primaryColorBrightness:
SchedulerBinding.instance?.window?.platformBrightness ??
Brightness.light,
);

static final TextTheme lightTextTheme = TextTheme(
Expand Down Expand Up @@ -75,6 +77,7 @@ class StylesConfig {
static final TextStyle _subtitle2 = TextStyle(
color: subTitleTextColor,
fontSize: Dim.tm2(decimal: -.5),
fontWeight: FontWeight.w400,
);

static final TextStyle _button = TextStyle(
Expand Down
5 changes: 3 additions & 2 deletions lib/models/base_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ abstract class BaseChannel extends CollectionItem {
@JsonKey(name: 'last_activity', defaultValue: 0)
int lastActivity;

@JsonKey(name: 'last_message')
Map<String, dynamic> lastMessage;

@JsonKey(name: 'user_last_access', defaultValue: 0)
int lastAccess;

// @JsonKey(required: true, name: 'messages_total', defaultValue: 0)
// int messagesTotal;
@JsonKey(
name: 'has_unread',
// defaultValue: 0,
Expand Down
8 changes: 7 additions & 1 deletion lib/models/channel.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:convert';
import 'package:json_annotation/json_annotation.dart';
import 'package:twake/models/base_channel.dart';

Expand All @@ -16,10 +17,15 @@ class Channel extends BaseChannel {
});

factory Channel.fromJson(Map<String, dynamic> json) {
if (json['last_message'] is String) {
json['last_message'] = jsonDecode(json['last_message']);
}
return _$ChannelFromJson(json);
}

Map<String, dynamic> toJson() {
return _$ChannelToJson(this);
var map = _$ChannelToJson(this);
map['last_message'] = jsonEncode(map['last_message']);
return map;
}
}
2 changes: 2 additions & 0 deletions lib/models/channel.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions lib/models/direct.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@ class Direct extends BaseChannel {
if (json['members'] is String) {
json['members'] = jsonDecode(json['members']);
}
if (json['last_message'] is String) {
json['last_message'] = jsonDecode(json['last_message']);
}
return _$DirectFromJson(json);
}

Map<String, dynamic> toJson() {
var map = _$DirectToJson(this);
map['members'] = jsonEncode(map['members']);
map['last_message'] = jsonEncode(map['last_message']);
return map;
}
}
Loading

0 comments on commit 1e7d93a

Please sign in to comment.