1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-26 00:27:30 +00:00

disable btndm

This commit is contained in:
Austin Huang 2021-02-13 13:26:02 -05:00
parent 06a6b07a53
commit c6bbc621f7
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
4 changed files with 83 additions and 62 deletions

View File

@ -11,7 +11,7 @@ android {
targetSdkVersion 29 targetSdkVersion 29
versionCode 58 versionCode 58
versionName '19.1.0' versionName '19.1.0-a1'
multiDexEnabled true multiDexEnabled true

View File

@ -3,77 +3,82 @@ package awais.instagrabber.asyncs;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.util.Log; import android.util.Log;
import org.json.JSONObject; import androidx.annotation.NonNull;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.net.HttpURLConnection; import java.io.IOException;
import java.net.URL; import java.util.Collections;
import java.util.Locale;
import awais.instagrabber.repositories.responses.directmessages.DirectThread;
import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.CookieUtils; import awais.instagrabber.utils.CookieUtils;
import awais.instagrabber.utils.NetworkUtils; import awais.instagrabber.utils.NetworkUtils;
import awais.instagrabber.utils.Utils; import awais.instagrabber.utils.Utils;
import awais.instagrabber.webservices.DirectMessagesService;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import static awais.instagrabber.utils.Utils.settingsHelper; import static awais.instagrabber.utils.Utils.settingsHelper;
public class CreateThreadAction extends AsyncTask<Void, Void, String> { public class CreateThreadAction extends AsyncTask<Void, Void, Void> {
private static final String TAG = "CommentAction"; private static final String TAG = "CommentAction";
private final String cookie; private final String cookie;
private final long userId; private final long userId;
private final OnTaskCompleteListener onTaskCompleteListener; private final OnTaskCompleteListener onTaskCompleteListener;
private final DirectMessagesService directMessagesService;
public CreateThreadAction(final String cookie, final long userId, final OnTaskCompleteListener onTaskCompleteListener) { public CreateThreadAction(final String cookie, final long userId, final OnTaskCompleteListener onTaskCompleteListener) {
this.cookie = cookie; this.cookie = cookie;
this.userId = userId; this.userId = userId;
this.onTaskCompleteListener = onTaskCompleteListener; this.onTaskCompleteListener = onTaskCompleteListener;
directMessagesService = DirectMessagesService.getInstance(CookieUtils.getCsrfTokenFromCookie(cookie),
CookieUtils.getUserIdFromCookie(cookie),
Utils.settingsHelper.getString(Constants.DEVICE_UUID));
} }
protected String doInBackground(Void... lmao) { protected Void doInBackground(Void... lmao) {
final String url = "https://i.instagram.com/api/v1/direct_v2/create_group_thread/"; final Call<DirectThread> createThreadRequest = directMessagesService.createThread(Collections.singletonList(userId), null);
HttpURLConnection urlConnection = null; createThreadRequest.enqueue(new Callback<DirectThread>() {
@Override
public void onResponse(@NonNull final Call<DirectThread> call, @NonNull final Response<DirectThread> response) {
if (!response.isSuccessful()) {
if (response.errorBody() != null) {
try { try {
urlConnection = (HttpURLConnection) new URL(url).openConnection(); final String string = response.errorBody().string();
urlConnection.setRequestMethod("POST"); final String msg = String.format(Locale.US,
urlConnection.setRequestProperty("User-Agent", Utils.settingsHelper.getString(Constants.APP_UA)); "onResponse: url: %s, responseCode: %d, errorBody: %s",
urlConnection.setUseCaches(false); call.request().url().toString(),
final String urlParameters = Utils.sign("{\"_csrftoken\":\"" + cookie.split("csrftoken=")[1].split(";")[0] response.code(),
+ "\",\"_uid\":\"" + CookieUtils.getUserIdFromCookie(cookie) string);
+ "\",\"__uuid\":\"" + settingsHelper.getString(Constants.DEVICE_UUID) Log.e(TAG, msg);
+ "\",\"recipient_users\":\"[" + userId // <- string of array of number (not joking) } catch (IOException e) {
+ "]\"}"); Log.e(TAG, "onResponse: ", e);
urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
if (urlParameters != null) {
urlConnection.setRequestProperty("Content-Length", "" + urlParameters.getBytes().length);
}
urlConnection.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(urlConnection.getOutputStream());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();
urlConnection.connect();
if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {
return new JSONObject(NetworkUtils.readFromConnection(urlConnection)).getString("thread_id");
}
} catch (Throwable ex) {
Log.e(TAG, "reply (CT): " + ex);
} finally {
if (urlConnection != null) {
urlConnection.disconnect();
} }
} }
return null; Log.e(TAG, "onResponse: request was not successful and response error body was null");
}
onTaskCompleteListener.onTaskComplete(response.body());
if (response.body() == null) {
Log.e(TAG, "onResponse: thread is null");
}
} }
@Override @Override
protected void onPostExecute(final String threadId) { public void onFailure(@NonNull final Call<DirectThread> call, @NonNull final Throwable t) {
if (threadId == null || onTaskCompleteListener == null) { onTaskCompleteListener.onTaskComplete(null);
return;
} }
onTaskCompleteListener.onTaskComplete(threadId); });
return null;
} }
// @Override
// protected void onPostExecute() {
// }
public interface OnTaskCompleteListener { public interface OnTaskCompleteListener {
void onTaskComplete(final String threadId); void onTaskComplete(final DirectThread thread);
} }
} }

View File

@ -216,10 +216,14 @@ public class StoryViewerFragment extends Fragment {
new AlertDialog.Builder(context) new AlertDialog.Builder(context)
.setTitle(R.string.reply_story) .setTitle(R.string.reply_story)
.setView(input) .setView(input)
.setPositiveButton(R.string.confirm, (d, w) -> new CreateThreadAction(cookie, currentStory.getUserId(), threadId -> { .setPositiveButton(R.string.confirm, (d, w) -> new CreateThreadAction(cookie, currentStory.getUserId(), thread -> {
if (thread == null) {
Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show();
return;
}
try { try {
final Call<DirectThreadBroadcastResponse> request = directMessagesService final Call<DirectThreadBroadcastResponse> request = directMessagesService
.broadcastStoryReply(BroadcastOptions.ThreadIdOrUserIds.of(threadId), .broadcastStoryReply(BroadcastOptions.ThreadIdOrUserIds.of(thread.getThreadId()),
input.getText().toString(), input.getText().toString(),
currentStory.getStoryMediaId(), currentStory.getStoryMediaId(),
String.valueOf(currentStory.getUserId())); String.valueOf(currentStory.getUserId()));

View File

@ -56,6 +56,7 @@ import awais.instagrabber.R;
import awais.instagrabber.activities.MainActivity; import awais.instagrabber.activities.MainActivity;
import awais.instagrabber.adapters.FeedAdapterV2; import awais.instagrabber.adapters.FeedAdapterV2;
import awais.instagrabber.adapters.HighlightsAdapter; import awais.instagrabber.adapters.HighlightsAdapter;
import awais.instagrabber.asyncs.CreateThreadAction;
import awais.instagrabber.asyncs.ProfileFetcher; import awais.instagrabber.asyncs.ProfileFetcher;
import awais.instagrabber.asyncs.ProfilePostFetchService; import awais.instagrabber.asyncs.ProfilePostFetchService;
import awais.instagrabber.asyncs.UsernameFetcher; import awais.instagrabber.asyncs.UsernameFetcher;
@ -305,9 +306,9 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
final String deviceUuid = Utils.settingsHelper.getString(Constants.DEVICE_UUID); final String deviceUuid = Utils.settingsHelper.getString(Constants.DEVICE_UUID);
final String csrfToken = CookieUtils.getCsrfTokenFromCookie(cookie); final String csrfToken = CookieUtils.getCsrfTokenFromCookie(cookie);
fragmentActivity = (MainActivity) requireActivity(); fragmentActivity = (MainActivity) requireActivity();
friendshipService = FriendshipService.getInstance(deviceUuid, csrfToken, userId); friendshipService = isLoggedIn ? FriendshipService.getInstance(deviceUuid, csrfToken, userId) : null;
storiesService = StoriesService.getInstance(); storiesService = isLoggedIn ? StoriesService.getInstance() : null;
mediaService = MediaService.getInstance(null, null, 0); mediaService = isLoggedIn ? MediaService.getInstance(null, null, 0) : null;
accountRepository = AccountRepository.getInstance(AccountDataSource.getInstance(getContext())); accountRepository = AccountRepository.getInstance(AccountDataSource.getInstance(getContext()));
favoriteRepository = FavoriteRepository.getInstance(FavoriteDataSource.getInstance(getContext())); favoriteRepository = FavoriteRepository.getInstance(FavoriteDataSource.getInstance(getContext()));
setHasOptionsMenu(true); setHasOptionsMenu(true);
@ -802,18 +803,19 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
private void setupButtons(final long profileId, final long myId) { private void setupButtons(final long profileId, final long myId) {
profileDetailsBinding.btnTagged.setVisibility(isReallyPrivate() ? View.GONE : View.VISIBLE); profileDetailsBinding.btnTagged.setVisibility(isReallyPrivate() ? View.GONE : View.VISIBLE);
profileDetailsBinding.btnDM.setVisibility(View.GONE); // temporary measure
if (isLoggedIn) { if (isLoggedIn) {
if (Objects.equals(profileId, myId)) { if (Objects.equals(profileId, myId)) {
profileDetailsBinding.btnTagged.setVisibility(View.VISIBLE); profileDetailsBinding.btnTagged.setVisibility(View.VISIBLE);
profileDetailsBinding.btnSaved.setVisibility(View.VISIBLE); profileDetailsBinding.btnSaved.setVisibility(View.VISIBLE);
profileDetailsBinding.btnLiked.setVisibility(View.VISIBLE); profileDetailsBinding.btnLiked.setVisibility(View.VISIBLE);
profileDetailsBinding.btnDM.setVisibility(View.GONE); // profileDetailsBinding.btnDM.setVisibility(View.GONE);
profileDetailsBinding.btnSaved.setText(R.string.saved); profileDetailsBinding.btnSaved.setText(R.string.saved);
return; return;
} }
profileDetailsBinding.btnSaved.setVisibility(View.GONE); profileDetailsBinding.btnSaved.setVisibility(View.GONE);
profileDetailsBinding.btnLiked.setVisibility(View.GONE); profileDetailsBinding.btnLiked.setVisibility(View.GONE);
profileDetailsBinding.btnDM.setVisibility(View.VISIBLE); // maybe there is a judgment mechanism? // profileDetailsBinding.btnDM.setVisibility(View.VISIBLE);
profileDetailsBinding.btnFollow.setVisibility(View.VISIBLE); profileDetailsBinding.btnFollow.setVisibility(View.VISIBLE);
final Context context = getContext(); final Context context = getContext();
if (context == null) return; if (context == null) return;
@ -977,17 +979,27 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
PostItemType.TAGGED); PostItemType.TAGGED);
NavHostFragment.findNavController(this).navigate(action); NavHostFragment.findNavController(this).navigate(action);
}); });
profileDetailsBinding.btnDM.setOnClickListener(v -> { // profileDetailsBinding.btnDM.setOnClickListener(v -> {
profileDetailsBinding.btnDM.setEnabled(false); // profileDetailsBinding.btnDM.setEnabled(false);
// new CreateThreadAction(cookie, profileModel.getPk(), threadId -> { // new CreateThreadAction(cookie, profileModel.getPk(), thread -> {
// if (isAdded()) { // if (thread == null) {
// final NavDirections action = ProfileFragmentDirections // Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show();
// .actionProfileFragmentToDMThreadFragment(threadId, profileModel.getUsername()); // profileDetailsBinding.btnDM.setEnabled(true);
// NavHostFragment.findNavController(this).navigate(action); // return;
// } // }
// profileDetailsBinding.btnDM.setEnabled(true); // if (isAdded()) {
// }).execute(); // final Bundle bundle = new Bundle();
}); // bundle.putString("threadId", thread.getThreadId());
// bundle.putString("title", thread.getThreadTitle());
// if (isAdded()) {
// final NavDirections action = ProfileFragmentDirections
// .actionProfileFragmentToDMThreadFragment(thread.getThreadId(), profileModel.getUsername());
// NavHostFragment.findNavController(this).navigate(action);
// }
// }
// profileDetailsBinding.btnDM.setEnabled(true);
// }).execute();
// });
profileDetailsBinding.mainProfileImage.setOnClickListener(v -> { profileDetailsBinding.mainProfileImage.setOnClickListener(v -> {
if (!hasStories) { if (!hasStories) {
// show profile pic // show profile pic