Removes notifications coming from one of the accounts set in the app.

This commit is contained in:
tom79 2017-08-29 16:36:40 +02:00
parent e27b3dad58
commit 71d533dadf
1 changed files with 25 additions and 9 deletions

View File

@ -292,6 +292,11 @@ public class StreamingService extends Service implements OnRetrieveStreamingInte
editor.apply(); editor.apply();
}else if(event == StreamingUserAsyncTask.EventStreaming.UPDATE ){ }else if(event == StreamingUserAsyncTask.EventStreaming.UPDATE ){
List<Account> accounts = new AccountDAO(getApplicationContext(),db).getAllAccount();
//It means there is no user in DB.
if( accounts == null )
return;
//lastePreviousContent contains the content of the last notification, if it was a mention it will avoid to push two notifications //lastePreviousContent contains the content of the last notification, if it was a mention it will avoid to push two notifications
if( account == null || (lastePreviousContent != null && lastePreviousContent.equals(status.getContent()))) { //troubles when getting the account if( account == null || (lastePreviousContent != null && lastePreviousContent.equals(status.getContent()))) { //troubles when getting the account
notify = false; notify = false;
@ -300,15 +305,26 @@ public class StreamingService extends Service implements OnRetrieveStreamingInte
notify = false; notify = false;
}else { }else {
notify = true; notify = true;
intent = new Intent(getApplicationContext(), MainActivity.class); //Retrieve users in db that owner has, and if the toot matches one of them we don't notify
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); for (Account act_tmp: accounts) {
intent.putExtra(INTENT_ACTION, HOME_TIMELINE_INTENT); String acct_from = status.getAccount().getAcct().trim();
intent.putExtra(PREF_KEY_ID, userId); String userid_from = status.getAccount().getId().trim();
long notif_id = Long.parseLong(userId); if( isCurrentAccountLoggedIn(acct_from, userid_from)) {
notificationId = ((notif_id + 2) > 2147483647) ? (int) (2147483647 - notif_id - 2) : (int) (notif_id + 2); notify = false;
SharedPreferences.Editor editor = sharedpreferences.edit(); break;
editor.putString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, status.getId()); }
editor.apply(); }
if( notify) {
intent = new Intent(getApplicationContext(), MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(INTENT_ACTION, HOME_TIMELINE_INTENT);
intent.putExtra(PREF_KEY_ID, userId);
long notif_id = Long.parseLong(userId);
notificationId = ((notif_id + 2) > 2147483647) ? (int) (2147483647 - notif_id - 2) : (int) (notif_id + 2);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, status.getId());
editor.apply();
}
} }
} }
if( notify){ if( notify){