Add conversations for private messages #829

This commit is contained in:
tom79 2019-02-27 10:27:01 +01:00
parent baee599f4f
commit 82aee9b79c
3 changed files with 21 additions and 7 deletions

View File

@ -257,7 +257,8 @@ public class ShowConversationActivity extends BaseActivity implements OnRetriev
finish(); finish();
if( conversationId != null) if( conversationId != null)
statusIdToFetch = conversationId; 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){ switch (theme){
case Helper.THEME_LIGHT: case Helper.THEME_LIGHT:
swipeRefreshLayout.setColorSchemeResources(R.color.mastodonC4, swipeRefreshLayout.setColorSchemeResources(R.color.mastodonC4,

View File

@ -39,12 +39,15 @@ public class RetrieveContextAsyncTask extends AsyncTask<Void, Void, Void> {
private Error error; private Error error;
private WeakReference<Context> contextReference; private WeakReference<Context> contextReference;
private boolean expanded; 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.contextReference = new WeakReference<>(context);
this.statusId = statusId; this.statusId = statusId;
this.listener = onRetrieveContextInterface; this.listener = onRetrieveContextInterface;
this.expanded = expanded; this.expanded = expanded;
this.directtimeline = directtimeline;
} }
@Override @Override
@ -59,10 +62,10 @@ public class RetrieveContextAsyncTask extends AsyncTask<Void, Void, Void> {
error = api.getError(); error = api.getError();
}else{ }else{
GNUAPI gnuapi = new GNUAPI(this.contextReference.get()); GNUAPI gnuapi = new GNUAPI(this.contextReference.get());
statusContext = gnuapi.getStatusContext(statusId); statusContext = gnuapi.getStatusContext(statusId, directtimeline);
//Retrieves the first toot //Retrieves the first toot
if (expanded && statusContext != null && statusContext.getAncestors() != null && statusContext.getAncestors().size() > 0) { 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(); error = gnuapi.getError();
} }

View File

@ -544,11 +544,18 @@ public class GNUAPI {
* @param statusId Id of the status * @param statusId Id of the status
* @return List<Status> * @return List<Status>
*/ */
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(); fr.gouv.etalab.mastodon.client.Entities.Context statusContext = new fr.gouv.etalab.mastodon.client.Entities.Context();
try { try {
HttpsConnection httpsConnection = new HttpsConnection(context); 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<String, String> params = new HashMap<>();
params.put("uri", statusId);
response = httpsConnection.get(getAbsoluteUrl("/direct_messages/conversation.json"), 60, params, prefKeyOauthTokenT);
}
statuses = parseStatuses(context, new JSONArray(response)); statuses = parseStatuses(context, new JSONArray(response));
if( statuses != null && statuses.size() > 0){ if( statuses != null && statuses.size() > 0){
ArrayList<Status> descendants = new ArrayList<>(); ArrayList<Status> descendants = new ArrayList<>();
@ -1831,7 +1838,10 @@ public class GNUAPI {
try { try {
status.setConversationId(resobj.get("statusnet_conversation_id").toString()); status.setConversationId(resobj.get("statusnet_conversation_id").toString());
}catch (Exception ignored){ }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 //Retrieves mentions
List<Mention> mentions = new ArrayList<>(); List<Mention> mentions = new ArrayList<>();