-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from humhub/95-notification-opens-the-dashboa…
…rd-instead-of-the-related-content Push redirect to correct page
- Loading branch information
Showing
8 changed files
with
175 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:http/http.dart'; | ||
import 'package:humhub/models/hum_hub.dart'; | ||
import 'package:humhub/models/manifest.dart'; | ||
import 'package:http/http.dart' as http; | ||
import 'api_provider.dart'; | ||
import 'connectivity_plugin.dart'; | ||
|
||
class PushOpenerController { | ||
late AsyncValue<Manifest>? asyncData; | ||
bool doesViewExist = false; | ||
final String url; | ||
late HumHub humhub; | ||
|
||
PushOpenerController({required this.url}); | ||
|
||
findManifest(String url) async { | ||
Uri uri = assumeUrl(url); | ||
for (var i = uri.pathSegments.length - 1; i >= 0; i--) { | ||
String urlIn = "${uri.origin}/${uri.pathSegments.getRange(0, i).join('/')}"; | ||
asyncData = await APIProvider.requestBasic(Manifest.get(i != 0 ? urlIn : uri.origin)); | ||
if (!asyncData!.hasError) break; | ||
} | ||
if (uri.pathSegments.isEmpty) { | ||
asyncData = await APIProvider.requestBasic(Manifest.get(uri.origin)); | ||
} | ||
await checkHumHubModuleView(uri); | ||
} | ||
|
||
checkHumHubModuleView(Uri uri) async { | ||
Response? response; | ||
response = await http.Client().get(Uri.parse(uri.origin)).catchError((err) { | ||
return Response("Found manifest but not humhub.modules.ui.view tag", 404); | ||
}); | ||
|
||
doesViewExist = response.statusCode == 200 && response.body.contains('humhub.modules.ui.view'); | ||
} | ||
|
||
Future<HumHub?> initHumHub() async { | ||
var hasConnection = await ConnectivityPlugin.hasConnectivity; | ||
if (!hasConnection) { | ||
asyncData = null; | ||
return null; | ||
} | ||
await findManifest(url); | ||
if (asyncData!.hasError || !doesViewExist) { | ||
asyncData = null; | ||
return null; | ||
} else { | ||
Manifest manifest = asyncData!.value!; | ||
String hash = HumHub.generateHash(32); | ||
HumHub instance = HumHub(manifest: manifest, randomHash: hash); | ||
humhub = instance; | ||
return instance; | ||
} | ||
} | ||
|
||
bool get allOk => !(asyncData == null || asyncData!.hasError || !doesViewExist); | ||
|
||
Uri assumeUrl(String url) { | ||
if (url.startsWith("https://") || url.startsWith("http://")) return Uri.parse(url); | ||
return Uri.parse("https://$url"); | ||
} | ||
|
||
String? validateUrl(String? value) { | ||
if (value == null || value.isEmpty) { | ||
return 'Specify you HumHub location'; | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters