Chat Favorite Screen & Fixes

merge-requests/55/head
Aamir Muhammad 3 years ago
parent ca4c9584b9
commit 5412dcaf35

@ -60,8 +60,6 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
"${ApiConsts.chatServerBaseApiUrl}${ApiConsts.chatRecentUrl}", "${ApiConsts.chatServerBaseApiUrl}${ApiConsts.chatRecentUrl}",
token: AppState().chatDetails!.response!.token, token: AppState().chatDetails!.response!.token,
); );
//logger.d(AppState().chatDetails!.response!.token);
ChatUserModel recentChat = userToList(response.body); ChatUserModel recentChat = userToList(response.body);
Response favRes = await ApiClient().getJsonForResponse( Response favRes = await ApiClient().getJsonForResponse(
@ -71,6 +69,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
ChatUserModel favUList = userToList(favRes.body); ChatUserModel favUList = userToList(favRes.body);
if (favUList.response != null) { if (favUList.response != null) {
favUsersList = favUList.response!; favUsersList = favUList.response!;
favUsersList.sort((ChatUser a, ChatUser b) => a.userName!.toLowerCase().compareTo(b.userName!.toLowerCase()));
for (dynamic user in recentChat.response!) { for (dynamic user in recentChat.response!) {
for (dynamic favUser in favUList.response!) { for (dynamic favUser in favUList.response!) {
if (user.id == favUser.id) { if (user.id == favUser.id) {
@ -80,7 +79,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
} }
} }
pChatHistory = recentChat.response; pChatHistory = recentChat.response;
pChatHistory!.sort((ChatUser a, ChatUser b) => a.userName!.toLowerCase()!.compareTo(b.userName!.toLowerCase()!)); pChatHistory!.sort((ChatUser a, ChatUser b) => a.userName!.toLowerCase().compareTo(b.userName!.toLowerCase()));
searchedChats = pChatHistory; searchedChats = pChatHistory;
isLoading = false; isLoading = false;
notifyListeners(); notifyListeners();
@ -94,8 +93,6 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
"${ApiConsts.chatServerBaseApiUrl}${ApiConsts.chatSingleUserHistoryUrl}/$senderUID/$receiverUID/$paginationVal", "${ApiConsts.chatServerBaseApiUrl}${ApiConsts.chatSingleUserHistoryUrl}/$senderUID/$receiverUID/$paginationVal",
token: AppState().chatDetails!.response!.token, token: AppState().chatDetails!.response!.token,
); );
logger.d(response.body);
if (response.statusCode == 204) { if (response.statusCode == 204) {
if (!loadMore) userChatHistory = []; if (!loadMore) userChatHistory = [];
Utils.showToast("No More Data To Load"); Utils.showToast("No More Data To Load");
@ -134,7 +131,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
Future<void> buildHubConnection() async { Future<void> buildHubConnection() async {
HttpConnectionOptions httpOp = HttpConnectionOptions(skipNegotiation: false, logMessageContent: true); HttpConnectionOptions httpOp = HttpConnectionOptions(skipNegotiation: false, logMessageContent: true);
hubConnection = await HubConnectionBuilder() hubConnection = HubConnectionBuilder()
.withUrl(ApiConsts.chatHubConnectionUrl + "?UserId=${AppState().chatDetails!.response!.id}&source=Web&access_token=${AppState().chatDetails!.response!.token}", options: httpOp) .withUrl(ApiConsts.chatHubConnectionUrl + "?UserId=${AppState().chatDetails!.response!.id}&source=Web&access_token=${AppState().chatDetails!.response!.token}", options: httpOp)
.withAutomaticReconnect(retryDelays: [2000, 5000, 10000, 20000]) .withAutomaticReconnect(retryDelays: [2000, 5000, 10000, 20000])
.configureLogging( .configureLogging(
@ -162,8 +159,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
hubConnection.on("OnGetUserChatHistoryNotDeliveredAsync", chatNotDelivered); hubConnection.on("OnGetUserChatHistoryNotDeliveredAsync", chatNotDelivered);
hubConnection.on("OnUpdateUserChatHistoryStatusAsync", updateUserChatStatus); hubConnection.on("OnUpdateUserChatHistoryStatusAsync", updateUserChatStatus);
} }
isLoading = false; // notifyListeners();
notifyListeners();
} }
void updateUserChatStatus(List<Object?>? args) { void updateUserChatStatus(List<Object?>? args) {
@ -171,7 +167,6 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
for (dynamic cItem in items[0]) { for (dynamic cItem in items[0]) {
for (SingleUserChatModel chat in userChatHistory) { for (SingleUserChatModel chat in userChatHistory) {
if (chat.userChatHistoryId.toString() == cItem["userChatHistoryId"].toString()) { if (chat.userChatHistoryId.toString() == cItem["userChatHistoryId"].toString()) {
logger.d(jsonEncode(chat));
chat.isSeen = cItem["isSeen"]; chat.isSeen = cItem["isSeen"];
chat.isDelivered = cItem["isDelivered"]; chat.isDelivered = cItem["isDelivered"];
notifyListeners(); notifyListeners();
@ -182,7 +177,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
void userCountAsync(List<Object?>? args) { void userCountAsync(List<Object?>? args) {
List items = args!.toList(); List items = args!.toList();
//print("---------------------------------User Count Async -------------------------------------"); //logger.d("---------------------------------User Count Async -------------------------------------");
//logger.d(items); //logger.d(items);
// for (var user in searchedChats!) { // for (var user in searchedChats!) {
// if (user.id == items.first["id"]) { // if (user.id == items.first["id"]) {
@ -256,13 +251,12 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
} }
userChatHistory.add(data.first); userChatHistory.add(data.first);
notifyListeners(); notifyListeners();
logger.d(isChatScreenActive);
// if (isChatScreenActive) scrollDown(); // if (isChatScreenActive) scrollDown();
} }
void onUserTyping(List<Object?>? parameters) { void onUserTyping(List<Object?>? parameters) {
print("==================== Typing Active =================="); // print("==================== Typing Active ==================");
logger.d(parameters); // logger.d(parameters);
for (ChatUser user in searchedChats!) { for (ChatUser user in searchedChats!) {
if (user.id == parameters![1] && parameters[0] == true) { if (user.id == parameters![1] && parameters[0] == true) {
user.isTyping = parameters[0] as bool?; user.isTyping = parameters[0] as bool?;

@ -1,8 +1,5 @@
import 'dart:async'; import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:easy_localization/easy_localization.dart'; import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart'; import 'package:flutter_svg/flutter_svg.dart';
import 'package:mohem_flutter_app/api/chat/chat_provider_model.dart'; import 'package:mohem_flutter_app/api/chat/chat_provider_model.dart';
@ -23,14 +20,14 @@ class ChatDetailScreen extends StatelessWidget {
dynamic userDetails; dynamic userDetails;
late ChatProviderModel data; late ChatProviderModel data;
ScrollController scrollController = ScrollController(); ScrollController scrollController = ScrollController();
RefreshController _refreshController = RefreshController(initialRefresh: false); final RefreshController _refreshController = RefreshController(initialRefresh: false);
void getMoreChat() async { void getMoreChat() async {
if (userDetails != null) { if (userDetails != null) {
data.paginationVal = data.paginationVal + 10; data.paginationVal = data.paginationVal + 10;
data.getSingleUserChatHistory(senderUID: AppState().chatDetails!.response!.id.toString(), receiverUID: userDetails["targetUser"].id, loadMore: true); data.getSingleUserChatHistory(senderUID: AppState().chatDetails!.response!.id.toString(), receiverUID: userDetails["targetUser"].id, loadMore: true);
} }
await Future.delayed(Duration(milliseconds: 1000)); await Future.delayed(const Duration(milliseconds: 1000));
_refreshController.refreshCompleted(); _refreshController.refreshCompleted();
} }
@ -61,6 +58,7 @@ class ChatDetailScreen extends StatelessWidget {
child: ListView.builder( child: ListView.builder(
controller: scrollController, controller: scrollController,
shrinkWrap: true, shrinkWrap: true,
reverse: false,
itemCount: m.userChatHistory.length, itemCount: m.userChatHistory.length,
padding: const EdgeInsets.only(top: 20), padding: const EdgeInsets.only(top: 20),
itemBuilder: (BuildContext context, int i) { itemBuilder: (BuildContext context, int i) {
@ -137,10 +135,11 @@ class ChatDetailScreen extends StatelessWidget {
height: 200, height: 200,
decoration: BoxDecoration( decoration: BoxDecoration(
image: DecorationImage( image: DecorationImage(
image: FileImage( image: FileImage(
m.selectedFile, m.selectedFile,
), ),
fit: BoxFit.cover), fit: BoxFit.cover,
),
borderRadius: const BorderRadius.all( borderRadius: const BorderRadius.all(
Radius.circular(0), Radius.circular(0),
), ),

Loading…
Cancel
Save