From 3f6ed5f78bd1bdab30699c277c9e6a20d154dd90 Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Mon, 28 Jun 2021 15:29:37 -0400 Subject: [PATCH] sending dm media shares with exact child https://t.me/barinsta_app/21890 --- .../instagrabber/fragments/PostViewV2Fragment.java | 4 ++-- .../instagrabber/managers/DirectMessagesManager.kt | 3 ++- .../directmessages/MediaShareBroadcastOptions.kt | 8 ++++++-- .../instagrabber/viewmodels/PostViewV2ViewModel.kt | 10 ++++++---- .../instagrabber/webservices/DirectMessagesService.kt | 3 ++- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/fragments/PostViewV2Fragment.java b/app/src/main/java/awais/instagrabber/fragments/PostViewV2Fragment.java index dbd53aa3..f8a2b584 100644 --- a/app/src/main/java/awais/instagrabber/fragments/PostViewV2Fragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/PostViewV2Fragment.java @@ -152,7 +152,7 @@ public class PostViewV2Fragment extends Fragment implements EditTextDialogFragme if (context != null) { Toast.makeText(context, R.string.sending, Toast.LENGTH_SHORT).show(); } - viewModel.shareDm((RankedRecipient) result); + viewModel.shareDm((RankedRecipient) result, sliderPosition); } else if ((result instanceof Set)) { try { // Log.d(TAG, "result: " + result); @@ -161,7 +161,7 @@ public class PostViewV2Fragment extends Fragment implements EditTextDialogFragme Toast.makeText(context, R.string.sending, Toast.LENGTH_SHORT).show(); } //noinspection unchecked - viewModel.shareDm((Set) result); + viewModel.shareDm((Set) result, sliderPosition); } catch (Exception e) { Log.e(TAG, "share: ", e); } diff --git a/app/src/main/java/awais/instagrabber/managers/DirectMessagesManager.kt b/app/src/main/java/awais/instagrabber/managers/DirectMessagesManager.kt index b1b4685c..d30a2e25 100644 --- a/app/src/main/java/awais/instagrabber/managers/DirectMessagesManager.kt +++ b/app/src/main/java/awais/instagrabber/managers/DirectMessagesManager.kt @@ -107,7 +107,8 @@ object DirectMessagesManager { deviceUuid, UUID.randomUUID().toString(), ThreadIdsOrUserIds(threadIds, userIds), - mediaId + mediaId, + secondId ) if (itemType == BroadcastItemType.PROFILE) DirectMessagesService.broadcastProfile( diff --git a/app/src/main/java/awais/instagrabber/repositories/requests/directmessages/MediaShareBroadcastOptions.kt b/app/src/main/java/awais/instagrabber/repositories/requests/directmessages/MediaShareBroadcastOptions.kt index 89b74998..c83ef73b 100644 --- a/app/src/main/java/awais/instagrabber/repositories/requests/directmessages/MediaShareBroadcastOptions.kt +++ b/app/src/main/java/awais/instagrabber/repositories/requests/directmessages/MediaShareBroadcastOptions.kt @@ -5,12 +5,16 @@ import awais.instagrabber.models.enums.BroadcastItemType class MediaShareBroadcastOptions( clientContext: String, threadIdsOrUserIds: ThreadIdsOrUserIds, - val mediaId: String + val mediaId: String, + val childId: String? ) : BroadcastOptions( clientContext, threadIdsOrUserIds, BroadcastItemType.MEDIA_SHARE ) { override val formMap: Map - get() = mapOf("media_id" to mediaId) + get() = listOfNotNull( + "media_id" to mediaId, + if (childId != null) "carousel_share_child_media_id" to childId else null + ).toMap() } \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/viewmodels/PostViewV2ViewModel.kt b/app/src/main/java/awais/instagrabber/viewmodels/PostViewV2ViewModel.kt index e8dbd563..df6972ea 100644 --- a/app/src/main/java/awais/instagrabber/viewmodels/PostViewV2ViewModel.kt +++ b/app/src/main/java/awais/instagrabber/viewmodels/PostViewV2ViewModel.kt @@ -331,19 +331,21 @@ class PostViewV2ViewModel : ViewModel() { return data } - fun shareDm(result: RankedRecipient) { + fun shareDm(result: RankedRecipient, child: Int) { if (messageManager == null) { messageManager = DirectMessagesManager } val mediaId = media.id ?: return - messageManager?.sendMedia(result, mediaId, null, BroadcastItemType.MEDIA_SHARE, viewModelScope) + val childId = if (child == -1) null else media.carouselMedia?.get(child)?.id + messageManager?.sendMedia(result, mediaId, childId, BroadcastItemType.MEDIA_SHARE, viewModelScope) } - fun shareDm(recipients: Set) { + fun shareDm(recipients: Set, child: Int) { if (messageManager == null) { messageManager = DirectMessagesManager } val mediaId = media.id ?: return - messageManager?.sendMedia(recipients, mediaId, null, BroadcastItemType.MEDIA_SHARE, viewModelScope) + val childId = if (child == -1) null else media.carouselMedia?.get(child)?.id + messageManager?.sendMedia(recipients, mediaId, childId, BroadcastItemType.MEDIA_SHARE, viewModelScope) } } \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/webservices/DirectMessagesService.kt b/app/src/main/java/awais/instagrabber/webservices/DirectMessagesService.kt index 7af8dd65..0d0aca64 100644 --- a/app/src/main/java/awais/instagrabber/webservices/DirectMessagesService.kt +++ b/app/src/main/java/awais/instagrabber/webservices/DirectMessagesService.kt @@ -164,8 +164,9 @@ object DirectMessagesService { clientContext: String, threadIdsOrUserIds: ThreadIdsOrUserIds, mediaId: String, + childId: String?, ): DirectThreadBroadcastResponse = - broadcast(csrfToken, userId, deviceUuid, MediaShareBroadcastOptions(clientContext, threadIdsOrUserIds, mediaId)) + broadcast(csrfToken, userId, deviceUuid, MediaShareBroadcastOptions(clientContext, threadIdsOrUserIds, mediaId, childId)) suspend fun broadcastProfile( csrfToken: String,