QuickBlox / quickblox-android-sdk

QuickBlox Android SDK includes code snippets with main use cases and framework JAR library.
BSD 3-Clause "New" or "Revised" License
417 stars 697 forks source link

Block/ Unblock is not working Properly #762

Closed Ahmadpashaquarterpi closed 2 years ago

Ahmadpashaquarterpi commented 3 years ago

I am using android sdk version: 3.9.11

Right now I am working on the block/unblock feature. but its not working properly.

it works properly as long as app is in the foreground, but when I close the app or move it to the Background. Privacy list stops working and blocked users can also send messages.

following is the code I am using:

private static String PRIVACY_LIST_NAME = "CHAZBIZ_LIST";

public static void updateAndApplyPrivacyList() {

    RealmResults<RealmQBFirebaseEntry> result = DatabaseService.getInstance().getEntriesByTypeAndStatus(BOTH, BLOCKED);

    QBPrivacyList qbPrivacyList = null;
    QBPrivacyListsManager qbPrivacyListsManager = QBChatService.getInstance().getPrivacyListsManager();

    if (qbPrivacyListsManager == null) {
        ToastUtils.shortToast("List Manager Unavailable");
        return;
    }

    try {
        if (!PRIVACY_LIST_NAME.isEmpty())
            qbPrivacyList = qbPrivacyListsManager.getPrivacyList(PRIVACY_LIST_NAME);
    } catch (SmackException.NotConnectedException e) {
        ToastUtils.shortToast("No Connection");
        //e.printStackTrace();
    } catch (XMPPException.XMPPErrorException e) {
        Log.d("Privacy List", "XMPP Error");
        //e.printStackTrace();
    } catch (SmackException.NoResponseException e) {
        ToastUtils.shortToast("No Response from Server");
        //e.printStackTrace();
    }

    if (qbPrivacyList != null) {
        try {

            qbPrivacyListsManager.declinePrivacyList();
            if (!PRIVACY_LIST_NAME.isEmpty())
                qbPrivacyListsManager.deletePrivacyList(PRIVACY_LIST_NAME);
            qbPrivacyList = null;
        } catch (SmackException.NotConnectedException e) {
            ToastUtils.shortToast("No Connection");
            //e.printStackTrace();
        } catch (XMPPException.XMPPErrorException e) {
            Log.d("Privacy List", "XMPP Error");
            //e.printStackTrace();
        } catch (SmackException.NoResponseException e) {
            ToastUtils.shortToast("No Response from Server");
            //e.printStackTrace();
        }
    }

    if (qbPrivacyList == null) { // CREATE NEW PRIVACY LIST
        qbPrivacyList = new QBPrivacyList();
        qbPrivacyList.setName(PRIVACY_LIST_NAME);
    }

    if (result != null) {

        ArrayList<QBPrivacyListItem> qbPrivacyListItems = new ArrayList<>();
        for (RealmQBFirebaseEntry entry : result) {
            QBPrivacyListItem qbPrivacyListItem = new QBPrivacyListItem();
            qbPrivacyListItem.setType(QBPrivacyListItem.Type.USER_ID);
            qbPrivacyListItem.setValueForType(String.valueOf(entry.getID()));
            qbPrivacyListItem.setAllow(false);
            qbPrivacyListItem.setMutualBlock(true);

            qbPrivacyListItems.add(qbPrivacyListItem);

        }

        qbPrivacyList.setItems(qbPrivacyListItems);

        try {
            if (qbPrivacyList.getItems().size() > 0) {
                qbPrivacyListsManager.createPrivacyList(qbPrivacyList);
                applyPrivacyList(PRIVACY_LIST_NAME);
            }
        } catch (SmackException.NotConnectedException e) {
            ToastUtils.shortToast("No Connection");
            //e.printStackTrace();
        } catch (XMPPException.XMPPErrorException e) {
            Log.d("Privacy List", "XMPP Error");
            //e.printStackTrace();
        } catch (SmackException.NoResponseException e) {
            ToastUtils.shortToast("No Response from Server");
            //e.printStackTrace();
        }
    }
}

private static void applyPrivacyList(String PRIVACY_LIST_NAME) {
    QBPrivacyListsManager qbPrivacyListsManager = QBChatService.getInstance().getPrivacyListsManager();

    if (qbPrivacyListsManager == null) {
        ToastUtils.shortToast("List Manager Unavailable");
        return;
    }

    try {
        qbPrivacyListsManager.applyPrivacyList(PRIVACY_LIST_NAME);
        //qbPrivacyListsManager.setPrivacyListAsDefault(PRIVACY_LIST_NAME);
    } catch (SmackException.NotConnectedException e) {
        ToastUtils.shortToast("No Connection");
        //e.printStackTrace();
    } catch (XMPPException.XMPPErrorException e) {
        Log.d("Privacy List", "XMPP Error");
        //e.printStackTrace();
    } catch (SmackException.NoResponseException e) {
        ToastUtils.shortToast("No Response from Server");
        //e.printStackTrace();
    }
}
vdovbnya-qb commented 3 years ago

@Ahmadpashaquarterpi Hello. Thanks for your issue. I checked this issue and was able to reproduce it. We are dealing with this problem. I'll let you know when there is new information. If you want more information contact the support team.

Ahmadpashaquarterpi commented 3 years ago

@vdovbnya-qb Thanks for the reply. Looking forward to solution as soon as possible.

Ahmadpashaquarterpi commented 3 years ago

Is this issue been resolved?

ghost commented 3 years ago

Hello @Ahmadpashaquarterpi ,

This is Nikolay from QuickBlox support.

Unfortunately, the issue hasn't been resolved. Our developers are still investigating it.

Once there is any news, I will update you.

Ahmadpashaquarterpi commented 3 years ago

Thanks @QB-nikolay-zolotarov

Please tell how much time is expected for it to be resolved?

ghost commented 3 years ago

@Ahmadpashaquarterpi You are most welcome.

Unfortunately, I cannot provide you with the exact time frames at this moment. ETA is 3 months.

ghost commented 2 years ago

@Ahmadpashaquarterpi the bug should be fixed now