Skip to content

Commit

Permalink
Merge pull request #42 from Tawkie/fix-social-network-url-redirect
Browse files Browse the repository at this point in the history
fix url redirect pattern
  • Loading branch information
ignyx authored Sep 12, 2024
2 parents c8fe4b0 + 47eafb9 commit 887e4be
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
5 changes: 5 additions & 0 deletions lib/pages/add_bridge/model/social_network.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class SocialNetwork {
displayNameSuffix; // The `(Network)` suffix to remove from displayname)
final String? urlLogin;
final String? urlRedirect;
final RegExp? urlRedirectPattern;
bool loading; // To find out if state is loading
bool connected; // To find out if state is disconnected
bool error; // Bool to indicate if there is an error
Expand All @@ -29,6 +30,7 @@ class SocialNetwork {
this.displayNameSuffix = "",
this.urlLogin,
this.urlRedirect,
this.urlRedirectPattern,
this.loading = true, // Default value true for loading
this.connected = false, // Default value false for connected
this.error = false, // Défaut à false
Expand Down Expand Up @@ -77,6 +79,7 @@ class SocialNetworkManager {
mxidPrefix: "@messenger2_",
urlLogin: "https://www.messenger.com/login/",
urlRedirect: "https://www.messenger.com/t/",
urlRedirectPattern: RegExp(r'^https:\/\/www\.messenger\.com\/.*\/t\/.*$'),
),
SocialNetwork(
logo: Logo(Logos.instagram),
Expand All @@ -89,6 +92,7 @@ class SocialNetworkManager {
mxidPrefix: "@instagram2_",
urlLogin: "https://www.instagram.com/accounts/login/",
urlRedirect: "https://www.instagram.com/",
urlRedirectPattern: RegExp(r'^https:\/\/www\.instagram\.com\/.*$'),
),
SocialNetwork(
logo: Logo(Logos.whatsapp),
Expand All @@ -111,6 +115,7 @@ class SocialNetworkManager {
mxidPrefix: "@linkedin_",
urlLogin: "https://www.linkedin.com/login/",
urlRedirect: "https://www.linkedin.com/feed/",
urlRedirectPattern: RegExp(r'^https:\/\/www\.linkedin\.com\/feed\/.*$'),
),
SocialNetwork(
logo: Container(),
Expand Down
11 changes: 6 additions & 5 deletions lib/pages/add_bridge/web_view_connection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,14 @@ class _WebViewConnectionState extends State<WebViewConnection> {
_webViewController = controller;
},
onLoadStop: (InAppWebViewController controller, Uri? url) async {
final urlString = url?.toString();
// Check the URL when the page finishes loading
switch (widget.network.name) {
case "Facebook Messenger":
final successfullyRedirected = !_facebookBridgeCreated &&
url != null &&
url.toString() != widget.network.urlLogin! &&
url.toString().contains(widget.network.urlRedirect!);
urlString != widget.network.urlLogin! &&
widget.network.urlRedirectPattern?.hasMatch(urlString!) == true;

if (successfullyRedirected) {
await _closeWebView();
Expand All @@ -138,8 +139,8 @@ class _WebViewConnectionState extends State<WebViewConnection> {
case "Instagram":
if (!_instagramBridgeCreated &&
url != null &&
url.toString() != widget.network.urlLogin! &&
url.toString().contains(widget.network.urlRedirect!)) {
urlString != widget.network.urlLogin! &&
widget.network.urlRedirectPattern?.hasMatch(urlString!) == true) {
// Close the WebView
await _closeWebView();
await showCustomLoadingDialog(
Expand All @@ -158,7 +159,7 @@ class _WebViewConnectionState extends State<WebViewConnection> {
case "Linkedin":
if (!_linkedinBridgeCreated &&
url != null &&
url.toString().contains(widget.network.urlRedirect!)) {
widget.network.urlRedirectPattern?.hasMatch(urlString!) == true) {
// Close the WebView
await _closeWebView();
await showCustomLoadingDialog(
Expand Down

0 comments on commit 887e4be

Please sign in to comment.