Skip to content

Commit

Permalink
Merge pull request #265 from bobs4462/main
Browse files Browse the repository at this point in the history
Bug fixes and new workspace creation features
  • Loading branch information
bmuddha authored Feb 8, 2021
2 parents d10ce01 + dc23538 commit 4aa9037
Show file tree
Hide file tree
Showing 63 changed files with 1,595 additions and 342 deletions.
15 changes: 13 additions & 2 deletions lib/blocs/add_channel_bloc/add_channel_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'dart:async';
import 'package:meta/meta.dart';

import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:twake/services/init.dart';
import 'package:twake/repositories/add_channel_repository.dart';

part 'add_channel_event.dart';
Expand Down Expand Up @@ -42,7 +42,6 @@ class AddChannelBloc extends Bloc<AddChannelEvent, AddChannelState> {
);

yield Updated(newRepo);

} else if (event is Create) {
yield Creation();
final type = repository.type;
Expand All @@ -57,6 +56,18 @@ class AddChannelBloc extends Bloc<AddChannelEvent, AddChannelState> {
repository.clear();
} else if (event is SetFlowType) {
yield FlowTypeSet(event.isDirect);
} else if (event is UpdateMembers) {
final channelId = event.channelId;
final members = event.members;
final result = await repository.updateMembers(
members: members,
channelId: channelId,
);
if (result) {
yield MembersUpdated(channelId: channelId, members: members);
} else {
yield Error('Members update failure!');
}
}
}
}
23 changes: 13 additions & 10 deletions lib/blocs/add_channel_bloc/add_channel_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@ abstract class AddChannelEvent extends Equatable {
const AddChannelEvent();
}

class LoadFromCache extends AddChannelEvent {
@override
List<Object> get props => [];
}

class Cache extends AddChannelEvent {
@override
List<Object> get props => [];
}

