Chat Tune Added

merge-requests/91/head
Aamir Muhammad 3 years ago
parent e94a8d9a5e
commit 7f043e6048

Binary file not shown.

@ -5,6 +5,7 @@ import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:http/http.dart';
import 'package:just_audio/just_audio.dart';
import 'package:mohem_flutter_app/api/chat/chat_api_client.dart';
import 'package:mohem_flutter_app/app_state/app_state.dart';
import 'package:mohem_flutter_app/classes/consts.dart';
@ -53,6 +54,8 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
Future<void> buildHubConnection() async {
chatHubConnection = await getHubConnection();
await chatHubConnection.start();
print("Startedddddddd");
chatHubConnection.on("OnDeliveredChatUserAsync", onMsgReceived);
}
Future<HubConnection> getHubConnection() async {
@ -74,7 +77,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
void registerEvents() {
chatHubConnection.on("OnUpdateUserStatusAsync", changeStatus);
chatHubConnection.on("OnDeliveredChatUserAsync", onMsgReceived);
// chatHubConnection.on("OnDeliveredChatUserAsync", onMsgReceived);
// hubConnection.on("OnSeenChatUserAsync", onChatSeen);
//hubConnection.on("OnUserTypingAsync", onUserTyping);
chatHubConnection.on("OnUserCountAsync", userCountAsync);
@ -134,6 +137,13 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
if (isNewChat) userChatHistory = [];
if (!loadMore) paginationVal = 0;
isChatScreenActive = true;
// if (chatHubConnection.state != HubConnectionState.Connected) {
// getUserAutoLoginToken().whenComplete(() async {
// await buildHubConnection();
// getSingleUserChatHistory(senderUID: senderUID, receiverUID: receiverUID, loadMore: loadMore);
// });
// return;
// }
Response response = await ChatApiClient().getSingleUserChatHistory(senderUID: senderUID, receiverUID: receiverUID, loadMore: loadMore, paginationVal: paginationVal);
if (response.statusCode == 204) {
if (isNewChat) {
@ -335,13 +345,13 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
}
}
}
setMsgTune();
userChatHistory.insert(0, data.first);
if (searchedChats != null && !isChatScreenActive) {
for (ChatUser user in searchedChats!) {
if (user.id == data.first.currentUserId) {
var tempCount = user.unreadMessageCount ?? 0;
int tempCount = user.unreadMessageCount ?? 0;
user.unreadMessageCount = tempCount + 1;
}
}
@ -351,6 +361,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
{"userChatHistoryId": data.first.userChatHistoryId, "TargetUserId": temp.first.targetUserId, "isDelivered": true, "isSeen": isChatScreenActive ? true : false}
];
updateUserChatHistoryOnMsg(list);
notifyListeners();
}
@ -731,6 +742,26 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
notifyListeners();
}
void setMsgTune() async {
AudioPlayer player = AudioPlayer();
await player.setVolume(1.0);
String audioAsset = "";
if (Platform.isAndroid) {
audioAsset = "assets/audio/pulse_tone_android.mp3";
} else {
audioAsset = "assets/audio/pulse_tune_ios.caf";
}
try {
await player.setAsset(audioAsset);
await player.load();
player.play();
} catch (e) {
print("Error: $e");
}
}
Future<void> playSuccessSound() async {}
///getUserAutoLoginToken().whenComplete(() {
// buildHubConnection();
// print("After Reconnect State: " + hubConnection.state.toString());

Loading…
Cancel
Save