From 82aee9b79c0b615d70932b9ca971bc8a218c7486 Mon Sep 17 00:00:00 2001 From: tom79 Date: Wed, 27 Feb 2019 10:27:01 +0100 Subject: [PATCH] Add conversations for private messages #829 --- .../activities/ShowConversationActivity.java | 3 ++- .../asynctasks/RetrieveContextAsyncTask.java | 9 ++++++--- .../fr/gouv/etalab/mastodon/client/GNUAPI.java | 16 +++++++++++++--- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowConversationActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowConversationActivity.java index 015fe6f1c..c4570b2c1 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowConversationActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowConversationActivity.java @@ -257,7 +257,8 @@ public class ShowConversationActivity extends BaseActivity implements OnRetriev finish(); if( conversationId != null) statusIdToFetch = conversationId; - new RetrieveContextAsyncTask(getApplicationContext(), expanded, statusIdToFetch, ShowConversationActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + + new RetrieveContextAsyncTask(getApplicationContext(),expanded, detailsStatus.getVisibility().equals("direct"), statusIdToFetch, ShowConversationActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); switch (theme){ case Helper.THEME_LIGHT: swipeRefreshLayout.setColorSchemeResources(R.color.mastodonC4, diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveContextAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveContextAsyncTask.java index ad7077d43..4b8346836 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveContextAsyncTask.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveContextAsyncTask.java @@ -39,12 +39,15 @@ public class RetrieveContextAsyncTask extends AsyncTask { private Error error; private WeakReference contextReference; private boolean expanded; + private boolean directtimeline; - public RetrieveContextAsyncTask(Context context, boolean expanded, String statusId, OnRetrieveContextInterface onRetrieveContextInterface){ + + public RetrieveContextAsyncTask(Context context, boolean expanded, boolean directtimeline, String statusId, OnRetrieveContextInterface onRetrieveContextInterface){ this.contextReference = new WeakReference<>(context); this.statusId = statusId; this.listener = onRetrieveContextInterface; this.expanded = expanded; + this.directtimeline = directtimeline; } @Override @@ -59,10 +62,10 @@ public class RetrieveContextAsyncTask extends AsyncTask { error = api.getError(); }else{ GNUAPI gnuapi = new GNUAPI(this.contextReference.get()); - statusContext = gnuapi.getStatusContext(statusId); + statusContext = gnuapi.getStatusContext(statusId, directtimeline); //Retrieves the first toot if (expanded && statusContext != null && statusContext.getAncestors() != null && statusContext.getAncestors().size() > 0) { - statusContext = gnuapi.getStatusContext(statusContext.getAncestors().get(0).getId()); + statusContext = gnuapi.getStatusContext(statusContext.getAncestors().get(0).getId(), directtimeline); } error = gnuapi.getError(); } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/GNUAPI.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/GNUAPI.java index ccc744011..fa362118b 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/GNUAPI.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/GNUAPI.java @@ -544,11 +544,18 @@ public class GNUAPI { * @param statusId Id of the status * @return List */ - public fr.gouv.etalab.mastodon.client.Entities.Context getStatusContext(String statusId) { + public fr.gouv.etalab.mastodon.client.Entities.Context getStatusContext(String statusId, boolean directtimeline) { fr.gouv.etalab.mastodon.client.Entities.Context statusContext = new fr.gouv.etalab.mastodon.client.Entities.Context(); try { HttpsConnection httpsConnection = new HttpsConnection(context); - String response = httpsConnection.get(getAbsoluteUrl(String.format("/statusnet/conversation/%s.json", statusId)), 60, null, prefKeyOauthTokenT); + String response; + if( !directtimeline) + response = httpsConnection.get(getAbsoluteUrl(String.format("/statusnet/conversation/%s.json", statusId)), 60, null, prefKeyOauthTokenT); + else { + HashMap params = new HashMap<>(); + params.put("uri", statusId); + response = httpsConnection.get(getAbsoluteUrl("/direct_messages/conversation.json"), 60, params, prefKeyOauthTokenT); + } statuses = parseStatuses(context, new JSONArray(response)); if( statuses != null && statuses.size() > 0){ ArrayList descendants = new ArrayList<>(); @@ -1831,7 +1838,10 @@ public class GNUAPI { try { status.setConversationId(resobj.get("statusnet_conversation_id").toString()); }catch (Exception ignored){ - status.setConversationId(resobj.get("id").toString()); + if( resobj.has("friendica_parent_uri")) + status.setConversationId(resobj.get("friendica_parent_uri").toString()); + else + status.setConversationId(resobj.get("id").toString()); } //Retrieves mentions List mentions = new ArrayList<>();