mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-12-23 05:16:58 +00:00
enforce _uuid consistency
This commit is contained in:
parent
2e58bab635
commit
c9f891e4e1
@ -29,8 +29,9 @@ public class FeedPostFetchService implements PostFetcher.PostFetchService {
|
||||
final List<Media> feedModels = new ArrayList<>();
|
||||
final String cookie = settingsHelper.getString(Constants.COOKIE);
|
||||
final String csrfToken = CookieUtils.getCsrfTokenFromCookie(cookie);
|
||||
final String deviceUuid = settingsHelper.getString(Constants.DEVICE_UUID);
|
||||
feedModels.clear();
|
||||
feedService.fetch(csrfToken, nextCursor, new ServiceCallback<PostsFetchResponse>() {
|
||||
feedService.fetch(csrfToken, deviceUuid, nextCursor, new ServiceCallback<PostsFetchResponse>() {
|
||||
@Override
|
||||
public void onSuccess(final PostsFetchResponse result) {
|
||||
if (result == null && feedModels.size() > 0) {
|
||||
|
@ -64,7 +64,7 @@ public final class CommentsViewerFragment extends BottomSheetDialogFragment impl
|
||||
private LinearLayoutManager layoutManager;
|
||||
private RecyclerLazyLoader lazyLoader;
|
||||
private String shortCode;
|
||||
private long userId;
|
||||
private long authorUserId, userIdFromCookie;
|
||||
private String endCursor = null;
|
||||
private Resources resources;
|
||||
private InputMethodManager imm;
|
||||
@ -140,14 +140,13 @@ public final class CommentsViewerFragment extends BottomSheetDialogFragment impl
|
||||
Toast.makeText(context, R.string.comment_send_empty_comment, Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
final long userId = CookieUtils.getUserIdFromCookie(cookie);
|
||||
if (userId == 0) return;
|
||||
if (userIdFromCookie == 0) return;
|
||||
String replyToId = null;
|
||||
final CommentModel commentModel = commentsAdapter.getSelected();
|
||||
if (commentModel != null) {
|
||||
replyToId = commentModel.getId();
|
||||
}
|
||||
mediaService.comment(postId, text.toString(), userId, replyToId, CookieUtils.getCsrfTokenFromCookie(cookie), new ServiceCallback<Boolean>() {
|
||||
mediaService.comment(postId, text.toString(), replyToId, new ServiceCallback<Boolean>() {
|
||||
@Override
|
||||
public void onSuccess(final Boolean result) {
|
||||
commentsAdapter.clearSelection();
|
||||
@ -171,7 +170,10 @@ public final class CommentsViewerFragment extends BottomSheetDialogFragment impl
|
||||
public void onCreate(@Nullable final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
fragmentActivity = (AppCompatActivity) getActivity();
|
||||
mediaService = MediaService.getInstance();
|
||||
final String deviceUuid = Utils.settingsHelper.getString(Constants.DEVICE_UUID);
|
||||
final String csrfToken = CookieUtils.getCsrfTokenFromCookie(cookie);
|
||||
userIdFromCookie = CookieUtils.getUserIdFromCookie(cookie);
|
||||
mediaService = MediaService.getInstance(deviceUuid, csrfToken, userIdFromCookie);
|
||||
// setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@ -231,7 +233,7 @@ public final class CommentsViewerFragment extends BottomSheetDialogFragment impl
|
||||
final CommentsViewerFragmentArgs fragmentArgs = CommentsViewerFragmentArgs.fromBundle(getArguments());
|
||||
shortCode = fragmentArgs.getShortCode();
|
||||
postId = fragmentArgs.getPostId();
|
||||
userId = fragmentArgs.getPostUserId();
|
||||
authorUserId = fragmentArgs.getPostUserId();
|
||||
// setTitle();
|
||||
binding.swipeRefreshLayout.setOnRefreshListener(this);
|
||||
binding.swipeRefreshLayout.setRefreshing(true);
|
||||
@ -289,10 +291,9 @@ public final class CommentsViewerFragment extends BottomSheetDialogFragment impl
|
||||
|
||||
String[] commentDialogList;
|
||||
|
||||
final long userIdFromCookie = CookieUtils.getUserIdFromCookie(cookie);
|
||||
if (!TextUtils.isEmpty(cookie)
|
||||
&& userIdFromCookie != 0
|
||||
&& (userIdFromCookie == commentModel.getProfileModel().getPk() || userIdFromCookie == userId)) {
|
||||
&& (userIdFromCookie == commentModel.getProfileModel().getPk() || userIdFromCookie == authorUserId)) {
|
||||
commentDialogList = new String[]{
|
||||
resources.getString(R.string.open_profile),
|
||||
resources.getString(R.string.comment_viewer_copy_comment),
|
||||
@ -324,7 +325,6 @@ public final class CommentsViewerFragment extends BottomSheetDialogFragment impl
|
||||
if (context == null) return;
|
||||
final DialogInterface.OnClickListener profileDialogListener = (dialog, which) -> {
|
||||
final User profileModel = commentModel.getProfileModel();
|
||||
final String csrfToken = CookieUtils.getCsrfTokenFromCookie(cookie);
|
||||
switch (which) {
|
||||
case 0: // open profile
|
||||
openProfile("@" + profileModel.getUsername());
|
||||
@ -354,11 +354,8 @@ public final class CommentsViewerFragment extends BottomSheetDialogFragment impl
|
||||
}, 200);
|
||||
break;
|
||||
case 4: // like/unlike comment
|
||||
if (csrfToken == null) {
|
||||
return;
|
||||
}
|
||||
if (!commentModel.getLiked()) {
|
||||
mediaService.commentLike(commentModel.getId(), csrfToken, new ServiceCallback<Boolean>() {
|
||||
mediaService.commentLike(commentModel.getId(), new ServiceCallback<Boolean>() {
|
||||
@Override
|
||||
public void onSuccess(final Boolean result) {
|
||||
if (!result) {
|
||||
@ -376,7 +373,7 @@ public final class CommentsViewerFragment extends BottomSheetDialogFragment impl
|
||||
});
|
||||
return;
|
||||
}
|
||||
mediaService.commentUnlike(commentModel.getId(), csrfToken, new ServiceCallback<Boolean>() {
|
||||
mediaService.commentUnlike(commentModel.getId(), new ServiceCallback<Boolean>() {
|
||||
@Override
|
||||
public void onSuccess(final Boolean result) {
|
||||
if (!result) {
|
||||
@ -416,10 +413,9 @@ public final class CommentsViewerFragment extends BottomSheetDialogFragment impl
|
||||
});
|
||||
break;
|
||||
case 6: // delete comment
|
||||
final long userId = CookieUtils.getUserIdFromCookie(cookie);
|
||||
if (userId == 0) return;
|
||||
if (userIdFromCookie == 0) return;
|
||||
mediaService.deleteComment(
|
||||
postId, userId, commentModel.getId(), csrfToken,
|
||||
postId, commentModel.getId(),
|
||||
new ServiceCallback<Boolean>() {
|
||||
@Override
|
||||
public void onSuccess(final Boolean result) {
|
||||
|
@ -118,7 +118,7 @@ public final class FollowViewerFragment extends Fragment implements SwipeRefresh
|
||||
@Override
|
||||
public void onCreate(@Nullable final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
friendshipService = FriendshipService.getInstance();
|
||||
friendshipService = FriendshipService.getInstance(null, null, 0);
|
||||
fragmentActivity = (AppCompatActivity) getActivity();
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ public final class LikesViewerFragment extends BottomSheetDialogFragment impleme
|
||||
final String cookie = settingsHelper.getString(Constants.COOKIE);
|
||||
isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) > 0;
|
||||
// final AppCompatActivity fragmentActivity = (AppCompatActivity) getActivity();
|
||||
mediaService = isLoggedIn ? MediaService.getInstance() : null;
|
||||
mediaService = isLoggedIn ? MediaService.getInstance(null, null, 0) : null;
|
||||
graphQLService = isLoggedIn ? null : GraphQLService.getInstance();
|
||||
// setHasOptionsMenu(true);
|
||||
}
|
||||
|
@ -60,7 +60,6 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe
|
||||
private NotificationViewModel notificationViewModel;
|
||||
private FriendshipService friendshipService;
|
||||
private MediaService mediaService;
|
||||
private long userId;
|
||||
private String csrfToken;
|
||||
private String type;
|
||||
private Context context;
|
||||
@ -133,7 +132,7 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe
|
||||
break;
|
||||
case 1:
|
||||
if (model.getType() == NotificationType.REQUEST) {
|
||||
friendshipService.approve(userId, model.getUserId(), csrfToken, new ServiceCallback<FriendshipChangeResponse>() {
|
||||
friendshipService.approve(model.getUserId(), new ServiceCallback<FriendshipChangeResponse>() {
|
||||
@Override
|
||||
public void onSuccess(final FriendshipChangeResponse result) {
|
||||
onRefresh();
|
||||
@ -175,7 +174,7 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe
|
||||
});
|
||||
break;
|
||||
case 2:
|
||||
friendshipService.ignore(userId, model.getUserId(), csrfToken, new ServiceCallback<FriendshipChangeResponse>() {
|
||||
friendshipService.ignore(model.getUserId(), new ServiceCallback<FriendshipChangeResponse>() {
|
||||
@Override
|
||||
public void onSuccess(final FriendshipChangeResponse result) {
|
||||
onRefresh();
|
||||
@ -218,10 +217,11 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe
|
||||
if (TextUtils.isEmpty(cookie)) {
|
||||
Toast.makeText(context, R.string.activity_notloggedin, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
friendshipService = FriendshipService.getInstance();
|
||||
mediaService = MediaService.getInstance();
|
||||
userId = CookieUtils.getUserIdFromCookie(cookie);
|
||||
mediaService = MediaService.getInstance(null, null, 0);
|
||||
final long userId = CookieUtils.getUserIdFromCookie(cookie);
|
||||
final String deviceUuid = Utils.settingsHelper.getString(Constants.DEVICE_UUID);
|
||||
csrfToken = CookieUtils.getCsrfTokenFromCookie(cookie);
|
||||
friendshipService = FriendshipService.getInstance(deviceUuid, csrfToken, userId);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
@ -99,7 +99,6 @@ import awais.instagrabber.webservices.StoriesService;
|
||||
import static androidx.core.content.PermissionChecker.checkSelfPermission;
|
||||
import static awais.instagrabber.fragments.HashTagFragment.ARG_HASHTAG;
|
||||
import static awais.instagrabber.utils.DownloadUtils.WRITE_PERMISSION;
|
||||
import static awais.instagrabber.utils.Utils.settingsHelper;
|
||||
|
||||
public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener {
|
||||
private static final String TAG = "ProfileFragment";
|
||||
@ -300,10 +299,15 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
||||
@Override
|
||||
public void onCreate(@Nullable final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
cookie = Utils.settingsHelper.getString(Constants.COOKIE);
|
||||
isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) > 0;
|
||||
final long userId = CookieUtils.getUserIdFromCookie(cookie);
|
||||
final String deviceUuid = Utils.settingsHelper.getString(Constants.DEVICE_UUID);
|
||||
final String csrfToken = CookieUtils.getCsrfTokenFromCookie(cookie);
|
||||
fragmentActivity = (MainActivity) requireActivity();
|
||||
friendshipService = FriendshipService.getInstance();
|
||||
friendshipService = FriendshipService.getInstance(deviceUuid, csrfToken, userId);
|
||||
storiesService = StoriesService.getInstance();
|
||||
mediaService = MediaService.getInstance();
|
||||
mediaService = MediaService.getInstance(null, null, 0);
|
||||
accountRepository = AccountRepository.getInstance(AccountDataSource.getInstance(getContext()));
|
||||
favoriteRepository = FavoriteRepository.getInstance(FavoriteDataSource.getInstance(getContext()));
|
||||
setHasOptionsMenu(true);
|
||||
@ -313,8 +317,6 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
||||
public View onCreateView(@NonNull final LayoutInflater inflater,
|
||||
final ViewGroup container,
|
||||
final Bundle savedInstanceState) {
|
||||
cookie = settingsHelper.getString(Constants.COOKIE);
|
||||
isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) > 0;
|
||||
if (root != null) {
|
||||
if (getArguments() != null) {
|
||||
final ProfileFragmentArgs fragmentArgs = ProfileFragmentArgs.fromBundle(getArguments());
|
||||
@ -380,7 +382,6 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
||||
friendshipService.toggleRestrict(
|
||||
profileModel.getPk(),
|
||||
!profileModel.getFriendshipStatus().isRestricted(),
|
||||
CookieUtils.getCsrfTokenFromCookie(cookie),
|
||||
new ServiceCallback<FriendshipRestrictResponse>() {
|
||||
@Override
|
||||
public void onSuccess(final FriendshipRestrictResponse result) {
|
||||
@ -396,13 +397,10 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
||||
return true;
|
||||
}
|
||||
if (item.getItemId() == R.id.block) {
|
||||
final long userIdFromCookie = CookieUtils.getUserIdFromCookie(cookie);
|
||||
if (!isLoggedIn) return false;
|
||||
if (profileModel.getFriendshipStatus().isBlocking()) {
|
||||
friendshipService.unblock(
|
||||
userIdFromCookie,
|
||||
profileModel.getPk(),
|
||||
CookieUtils.getCsrfTokenFromCookie(cookie),
|
||||
new ServiceCallback<FriendshipChangeResponse>() {
|
||||
@Override
|
||||
public void onSuccess(final FriendshipChangeResponse result) {
|
||||
@ -418,9 +416,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
||||
return true;
|
||||
}
|
||||
friendshipService.block(
|
||||
userIdFromCookie,
|
||||
profileModel.getPk(),
|
||||
CookieUtils.getCsrfTokenFromCookie(cookie),
|
||||
new ServiceCallback<FriendshipChangeResponse>() {
|
||||
@Override
|
||||
public void onSuccess(final FriendshipChangeResponse result) {
|
||||
@ -894,7 +890,6 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
||||
|
||||
private void setupCommonListeners() {
|
||||
final Context context = getContext();
|
||||
final long userIdFromCookie = CookieUtils.getUserIdFromCookie(cookie);
|
||||
profileDetailsBinding.btnFollow.setOnClickListener(v -> {
|
||||
if (profileModel.getFriendshipStatus().isFollowing() && profileModel.isPrivate()) {
|
||||
new AlertDialog.Builder(context)
|
||||
@ -902,9 +897,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
||||
.setMessage(R.string.priv_acc_confirm)
|
||||
.setPositiveButton(R.string.confirm, (d, w) ->
|
||||
friendshipService.unfollow(
|
||||
userIdFromCookie,
|
||||
profileModel.getPk(),
|
||||
CookieUtils.getCsrfTokenFromCookie(cookie),
|
||||
new ServiceCallback<FriendshipChangeResponse>() {
|
||||
@Override
|
||||
public void onSuccess(final FriendshipChangeResponse result) {
|
||||
@ -921,9 +914,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
||||
.show();
|
||||
} else if (profileModel.getFriendshipStatus().isFollowing() || profileModel.getFriendshipStatus().isOutgoingRequest()) {
|
||||
friendshipService.unfollow(
|
||||
userIdFromCookie,
|
||||
profileModel.getPk(),
|
||||
CookieUtils.getCsrfTokenFromCookie(cookie),
|
||||
new ServiceCallback<FriendshipChangeResponse>() {
|
||||
@Override
|
||||
public void onSuccess(final FriendshipChangeResponse result) {
|
||||
@ -938,9 +929,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
||||
});
|
||||
} else {
|
||||
friendshipService.follow(
|
||||
userIdFromCookie,
|
||||
profileModel.getPk(),
|
||||
CookieUtils.getCsrfTokenFromCookie(cookie),
|
||||
new ServiceCallback<FriendshipChangeResponse>() {
|
||||
@Override
|
||||
public void onSuccess(final FriendshipChangeResponse result) {
|
||||
|
@ -79,7 +79,7 @@ public class DirectSettingsViewModel extends AndroidViewModel {
|
||||
throw new IllegalArgumentException("User is not logged in!");
|
||||
}
|
||||
directMessagesService = DirectMessagesService.getInstance(csrfToken, userId, deviceUuid);
|
||||
friendshipService = FriendshipService.getInstance();
|
||||
friendshipService = FriendshipService.getInstance(deviceUuid, csrfToken, userId);
|
||||
resources = getApplication().getResources();
|
||||
}
|
||||
|
||||
@ -264,7 +264,7 @@ public class DirectSettingsViewModel extends AndroidViewModel {
|
||||
|
||||
private LiveData<Resource<Object>> blockUser(final User user) {
|
||||
final MutableLiveData<Resource<Object>> data = new MutableLiveData<>();
|
||||
friendshipService.block(userId, user.getPk(), csrfToken, new ServiceCallback<FriendshipChangeResponse>() {
|
||||
friendshipService.block(user.getPk(), new ServiceCallback<FriendshipChangeResponse>() {
|
||||
@Override
|
||||
public void onSuccess(final FriendshipChangeResponse result) {
|
||||
// refresh thread
|
||||
@ -281,7 +281,7 @@ public class DirectSettingsViewModel extends AndroidViewModel {
|
||||
|
||||
private LiveData<Resource<Object>> unblockUser(final User user) {
|
||||
final MutableLiveData<Resource<Object>> data = new MutableLiveData<>();
|
||||
friendshipService.unblock(userId, user.getPk(), csrfToken, new ServiceCallback<FriendshipChangeResponse>() {
|
||||
friendshipService.unblock(user.getPk(), new ServiceCallback<FriendshipChangeResponse>() {
|
||||
@Override
|
||||
public void onSuccess(final FriendshipChangeResponse result) {
|
||||
// refresh thread
|
||||
@ -298,7 +298,7 @@ public class DirectSettingsViewModel extends AndroidViewModel {
|
||||
|
||||
private LiveData<Resource<Object>> restrictUser(final User user) {
|
||||
final MutableLiveData<Resource<Object>> data = new MutableLiveData<>();
|
||||
friendshipService.toggleRestrict(user.getPk(), true, csrfToken, new ServiceCallback<FriendshipRestrictResponse>() {
|
||||
friendshipService.toggleRestrict(user.getPk(), true, new ServiceCallback<FriendshipRestrictResponse>() {
|
||||
@Override
|
||||
public void onSuccess(final FriendshipRestrictResponse result) {
|
||||
// refresh thread
|
||||
@ -315,7 +315,7 @@ public class DirectSettingsViewModel extends AndroidViewModel {
|
||||
|
||||
private LiveData<Resource<Object>> unRestrictUser(final User user) {
|
||||
final MutableLiveData<Resource<Object>> data = new MutableLiveData<>();
|
||||
friendshipService.toggleRestrict(user.getPk(), false, csrfToken, new ServiceCallback<FriendshipRestrictResponse>() {
|
||||
friendshipService.toggleRestrict(user.getPk(), false, new ServiceCallback<FriendshipRestrictResponse>() {
|
||||
@Override
|
||||
public void onSuccess(final FriendshipRestrictResponse result) {
|
||||
// refresh thread
|
||||
|
@ -99,7 +99,7 @@ public class DirectThreadViewModel extends AndroidViewModel {
|
||||
throw new IllegalArgumentException("User is not logged in!");
|
||||
}
|
||||
service = DirectMessagesService.getInstance(csrfToken, userId, deviceUuid);
|
||||
mediaService = MediaService.getInstance();
|
||||
mediaService = MediaService.getInstance(deviceUuid, csrfToken, userId);
|
||||
contentResolver = application.getContentResolver();
|
||||
recordingsDir = DirectoryUtils.getOutputMediaDirectory(application, "Recordings");
|
||||
this.application = application;
|
||||
@ -395,7 +395,7 @@ public class DirectThreadViewModel extends AndroidViewModel {
|
||||
.setUploadId(uploadDmVideoOptions.getUploadId())
|
||||
.setSourceType("2")
|
||||
.setVideoOptions(new UploadFinishOptions.VideoOptions().setLength(duration / 1000f));
|
||||
final Call<String> uploadFinishRequest = mediaService.uploadFinish(userId, csrfToken, uploadFinishOptions);
|
||||
final Call<String> uploadFinishRequest = mediaService.uploadFinish(uploadFinishOptions);
|
||||
uploadFinishRequest.enqueue(new Callback<String>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull final Call<String> call, @NonNull final Response<String> response) {
|
||||
@ -512,7 +512,7 @@ public class DirectThreadViewModel extends AndroidViewModel {
|
||||
final UploadFinishOptions uploadFinishOptions = new UploadFinishOptions()
|
||||
.setUploadId(uploadDmVoiceOptions.getUploadId())
|
||||
.setSourceType("4");
|
||||
final Call<String> uploadFinishRequest = mediaService.uploadFinish(userId, csrfToken, uploadFinishOptions);
|
||||
final Call<String> uploadFinishRequest = mediaService.uploadFinish(uploadFinishOptions);
|
||||
uploadFinishRequest.enqueue(new Callback<String>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull final Call<String> call, @NonNull final Response<String> response) {
|
||||
|
@ -43,16 +43,16 @@ public class PostViewV2ViewModel extends ViewModel {
|
||||
private final MutableLiveData<List<Integer>> options = new MutableLiveData<>(new ArrayList<>());
|
||||
private final MediaService mediaService;
|
||||
private final long viewerId;
|
||||
private final String csrfToken;
|
||||
private final boolean isLoggedIn;
|
||||
|
||||
private Media media;
|
||||
|
||||
public PostViewV2ViewModel() {
|
||||
mediaService = MediaService.getInstance();
|
||||
final String cookie = settingsHelper.getString(Constants.COOKIE);
|
||||
final String deviceUuid = settingsHelper.getString(Constants.DEVICE_UUID);
|
||||
final String csrfToken = CookieUtils.getCsrfTokenFromCookie(cookie);
|
||||
viewerId = CookieUtils.getUserIdFromCookie(cookie);
|
||||
csrfToken = CookieUtils.getCsrfTokenFromCookie(cookie);
|
||||
mediaService = MediaService.getInstance(deviceUuid, csrfToken, viewerId);
|
||||
isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) > 0;
|
||||
}
|
||||
|
||||
@ -142,14 +142,14 @@ public class PostViewV2ViewModel extends ViewModel {
|
||||
public LiveData<Resource<Object>> like() {
|
||||
final MutableLiveData<Resource<Object>> data = new MutableLiveData<>();
|
||||
data.postValue(Resource.loading(null));
|
||||
mediaService.like(media.getPk(), viewerId, csrfToken, getLikeUnlikeCallback(data));
|
||||
mediaService.like(media.getPk(), getLikeUnlikeCallback(data));
|
||||
return data;
|
||||
}
|
||||
|
||||
public LiveData<Resource<Object>> unlike() {
|
||||
final MutableLiveData<Resource<Object>> data = new MutableLiveData<>();
|
||||
data.postValue(Resource.loading(null));
|
||||
mediaService.unlike(media.getPk(), viewerId, csrfToken, getLikeUnlikeCallback(data));
|
||||
mediaService.unlike(media.getPk(), getLikeUnlikeCallback(data));
|
||||
return data;
|
||||
}
|
||||
|
||||
@ -196,14 +196,14 @@ public class PostViewV2ViewModel extends ViewModel {
|
||||
public LiveData<Resource<Object>> save() {
|
||||
final MutableLiveData<Resource<Object>> data = new MutableLiveData<>();
|
||||
data.postValue(Resource.loading(null));
|
||||
mediaService.save(media.getPk(), viewerId, csrfToken, getSaveUnsaveCallback(data));
|
||||
mediaService.save(media.getPk(), getSaveUnsaveCallback(data));
|
||||
return data;
|
||||
}
|
||||
|
||||
public LiveData<Resource<Object>> unsave() {
|
||||
final MutableLiveData<Resource<Object>> data = new MutableLiveData<>();
|
||||
data.postValue(Resource.loading(null));
|
||||
mediaService.unsave(media.getPk(), viewerId, csrfToken, getSaveUnsaveCallback(data));
|
||||
mediaService.unsave(media.getPk(), getSaveUnsaveCallback(data));
|
||||
return data;
|
||||
}
|
||||
|
||||
@ -232,7 +232,7 @@ public class PostViewV2ViewModel extends ViewModel {
|
||||
public LiveData<Resource<Object>> updateCaption(final String caption) {
|
||||
final MutableLiveData<Resource<Object>> data = new MutableLiveData<>();
|
||||
data.postValue(Resource.loading(null));
|
||||
mediaService.editCaption(media.getPk(), viewerId, caption, csrfToken, new ServiceCallback<Boolean>() {
|
||||
mediaService.editCaption(media.getPk(), caption, new ServiceCallback<Boolean>() {
|
||||
@Override
|
||||
public void onSuccess(final Boolean result) {
|
||||
if (result) {
|
||||
|
@ -47,10 +47,11 @@ public class FeedService extends BaseService {
|
||||
}
|
||||
|
||||
public void fetch(final String csrfToken,
|
||||
final String deviceUuid,
|
||||
final String cursor,
|
||||
final ServiceCallback<PostsFetchResponse> callback) {
|
||||
final Map<String, String> form = new HashMap<>();
|
||||
form.put("_uuid", UUID.randomUUID().toString());
|
||||
form.put("_uuid", deviceUuid);
|
||||
form.put("_csrftoken", csrfToken);
|
||||
form.put("phone_id", UUID.randomUUID().toString());
|
||||
form.put("device_id", UUID.randomUUID().toString());
|
||||
|
@ -13,6 +13,7 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
import awais.instagrabber.models.FollowModel;
|
||||
@ -32,58 +33,71 @@ public class FriendshipService extends BaseService {
|
||||
private static final String TAG = "FriendshipService";
|
||||
|
||||
private final FriendshipRepository repository;
|
||||
private final String deviceUuid, csrfToken;
|
||||
private final long userId;
|
||||
|
||||
private static FriendshipService instance;
|
||||
|
||||
private FriendshipService() {
|
||||
private FriendshipService(final String deviceUuid,
|
||||
final String csrfToken,
|
||||
final long userId) {
|
||||
this.deviceUuid = deviceUuid;
|
||||
this.csrfToken = csrfToken;
|
||||
this.userId = userId;
|
||||
final Retrofit retrofit = getRetrofitBuilder()
|
||||
.baseUrl("https://i.instagram.com")
|
||||
.build();
|
||||
repository = retrofit.create(FriendshipRepository.class);
|
||||
}
|
||||
|
||||
public static FriendshipService getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new FriendshipService();
|
||||
public String getCsrfToken() {
|
||||
return csrfToken;
|
||||
}
|
||||
|
||||
public String getDeviceUuid() {
|
||||
return deviceUuid;
|
||||
}
|
||||
|
||||
public long getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public static FriendshipService getInstance(final String deviceUuid, final String csrfToken, final long userId) {
|
||||
if (instance == null
|
||||
|| !Objects.equals(instance.getCsrfToken(), csrfToken)
|
||||
|| !Objects.equals(instance.getDeviceUuid(), deviceUuid)
|
||||
|| !Objects.equals(instance.getUserId(), userId)) {
|
||||
instance = new FriendshipService(deviceUuid, csrfToken, userId);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void follow(final long userId,
|
||||
final long targetUserId,
|
||||
final String csrfToken,
|
||||
public void follow(final long targetUserId,
|
||||
final ServiceCallback<FriendshipChangeResponse> callback) {
|
||||
change("create", userId, targetUserId, csrfToken, callback);
|
||||
change("create", targetUserId, callback);
|
||||
}
|
||||
|
||||
public void unfollow(final long userId,
|
||||
final long targetUserId,
|
||||
final String csrfToken,
|
||||
public void unfollow(final long targetUserId,
|
||||
final ServiceCallback<FriendshipChangeResponse> callback) {
|
||||
change("destroy", userId, targetUserId, csrfToken, callback);
|
||||
change("destroy", targetUserId, callback);
|
||||
}
|
||||
|
||||
public void block(final long userId,
|
||||
final long targetUserId,
|
||||
final String csrfToken,
|
||||
public void block(final long targetUserId,
|
||||
final ServiceCallback<FriendshipChangeResponse> callback) {
|
||||
change("block", userId, targetUserId, csrfToken, callback);
|
||||
change("block", targetUserId, callback);
|
||||
}
|
||||
|
||||
public void unblock(final long userId,
|
||||
final long targetUserId,
|
||||
final String csrfToken,
|
||||
public void unblock(final long targetUserId,
|
||||
final ServiceCallback<FriendshipChangeResponse> callback) {
|
||||
change("unblock", userId, targetUserId, csrfToken, callback);
|
||||
change("unblock", targetUserId, callback);
|
||||
}
|
||||
|
||||
public void toggleRestrict(final long targetUserId,
|
||||
final boolean restrict,
|
||||
final String csrfToken,
|
||||
final ServiceCallback<FriendshipRestrictResponse> callback) {
|
||||
final Map<String, String> form = new HashMap<>(3);
|
||||
form.put("_csrftoken", csrfToken);
|
||||
form.put("_uuid", UUID.randomUUID().toString());
|
||||
form.put("_uuid", deviceUuid);
|
||||
form.put("target_user_id", String.valueOf(targetUserId));
|
||||
final String action = restrict ? "restrict" : "unrestrict";
|
||||
final Call<FriendshipRestrictResponse> request = repository.toggleRestrict(Constants.I_USER_AGENT, action, form);
|
||||
@ -106,29 +120,23 @@ public class FriendshipService extends BaseService {
|
||||
});
|
||||
}
|
||||
|
||||
public void approve(final long userId,
|
||||
final long targetUserId,
|
||||
final String csrfToken,
|
||||
public void approve(final long targetUserId,
|
||||
final ServiceCallback<FriendshipChangeResponse> callback) {
|
||||
change("approve", userId, targetUserId, csrfToken, callback);
|
||||
change("approve", targetUserId, callback);
|
||||
}
|
||||
|
||||
public void ignore(final long userId,
|
||||
final long targetUserId,
|
||||
final String csrfToken,
|
||||
public void ignore(final long targetUserId,
|
||||
final ServiceCallback<FriendshipChangeResponse> callback) {
|
||||
change("ignore", userId, targetUserId, csrfToken, callback);
|
||||
change("ignore", targetUserId, callback);
|
||||
}
|
||||
|
||||
private void change(final String action,
|
||||
final long userId,
|
||||
final long targetUserId,
|
||||
final String csrfToken,
|
||||
final ServiceCallback<FriendshipChangeResponse> callback) {
|
||||
final Map<String, Object> form = new HashMap<>(5);
|
||||
form.put("_csrftoken", csrfToken);
|
||||
form.put("_uid", userId);
|
||||
form.put("_uuid", UUID.randomUUID().toString());
|
||||
form.put("_uuid", deviceUuid);
|
||||
form.put("radio_type", "wifi-none");
|
||||
form.put("user_id", targetUserId);
|
||||
final Map<String, String> signedForm = Utils.sign(form);
|
||||
|
@ -14,6 +14,7 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
import awais.instagrabber.repositories.MediaRepository;
|
||||
@ -34,19 +35,41 @@ public class MediaService extends BaseService {
|
||||
private static final String TAG = "MediaService";
|
||||
|
||||
private final MediaRepository repository;
|
||||
private final String deviceUuid, csrfToken;
|
||||
private final long userId;
|
||||
|
||||
private static MediaService instance;
|
||||
|
||||
private MediaService() {
|
||||
private MediaService(final String deviceUuid,
|
||||
final String csrfToken,
|
||||
final long userId) {
|
||||
this.deviceUuid = deviceUuid;
|
||||
this.csrfToken = csrfToken;
|
||||
this.userId = userId;
|
||||
final Retrofit retrofit = getRetrofitBuilder()
|
||||
.baseUrl("https://i.instagram.com")
|
||||
.build();
|
||||
repository = retrofit.create(MediaRepository.class);
|
||||
}
|
||||
|
||||
public static MediaService getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new MediaService();
|
||||
public String getCsrfToken() {
|
||||
return csrfToken;
|
||||
}
|
||||
|
||||
public String getDeviceUuid() {
|
||||
return deviceUuid;
|
||||
}
|
||||
|
||||
public long getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public static MediaService getInstance(final String deviceUuid, final String csrfToken, final long userId) {
|
||||
if (instance == null
|
||||
|| !Objects.equals(instance.getCsrfToken(), csrfToken)
|
||||
|| !Objects.equals(instance.getDeviceUuid(), deviceUuid)
|
||||
|| !Objects.equals(instance.getUserId(), userId)) {
|
||||
instance = new MediaService(deviceUuid, csrfToken, userId);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
@ -78,43 +101,33 @@ public class MediaService extends BaseService {
|
||||
}
|
||||
|
||||
public void like(final String mediaId,
|
||||
final long userId,
|
||||
final String csrfToken,
|
||||
final ServiceCallback<Boolean> callback) {
|
||||
action(mediaId, userId, "like", csrfToken, callback);
|
||||
action(mediaId, "like", callback);
|
||||
}
|
||||
|
||||
public void unlike(final String mediaId,
|
||||
final long userId,
|
||||
final String csrfToken,
|
||||
final ServiceCallback<Boolean> callback) {
|
||||
action(mediaId, userId, "unlike", csrfToken, callback);
|
||||
action(mediaId, "unlike", callback);
|
||||
}
|
||||
|
||||
public void save(final String mediaId,
|
||||
final long userId,
|
||||
final String csrfToken,
|
||||
final ServiceCallback<Boolean> callback) {
|
||||
action(mediaId, userId, "save", csrfToken, callback);
|
||||
action(mediaId, "save", callback);
|
||||
}
|
||||
|
||||
public void unsave(final String mediaId,
|
||||
final long userId,
|
||||
final String csrfToken,
|
||||
final ServiceCallback<Boolean> callback) {
|
||||
action(mediaId, userId, "unsave", csrfToken, callback);
|
||||
action(mediaId, "unsave", callback);
|
||||
}
|
||||
|
||||
private void action(final String mediaId,
|
||||
final long userId,
|
||||
final String action,
|
||||
final String csrfToken,
|
||||
final ServiceCallback<Boolean> callback) {
|
||||
final Map<String, Object> form = new HashMap<>(4);
|
||||
form.put("media_id", mediaId);
|
||||
form.put("_csrftoken", csrfToken);
|
||||
form.put("_uid", userId);
|
||||
form.put("_uuid", UUID.randomUUID().toString());
|
||||
form.put("_uuid", deviceUuid);
|
||||
// form.put("radio_type", "wifi-none");
|
||||
final Map<String, String> signedForm = Utils.sign(form);
|
||||
final Call<String> request = repository.action(action, mediaId, signedForm);
|
||||
@ -149,9 +162,7 @@ public class MediaService extends BaseService {
|
||||
|
||||
public void comment(@NonNull final String mediaId,
|
||||
@NonNull final String comment,
|
||||
final long userId,
|
||||
final String replyToCommentId,
|
||||
final String csrfToken,
|
||||
@NonNull final ServiceCallback<Boolean> callback) {
|
||||
final String module = "self_comments_v2";
|
||||
final Map<String, Object> form = new HashMap<>();
|
||||
@ -159,7 +170,7 @@ public class MediaService extends BaseService {
|
||||
form.put("idempotence_token", UUID.randomUUID().toString());
|
||||
form.put("_csrftoken", csrfToken);
|
||||
form.put("_uid", userId);
|
||||
form.put("_uuid", UUID.randomUUID().toString());
|
||||
form.put("_uuid", deviceUuid);
|
||||
form.put("comment_text", comment);
|
||||
form.put("containermodule", module);
|
||||
if (!TextUtils.isEmpty(replyToCommentId)) {
|
||||
@ -194,23 +205,19 @@ public class MediaService extends BaseService {
|
||||
}
|
||||
|
||||
public void deleteComment(final String mediaId,
|
||||
final long userId,
|
||||
final String commentId,
|
||||
final String csrfToken,
|
||||
@NonNull final ServiceCallback<Boolean> callback) {
|
||||
deleteComments(mediaId, userId, Collections.singletonList(commentId), csrfToken, callback);
|
||||
deleteComments(mediaId, Collections.singletonList(commentId), callback);
|
||||
}
|
||||
|
||||
public void deleteComments(final String mediaId,
|
||||
final long userId,
|
||||
final List<String> commentIds,
|
||||
final String csrfToken,
|
||||
@NonNull final ServiceCallback<Boolean> callback) {
|
||||
final Map<String, Object> form = new HashMap<>();
|
||||
form.put("comment_ids_to_delete", TextUtils.join(",", commentIds));
|
||||
form.put("_csrftoken", csrfToken);
|
||||
form.put("_uid", userId);
|
||||
form.put("_uuid", UUID.randomUUID().toString());
|
||||
form.put("_uuid", deviceUuid);
|
||||
final Map<String, String> signedForm = Utils.sign(form);
|
||||
final Call<String> bulkDeleteRequest = repository.commentsBulkDelete(mediaId, signedForm);
|
||||
bulkDeleteRequest.enqueue(new Callback<String>() {
|
||||
@ -241,12 +248,11 @@ public class MediaService extends BaseService {
|
||||
}
|
||||
|
||||
public void commentLike(@NonNull final String commentId,
|
||||
@NonNull final String csrfToken,
|
||||
@NonNull final ServiceCallback<Boolean> callback) {
|
||||
final Map<String, Object> form = new HashMap<>();
|
||||
form.put("_csrftoken", csrfToken);
|
||||
// form.put("_uid", userId);
|
||||
// form.put("_uuid", UUID.randomUUID().toString());
|
||||
// form.put("_uuid", deviceUuid);
|
||||
final Map<String, String> signedForm = Utils.sign(form);
|
||||
final Call<String> commentLikeRequest = repository.commentLike(commentId, signedForm);
|
||||
commentLikeRequest.enqueue(new Callback<String>() {
|
||||
@ -277,12 +283,11 @@ public class MediaService extends BaseService {
|
||||
}
|
||||
|
||||
public void commentUnlike(final String commentId,
|
||||
@NonNull final String csrfToken,
|
||||
@NonNull final ServiceCallback<Boolean> callback) {
|
||||
final Map<String, Object> form = new HashMap<>();
|
||||
form.put("_csrftoken", csrfToken);
|
||||
// form.put("_uid", userId);
|
||||
// form.put("_uuid", UUID.randomUUID().toString());
|
||||
// form.put("_uuid", deviceUuid);
|
||||
final Map<String, String> signedForm = Utils.sign(form);
|
||||
final Call<String> commentUnlikeRequest = repository.commentUnlike(commentId, signedForm);
|
||||
commentUnlikeRequest.enqueue(new Callback<String>() {
|
||||
@ -313,14 +318,12 @@ public class MediaService extends BaseService {
|
||||
}
|
||||
|
||||
public void editCaption(final String postId,
|
||||
final long userId,
|
||||
final String newCaption,
|
||||
@NonNull final String csrfToken,
|
||||
@NonNull final ServiceCallback<Boolean> callback) {
|
||||
final Map<String, Object> form = new HashMap<>();
|
||||
form.put("_csrftoken", csrfToken);
|
||||
form.put("_uid", userId);
|
||||
form.put("_uuid", UUID.randomUUID().toString());
|
||||
form.put("_uuid", deviceUuid);
|
||||
form.put("igtv_feed_preview", "false");
|
||||
form.put("media_id", postId);
|
||||
form.put("caption_text", newCaption);
|
||||
@ -411,9 +414,7 @@ public class MediaService extends BaseService {
|
||||
});
|
||||
}
|
||||
|
||||
public Call<String> uploadFinish(final long userId,
|
||||
@NonNull final String csrfToken,
|
||||
@NonNull final UploadFinishOptions options) {
|
||||
public Call<String> uploadFinish(@NonNull final UploadFinishOptions options) {
|
||||
if (options.getVideoOptions() != null) {
|
||||
final UploadFinishOptions.VideoOptions videoOptions = options.getVideoOptions();
|
||||
if (videoOptions.getClips() == null) {
|
||||
@ -430,7 +431,7 @@ public class MediaService extends BaseService {
|
||||
.put("_csrftoken", csrfToken)
|
||||
.put("source_type", options.getSourceType())
|
||||
.put("_uid", String.valueOf(userId))
|
||||
.put("_uuid", UUID.randomUUID().toString())
|
||||
.put("_uuid", deviceUuid)
|
||||
.put("upload_id", options.getUploadId());
|
||||
if (options.getVideoOptions() != null) {
|
||||
formBuilder.putAll(options.getVideoOptions().getMap());
|
||||
|
Loading…
Reference in New Issue
Block a user