From 816840591d1e0b32df94945662218927a5b8078a Mon Sep 17 00:00:00 2001 From: fahadsaleem Date: Wed, 13 Dec 2023 17:43:27 +0500 Subject: [PATCH] issue/PresenceType Enum --- example/lib/main.dart | 7 ++- ios/xmpp_plugin.podspec | 2 +- lib/ennums/typing_status.dart | 8 +-- lib/message_event.dart | 10 ++-- lib/xmpp_plugin.dart | 100 +++++++++++++++++++++++----------- pubspec.yaml | 2 +- 6 files changed, 80 insertions(+), 49 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index b2f269b..4a3ee55 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,7 +1,6 @@ import 'dart:async'; import 'dart:developer'; import 'dart:io'; -import 'package:share_plus/share_plus.dart'; import 'package:flutter/material.dart'; import 'package:flutter_xmpp_example/constants.dart'; @@ -9,6 +8,7 @@ import 'package:flutter_xmpp_example/homepage.dart'; import 'package:flutter_xmpp_example/native_log_helper.dart'; import 'package:flutter_xmpp_example/utils.dart'; import 'package:permission_handler/permission_handler.dart'; +import 'package:share_plus/share_plus.dart'; import 'package:xmpp_plugin/custom_element.dart'; import 'package:xmpp_plugin/ennums/xmpp_connection_state.dart'; import 'package:xmpp_plugin/error_response_event.dart'; @@ -70,6 +70,8 @@ class _MyAppState extends State case AppLifecycleState.resumed: log('resumed detachedCallBack()'); break; + case AppLifecycleState.hidden: + break; } } @@ -214,7 +216,8 @@ class _MyAppState extends State await flutterXmpp.getAdmins(groupName); } - Future changePresenceType(presenceType, presenceMode) async { + Future changePresenceType( + String presenceType, String presenceMode) async { await flutterXmpp.changePresenceType(presenceType, presenceMode); } diff --git a/ios/xmpp_plugin.podspec b/ios/xmpp_plugin.podspec index fbf8461..545af85 100644 --- a/ios/xmpp_plugin.podspec +++ b/ios/xmpp_plugin.podspec @@ -16,7 +16,7 @@ A new Flutter project. s.source_files = 'Classes/**/*' s.dependency 'Flutter' s.dependency 'XMPPFramework/Swift' - s.platform = :ios, '9.0' + s.platform = :ios, '11.0' # Flutter.framework does not contain a i386 slice. s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' } diff --git a/lib/ennums/typing_status.dart b/lib/ennums/typing_status.dart index 9abcce0..859e7bf 100644 --- a/lib/ennums/typing_status.dart +++ b/lib/ennums/typing_status.dart @@ -1,7 +1 @@ -enum TypingStatus { - COMPOSING, - PAUSED, - ACTIVE, - GONE, - INACTIVE; -} +enum TypingStatus { COMPOSING, PAUSED, ACTIVE, GONE, INACTIVE } diff --git a/lib/message_event.dart b/lib/message_event.dart index 24f8a78..e6818bf 100644 --- a/lib/message_event.dart +++ b/lib/message_event.dart @@ -1,3 +1,4 @@ +import 'ennums/presence_type.dart'; class MessageEvent { String? customText; @@ -10,8 +11,8 @@ class MessageEvent { String? msgtype; String? bubbleType; String? mediaURL; - String? presenceType; - String? presenceMode; + PresenceType? presenceType; + PresenceMode? presenceMode; String? chatStateType; int? isReadSent; @@ -44,11 +45,10 @@ class MessageEvent { 'msgtype': msgtype, 'bubbleType': bubbleType, 'mediaURL': mediaURL, - 'presenceType': presenceType, - 'presenceMode': presenceMode, + 'presenceType': presenceType?.name, + 'presenceMode': presenceMode?.name, 'isReadSent': isReadSent, 'chatStateType': chatStateType, - }; } diff --git a/lib/xmpp_plugin.dart b/lib/xmpp_plugin.dart index cc84d63..c72a1ec 100644 --- a/lib/xmpp_plugin.dart +++ b/lib/xmpp_plugin.dart @@ -33,9 +33,12 @@ abstract class DataChangeEvents { class XmppConnection { static const MethodChannel _channel = MethodChannel('flutter_xmpp/method'); static const EventChannel _eventChannel = EventChannel('flutter_xmpp/stream'); - static const EventChannel _successEventChannel = EventChannel('flutter_xmpp/success_event_stream'); - static const EventChannel _connectionEventChannel = EventChannel('flutter_xmpp/connection_event_stream'); - static const EventChannel _errorEventChannel = EventChannel('flutter_xmpp/error_event_stream'); + static const EventChannel _successEventChannel = + EventChannel('flutter_xmpp/success_event_stream'); + static const EventChannel _connectionEventChannel = + EventChannel('flutter_xmpp/connection_event_stream'); + static const EventChannel _errorEventChannel = + EventChannel('flutter_xmpp/error_event_stream'); static late StreamSubscription streamGetMsg; static late StreamSubscription successEventStream; static late StreamSubscription connectionEventStream; @@ -72,7 +75,8 @@ class XmppConnection { await _channel.invokeMethod('logout'); } - Future sendMessage(String toJid, String body, String id, int time) async { + Future sendMessage( + String toJid, String body, String id, int time) async { final params = { "to_jid": toJid, "body": body, @@ -84,10 +88,12 @@ class XmppConnection { return status; } - Future sendMessageWithType(String toJid, - String body, - String id, - int time,) async { + Future sendMessageWithType( + String toJid, + String body, + String id, + int time, + ) async { final params = { "to_jid": toJid, "body": body, @@ -99,7 +105,8 @@ class XmppConnection { return status; } - Future sendGroupMessage(String toJid, String body, String id, int time) async { + Future sendGroupMessage( + String toJid, String body, String id, int time) async { final params = { "to_jid": toJid, "body": body, @@ -107,14 +114,17 @@ class XmppConnection { "time": time.toString(), }; printLogForMethodCall('send_group_message', params); - final String status = await _channel.invokeMethod('send_group_message', params); + final String status = + await _channel.invokeMethod('send_group_message', params); return status; } - Future sendGroupMessageWithType(String toJid, - String body, - String id, - int time,) async { + Future sendGroupMessageWithType( + String toJid, + String body, + String id, + int time, + ) async { final params = { "to_jid": toJid, "body": body, @@ -122,7 +132,8 @@ class XmppConnection { "time": time.toString(), }; printLogForMethodCall('send_group_message', params); - final String status = await _channel.invokeMethod('send_group_message', params); + final String status = + await _channel.invokeMethod('send_group_message', params); return status; } @@ -156,22 +167,28 @@ class XmppConnection { }, ); - connectionEventStream = _connectionEventChannel.receiveBroadcastStream().listen((connectionData) { - ConnectionEvent connectionEvent = ConnectionEvent.fromJson(connectionData); + connectionEventStream = _connectionEventChannel + .receiveBroadcastStream() + .listen((connectionData) { + ConnectionEvent connectionEvent = + ConnectionEvent.fromJson(connectionData); dataChangelist.forEach((element) { element.onConnectionEvents(connectionEvent); }); }, onError: _onError); - successEventStream = _successEventChannel.receiveBroadcastStream().listen((successData) { - SuccessResponseEvent eventModel = SuccessResponseEvent.fromJson(successData); + successEventStream = + _successEventChannel.receiveBroadcastStream().listen((successData) { + SuccessResponseEvent eventModel = + SuccessResponseEvent.fromJson(successData); print("success event ${eventModel.toSuccessResponseData()}"); dataChangelist.forEach((element) { element.onSuccessEvent(eventModel); }); }, onError: _onError); - errorEventStream = _errorEventChannel.receiveBroadcastStream().listen((errorData) { + errorEventStream = + _errorEventChannel.receiveBroadcastStream().listen((errorData) { ErrorResponseEvent eventModel = ErrorResponseEvent.fromJson(errorData); print("Error event ${eventModel.toErrorResponseData()}"); dataChangelist.forEach((element) { @@ -218,7 +235,8 @@ class XmppConnection { return await _channel.invokeMethod('join_muc_group', params); } - Future sendCustomMessage(String toJid, String body, String id, String customString, int time) async { + Future sendCustomMessage(String toJid, String body, String id, + String customString, int time) async { final params = { "to_jid": toJid, "body": body, @@ -233,7 +251,8 @@ class XmppConnection { log('call method to app from flutter methodName: $methodName: params: $params'); } - Future sendCustomGroupMessage(String toJid, String body, String id, String customString, int time) async { + Future sendCustomGroupMessage(String toJid, String body, String id, + String customString, int time) async { final params = { "to_jid": toJid, "body": body, @@ -244,7 +263,8 @@ class XmppConnection { await _channel.invokeMethod('send_customgroup_message', params); } - Future sendDelieveryReceipt(String toJid, String msgId, String receiptID) async { + Future sendDelieveryReceipt( + String toJid, String msgId, String receiptID) async { final params = {"toJid": toJid, "msgId": msgId, "receiptId": receiptID}; await _channel.invokeMethod('send_delivery_receipt', params); } @@ -254,7 +274,8 @@ class XmppConnection { await _channel.invokeMethod('add_members_in_group', params); } - Future addAdminsInGroup(String groupName, List adminMembers) async { + Future addAdminsInGroup( + String groupName, List adminMembers) async { final params = {"group_name": groupName, "members_jid": adminMembers}; await _channel.invokeMethod('add_admins_in_group', params); } @@ -293,7 +314,8 @@ class XmppConnection { Future getOnlineMemberCount(String groupName) async { final params = {"group_name": groupName}; - int memberCount = await _channel.invokeMethod('get_online_member_count', params); + int memberCount = + await _channel.invokeMethod('get_online_member_count', params); print('checkGroups getOccupantsSize: $memberCount'); return memberCount; } @@ -332,14 +354,23 @@ class XmppConnection { return admins; } - Future requestMamMessages(String userJid, String requestSince, String requestBefore, String limit) async { - print(" Plugin : User Jid : $userJid , Request since : $requestSince , Request Before : $requestBefore, Limit : $limit "); - final params = {"userJid": userJid, "requestBefore": requestBefore, "requestSince": requestSince, "limit": limit}; + Future requestMamMessages(String userJid, String requestSince, + String requestBefore, String limit) async { + print( + " Plugin : User Jid : $userJid , Request since : $requestSince , Request Before : $requestBefore, Limit : $limit "); + final params = { + "userJid": userJid, + "requestBefore": requestBefore, + "requestSince": requestSince, + "limit": limit + }; await _channel.invokeMethod('request_mam', params); } - Future changeTypingStatus(String userJid, - String typingstatus,) async { + Future changeTypingStatus( + String userJid, + String typingstatus, + ) async { print(" Plugin : User Jid : $userJid , Typing Status : $typingstatus "); final params = { "userJid": userJid, @@ -348,15 +379,18 @@ class XmppConnection { await _channel.invokeMethod('change_typing_status', params); } - Future changePresenceType(String presenceType, String presenceMode) async { - print(" Plugin : presenceType : $presenceType , presenceMode : $presenceMode"); + Future changePresenceType( + String presenceType, String presenceMode) async { + print( + " Plugin : presenceType : $presenceType , presenceMode : $presenceMode"); final params = {"presenceType": presenceType, "presenceMode": presenceMode}; await _channel.invokeMethod('change_presence_type', params); } Future getConnectionStatus() async { printLogForMethodCall('get_connection_status', ''); - String connectionState = await _channel.invokeMethod('get_connection_status'); + String connectionState = + await _channel.invokeMethod('get_connection_status'); return connectionState.toConnectionState(); } diff --git a/pubspec.yaml b/pubspec.yaml index 4ae1989..91f64fb 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,7 +4,7 @@ version: 2.3.1 homepage: https://github.com/vavadiyahiren/xmpp_plugin environment: - sdk: '>=2.18.4 <4.0.0' + sdk: ">=2.18.4 <4.0.0" flutter: ">=2.5.0" dependencies: