Manage conversations
This commit is contained in:
parent
0160588284
commit
f934a4800f
|
@ -847,9 +847,22 @@ public abstract class BaseMainActivity extends BaseActivity
|
||||||
displayStatusFragment.scrollToTop();
|
displayStatusFragment.scrollToTop();
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
if (display_direct)
|
if (display_direct) {
|
||||||
|
|
||||||
|
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||||
|
String instanceVersion = sharedpreferences.getString(Helper.INSTANCE_VERSION + userId + instance, null);
|
||||||
|
if (instanceVersion != null) {
|
||||||
|
Version currentVersion = new Version(instanceVersion);
|
||||||
|
Version minVersion = new Version("2.6");
|
||||||
|
if (currentVersion.compareTo(minVersion) == 1 || currentVersion.equals(minVersion)) {
|
||||||
|
updateTimeLine(RetrieveFeedsAsyncTask.Type.CONVERSATION, 0);
|
||||||
|
} else {
|
||||||
updateTimeLine(RetrieveFeedsAsyncTask.Type.DIRECT, 0);
|
updateTimeLine(RetrieveFeedsAsyncTask.Type.DIRECT, 0);
|
||||||
else if (display_local)
|
}
|
||||||
|
}else{
|
||||||
|
updateTimeLine(RetrieveFeedsAsyncTask.Type.DIRECT, 0);
|
||||||
|
}
|
||||||
|
}else if (display_local)
|
||||||
updateTimeLine(RetrieveFeedsAsyncTask.Type.LOCAL, 0);
|
updateTimeLine(RetrieveFeedsAsyncTask.Type.LOCAL, 0);
|
||||||
else if (display_global)
|
else if (display_global)
|
||||||
updateTimeLine(RetrieveFeedsAsyncTask.Type.PUBLIC, 0);
|
updateTimeLine(RetrieveFeedsAsyncTask.Type.PUBLIC, 0);
|
||||||
|
@ -2210,7 +2223,20 @@ public abstract class BaseMainActivity extends BaseActivity
|
||||||
return notificationsFragment;
|
return notificationsFragment;
|
||||||
}else if( position == 2 && display_direct) {
|
}else if( position == 2 && display_direct) {
|
||||||
statusFragment = new DisplayStatusFragment();
|
statusFragment = new DisplayStatusFragment();
|
||||||
|
|
||||||
|
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||||
|
String instanceVersion = sharedpreferences.getString(Helper.INSTANCE_VERSION + userId + instance, null);
|
||||||
|
if (instanceVersion != null) {
|
||||||
|
Version currentVersion = new Version(instanceVersion);
|
||||||
|
Version minVersion = new Version("2.6");
|
||||||
|
if (currentVersion.compareTo(minVersion) == 1 || currentVersion.equals(minVersion)) {
|
||||||
|
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.CONVERSATION);
|
||||||
|
} else {
|
||||||
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.DIRECT);
|
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.DIRECT);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.DIRECT);
|
||||||
|
}
|
||||||
statusFragment.setArguments(bundle);
|
statusFragment.setArguments(bundle);
|
||||||
return statusFragment;
|
return statusFragment;
|
||||||
}else if(position == 2 && display_local ){
|
}else if(position == 2 && display_local ){
|
||||||
|
@ -2373,7 +2399,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
||||||
|
|
||||||
public void updateTimeLine(RetrieveFeedsAsyncTask.Type type, int value){
|
public void updateTimeLine(RetrieveFeedsAsyncTask.Type type, int value){
|
||||||
|
|
||||||
if( type == RetrieveFeedsAsyncTask.Type.DIRECT ){
|
if( type == RetrieveFeedsAsyncTask.Type.DIRECT || type == RetrieveFeedsAsyncTask.Type.CONVERSATION){
|
||||||
if (tabLayout.getTabAt(2) != null && display_direct) {
|
if (tabLayout.getTabAt(2) != null && display_direct) {
|
||||||
View tabDirect = tabLayout.getTabAt(2).getCustomView();
|
View tabDirect = tabLayout.getTabAt(2).getCustomView();
|
||||||
assert tabDirect != null;
|
assert tabDirect != null;
|
||||||
|
|
|
@ -60,6 +60,7 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||||
HOME,
|
HOME,
|
||||||
LOCAL,
|
LOCAL,
|
||||||
DIRECT,
|
DIRECT,
|
||||||
|
CONVERSATION,
|
||||||
PUBLIC,
|
PUBLIC,
|
||||||
HASHTAG,
|
HASHTAG,
|
||||||
LIST,
|
LIST,
|
||||||
|
@ -152,6 +153,9 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||||
case DIRECT:
|
case DIRECT:
|
||||||
apiResponse = api.getDirectTimeline(max_id);
|
apiResponse = api.getDirectTimeline(max_id);
|
||||||
break;
|
break;
|
||||||
|
case CONVERSATION:
|
||||||
|
apiResponse = api.getConversationTimeline(max_id);
|
||||||
|
break;
|
||||||
case REMOTE_INSTANCE:
|
case REMOTE_INSTANCE:
|
||||||
if( this.name != null && this.remoteInstance != null){ //For Peertube channels
|
if( this.name != null && this.remoteInstance != null){ //For Peertube channels
|
||||||
apiResponse = api.getPeertubeChannelVideos(this.remoteInstance, this.name);
|
apiResponse = api.getPeertubeChannelVideos(this.remoteInstance, this.name);
|
||||||
|
|
|
@ -56,6 +56,7 @@ public class API {
|
||||||
private Attachment attachment;
|
private Attachment attachment;
|
||||||
private List<Account> accounts;
|
private List<Account> accounts;
|
||||||
private List<Status> statuses;
|
private List<Status> statuses;
|
||||||
|
private List<Conversation> conversations;
|
||||||
private int tootPerPage, accountPerPage, notificationPerPage;
|
private int tootPerPage, accountPerPage, notificationPerPage;
|
||||||
private int actionCode;
|
private int actionCode;
|
||||||
private String instance;
|
private String instance;
|
||||||
|
@ -495,6 +496,54 @@ public class API {
|
||||||
return getDirectTimeline(max_id, null, tootPerPage);
|
return getDirectTimeline(max_id, null, tootPerPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves conversation timeline for the account *synchronously*
|
||||||
|
* @param max_id String id max
|
||||||
|
* @return APIResponse
|
||||||
|
*/
|
||||||
|
public APIResponse getConversationTimeline( String max_id) {
|
||||||
|
return getConversationTimeline(max_id, null, tootPerPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves conversation timeline for the account *synchronously*
|
||||||
|
* @param max_id String id max
|
||||||
|
* @param since_id String since the id
|
||||||
|
* @param limit int limit - max value 40
|
||||||
|
* @return APIResponse
|
||||||
|
*/
|
||||||
|
private APIResponse getConversationTimeline(String max_id, String since_id, int limit) {
|
||||||
|
|
||||||
|
HashMap<String, String> params = new HashMap<>();
|
||||||
|
if (max_id != null)
|
||||||
|
params.put("max_id", max_id);
|
||||||
|
if (since_id != null)
|
||||||
|
params.put("since_id", since_id);
|
||||||
|
if (0 > limit || limit > 80)
|
||||||
|
limit = 80;
|
||||||
|
params.put("limit",String.valueOf(limit));
|
||||||
|
conversations = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||||
|
String response = httpsConnection.get(getAbsoluteUrl("/conversations"), 60, params, prefKeyOauthTokenT);
|
||||||
|
apiResponse.setSince_id(httpsConnection.getSince_id());
|
||||||
|
apiResponse.setMax_id(httpsConnection.getMax_id());
|
||||||
|
conversations = parseConversations(new JSONArray(response));
|
||||||
|
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||||
|
setError(e.getStatusCode(), e);
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (KeyManagementException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
apiResponse.setConversations(conversations);
|
||||||
|
return apiResponse;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves direct timeline for the account since an Id value *synchronously*
|
* Retrieves direct timeline for the account since an Id value *synchronously*
|
||||||
* @return APIResponse
|
* @return APIResponse
|
||||||
|
@ -2576,6 +2625,46 @@ public class API {
|
||||||
return howToVideo;
|
return howToVideo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse json response for several conversations
|
||||||
|
* @param jsonArray JSONArray
|
||||||
|
* @return List<Conversation>
|
||||||
|
*/
|
||||||
|
private List<Conversation> parseConversations(JSONArray jsonArray){
|
||||||
|
|
||||||
|
List<Conversation> conversations = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
int i = 0;
|
||||||
|
while (i < jsonArray.length() ){
|
||||||
|
|
||||||
|
JSONObject resobj = jsonArray.getJSONObject(i);
|
||||||
|
Conversation conversation = parseConversation(context, resobj);
|
||||||
|
i++;
|
||||||
|
conversations.add(conversation);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (JSONException e) {
|
||||||
|
setDefaultError(e);
|
||||||
|
}
|
||||||
|
return conversations;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse json response for unique conversation
|
||||||
|
* @param resobj JSONObject
|
||||||
|
* @return Conversation
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("InfiniteRecursion")
|
||||||
|
private Conversation parseConversation(Context context, JSONObject resobj) {
|
||||||
|
Conversation conversation = new Conversation();
|
||||||
|
try {
|
||||||
|
conversation.setId(resobj.get("id").toString());
|
||||||
|
conversation.setUnread(Boolean.parseBoolean(resobj.get("unread").toString()));
|
||||||
|
conversation.setAccounts(parseAccountResponse(resobj.getJSONArray("accounts")));
|
||||||
|
conversation.setLast_status(parseStatuses(context, resobj.getJSONObject("last_status")));
|
||||||
|
}catch (JSONException ignored) {}
|
||||||
|
return conversation;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Parse json response for several status
|
* Parse json response for several status
|
||||||
* @param jsonArray JSONArray
|
* @param jsonArray JSONArray
|
||||||
|
|
|
@ -28,6 +28,7 @@ public class APIResponse {
|
||||||
private List<Account> accounts = null;
|
private List<Account> accounts = null;
|
||||||
private List<Status> statuses = null;
|
private List<Status> statuses = null;
|
||||||
private List<Context> contexts = null;
|
private List<Context> contexts = null;
|
||||||
|
private List<Conversation> conversations = null;
|
||||||
private List<Notification> notifications = null;
|
private List<Notification> notifications = null;
|
||||||
private List<Relationship> relationships = null;
|
private List<Relationship> relationships = null;
|
||||||
private List<HowToVideo> howToVideos = null;
|
private List<HowToVideo> howToVideos = null;
|
||||||
|
@ -159,4 +160,12 @@ public class APIResponse {
|
||||||
public void setPeertubes(List<Peertube> peertubes) {
|
public void setPeertubes(List<Peertube> peertubes) {
|
||||||
this.peertubes = peertubes;
|
this.peertubes = peertubes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Conversation> getConversations() {
|
||||||
|
return conversations;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConversations(List<Conversation> conversations) {
|
||||||
|
this.conversations = conversations;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,7 @@ import fr.gouv.etalab.mastodon.asynctasks.RetrieveMissingFeedsAsyncTask;
|
||||||
import fr.gouv.etalab.mastodon.asynctasks.RetrievePeertubeSearchAsyncTask;
|
import fr.gouv.etalab.mastodon.asynctasks.RetrievePeertubeSearchAsyncTask;
|
||||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||||
|
import fr.gouv.etalab.mastodon.client.Entities.Conversation;
|
||||||
import fr.gouv.etalab.mastodon.client.Entities.Peertube;
|
import fr.gouv.etalab.mastodon.client.Entities.Peertube;
|
||||||
import fr.gouv.etalab.mastodon.client.Entities.RemoteInstance;
|
import fr.gouv.etalab.mastodon.client.Entities.RemoteInstance;
|
||||||
import fr.gouv.etalab.mastodon.drawers.PeertubeAdapter;
|
import fr.gouv.etalab.mastodon.drawers.PeertubeAdapter;
|
||||||
|
@ -366,6 +367,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
flag_loading = false;
|
flag_loading = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( type == RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE && peertubeAdapater != null){
|
if( type == RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE && peertubeAdapater != null){
|
||||||
int previousPosition = this.peertubes.size();
|
int previousPosition = this.peertubes.size();
|
||||||
if( max_id == null)
|
if( max_id == null)
|
||||||
|
@ -381,6 +383,14 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
firstLoad = false;
|
firstLoad = false;
|
||||||
flag_loading = false;
|
flag_loading = false;
|
||||||
}else {
|
}else {
|
||||||
|
//Add conversation in status
|
||||||
|
if( type == RetrieveFeedsAsyncTask.Type.CONVERSATION ){
|
||||||
|
List<Conversation> conversations = apiResponse.getConversations();
|
||||||
|
List<Status> statusesConversations = new ArrayList<>();
|
||||||
|
for( Conversation conversation: conversations)
|
||||||
|
statusesConversations.add(conversation.getLast_status());
|
||||||
|
apiResponse.setStatuses(statusesConversations);
|
||||||
|
}
|
||||||
int previousPosition = this.statuses.size();
|
int previousPosition = this.statuses.size();
|
||||||
List<Status> statuses = Helper.filterToots(context, apiResponse.getStatuses(), mutedAccount, type);
|
List<Status> statuses = Helper.filterToots(context, apiResponse.getStatuses(), mutedAccount, type);
|
||||||
List<Status> notFilteredStatuses = apiResponse.getStatuses();
|
List<Status> notFilteredStatuses = apiResponse.getStatuses();
|
||||||
|
|
|
@ -1188,34 +1188,23 @@ public class Helper {
|
||||||
|
|
||||||
|
|
||||||
final NavigationView navigationView = activity.findViewById(R.id.nav_view);
|
final NavigationView navigationView = activity.findViewById(R.id.nav_view);
|
||||||
navigationView.getMenu().clear();
|
|
||||||
MainActivity.lastNotificationId = null;
|
MainActivity.lastNotificationId = null;
|
||||||
MainActivity.lastHomeId = null;
|
MainActivity.lastHomeId = null;
|
||||||
navigationView.inflateMenu(R.menu.activity_main_drawer);
|
|
||||||
SQLiteDatabase db = Sqlite.getInstance(activity, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
SQLiteDatabase db = Sqlite.getInstance(activity, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||||
Account account = new AccountDAO(activity,db).getAccountByID(userID);
|
Account account = new AccountDAO(activity,db).getAccountByID(userID);
|
||||||
//Can happen when an account has been deleted and there is a click on an old notification
|
//Can happen when an account has been deleted and there is a click on an old notification
|
||||||
if( account == null)
|
if( account == null)
|
||||||
return;
|
return;
|
||||||
//Locked account can see follow request
|
|
||||||
if (account.isLocked()) {
|
|
||||||
navigationView.getMenu().findItem(R.id.nav_follow_request).setVisible(true);
|
|
||||||
} else {
|
|
||||||
navigationView.getMenu().findItem(R.id.nav_follow_request).setVisible(false);
|
|
||||||
}
|
|
||||||
SharedPreferences sharedpreferences = activity.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
SharedPreferences sharedpreferences = activity.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||||
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, account.getToken());
|
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, account.getToken());
|
||||||
editor.putString(Helper.PREF_KEY_ID, account.getId());
|
editor.putString(Helper.PREF_KEY_ID, account.getId());
|
||||||
editor.putString(Helper.PREF_INSTANCE, account.getInstance().trim());
|
editor.putString(Helper.PREF_INSTANCE, account.getInstance().trim());
|
||||||
editor.apply();
|
editor.apply();
|
||||||
activity.recreate();
|
Intent intent = activity.getIntent();
|
||||||
if( checkItem ) {
|
activity.finish();
|
||||||
Intent intent = new Intent(activity, MainActivity.class);
|
|
||||||
intent.putExtra(INTENT_ACTION, CHANGE_USER_INTENT);
|
|
||||||
activity.startActivity(intent);
|
activity.startActivity(intent);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("SameParameterValue")
|
@SuppressWarnings("SameParameterValue")
|
||||||
|
|
Loading…
Reference in New Issue