@@ -195,6 +195,16 @@ private void onNavigating(object sender, WebNavigatingEventArgs e)
195195 string app_id = current_url . Substring ( "ixian:app:" . Length ) ;
196196 onApp ( app_id ) ;
197197 }
198+ else if ( current_url . StartsWith ( "ixian:installApp:" ) )
199+ {
200+ string app_url = current_url . Substring ( "ixian:installApp:" . Length ) ;
201+ onInstallApp ( app_url ) ;
202+ }
203+ else if ( current_url . StartsWith ( "ixian:joinApp:" ) )
204+ {
205+ string app_id = current_url . Substring ( "ixian:joinApp:" . Length ) ;
206+ onJoinApp ( app_id ) ;
207+ }
198208 else if ( current_url . StartsWith ( "ixian:loadContacts" ) )
199209 {
200210 loadContacts ( ) ;
@@ -735,17 +745,75 @@ public void onConfirmPaymentRequest(FriendMessage msg, string amount)
735745 public void onApp ( string app_id )
736746 {
737747 Address [ ] user_addresses = new Address [ ] { friend . walletAddress } ;
738- MiniAppPage custom_app_page = new MiniAppPage ( app_id , IxianHandler . getWalletStorage ( ) . getPrimaryAddress ( ) , user_addresses , Node . MiniAppManager . getAppEntryPoint ( app_id ) ) ;
739- custom_app_page . accepted = true ;
740- Node . MiniAppManager . addAppPage ( custom_app_page ) ;
748+
749+ byte [ ] ? session_id = null ;
750+ if ( homePage != null )
751+ {
752+ session_id = homePage . onJoinApp ( app_id , user_addresses ) ;
753+ }
754+ else
755+ {
756+ MiniAppPage custom_app_page = new MiniAppPage ( app_id , IxianHandler . getWalletStorage ( ) . getPrimaryAddress ( ) , user_addresses , Node . MiniAppManager . getAppEntryPoint ( app_id ) ) ;
757+ custom_app_page . accepted = true ;
758+ Node . MiniAppManager . addAppPage ( custom_app_page ) ;
759+ session_id = custom_app_page . sessionId ;
760+ MainThread . BeginInvokeOnMainThread ( ( ) =>
761+ {
762+ Navigation . PushAsync ( custom_app_page , Config . defaultXamarinAnimations ) ;
763+ } ) ;
764+ }
765+
766+
767+ if ( session_id == null )
768+ {
769+ return ;
770+ }
771+
772+ FriendList . addMessageWithType ( session_id , FriendMessageType . appSession , friend . walletAddress , 0 , app_id , true , null , 0 , false ) ;
773+ StreamProcessor . sendAppRequest ( friend , app_id , session_id , null ) ;
774+ }
775+
776+ public void onJoinApp ( string app_id )
777+ {
778+
779+ Address [ ] user_addresses = new Address [ ] { friend . walletAddress } ;
780+ if ( homePage != null )
781+ {
782+ homePage . onJoinApp ( app_id , user_addresses ) ;
783+ return ;
784+ }
785+
786+ MiniAppPage miniAppPage = new MiniAppPage ( app_id , IxianHandler . getWalletStorage ( ) . getPrimaryAddress ( ) , user_addresses , Node . MiniAppManager . getAppEntryPoint ( app_id ) ) ;
787+ miniAppPage . accepted = true ;
788+ Node . MiniAppManager . addAppPage ( miniAppPage ) ;
741789
742790 MainThread . BeginInvokeOnMainThread ( ( ) =>
743791 {
744- Navigation . PushAsync ( custom_app_page , Config . defaultXamarinAnimations ) ;
792+ Navigation . PushAsync ( miniAppPage , Config . defaultXamarinAnimations ) ;
745793 } ) ;
746794
747- FriendList . addMessageWithType ( custom_app_page . sessionId , FriendMessageType . appSession , friend . walletAddress , 0 , app_id , true , null , 0 , false ) ;
748- StreamProcessor . sendAppRequest ( friend , app_id , custom_app_page . sessionId , null ) ;
795+ }
796+
797+ public async void onInstallApp ( string app_url )
798+ {
799+ if ( homePage != null )
800+ {
801+ homePage . onInstallApp ( app_url ) ;
802+ return ;
803+ }
804+
805+ MiniApp ? app = await Node . MiniAppManager . fetch ( app_url ) ;
806+ if ( app == null )
807+ {
808+ return ;
809+ }
810+
811+ app . url = app_url ;
812+
813+ MainThread . BeginInvokeOnMainThread ( ( ) =>
814+ {
815+ Navigation . PushAsync ( new AppDetailsPage ( app ) , Config . defaultXamarinAnimations ) ;
816+ } ) ;
749817 }
750818
751819 private void onKickUser ( Address address )
@@ -1157,8 +1225,51 @@ public void insertMessage(FriendMessage message, int channel)
11571225 Utils . sendUiCommand ( this , "addFile" , Crypto . hashToString ( message . id ) , address , nick , avatar , uid , name , message . timestamp . ToString ( ) , message . localSender . ToString ( ) , message . confirmed . ToString ( ) , message . read . ToString ( ) , progress , message . completed . ToString ( ) , paid . ToString ( ) ) ;
11581226 }
11591227 }
1160-
1161- if ( message . type == FriendMessageType . standard )
1228+
1229+ if ( message . type == FriendMessageType . appSession )
1230+ {
1231+ MiniAppManager am = Node . MiniAppManager ;
1232+
1233+ string app_id ;
1234+ string app_install_url = "" ;
1235+ string app_name = "" ;
1236+ if ( message . message . Contains ( "||" ) )
1237+ {
1238+ string [ ] app_id_data = message . message . Split ( new [ ] { "||" } , StringSplitOptions . None ) ;
1239+ app_id = app_id_data [ 0 ] ;
1240+ app_install_url = app_id_data . Length > 1 ? app_id_data [ 1 ] : "" ;
1241+ app_name = app_id_data . Length > 2 ? app_id_data [ 2 ] : "" ;
1242+ }
1243+ else
1244+ {
1245+ app_id = message . message ;
1246+ }
1247+
1248+
1249+ MiniApp app = am . getApp ( app_id ) ;
1250+ string app_state = "" ;
1251+
1252+ if ( app == null )
1253+ {
1254+ app_state = "Missing" ;
1255+ }
1256+ else
1257+ {
1258+ app_name = app . name ;
1259+ }
1260+
1261+
1262+ if ( message . localSender )
1263+ {
1264+ Utils . sendUiCommand ( this , "addAppRequest" , Crypto . hashToString ( message . id ) , app_id , app_name , address , nick , avatar , message . timestamp . ToString ( ) , message . localSender . ToString ( ) , message . confirmed . ToString ( ) , message . read . ToString ( ) , app_state , app_install_url ) ;
1265+ }
1266+ else
1267+ {
1268+ Utils . sendUiCommand ( this , "addAppRequest" , Crypto . hashToString ( message . id ) , app_id , app_name , address , nick , avatar , message . timestamp . ToString ( ) , message . localSender . ToString ( ) , message . confirmed . ToString ( ) , message . read . ToString ( ) , app_state , app_install_url ) ;
1269+ }
1270+ }
1271+
1272+ if ( message . type == FriendMessageType . standard )
11621273 {
11631274 // Normal chat message
11641275 // Call webview methods on the main UI thread only
0 commit comments