From abd6fa1c289d8375de61639a8e9d29f8bf5e156a Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Fri, 9 Apr 2021 19:13:59 +0900 Subject: [PATCH 1/7] Null check. Fixes https://github.com/austinhuang0131/barinsta/issues/1021 --- .../viewholder/directmessages/DirectItemViewHolder.java | 5 +++-- app/src/main/java/awais/instagrabber/utils/DMUtils.java | 9 ++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemViewHolder.java index 96476b10..17a0956c 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemViewHolder.java @@ -112,6 +112,7 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder imple } public void bind(final int position, final DirectItem item) { + if (item == null) return; this.item = item; messageDirection = isSelf(item) ? MessageDirection.OUTGOING : MessageDirection.INCOMING; // Asynchronous binding causes some weird behaviour @@ -123,7 +124,7 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder imple setupLongClickListener(position, messageDirection); } - private void bindBase(final DirectItem item, final MessageDirection messageDirection, final int position) { + private void bindBase(@NonNull final DirectItem item, final MessageDirection messageDirection, final int position) { final FrameLayout.LayoutParams containerLayoutParams = (FrameLayout.LayoutParams) binding.container.getLayoutParams(); final DirectItemType itemType = item.getItemType(); setMessageDirectionGravity(messageDirection, containerLayoutParams); @@ -188,7 +189,7 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder imple containerLayoutParams.gravity = Gravity.CENTER; } - private void setMessageInfo(final DirectItem item, final MessageDirection messageDirection) { + private void setMessageInfo(@NonNull final DirectItem item, final MessageDirection messageDirection) { if (showMessageInfo()) { binding.messageInfo.setVisibility(View.VISIBLE); binding.deliveryStatus.setVisibility(messageDirection == MessageDirection.OUTGOING ? View.VISIBLE : View.GONE); diff --git a/app/src/main/java/awais/instagrabber/utils/DMUtils.java b/app/src/main/java/awais/instagrabber/utils/DMUtils.java index 12aa2e07..904a7055 100644 --- a/app/src/main/java/awais/instagrabber/utils/DMUtils.java +++ b/app/src/main/java/awais/instagrabber/utils/DMUtils.java @@ -23,18 +23,21 @@ import awais.instagrabber.repositories.responses.directmessages.DirectThreadLast import awais.instagrabber.repositories.responses.directmessages.RavenExpiringMediaActionSummary; public final class DMUtils { - public static boolean isRead(final DirectItem item, + public static boolean isRead(@NonNull final DirectItem item, @NonNull final Map lastSeenAt, - final List userIdsToCheck) { + @NonNull final List userIdsToCheck) { // Further check if directStory exists // if (read && directStory != null) { // read = false; // } + if (item == null) return false; return lastSeenAt.entrySet() .stream() .filter(entry -> userIdsToCheck.contains(entry.getKey())) .anyMatch(entry -> { - final String userLastSeenTsString = entry.getValue().getTimestamp(); + final DirectThreadLastSeenAt threadLastSeenAt = entry.getValue(); + if (threadLastSeenAt == null) return false; + final String userLastSeenTsString = threadLastSeenAt.getTimestamp(); if (userLastSeenTsString == null) return false; final long userTs = Long.parseLong(userLastSeenTsString); final long itemTs = item.getTimestamp(); From bb29e847f53bd56424cd6e91486ada7a977d07ab Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Fri, 9 Apr 2021 19:29:38 +0900 Subject: [PATCH 2/7] Check for all dm related values before initializing. Fixes https://github.com/austinhuang0131/barinsta/issues/1019 --- .../instagrabber/activities/MainActivity.java | 35 ++++++++++++++----- .../instagrabber/managers/InboxManager.java | 8 +++-- .../instagrabber/managers/ThreadManager.java | 6 ++-- 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/activities/MainActivity.java b/app/src/main/java/awais/instagrabber/activities/MainActivity.java index 268b9ca5..8882bed9 100644 --- a/app/src/main/java/awais/instagrabber/activities/MainActivity.java +++ b/app/src/main/java/awais/instagrabber/activities/MainActivity.java @@ -57,6 +57,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Deque; import java.util.List; +import java.util.UUID; import java.util.stream.Collectors; import awais.instagrabber.BuildConfig; @@ -85,8 +86,8 @@ import awais.instagrabber.utils.TextUtils; import awais.instagrabber.utils.Utils; import awais.instagrabber.utils.emoji.EmojiParser; import awais.instagrabber.viewmodels.AppStateViewModel; -import awais.instagrabber.webservices.RetrofitFactory; import awais.instagrabber.viewmodels.DirectInboxViewModel; +import awais.instagrabber.webservices.RetrofitFactory; import awais.instagrabber.webservices.SearchService; import retrofit2.Call; import retrofit2.Callback; @@ -137,9 +138,7 @@ public class MainActivity extends BaseLanguageActivity implements FragmentManage RetrofitFactory.setup(this); super.onCreate(savedInstanceState); binding = ActivityMainBinding.inflate(getLayoutInflater()); - final String cookie = settingsHelper.getString(Constants.COOKIE); - CookieUtils.setupCookies(cookie); - isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) != 0; + setupCookie(); if (settingsHelper.getBoolean(Constants.FLAG_SECURE)) getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE); setContentView(binding.getRoot()); @@ -165,7 +164,7 @@ public class MainActivity extends BaseLanguageActivity implements FragmentManage new ViewModelProvider(this).get(AppStateViewModel.class); // Just initiate the App state here final Intent intent = getIntent(); handleIntent(intent); - if (!TextUtils.isEmpty(cookie) && settingsHelper.getBoolean(Constants.CHECK_ACTIVITY)) { + if (isLoggedIn && settingsHelper.getBoolean(Constants.CHECK_ACTIVITY)) { bindActivityCheckerService(); } getSupportFragmentManager().addOnBackStackChangedListener(this); @@ -180,6 +179,26 @@ public class MainActivity extends BaseLanguageActivity implements FragmentManage initDmUnreadCount(); } + private void setupCookie() { + final String cookie = settingsHelper.getString(Constants.COOKIE); + long userId = 0; + String csrfToken = null; + if (!TextUtils.isEmpty(cookie)) { + userId = CookieUtils.getUserIdFromCookie(cookie); + csrfToken = CookieUtils.getCsrfTokenFromCookie(cookie); + } + if (TextUtils.isEmpty(cookie) || userId == 0 || TextUtils.isEmpty(csrfToken)) { + isLoggedIn = false; + return; + } + final String deviceUuid = settingsHelper.getString(Constants.DEVICE_UUID); + if (TextUtils.isEmpty(deviceUuid)) { + settingsHelper.putString(Constants.DEVICE_UUID, UUID.randomUUID().toString()); + } + CookieUtils.setupCookies(cookie); + isLoggedIn = true; + } + private void initDmService() { if (!isLoggedIn) return; final boolean enabled = settingsHelper.getBoolean(PreferenceKeys.PREF_ENABLE_DM_AUTO_REFRESH); @@ -916,9 +935,9 @@ public class MainActivity extends BaseLanguageActivity implements FragmentManage return currentTabs; } -// public boolean isNavRootInCurrentTabs(@IdRes final int navRootId) { -// return showBottomViewDestinations.stream().anyMatch(id -> id == navRootId); -// } + // public boolean isNavRootInCurrentTabs(@IdRes final int navRootId) { + // return showBottomViewDestinations.stream().anyMatch(id -> id == navRootId); + // } private void setNavBarDMUnreadCountBadge(final int unseenCount) { final BadgeDrawable badge = binding.bottomNavView.getOrCreateBadge(R.id.direct_messages_nav_graph); diff --git a/app/src/main/java/awais/instagrabber/managers/InboxManager.java b/app/src/main/java/awais/instagrabber/managers/InboxManager.java index 98e12b46..efca55f5 100644 --- a/app/src/main/java/awais/instagrabber/managers/InboxManager.java +++ b/app/src/main/java/awais/instagrabber/managers/InboxManager.java @@ -82,8 +82,12 @@ public final class InboxManager { final long userId = CookieUtils.getUserIdFromCookie(cookie); final String deviceUuid = settingsHelper.getString(Constants.DEVICE_UUID); final String csrfToken = CookieUtils.getCsrfTokenFromCookie(cookie); - if (TextUtils.isEmpty(csrfToken) || userId <= 0 || TextUtils.isEmpty(deviceUuid)) { - throw new IllegalArgumentException("User is not logged in!"); + if (TextUtils.isEmpty(csrfToken)) { + throw new IllegalArgumentException("csrfToken is empty!"); + } else if (userId == 0) { + throw new IllegalArgumentException("user id invalid"); + } else if (TextUtils.isEmpty(deviceUuid)) { + throw new IllegalArgumentException("device uuid is empty!"); } service = DirectMessagesService.getInstance(csrfToken, userId, deviceUuid); diff --git a/app/src/main/java/awais/instagrabber/managers/ThreadManager.java b/app/src/main/java/awais/instagrabber/managers/ThreadManager.java index 8efff504..c76728e3 100644 --- a/app/src/main/java/awais/instagrabber/managers/ThreadManager.java +++ b/app/src/main/java/awais/instagrabber/managers/ThreadManager.java @@ -156,9 +156,9 @@ public final class ThreadManager { viewerId = CookieUtils.getUserIdFromCookie(cookie); final String deviceUuid = settingsHelper.getString(Constants.DEVICE_UUID); final String csrfToken = CookieUtils.getCsrfTokenFromCookie(cookie); - if (TextUtils.isEmpty(csrfToken) || viewerId <= 0 || TextUtils.isEmpty(deviceUuid)) { - throw new IllegalArgumentException("User is not logged in!"); - } + // if (TextUtils.isEmpty(csrfToken) || viewerId <= 0 || TextUtils.isEmpty(deviceUuid)) { + // throw new IllegalArgumentException("User is not logged in!"); + // } service = DirectMessagesService.getInstance(csrfToken, viewerId, deviceUuid); mediaService = MediaService.getInstance(deviceUuid, csrfToken, viewerId); friendshipService = FriendshipService.getInstance(deviceUuid, csrfToken, viewerId); From 1fdd9077d5b776a121d78ea498ca000801345db6 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Fri, 9 Apr 2021 19:36:11 +0900 Subject: [PATCH 3/7] Remove invalid gifs before submitting to adapter. Fixes https://github.com/austinhuang0131/barinsta/issues/1013 --- .../viewmodels/GifPickerViewModel.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/viewmodels/GifPickerViewModel.java b/app/src/main/java/awais/instagrabber/viewmodels/GifPickerViewModel.java index dd014204..69450281 100644 --- a/app/src/main/java/awais/instagrabber/viewmodels/GifPickerViewModel.java +++ b/app/src/main/java/awais/instagrabber/viewmodels/GifPickerViewModel.java @@ -13,12 +13,17 @@ import java.io.IOException; import java.util.Collections; import java.util.List; import java.util.Locale; +import java.util.Objects; +import java.util.stream.Collectors; import awais.instagrabber.R; import awais.instagrabber.models.Resource; +import awais.instagrabber.repositories.responses.AnimatedMediaFixedHeight; import awais.instagrabber.repositories.responses.giphy.GiphyGif; +import awais.instagrabber.repositories.responses.giphy.GiphyGifImages; import awais.instagrabber.repositories.responses.giphy.GiphyGifResponse; import awais.instagrabber.repositories.responses.giphy.GiphyGifResults; +import awais.instagrabber.utils.TextUtils; import awais.instagrabber.webservices.GifService; import retrofit2.Call; import retrofit2.Callback; @@ -92,12 +97,25 @@ public class GifPickerViewModel extends ViewModel { final GiphyGifResults results = giphyGifResponse.getResults(); images.postValue(Resource.success( ImmutableList.builder() - .addAll(results.getGiphy() == null ? Collections.emptyList() : results.getGiphy()) - .addAll(results.getGiphyGifs() == null ? Collections.emptyList() : results.getGiphyGifs()) + .addAll(results.getGiphy() == null ? Collections.emptyList() : filterInvalid(results.getGiphy())) + .addAll(results.getGiphyGifs() == null ? Collections.emptyList() : filterInvalid(results.getGiphyGifs())) .build() )); } + private List filterInvalid(@NonNull final List giphyGifs) { + return giphyGifs.stream() + .filter(Objects::nonNull) + .filter(giphyGif -> { + final GiphyGifImages images = giphyGif.getImages(); + if (images == null) return false; + final AnimatedMediaFixedHeight fixedHeight = images.getFixedHeight(); + if (fixedHeight == null) return false; + return !TextUtils.isEmpty(fixedHeight.getWebp()); + }) + .collect(Collectors.toList()); + } + // @NonNull // private List getGiphyGifImages(@NonNull final List giphy) { // return giphy.stream() From f570ea6146401a41b32f74c79a8afd58ecf9e794 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Fri, 9 Apr 2021 19:51:37 +0900 Subject: [PATCH 4/7] Null checks. Fixes https://github.com/austinhuang0131/barinsta/issues/992 --- .../fragments/settings/MorePreferencesFragment.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/fragments/settings/MorePreferencesFragment.java b/app/src/main/java/awais/instagrabber/fragments/settings/MorePreferencesFragment.java index 8348123b..a07c9221 100644 --- a/app/src/main/java/awais/instagrabber/fragments/settings/MorePreferencesFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/settings/MorePreferencesFragment.java @@ -88,13 +88,17 @@ public class MorePreferencesFragment extends BasePreferencesFragment { public void onSuccess(@NonNull final List accounts) { if (!isLoggedIn) { if (accounts.size() > 0) { - accountCategory.addPreference(getAccountSwitcherPreference(null, context)); + final AccountSwitcherPreference preference = getAccountSwitcherPreference(null, context); + if (preference == null) return; + accountCategory.addPreference(preference); } // Need to show something to trigger login activity - accountCategory.addPreference(getPreference(R.string.add_account, R.drawable.ic_add, preference -> { + final Preference preference1 = getPreference(R.string.add_account, R.drawable.ic_add, preference -> { startActivityForResult(new Intent(getContext(), Login.class), Constants.LOGIN_RESULT_CODE); return true; - })); + }); + if (preference1 == null) return; + accountCategory.addPreference(preference1); } if (accounts.size() > 0) { accountCategory From 1c1e5f0654304a8bcb7361f3092e822d9f953c66 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Fri, 9 Apr 2021 19:54:38 +0900 Subject: [PATCH 5/7] Null check. Fixes https://github.com/austinhuang0131/barinsta/issues/991 --- .../fragments/StoryListViewerFragment.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/fragments/StoryListViewerFragment.java b/app/src/main/java/awais/instagrabber/fragments/StoryListViewerFragment.java index ee997c86..73efea84 100644 --- a/app/src/main/java/awais/instagrabber/fragments/StoryListViewerFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/StoryListViewerFragment.java @@ -24,6 +24,7 @@ import androidx.recyclerview.widget.LinearLayoutManager; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import awais.instagrabber.R; @@ -98,8 +99,7 @@ public final class StoryListViewerFragment extends Fragment implements SwipeRefr final Context context = getContext(); Toast.makeText(context, R.string.empty_list, Toast.LENGTH_SHORT).show(); } catch (Exception ignored) {} - } - else { + } else { endCursor = result.getNextCursor(); final List models = archivesViewModel.getList().getValue(); final List modelsCopy = models == null ? new ArrayList<>() : new ArrayList<>(models); @@ -198,7 +198,13 @@ public final class StoryListViewerFragment extends Fragment implements SwipeRefr adapter = new FeedStoriesListAdapter(clickListener); binding.rvStories.setLayoutManager(layoutManager); binding.rvStories.setAdapter(adapter); - feedStoriesViewModel.getList().observe(getViewLifecycleOwner(), adapter::submitList); + feedStoriesViewModel.getList().observe(getViewLifecycleOwner(), list -> { + if (list == null) { + adapter.submitList(Collections.emptyList()); + return; + } + adapter.submitList(list); + }); } else { if (actionBar != null) actionBar.setTitle(R.string.action_archive); final RecyclerLazyLoader lazyLoader = new RecyclerLazyLoader(layoutManager, (page, totalItemsCount) -> { From 977ccce22c04693599ea45a06b94ff3a6950a677 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Fri, 9 Apr 2021 19:57:56 +0900 Subject: [PATCH 6/7] Null checks. Fixes https://github.com/austinhuang0131/barinsta/issues/990 --- .../directmessages/DirectMessageThreadFragment.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java b/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java index 57f17cf2..73bf0244 100644 --- a/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java @@ -414,10 +414,14 @@ public class DirectMessageThreadFragment extends Fragment implements DirectReact case SUCCESS: Toast.makeText(context, R.string.marked_as_seen, Toast.LENGTH_SHORT).show(); case LOADING: - item.setEnabled(false); + if (item != null) { + item.setEnabled(false); + } break; case ERROR: - item.setEnabled(true); + if (item != null) { + item.setEnabled(true); + } if (resource.message != null) { Snackbar.make(context, binding.getRoot(), resource.message, Snackbar.LENGTH_LONG).show(); return; @@ -956,7 +960,9 @@ public class DirectMessageThreadFragment extends Fragment implements DirectReact } final DirectThread thread = threadLiveData.getValue(); if (thread == null) return; - markAsSeenMenuItem.setEnabled(!DMUtils.isRead(thread)); + if (markAsSeenMenuItem != null) { + markAsSeenMenuItem.setEnabled(!DMUtils.isRead(thread)); + } }); if (itemsAdapter == null) return; itemsAdapter.submitList(items, () -> { From 99431fd077776b1a8ac3d0ed9b6a37e298d9abe4 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Fri, 9 Apr 2021 20:05:18 +0900 Subject: [PATCH 7/7] Null checks. Fixes https://github.com/austinhuang0131/barinsta/issues/981 --- .../instagrabber/managers/ThreadManager.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/awais/instagrabber/managers/ThreadManager.java b/app/src/main/java/awais/instagrabber/managers/ThreadManager.java index c76728e3..5b84c97c 100644 --- a/app/src/main/java/awais/instagrabber/managers/ThreadManager.java +++ b/app/src/main/java/awais/instagrabber/managers/ThreadManager.java @@ -27,6 +27,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; @@ -564,6 +565,7 @@ public final class ThreadManager { private List addEmoji(final List reactionList, final String emoji, final boolean shouldReplaceIfAlreadyReacted) { + if (currentUser == null) return reactionList; final List temp = reactionList == null ? new ArrayList<>() : new ArrayList<>(reactionList); int index = -1; for (int i = 0; i < temp.size(); i++) { @@ -1311,6 +1313,7 @@ public final class ThreadManager { final MutableLiveData> data = new MutableLiveData<>(); final Call addUsersRequest = service.addUsers(threadId, users.stream() + .filter(Objects::nonNull) .map(User::getPk) .collect(Collectors.toList())); handleDetailsChangeRequest(data, addUsersRequest); @@ -1319,6 +1322,10 @@ public final class ThreadManager { public LiveData> removeMember(final User user) { final MutableLiveData> data = new MutableLiveData<>(); + if (user == null) { + data.postValue(Resource.error("user is null!", null)); + return data; + } final Call request = service.removeUsers(threadId, Collections.singleton(user.getPk())); request.enqueue(new Callback() { @Override @@ -1337,6 +1344,7 @@ public final class ThreadManager { leftUsersValue = Collections.emptyList(); } final List updatedActiveUsers = activeUsers.stream() + .filter(Objects::nonNull) .filter(u -> u.getPk() != user.getPk()) .collect(Collectors.toList()); final ImmutableList.Builder updatedLeftUsersBuilder = ImmutableList.builder().addAll(leftUsersValue); @@ -1357,12 +1365,14 @@ public final class ThreadManager { } public boolean isAdmin(final User user) { + if (user == null) return false; final List adminUserIdsValue = adminUserIds.getValue(); return adminUserIdsValue != null && adminUserIdsValue.contains(user.getPk()); } public LiveData> makeAdmin(final User user) { final MutableLiveData> data = new MutableLiveData<>(); + if (user == null) return data; if (isAdmin(user)) return data; final Call request = service.addAdmins(threadId, Collections.singleton(user.getPk())); request.enqueue(new Callback() { @@ -1399,6 +1409,7 @@ public final class ThreadManager { public LiveData> removeAdmin(final User user) { final MutableLiveData> data = new MutableLiveData<>(); + if (user == null) return data; if (!isAdmin(user)) return data; final Call request = service.removeAdmins(threadId, Collections.singleton(user.getPk())); request.enqueue(new Callback() { @@ -1411,6 +1422,7 @@ public final class ThreadManager { final List currentAdmins = adminUserIds.getValue(); if (currentAdmins == null) return; final List updatedAdminUserIds = currentAdmins.stream() + .filter(Objects::nonNull) .filter(userId1 -> userId1 != user.getPk()) .collect(Collectors.toList()); final DirectThread currentThread = ThreadManager.this.thread.getValue(); @@ -1583,6 +1595,7 @@ public final class ThreadManager { public LiveData> blockUser(final User user) { final MutableLiveData> data = new MutableLiveData<>(); + if (user == null) return data; friendshipService.block(user.getPk(), new ServiceCallback() { @Override public void onSuccess(final FriendshipChangeResponse result) { @@ -1600,6 +1613,7 @@ public final class ThreadManager { public LiveData> unblockUser(final User user) { final MutableLiveData> data = new MutableLiveData<>(); + if (user == null) return data; friendshipService.unblock(user.getPk(), new ServiceCallback() { @Override public void onSuccess(final FriendshipChangeResponse result) { @@ -1617,6 +1631,7 @@ public final class ThreadManager { public LiveData> restrictUser(final User user) { final MutableLiveData> data = new MutableLiveData<>(); + if (user == null) return data; friendshipService.toggleRestrict(user.getPk(), true, new ServiceCallback() { @Override public void onSuccess(final FriendshipRestrictResponse result) { @@ -1634,6 +1649,7 @@ public final class ThreadManager { public LiveData> unRestrictUser(final User user) { final MutableLiveData> data = new MutableLiveData<>(); + if (user == null) return data; friendshipService.toggleRestrict(user.getPk(), false, new ServiceCallback() { @Override public void onSuccess(final FriendshipRestrictResponse result) { @@ -1654,7 +1670,10 @@ public final class ThreadManager { data.postValue(Resource.loading(null)); final Call approveUsersRequest = service .approveParticipantRequests(threadId, - users.stream().map(User::getPk).collect(Collectors.toList())); + users.stream() + .filter(Objects::nonNull) + .map(User::getPk) + .collect(Collectors.toList())); handleDetailsChangeRequest(data, approveUsersRequest, () -> pendingUserApproveDenySuccessAction(users)); return data; } @@ -1811,6 +1830,7 @@ public final class ThreadManager { @Override public void onResponse(@NonNull final Call call, @NonNull final Response response) { + if (currentUser == null) return; if (!response.isSuccessful()) { handleErrorBody(call, response, data); return;