class Clear extends AddChannelEvent {
@override
List<Object> get props => [];
Expand Down Expand Up @@ -69,3 +59,16 @@ class SetFlowStage extends AddChannelEvent {
@override
List<Object> get props => [stage];
}

class UpdateMembers extends AddChannelEvent {
final String channelId;
final List<String> members;

UpdateMembers({
@required this.channelId,
@required this.members,
});

@override
List<Object> get props => [channelId, members];
}
37 changes: 13 additions & 24 deletions lib/blocs/add_channel_bloc/add_channel_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,6 @@ class AddChannelInitial extends AddChannelState {
List<Object> get props => [];
}

class AddChannelLoading extends AddChannelState {
@override
List<Object> get props => [];
}

class AddChannelLoaded extends AddChannelState {
final InitData initData;

AddChannelLoaded(this.initData);

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

class AddChannelCaching extends AddChannelState {
@override
List<Object> get props => [];
}

class AddChannelCached extends AddChannelState {
@override
List<Object> get props => [];
}

class Updated extends AddChannelState {
final AddChannelRepository repository;

Expand Down Expand Up @@ -83,3 +59,16 @@ class StageUpdated extends AddChannelState {
@override
List<Object> get props => [stage];
}

class MembersUpdated extends AddChannelState {
final String channelId;
final List<String> members;

MembersUpdated({
@required this.channelId,
@required this.members,
});

@override
List<Object> get props => [channelId, members];
}
53 changes: 53 additions & 0 deletions lib/blocs/add_workspace_cubit/add_workspace_cubit.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import 'package:bloc/bloc.dart';
import 'package:meta/meta.dart';
import 'package:twake/repositories/add_workspace_repository.dart';
import 'add_workspace_state.dart';

class AddWorkspaceCubit extends Cubit<AddWorkspaceState> {
final AddWorkspaceRepository repository;

AddWorkspaceCubit(this.repository) : super(AddWorkspaceInitial());

void create() async {
final result = await repository.create();
if (result.isNotEmpty) {
emit(Created(result));
} else {
emit(Error('Workspace creation failure!'));
}
}

// void updateMembers({
// @required String workspaceId,
// @required List<String> members,
// }) async {
// final result = await repository.updateMembers(
// members: members,
// workspaceId: workspaceId,
// );
// if (result) {
// emit(MembersUpdated(workspaceId: workspaceId, members: members));
// } else {
// emit(Error('Members update failure!'));
// }
// }

void clear() {
repository.clear();
}

void update({String name, List<String> members}) {
repository.name = name ?? repository.name;
repository.members = members ?? repository.members ?? [];

var newRepo = AddWorkspaceRepository(
name: repository.name,
members: repository.members,
);
emit(Updated(newRepo));
}

void setFlowStage(FlowStage stage) {
emit(StageUpdated(stage));
}
}
66 changes: 66 additions & 0 deletions lib/blocs/add_workspace_cubit/add_workspace_state.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import 'package:meta/meta.dart';
import 'package:equatable/equatable.dart';
import 'package:twake/repositories/add_workspace_repository.dart';

abstract class AddWorkspaceState extends Equatable {
const AddWorkspaceState();
}

class AddWorkspaceInitial extends AddWorkspaceState {
@override
List<Object> get props => [];
}

class Updated extends AddWorkspaceState {
final AddWorkspaceRepository repository;

Updated(this.repository);

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

class Creation extends AddWorkspaceState {
@override
List<Object> get props => [];
}

class Created extends AddWorkspaceState {
final String workspaceId;

Created(this.workspaceId);

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

class Error extends AddWorkspaceState {
final String message;

Error(this.message);

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

class StageUpdated extends AddWorkspaceState {
final FlowStage stage;

StageUpdated(this.stage);

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

class MembersUpdated extends AddWorkspaceState {
final String workspaceId;
final List<String> members;

MembersUpdated({
@required this.workspaceId,
@required this.members,
});

@override
List<Object> get props => [workspaceId, members];
}
5 changes: 2 additions & 3 deletions lib/blocs/auth_bloc/auth_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
print('CURRENT PAGE ${await webView.webViewController.getUrl()}');
final js =
'''!function(l,p){function f(){document.getElementById("userfield").value=l,document.getElementById("passwordfield").value=p,document.getElementById("lform").submit()}"complete"===document.readyState||"interactive"===document.readyState?setTimeout(f,1):document.addEventListener("DOMContentLoaded",f)}("${event.username}","${event.password.replaceAll('"', '\\"')}");''';
print('JS: $js');
// print('JS: $js');
await webView.webViewController.evaluateJavascript(source: js);
} else if (event is SetAuthData) {
print('AUTH DATA ${event.authData}');
Expand Down Expand Up @@ -141,8 +141,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {

Future<void> runWebView() async {
await CookieManager.instance().deleteAllCookies();
final c = await CookieManager.instance().getCookies(url: 'auth.twake.app');
print('COOKIES: $c');
await CookieManager.instance().getCookies(url: 'auth.twake.app');
_prevUrl = '';
await webView.dispose();
webView.run();
Expand Down
15 changes: 14 additions & 1 deletion lib/blocs/base_channel_bloc/base_channel_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,25 @@ abstract class BaseChannelBloc extends Bloc<ChannelsEvent, ChannelState> {
Future<void> updateMessageCount(ModifyMessageCount event) async {
final ch = await repository.getItemById(event.channelId);
if (ch != null) {
ch.messagesTotal += event.totalModifier ?? 0;
// ch.messagesTotal += event.totalModifier ?? 0;
ch.hasUnread = 1;
ch.messagesUnread += event.unreadModifier ?? 0;
ch.lastActivity =
event.timeStamp ?? DateTime.now().millisecondsSinceEpoch;
repository.saveOne(ch);
} else
return;
}

Future<void> updateChannelState(ModifyChannelState event) async {
final ch = await repository.getItemById(event.channelId);
if (ch != null) {
ch.hasUnread = 1;
if (event.threadId != null || event.messageId != null) {
ch.messagesUnread += 1;
}
repository.saveOne(ch);
} else
return;
}
}
19 changes: 19 additions & 0 deletions lib/blocs/channels_bloc/channel_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,25 @@ class ModifyMessageCount extends ChannelsEvent {
List<Object> get props => [channelId];
}

class ModifyChannelState extends ChannelsEvent {
final String channelId;
final String workspaceId;
final String companyId;
final String threadId;
final String messageId;

ModifyChannelState({
this.channelId,
this.workspaceId,
this.companyId,
this.threadId,
this.messageId,
});

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

class RemoveChannel extends ChannelsEvent {
final String channelId;
RemoveChannel(this.channelId);
Expand Down
10 changes: 7 additions & 3 deletions lib/blocs/channels_bloc/channel_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ class ChannelsLoaded extends ChannelState {

class ChannelPicked extends ChannelsLoaded {
final BaseChannel selected;
const ChannelPicked({List<BaseChannel> channels, this.selected})
: super(channels: channels);
final int hasUnread;
const ChannelPicked({
List<BaseChannel> channels,
this.selected,
this.hasUnread: 0,
}) : super(channels: channels);

@override
List<Object> get props => [selected.id];
List<Object> get props => [selected.id, hasUnread];
}

class ChannelsLoading extends ChannelState {
Expand Down
20 changes: 19 additions & 1 deletion lib/blocs/channels_bloc/channels_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,23 @@ class ChannelsBloc extends BaseChannelBloc {
});
_notificationSubscription =
notificationBloc.listen((NotificationState state) {
if (state is BaseChannelMessageNotification) {
if (state is ChannelMessageNotification) {
this.add(ModifyMessageCount(
channelId: state.data.channelId,
workspaceId: state.data.workspaceId,
totalModifier: 1,
unreadModifier: 1,
));
} else if (state is ChannnelUpdateNotification) {
this.add(
ModifyChannelState(
channelId: state.data.channelId,
workspaceId: state.data.workspaceId,
companyId: state.data.companyId,
threadId: state.data.threadId,
messageId: state.data.messageId,
),
);
}
});
selectedParentId = workspacesBloc.repository.selected.id;
Expand Down Expand Up @@ -79,10 +89,12 @@ class ChannelsBloc extends BaseChannelBloc {
repository.select(event.channelId, saveToStore: false);

repository.selected.messagesUnread = 0;
repository.selected.hasUnread = 0;
repository.saveOne(repository.selected);
final newState = ChannelPicked(
channels: repository.items,
selected: repository.selected,
hasUnread: repository.selected.hasUnread,
);
yield newState;
} else if (event is ModifyMessageCount) {
Expand All @@ -103,6 +115,12 @@ class ChannelsBloc extends BaseChannelBloc {
// channels: repository.items,
// selected: selected,
// );
} else if (event is ModifyChannelState) {
await updateChannelState(event);
yield ChannelsLoaded(
channels: repository.items,
force: DateTime.now().toString(),
);
}
}

Expand Down
Loading

0 comments on commit 4aa9037

Please sign in to comment.