Skip to content

Commit

Permalink
Merge pull request #27 from LiveHelperChat/master-1.5
Browse files Browse the repository at this point in the history
Closed chats tab
  • Loading branch information
remdex authored Dec 28, 2020
2 parents 185c4f8 + c45548a commit 1f39402
Show file tree
Hide file tree
Showing 65 changed files with 229 additions and 49 deletions.
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ android {
applicationId "com.livehelperchat.chat"
minSdkVersion 16
targetSdkVersion 29
versionCode 33
versionName "1.4"
versionCode 34
versionName "1.5"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

Expand Down
Empty file modified lib/bloc/bloc.dart
100644 → 100755
Empty file.
Empty file modified lib/bloc/chatmessages/chat_messages_bloc.dart
100644 → 100755
Empty file.
Empty file modified lib/bloc/chatmessages/chat_messages_event.dart
100644 → 100755
Empty file.
Empty file modified lib/bloc/chatmessages/chat_messages_state.dart
100644 → 100755
Empty file.
34 changes: 28 additions & 6 deletions lib/bloc/chats_list/chatslist_bloc.dart
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class ChatslistBloc extends Bloc<ChatslistEvent, ChatListState> {
activeChatList: server.activeChatList,
pendingChatList: server.pendingChatList,
transferChatList: server.transferChatList,
twilioChatList: server.twilioChatList);
twilioChatList: server.twilioChatList,
closedChatList: server.closedChatList);
} catch (ex) {
yield ChatListLoadError(message: "${ex?.message}");
}
Expand All @@ -70,22 +71,30 @@ class ChatslistBloc extends Bloc<ChatslistEvent, ChatListState> {
List<Chat> pendingChats = List.from(currentState.pendingChatList);
List<Chat> transferChats = List.from(currentState.transferChatList);
List<Chat> twilioChats = List.from(currentState.twilioChatList);
List<Chat> closedChats = List.from(currentState.closedChatList);

List<Chat> activeList =
await _cleanList(ChatListName.active, server, activeChats);

List<Chat> closedList =
await _cleanList(ChatListName.closed, server, closedChats);

List<Chat> pendingList =
await _cleanList(ChatListName.pending, server, pendingChats);

List<Chat> transferList =
await _cleanList(ChatListName.transfer, server, transferChats);

List<Chat> twilioList =
await _cleanList(ChatListName.twilio, server, twilioChats);

yield ChatListLoaded(
activeChatList: _sortByLastMessageTime(activeList),
pendingChatList: pendingList,
transferChatList: transferList,
twilioChatList: twilioList);
twilioChatList: _sortByLastMessageTime(twilioList),
closedChatList: _sortById(closedList)
);
}
} on Exception {
yield ChatListLoadError(message: "Chat list could not be loaded");
Expand All @@ -103,10 +112,6 @@ class ChatslistBloc extends Bloc<ChatslistEvent, ChatListState> {
await Future.forEach(listServers, (Server server) async {
if (server.isLoggedIn) {
var srvr = await serverRepository.fetchChatList(server);

if (server.twilioInstalled == true) {
//srvr = await serverRepository.getTwilioChats(srvr);
}
serverList.add(srvr);
}
});
Expand Down Expand Up @@ -138,6 +143,18 @@ class ChatslistBloc extends Bloc<ChatslistEvent, ChatListState> {
await _updateChatList(listToClean, server.pendingChatList);
}
return listToClean;

case ChatListName.closed:
if (server.closedChatList.length == 0) {
if (listToClean.length > 0) {
listToClean.removeWhere((chat) => chat.serverid == server.id);
}
} else {
listToClean =
await _updateChatList(listToClean, server.closedChatList);
}
return listToClean;

case ChatListName.transfer:
if (server.transferChatList.length == 0) {
if (listToClean.length > 0) {
Expand Down Expand Up @@ -184,6 +201,11 @@ class ChatslistBloc extends Bloc<ChatslistEvent, ChatListState> {
return listToSort;
}

List<Chat> _sortById(List<Chat> listToSort) {
listToSort.sort((a, b) => a.id.compareTo(b.id));
return listToSort;
}

/*Remove chats which have been closed from another device */
Future<List<Chat>> _removeMissingChatFromList(
List<Chat> chatToClean, List<Chat> listToCompare) async {
Expand Down
Empty file modified lib/bloc/chats_list/chatslist_event.dart
100644 → 100755
Empty file.
7 changes: 6 additions & 1 deletion lib/bloc/chats_list/chatslist_state.dart
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
part of 'chatslist_bloc.dart';

enum ChatListName { active, pending, transfer, twilio }
enum ChatListName { active, pending, transfer, twilio, closed }

abstract class ChatListState extends Equatable {
ChatListState();
Expand All @@ -25,26 +25,30 @@ class ChatListLoaded extends ChatListState {
final List<Chat> pendingChatList;
final List<Chat> transferChatList;
final List<Chat> twilioChatList;
final List<Chat> closedChatList;
final bool isLoading;

ChatListLoaded(
{this.activeChatList = const [],
this.pendingChatList = const [],
this.transferChatList = const [],
this.twilioChatList = const [],
this.closedChatList = const [],
this.isLoading = false});

ChatListLoaded copyWith(
{List<Chat> activeChatList,
List<Chat> pendingChatList,
List<Chat> transferChatList,
List<Chat> twilioChatList,
List<Chat> closedChatList,
bool isLoading = false}) {
return ChatListLoaded(
activeChatList: activeChatList ?? this.activeChatList,
pendingChatList: pendingChatList ?? this.pendingChatList,
transferChatList: transferChatList ?? this.transferChatList,
twilioChatList: twilioChatList ?? this.twilioChatList,
closedChatList: closedChatList ?? this.closedChatList,
isLoading: isLoading ?? this.isLoading);
}

Expand All @@ -54,6 +58,7 @@ class ChatListLoaded extends ChatListState {
pendingChatList,
transferChatList,
twilioChatList,
closedChatList,
isLoading
];
}
Empty file modified lib/bloc/fcm/fcmtoken_bloc.dart
100644 → 100755
Empty file.
Empty file modified lib/bloc/fcm/fcmtoken_event.dart
100644 → 100755
Empty file.
Empty file modified lib/bloc/fcm/fcmtoken_state.dart
100644 → 100755
Empty file.
Empty file modified lib/bloc/login_form/loginform_bloc.dart
100644 → 100755
Empty file.
Empty file modified lib/bloc/login_form/loginform_event.dart
100644 → 100755
Empty file.
Empty file modified lib/bloc/login_form/loginform_state.dart
100644 → 100755
Empty file.
Empty file modified lib/bloc/server/server_bloc.dart
100644 → 100755
Empty file.
Empty file modified lib/bloc/server/server_event.dart
100644 → 100755
Empty file.
Empty file modified lib/bloc/server/server_state.dart
100644 → 100755
Empty file.
Empty file modified lib/bloc/simple_bloc_observer.dart
100644 → 100755
Empty file.
Empty file modified lib/bloc/twilio_bloc.dart
100644 → 100755
Empty file.
Empty file modified lib/bloc/twilio_event.dart
100644 → 100755
Empty file.
Empty file modified lib/bloc/twilio_state.dart
100644 → 100755
Empty file.
Empty file modified lib/data/database.dart
100644 → 100755
Empty file.
Empty file modified lib/generated/i18n.dart
100644 → 100755
Empty file.
Empty file modified lib/globals.dart
100644 → 100755
Empty file.
Empty file modified lib/main.dart
100644 → 100755
Empty file.
Empty file modified lib/model/chat.dart
100644 → 100755
Empty file.
Empty file modified lib/model/department.dart
100644 → 100755
Empty file.
Empty file modified lib/model/local_notification.dart
100644 → 100755
Empty file.
Empty file modified lib/model/message.dart
100644 → 100755
Empty file.
Empty file modified lib/model/model.dart
100644 → 100755
Empty file.
Empty file modified lib/model/notification_channel.dart
100644 → 100755
Empty file.
15 changes: 12 additions & 3 deletions lib/model/server.dart
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class Server {
List<Chat> activeChatList;
List<Chat> transferChatList;
List<Chat> twilioChatList;
List<Chat> closedChatList;

Server(
{this.id,
Expand Down Expand Up @@ -97,6 +98,7 @@ class Server {
activeChatList = List<Chat>();
transferChatList = List<Chat>();
twilioChatList = List<Chat>();
closedChatList = List<Chat>();
}

String getUrl() => appendIndexToUrl ? url + "/index.php" : url;
Expand Down Expand Up @@ -156,9 +158,7 @@ class Server {
this.activeChatList ??= new List<Chat>();
this.activeChatList = _cleanUpLists(this.activeChatList, newChatList);
//Sort list by last message time
this
.activeChatList
.sort((a, b) => b.last_msg_time.compareTo(a.last_msg_time));
this.activeChatList.sort((a, b) => b.last_msg_time.compareTo(a.last_msg_time));
break;
case "pending":
this.pendingChatList ??= new List<Chat>();
Expand All @@ -169,9 +169,15 @@ class Server {
this.transferChatList =
_cleanUpLists(this.transferChatList, newChatList);
break;
case "closed":
this.closedChatList ??= new List<Chat>();
this.closedChatList = _cleanUpLists(this.closedChatList, newChatList);
this.closedChatList.sort((a, b) => a.id.compareTo(b.id));
break;
case "twilio":
this.twilioChatList ??= new List<Chat>();
this.twilioChatList = _cleanUpLists(this.twilioChatList, newChatList);
this.twilioChatList.sort((a, b) => b.last_msg_time.compareTo(a.last_msg_time));
break;
}
}
Expand Down Expand Up @@ -223,6 +229,9 @@ class Server {
case 'transfer':
this.transferChatList?.clear();
break;
case 'closed':
this.closedChatList?.clear();
break;
case 'twilio':
this.twilioChatList?.clear();
break;
Expand Down
Empty file modified lib/model/twilio_phone.dart
100644 → 100755
Empty file.
Empty file modified lib/model/user.dart
100644 → 100755
Empty file.
Empty file modified lib/pages/chat/chat_page.dart
100644 → 100755
Empty file.
Empty file modified lib/pages/chat/twilio_sms_chat.dart
100644 → 100755
Empty file.
Empty file modified lib/pages/config/department_hours.dart
100644 → 100755
Empty file.
Empty file modified lib/pages/config/server_settings.dart
100644 → 100755
Empty file.
Empty file modified lib/pages/lists/chat_list_active.dart
100644 → 100755
Empty file.
126 changes: 126 additions & 0 deletions lib/pages/lists/chat_list_closed.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:livehelp/bloc/bloc.dart';

import 'package:livehelp/model/model.dart';
import 'package:livehelp/widget/widget.dart';
import 'package:livehelp/utils/utils.dart';

import 'package:livehelp/utils/routes.dart' as LHCRouter;

class ClosedListWidget extends StatefulWidget {
ClosedListWidget(
{Key key,
this.listOfServers,
@required this.callBackDeleteChat,
this.refreshList})
: super(key: key);

final List<Server> listOfServers;
final Function(Server, Chat) callBackDeleteChat;

final VoidCallback refreshList;

@override
_ClosedListWidgetState createState() => new _ClosedListWidgetState();
}

class _ClosedListWidgetState extends State<ClosedListWidget> {
@override
void initState() {
super.initState();
}

@override
Widget build(BuildContext context) {
return BlocBuilder<ChatslistBloc, ChatListState>(builder: (context, state) {
if (state is ChatslistInitial) {
return Center(child: CircularProgressIndicator());
}

if (state is ChatListLoaded) {
if (state.isLoading) {
return Center(
child: CircularProgressIndicator(),
);
} else {
return ListView.builder(
itemCount: state.closedChatList.length,
itemBuilder: (BuildContext context, int index) {
Chat chat = state.closedChatList.reversed.toList()[index];
Server server = widget.listOfServers.firstWhere(
(srvr) => srvr.id == chat.serverid,
orElse: () => null);

return GestureDetector(
child: ChatItemWidget(
server: server,
chat: chat,
menuBuilder: _itemMenuBuilder(),
onMenuSelected: (selectedOption) {
onItemSelected(context, server, chat, selectedOption);
},
),
onTap: () {
final routeArgs = RouteArguments(chatId: chat.id);
final routeSettings = RouteSettings(
name: AppRoutes.chatPage, arguments: routeArgs);
var route = LHCRouter.Router.generateRouteChatPage(
routeSettings, chat, server, false, widget.refreshList);
Navigator.of(context).push(route);
},
);
});
}
}

if (state is ChatListLoadError) {
return ErrorReloadButton(
child: Text("An error occurred: ${state.message}"),
actionText: 'Reload',
onButtonPress: () {
context.bloc<ChatslistBloc>().add(ChatListInitialise());
},
);
}

return ListView.builder(
itemCount: 1,
itemBuilder: (BuildContext context, int index) {
return Text("No list available");
});
});
}

List<PopupMenuEntry<ChatItemMenuOption>> _itemMenuBuilder() {
return <PopupMenuEntry<ChatItemMenuOption>>[
const PopupMenuItem<ChatItemMenuOption>(
value: ChatItemMenuOption.PREVIEW,
child: const Text('Preview'),
),
const PopupMenuItem<ChatItemMenuOption>(
value: ChatItemMenuOption.REJECT,
child: const Text('Delete permanently'),
),
];
}

void onItemSelected(BuildContext ctxt, Server srvr, Chat chat,
ChatItemMenuOption selectedMenu) {
switch (selectedMenu) {
case ChatItemMenuOption.PREVIEW:
final routeArgs = RouteArguments(chatId: chat.id);
final routeSettings =
RouteSettings(name: AppRoutes.chatPage, arguments: routeArgs);
var route = LHCRouter.Router.generateRouteChatPage(
routeSettings, chat, srvr, true, widget.refreshList);
Navigator.of(ctxt).push(route);
break;
case ChatItemMenuOption.REJECT:
widget.callBackDeleteChat(srvr, chat);
break;
default:
break;
}
}
}
Empty file modified lib/pages/lists/chat_list_pending.dart
100644 → 100755
Empty file.
Empty file modified lib/pages/lists/chat_list_transferred.dart
100644 → 100755
Empty file.
Empty file modified lib/pages/lists/chat_list_twilio.dart
100644 → 100755
Empty file.
Empty file modified lib/pages/login_form.dart
100644 → 100755
Empty file.
26 changes: 26 additions & 0 deletions lib/pages/main_page.dart
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class _MainPageState extends State<MainPage>
List<dynamic> activeChatStore = new List();
List<dynamic> pendingChatStore = new List();
List<dynamic> transferChatStore = new List();
List<dynamic> closedChatStore = new List();

Timer _timerChatList;
Server _selectedServer;
Expand Down Expand Up @@ -214,6 +215,23 @@ class _MainPageState extends State<MainPage>
number: "0",
);
}),
),
Tab(
child: BlocBuilder<ChatslistBloc, ChatListState>(
builder: (context, state) {
if (state is ChatListLoaded) {
return ChatNumberIndcator(
title: "Closed",
offstage: state.closedChatList.length == 0,
number: state.closedChatList.length.toString(),
);
}
return ChatNumberIndcator(
title: "Closed",
offstage: true,
number: "0",
);
}),
)
];

Expand Down Expand Up @@ -242,6 +260,14 @@ class _MainPageState extends State<MainPage>
listOfServers: listServers,
refreshList: _loadChatList,
),
ClosedListWidget(
listOfServers: listServers,
refreshList: _loadChatList,
callBackDeleteChat: (server, chat) {
_chatListBloc
.add(DeleteChatMainPage(server: server, chat: chat));
},
),
];

if (state is ServerListFromDBLoaded) {
Expand Down
1 change: 1 addition & 0 deletions lib/pages/pages.dart
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export 'servers_manage.dart';
export 'lists/chat_list_active.dart';
export 'lists/chat_list_pending.dart';
export 'lists/chat_list_transferred.dart';
export 'lists/chat_list_closed.dart';
Empty file modified lib/pages/servers_manage.dart
100644 → 100755
Empty file.
Empty file modified lib/pages/token_inherited_widget.dart
100644 → 100755
Empty file.
Loading

0 comments on commit 1f39402

Please sign in to comment.