From 8d6444b46b166f470794186a76926a0de1a1647a Mon Sep 17 00:00:00 2001 From: tom79 Date: Wed, 17 Apr 2019 16:25:42 +0200 Subject: [PATCH 1/7] Improve utm parameters detection --- .../mastodon/client/Entities/Status.java | 4 +- .../gouv/etalab/mastodon/helper/Helper.java | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java index 74c3b12dd..0ba3a6a4b 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java @@ -318,9 +318,7 @@ public class Status implements Parcelable{ public void setContent(String content) { //Remove UTM by default - this.content = content.replaceAll("&utm_\\w+=[0-9a-zA-Z._-]*", ""); - this.content = this.content.replaceAll("&utm_\\w+=[0-9a-zA-Z._-]*", ""); - this.content = this.content.replaceAll("\\?utm_\\w+=[0-9a-zA-Z._-]*", "?"); + this.content = Helper.remove_tracking_param(content); } public Status getReblog() { diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java index ffb938ac1..9e756ee77 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java @@ -452,6 +452,8 @@ public class Helper { TOOT } + + /** * Converts emojis in input to unicode * @param input String @@ -3758,6 +3760,47 @@ public class Helper { } + /* + * List from ClearUrls + * https://gitlab.com/KevinRoebert/ClearUrls/blob/master/data/data.min.json#L106 + */ + private static final String[] UTM_PARAMS = { + "utm_\\w+", + "ga_source", + "ga_medium", + "ga_term", + "ga_content", + "ga_campaign", + "ga_place", + "yclid", + "_openstat", + "fb_action_ids", + "fb_action_types", + "fb_source", + "fb_ref", + "fbclid", + "action_object_map", + "action_type_map", + "action_ref_map", + "gs_l", + "mkt_tok", + "hmb_campaign", + "hmb_medium", + "hmb_source", + "[\\?|&]ref[\\_]?" + }; + + public static String remove_tracking_param(String original_content){ + if( original_content == null) + return original_content; + String cleaned_content = original_content; + for(String utm: UTM_PARAMS){ + cleaned_content = cleaned_content.replaceAll("&"+utm+"=[0-9a-zA-Z._-]*", ""); + cleaned_content = cleaned_content.replaceAll("&"+utm+"=[0-9a-zA-Z._-]*", ""); + cleaned_content = cleaned_content.replaceAll("\\?"+utm+"=[0-9a-zA-Z._-]*", "?"); + } + return cleaned_content; + } } From 78c3d7c6606613f34412e12b5a313ac730c51f27 Mon Sep 17 00:00:00 2001 From: tom79 Date: Wed, 17 Apr 2019 17:22:27 +0200 Subject: [PATCH 2/7] Fix version name --- .../java/fr/gouv/etalab/mastodon/client/Entities/Version.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Version.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Version.java index 9c6ceb501..42cdac5ba 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Version.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Version.java @@ -19,6 +19,10 @@ public class Version implements Comparable { public Version(String version) { if(version == null) version = "2.1"; + if( version.contains("+")){ + String[] versionA = version.split("\\+"); + version = versionA[0]; + } if( version.endsWith(".")) version = version.substring(0, version.length() - 1); version = version.replaceAll("[^\\d.]", ""); From 55d73c67db837bde5b7c3eace57f85de25b07b8f Mon Sep 17 00:00:00 2001 From: tom79 Date: Wed, 17 Apr 2019 17:23:03 +0200 Subject: [PATCH 3/7] Move to the last version --- .../java/fr/gouv/etalab/mastodon/client/Entities/Version.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Version.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Version.java index 42cdac5ba..2245ea696 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Version.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Version.java @@ -18,7 +18,7 @@ public class Version implements Comparable { public Version(String version) { if(version == null) - version = "2.1"; + version = "2.8"; if( version.contains("+")){ String[] versionA = version.split("\\+"); version = versionA[0]; @@ -27,7 +27,7 @@ public class Version implements Comparable { version = version.substring(0, version.length() - 1); version = version.replaceAll("[^\\d.]", ""); if(!version.matches("[0-9]+(\\.[0-9]+)*")) - version = "2.1"; + version = "2.8"; this.version = version; } From ef7dd73a22b84361f61c0270ee22d3ffe81b9256 Mon Sep 17 00:00:00 2001 From: tom79 Date: Wed, 17 Apr 2019 17:23:42 +0200 Subject: [PATCH 4/7] Move to the last version --- .../java/fr/gouv/etalab/mastodon/client/Entities/Version.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Version.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Version.java index 2245ea696..42cdac5ba 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Version.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Version.java @@ -18,7 +18,7 @@ public class Version implements Comparable { public Version(String version) { if(version == null) - version = "2.8"; + version = "2.1"; if( version.contains("+")){ String[] versionA = version.split("\\+"); version = versionA[0]; @@ -27,7 +27,7 @@ public class Version implements Comparable { version = version.substring(0, version.length() - 1); version = version.replaceAll("[^\\d.]", ""); if(!version.matches("[0-9]+(\\.[0-9]+)*")) - version = "2.8"; + version = "2.1"; this.version = version; } From 12b76915c881774bfe41bb761429c5880164d8e0 Mon Sep 17 00:00:00 2001 From: tom79 Date: Wed, 17 Apr 2019 17:40:11 +0200 Subject: [PATCH 5/7] Fix issue #882 --- .../java/fr/gouv/etalab/mastodon/activities/TootActivity.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java index 7f1305b18..1f296f8b2 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java @@ -2007,6 +2007,9 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface, if(restored != -1){ SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); new StatusStoredDAO(getApplicationContext(), db).remove(restored); + }else if(currentToId != -1){ + SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); + new StatusStoredDAO(getApplicationContext(), db).remove(currentToId); } //Clear the toot toot_content.setText(""); From 28ebf3b72b3b408690d714b848e476f6dd1707af Mon Sep 17 00:00:00 2001 From: tom79 Date: Wed, 17 Apr 2019 17:56:33 +0200 Subject: [PATCH 6/7] Fix issue #886 - Add live notifications for Pleroma --- .../services/LiveNotificationService.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/services/LiveNotificationService.java b/app/src/main/java/fr/gouv/etalab/mastodon/services/LiveNotificationService.java index a02f07b16..9645944cd 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/services/LiveNotificationService.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/services/LiveNotificationService.java @@ -35,7 +35,6 @@ import android.preference.PreferenceManager; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.content.LocalBroadcastManager; - import com.bumptech.glide.Glide; import com.bumptech.glide.load.DataSource; import com.bumptech.glide.load.engine.GlideException; @@ -61,6 +60,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Timer; import java.util.TimerTask; @@ -129,7 +129,7 @@ public class LiveNotificationService extends Service implements NetworkStateRece List accountStreams = new AccountDAO(getApplicationContext(), db).getAllAccountCrossAction(); if (accountStreams != null) { for (final Account accountStream : accountStreams) { - if( accountStream.getSocial() == null || accountStream.getSocial().equals("MASTODON")) { + if( accountStream.getSocial() == null || accountStream.getSocial().equals("MASTODON") || accountStream.getSocial().equals("PLEROMA")) { thread = new Thread() { @Override public void run() { @@ -145,15 +145,15 @@ public class LiveNotificationService extends Service implements NetworkStateRece }else { String key = account.getAcct() + "@" + account.getInstance(); if(webSocketFutures.containsKey(key)){ - if (webSocketFutures.get(key) != null && webSocketFutures.get(key).isOpen()) { + if (webSocketFutures.get(key) != null && Objects.requireNonNull(webSocketFutures.get(key)).isOpen()) { try { - webSocketFutures.get(key).close(); + Objects.requireNonNull(webSocketFutures.get(key)).close(); }catch (Exception ignored){} } } if(threads.containsKey(key)){ - if (threads.get(key) != null && !threads.get(key).isAlive()) { - threads.get(key).interrupt(); + if (threads.get(key) != null && !Objects.requireNonNull(threads.get(key)).isAlive()) { + Objects.requireNonNull(threads.get(key)).interrupt(); } } Thread thread = new Thread() { @@ -220,13 +220,16 @@ public class LiveNotificationService extends Service implements NetworkStateRece headers.add("Connection", "Keep-Alive"); headers.add("method", "GET"); headers.add("scheme", "https"); - String urlKey = "wss://" + account.getInstance() + "/api/v1/streaming/?stream=user:notification&access_token=" + account.getToken(); + String notif_url = "user:notification"; + if( account.getSocial().toUpperCase().equals("PLEROMA")) + notif_url = "user"; + String urlKey = "wss://" + account.getInstance() + "/api/v1/streaming/?stream="+notif_url+"&access_token=" + account.getToken(); Uri url = Uri.parse(urlKey); AsyncHttpRequest.setDefaultHeaders(headers, url); if( webSocketFutures.containsKey(urlKey) ){ try { if( webSocketFutures.get(urlKey) != null && webSocketFutures.get(urlKey).isOpen()) - webSocketFutures.get(urlKey).close(); + Objects.requireNonNull(webSocketFutures.get(urlKey)).close(); } catch (Exception ignored) {} } if( Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT ) { @@ -239,7 +242,7 @@ public class LiveNotificationService extends Service implements NetworkStateRece e.printStackTrace(); } } - AsyncHttpClient.getDefaultInstance().websocket("wss://" + account.getInstance() + "/api/v1/streaming/?stream=user:notification&access_token=" + account.getToken(), "wss", new AsyncHttpClient.WebSocketConnectCallback() { + AsyncHttpClient.getDefaultInstance().websocket("wss://" + account.getInstance() + "/api/v1/streaming/?stream="+notif_url+"&access_token=" + account.getToken(), "wss", new AsyncHttpClient.WebSocketConnectCallback() { @Override public void onCompleted(Exception ex, WebSocket webSocket) { webSocketFutures.put(account.getAcct()+"@"+account.getInstance(), webSocket); From 68361efe65bb7aa0791385f67db9d5d6e2ed42aa Mon Sep 17 00:00:00 2001 From: tom79 Date: Wed, 17 Apr 2019 17:59:59 +0200 Subject: [PATCH 7/7] Release 1.79.0-beta-1 --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 0e620ad50..97662c710 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,8 +7,8 @@ android { applicationId "fr.gouv.etalab.mastodon" minSdkVersion 16 targetSdkVersion 28 - versionCode 251 - versionName "1.78.0" + versionCode 252 + versionName "1.79.0-beta-1" multiDexEnabled true } dexOptions {