1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-22 14:47:29 +00:00

Check for all dm related values before initializing. Fixes https://github.com/austinhuang0131/barinsta/issues/1019

This commit is contained in:
Ammar Githam 2021-04-09 19:29:38 +09:00
parent abd6fa1c28
commit bb29e847f5
3 changed files with 36 additions and 13 deletions

View File

@ -57,6 +57,7 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Deque; import java.util.Deque;
import java.util.List; import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import awais.instagrabber.BuildConfig; import awais.instagrabber.BuildConfig;
@ -85,8 +86,8 @@ import awais.instagrabber.utils.TextUtils;
import awais.instagrabber.utils.Utils; import awais.instagrabber.utils.Utils;
import awais.instagrabber.utils.emoji.EmojiParser; import awais.instagrabber.utils.emoji.EmojiParser;
import awais.instagrabber.viewmodels.AppStateViewModel; import awais.instagrabber.viewmodels.AppStateViewModel;
import awais.instagrabber.webservices.RetrofitFactory;
import awais.instagrabber.viewmodels.DirectInboxViewModel; import awais.instagrabber.viewmodels.DirectInboxViewModel;
import awais.instagrabber.webservices.RetrofitFactory;
import awais.instagrabber.webservices.SearchService; import awais.instagrabber.webservices.SearchService;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.Callback; import retrofit2.Callback;
@ -137,9 +138,7 @@ public class MainActivity extends BaseLanguageActivity implements FragmentManage
RetrofitFactory.setup(this); RetrofitFactory.setup(this);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
binding = ActivityMainBinding.inflate(getLayoutInflater()); binding = ActivityMainBinding.inflate(getLayoutInflater());
final String cookie = settingsHelper.getString(Constants.COOKIE); setupCookie();
CookieUtils.setupCookies(cookie);
isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) != 0;
if (settingsHelper.getBoolean(Constants.FLAG_SECURE)) if (settingsHelper.getBoolean(Constants.FLAG_SECURE))
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
setContentView(binding.getRoot()); 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 new ViewModelProvider(this).get(AppStateViewModel.class); // Just initiate the App state here
final Intent intent = getIntent(); final Intent intent = getIntent();
handleIntent(intent); handleIntent(intent);
if (!TextUtils.isEmpty(cookie) && settingsHelper.getBoolean(Constants.CHECK_ACTIVITY)) { if (isLoggedIn && settingsHelper.getBoolean(Constants.CHECK_ACTIVITY)) {
bindActivityCheckerService(); bindActivityCheckerService();
} }
getSupportFragmentManager().addOnBackStackChangedListener(this); getSupportFragmentManager().addOnBackStackChangedListener(this);
@ -180,6 +179,26 @@ public class MainActivity extends BaseLanguageActivity implements FragmentManage
initDmUnreadCount(); 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() { private void initDmService() {
if (!isLoggedIn) return; if (!isLoggedIn) return;
final boolean enabled = settingsHelper.getBoolean(PreferenceKeys.PREF_ENABLE_DM_AUTO_REFRESH); final boolean enabled = settingsHelper.getBoolean(PreferenceKeys.PREF_ENABLE_DM_AUTO_REFRESH);
@ -916,9 +935,9 @@ public class MainActivity extends BaseLanguageActivity implements FragmentManage
return currentTabs; return currentTabs;
} }
// public boolean isNavRootInCurrentTabs(@IdRes final int navRootId) { // public boolean isNavRootInCurrentTabs(@IdRes final int navRootId) {
// return showBottomViewDestinations.stream().anyMatch(id -> id == navRootId); // return showBottomViewDestinations.stream().anyMatch(id -> id == navRootId);
// } // }
private void setNavBarDMUnreadCountBadge(final int unseenCount) { private void setNavBarDMUnreadCountBadge(final int unseenCount) {
final BadgeDrawable badge = binding.bottomNavView.getOrCreateBadge(R.id.direct_messages_nav_graph); final BadgeDrawable badge = binding.bottomNavView.getOrCreateBadge(R.id.direct_messages_nav_graph);

View File

@ -82,8 +82,12 @@ public final class InboxManager {
final long userId = CookieUtils.getUserIdFromCookie(cookie); final long userId = CookieUtils.getUserIdFromCookie(cookie);
final String deviceUuid = settingsHelper.getString(Constants.DEVICE_UUID); final String deviceUuid = settingsHelper.getString(Constants.DEVICE_UUID);
final String csrfToken = CookieUtils.getCsrfTokenFromCookie(cookie); final String csrfToken = CookieUtils.getCsrfTokenFromCookie(cookie);
if (TextUtils.isEmpty(csrfToken) || userId <= 0 || TextUtils.isEmpty(deviceUuid)) { if (TextUtils.isEmpty(csrfToken)) {
throw new IllegalArgumentException("User is not logged in!"); 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); service = DirectMessagesService.getInstance(csrfToken, userId, deviceUuid);

View File

@ -156,9 +156,9 @@ public final class ThreadManager {
viewerId = CookieUtils.getUserIdFromCookie(cookie); viewerId = CookieUtils.getUserIdFromCookie(cookie);
final String deviceUuid = settingsHelper.getString(Constants.DEVICE_UUID); final String deviceUuid = settingsHelper.getString(Constants.DEVICE_UUID);
final String csrfToken = CookieUtils.getCsrfTokenFromCookie(cookie); final String csrfToken = CookieUtils.getCsrfTokenFromCookie(cookie);
if (TextUtils.isEmpty(csrfToken) || viewerId <= 0 || TextUtils.isEmpty(deviceUuid)) { // if (TextUtils.isEmpty(csrfToken) || viewerId <= 0 || TextUtils.isEmpty(deviceUuid)) {
throw new IllegalArgumentException("User is not logged in!"); // throw new IllegalArgumentException("User is not logged in!");
} // }
service = DirectMessagesService.getInstance(csrfToken, viewerId, deviceUuid); service = DirectMessagesService.getInstance(csrfToken, viewerId, deviceUuid);
mediaService = MediaService.getInstance(deviceUuid, csrfToken, viewerId); mediaService = MediaService.getInstance(deviceUuid, csrfToken, viewerId);
friendshipService = FriendshipService.getInstance(deviceUuid, csrfToken, viewerId); friendshipService = FriendshipService.getInstance(deviceUuid, csrfToken, viewerId);