Fix notification with polls

This commit is contained in:
tom79 2019-03-30 16:43:03 +01:00
parent 881db26670
commit 6f205f3214
4 changed files with 25 additions and 5 deletions

View File

@ -58,7 +58,7 @@ public class ManagePollAsyncTask extends AsyncTask<Void, Void, Void> {
if (type == type_s.SUBMIT){
poll = new API(contextReference.get()).submiteVote(status.getPoll().getId(),choices);
}else if( type == type_s.REFRESH){
poll = new API(contextReference.get()).getPoll(status.getPoll().getId());
poll = new API(contextReference.get()).getPoll(status);
}
return null;
}

View File

@ -78,6 +78,8 @@ import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
import static fr.gouv.etalab.mastodon.client.API.StatusAction.REFRESHPOLL;
/**
* Created by Thomas on 23/04/2017.
@ -2212,13 +2214,21 @@ public class API {
/**
* Public api call to refresh a poll
* @param pollId
* @return
* @param status Status
* @return Poll
*/
public Poll getPoll(String pollId){
public Poll getPoll(Status status){
try {
HttpsConnection httpsConnection = new HttpsConnection(context);
String response = httpsConnection.get(getAbsoluteUrl(String.format("/polls/%s", pollId)), 60, null, prefKeyOauthTokenT);
String response = httpsConnection.get(getAbsoluteUrl(String.format("/polls/%s", status.getPoll().getId())), 60, null, prefKeyOauthTokenT);
Poll poll = parsePoll(context, new JSONObject(response));
Bundle b = new Bundle();
b.putParcelable("poll", poll);
b.putParcelable("status", status);
b.putSerializable("action", REFRESHPOLL);
Intent intentBC = new Intent(Helper.RECEIVE_ACTION);
intentBC.putExtras(b);
LocalBroadcastManager.getInstance(context).sendBroadcast(intentBC);
return parsePoll(context, new JSONObject(response));
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);

View File

@ -49,6 +49,7 @@ import fr.gouv.etalab.mastodon.client.API;
import fr.gouv.etalab.mastodon.client.APIResponse;
import fr.gouv.etalab.mastodon.client.Entities.Account;
import fr.gouv.etalab.mastodon.client.Entities.Notification;
import fr.gouv.etalab.mastodon.client.Entities.Poll;
import fr.gouv.etalab.mastodon.client.Entities.Status;
import fr.gouv.etalab.mastodon.drawers.NotificationsListAdapter;
import fr.gouv.etalab.mastodon.helper.Helper;
@ -156,6 +157,10 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
Bundle b = intent.getExtras();
assert b != null;
Status status = b.getParcelable("status");
Poll poll = b.getParcelable("poll");
if (poll != null && status != null){
status.setPoll(poll);
}
API.StatusAction statusAction = (API.StatusAction) b.getSerializable("action");
if (status != null) {
notificationsListAdapter.notifyNotificationWithActionChanged(statusAction, status);

View File

@ -58,6 +58,7 @@ import fr.gouv.etalab.mastodon.client.APIResponse;
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.Poll;
import fr.gouv.etalab.mastodon.client.Entities.RemoteInstance;
import fr.gouv.etalab.mastodon.client.Entities.Status;
import fr.gouv.etalab.mastodon.client.Entities.TagTimeline;
@ -244,6 +245,10 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
Bundle b = intent.getExtras();
assert b != null;
Status status = b.getParcelable("status");
Poll poll = b.getParcelable("poll");
if (poll != null && status != null){
status.setPoll(poll);
}
API.StatusAction statusAction = (API.StatusAction) b.getSerializable("action");
if( status != null && statusListAdapter != null) {
statusListAdapter.notifyStatusWithActionChanged(statusAction, status);