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,15 +44,18 @@ public class NotificationsHelper {
/** /**
* Get the notifications count * 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 * @return Notifications count / NULL in case of failure
*/ */
@Nullable @Nullable
public NotificationsCount pullCount(){ public NotificationsCount pullCount(boolean include_calls){
//Perform an API request //Perform an API request
APIRequest params = new APIRequest(mContext, APIRequest params = new APIRequest(mContext,
"notifications/count_all_news"); "notifications/count_all_news");
params.addBoolean("friends_request", true); params.addBoolean("friends_request", true);
if(include_calls)
params.addBoolean("include_calls", true); params.addBoolean("include_calls", true);
//Try to perform the request and parse results //Try to perform the request and parse results
@ -66,6 +69,8 @@ public class NotificationsHelper {
res.setNotificationsCount(object.getInt("notifications")); res.setNotificationsCount(object.getInt("notifications"));
res.setConversationsCount(object.getInt("conversations")); res.setConversationsCount(object.getInt("conversations"));
res.setFriendsRequestsCount(object.getInt("friends_request")); res.setFriendsRequestsCount(object.getInt("friends_request"));
if(include_calls)
res.setPendingCalls(object.getInt("calls")); res.setPendingCalls(object.getInt("calls"));
return res; 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.R;
import org.communiquons.android.comunic.client.data.helpers.AccountHelper; 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.models.NotificationsCount;
import org.communiquons.android.comunic.client.data.helpers.NotificationsHelper; import org.communiquons.android.comunic.client.data.helpers.NotificationsHelper;
import org.communiquons.android.comunic.client.data.utils.PreferencesUtils; import org.communiquons.android.comunic.client.data.utils.PreferencesUtils;
@ -119,7 +120,7 @@ public class NotificationsService extends IntentService {
} }
//Pull the number of notifications //Pull the number of notifications
NotificationsCount count = mNotifHelper.pullCount(); NotificationsCount count = mNotifHelper.pullCount(CallsHelper.IsCallSystemAvailable());
//Check for error //Check for error
if(count == null){ if(count == null){