Get number of pending calls only if call system is available

This commit is contained in:
Pierre HUBERT 2019-02-23 13:33:19 +01:00
parent b1170d9075
commit 18c8d7e391
2 changed files with 10 additions and 4 deletions

View File

@ -44,16 +44,19 @@ public class NotificationsHelper {
/**
* Get the notifications count
*
* @param include_calls Specify whether pending calls should be included or not in the count
* @return Notifications count / NULL in case of failure
*/
@Nullable
public NotificationsCount pullCount(){
public NotificationsCount pullCount(boolean include_calls){
//Perform an API request
APIRequest params = new APIRequest(mContext,
"notifications/count_all_news");
params.addBoolean("friends_request", true);
params.addBoolean("include_calls", true);
if(include_calls)
params.addBoolean("include_calls", true);
//Try to perform the request and parse results
try {
@ -66,7 +69,9 @@ public class NotificationsHelper {
res.setNotificationsCount(object.getInt("notifications"));
res.setConversationsCount(object.getInt("conversations"));
res.setFriendsRequestsCount(object.getInt("friends_request"));
res.setPendingCalls(object.getInt("calls"));
if(include_calls)
res.setPendingCalls(object.getInt("calls"));
return res;

View File

@ -14,6 +14,7 @@ import android.util.Log;
import org.communiquons.android.comunic.client.R;
import org.communiquons.android.comunic.client.data.helpers.AccountHelper;
import org.communiquons.android.comunic.client.data.helpers.CallsHelper;
import org.communiquons.android.comunic.client.data.models.NotificationsCount;
import org.communiquons.android.comunic.client.data.helpers.NotificationsHelper;
import org.communiquons.android.comunic.client.data.utils.PreferencesUtils;
@ -119,7 +120,7 @@ public class NotificationsService extends IntentService {
}
//Pull the number of notifications
NotificationsCount count = mNotifHelper.pullCount();
NotificationsCount count = mNotifHelper.pullCount(CallsHelper.IsCallSystemAvailable());
//Check for error
if(count == null){