1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-12-23 05:16:58 +00:00

pluralize dm recipient options

as used in the official client
This commit is contained in:
Austin Huang 2021-06-14 21:12:52 -04:00
parent 95b90ab72f
commit e89c1ac9ef
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
13 changed files with 69 additions and 71 deletions

View File

@ -17,8 +17,8 @@ import awais.instagrabber.models.Resource.Companion.success
import awais.instagrabber.models.enums.DirectItemType
import awais.instagrabber.repositories.requests.UploadFinishOptions
import awais.instagrabber.repositories.requests.VideoOptions
import awais.instagrabber.repositories.requests.directmessages.ThreadIdOrUserIds
import awais.instagrabber.repositories.requests.directmessages.ThreadIdOrUserIds.Companion.of
import awais.instagrabber.repositories.requests.directmessages.ThreadIdsOrUserIds
import awais.instagrabber.repositories.requests.directmessages.ThreadIdsOrUserIds.Companion.of
import awais.instagrabber.repositories.responses.User
import awais.instagrabber.repositories.responses.directmessages.*
import awais.instagrabber.repositories.responses.giphy.GiphyGif
@ -61,7 +61,7 @@ class ThreadManager(
private val _pendingRequests = MutableLiveData<DirectThreadParticipantRequestsResponse?>(null)
val pendingRequests: LiveData<DirectThreadParticipantRequestsResponse?> = _pendingRequests
private val inboxManager: InboxManager = if (pending) DirectMessagesManager.pendingInboxManager else DirectMessagesManager.inboxManager
private val threadIdOrUserIds: ThreadIdOrUserIds = of(threadId)
private val threadIdsOrUserIds: ThreadIdsOrUserIds = of(threadId)
private val friendshipRepository: FriendshipRepository by lazy { FriendshipRepository.getInstance() }
private val mediaRepository: MediaRepository by lazy { MediaRepository.getInstance() }
@ -353,7 +353,7 @@ class ThreadManager(
viewerId,
deviceUuid,
clientContext,
threadIdOrUserIds,
threadIdsOrUserIds,
text,
repliedToItemId,
repliedToClientContext
@ -411,7 +411,7 @@ class ThreadManager(
userId,
deviceUuid,
clientContext,
threadIdOrUserIds,
threadIdsOrUserIds,
giphyGif
)
parseResponse(request, data, directItem)
@ -460,7 +460,7 @@ class ThreadManager(
viewerId,
deviceUuid,
clientContext,
threadIdOrUserIds,
threadIdsOrUserIds,
uploadDmVoiceOptions.uploadId,
waveform,
samplingFreq
@ -504,7 +504,7 @@ class ThreadManager(
userId,
deviceUuid,
clientContext,
threadIdOrUserIds,
threadIdsOrUserIds,
itemId,
emojiUnicode,
false
@ -544,7 +544,7 @@ class ThreadManager(
viewerId,
deviceUuid,
clientContext,
threadIdOrUserIds,
threadIdsOrUserIds,
itemId1,
null,
true
@ -732,7 +732,7 @@ class ThreadManager(
if (handleInvalidResponse(data, response)) return@launch
val response1 = response.response ?: return@launch
val uploadId = response1.optString("upload_id")
val response2 = DirectMessagesService.broadcastPhoto(csrfToken, viewerId, deviceUuid, clientContext, threadIdOrUserIds, uploadId)
val response2 = DirectMessagesService.broadcastPhoto(csrfToken, viewerId, deviceUuid, clientContext, threadIdsOrUserIds, uploadId)
parseResponse(response2, data, directItem)
} catch (e: Exception) {
data.postValue(error(e.message, null))
@ -798,7 +798,7 @@ class ThreadManager(
viewerId,
deviceUuid,
clientContext,
threadIdOrUserIds,
threadIdsOrUserIds,
uploadDmVideoOptions.uploadId,
"",
true

View File

@ -5,11 +5,11 @@ import awais.instagrabber.repositories.responses.giphy.GiphyGif
class AnimatedMediaBroadcastOptions(
clientContext: String,
threadIdOrUserIds: ThreadIdOrUserIds,
threadIdsOrUserIds: ThreadIdsOrUserIds,
val giphyGif: GiphyGif
) : BroadcastOptions(
clientContext,
threadIdOrUserIds,
threadIdsOrUserIds,
BroadcastItemType.ANIMATED_MEDIA
) {
override val formMap: Map<String, String>

View File

@ -4,31 +4,15 @@ import awais.instagrabber.models.enums.BroadcastItemType
sealed class BroadcastOptions(
val clientContext: String,
private val threadIdOrUserIds: ThreadIdOrUserIds,
private val threadIdsOrUserIds: ThreadIdsOrUserIds,
val itemType: BroadcastItemType
) {
var repliedToItemId: String? = null
var repliedToClientContext: String? = null
val threadId: String?
get() = threadIdOrUserIds.threadId
val userIds: List<String>?
get() = threadIdOrUserIds.userIds
val threadIds: List<String>?
get() = threadIdsOrUserIds.threadIds
val userIds: List<List<String>>?
get() = threadIdsOrUserIds.userIds
abstract val formMap: Map<String, String>
}
// TODO convert to data class once usages are migrated to kotlin
class ThreadIdOrUserIds(val threadId: String? = null, val userIds: List<String>? = null) {
companion object {
@JvmStatic
fun of(threadId: String?): ThreadIdOrUserIds {
return ThreadIdOrUserIds(threadId, null)
}
@JvmStatic
fun of(userIds: List<String>?): ThreadIdOrUserIds {
return ThreadIdOrUserIds(null, userIds)
}
}
}

View File

@ -5,12 +5,12 @@ import org.json.JSONArray
class LinkBroadcastOptions(
clientContext: String,
threadIdOrUserIds: ThreadIdOrUserIds,
threadIdsOrUserIds: ThreadIdsOrUserIds,
val linkText: String,
val urls: List<String>
) : BroadcastOptions(
clientContext,
threadIdOrUserIds,
threadIdsOrUserIds,
BroadcastItemType.LINK
) {
override val formMap: Map<String, String>

View File

@ -4,11 +4,11 @@ import awais.instagrabber.models.enums.BroadcastItemType
class MediaShareBroadcastOptions(
clientContext: String,
threadIdOrUserIds: ThreadIdOrUserIds,
threadIdsOrUserIds: ThreadIdsOrUserIds,
val mediaId: String
) : BroadcastOptions(
clientContext,
threadIdOrUserIds,
threadIdsOrUserIds,
BroadcastItemType.MEDIA_SHARE
) {
override val formMap: Map<String, String>

View File

@ -4,12 +4,12 @@ import awais.instagrabber.models.enums.BroadcastItemType
class PhotoBroadcastOptions(
clientContext: String,
threadIdOrUserIds: ThreadIdOrUserIds,
threadIdsOrUserIds: ThreadIdsOrUserIds,
val allowFullAspectRatio: Boolean,
val uploadId: String
) : BroadcastOptions(
clientContext,
threadIdOrUserIds,
threadIdsOrUserIds,
BroadcastItemType.IMAGE
) {
override val formMap: Map<String, String>

View File

@ -4,11 +4,11 @@ import awais.instagrabber.models.enums.BroadcastItemType
class ReactionBroadcastOptions(
clientContext: String,
threadIdOrUserIds: ThreadIdOrUserIds,
threadIdsOrUserIds: ThreadIdsOrUserIds,
val itemId: String,
val emoji: String?,
val delete: Boolean
) : BroadcastOptions(clientContext, threadIdOrUserIds, BroadcastItemType.REACTION) {
) : BroadcastOptions(clientContext, threadIdsOrUserIds, BroadcastItemType.REACTION) {
override val formMap: Map<String, String>
get() = listOfNotNull(
"item_id" to itemId,

View File

@ -4,11 +4,11 @@ import awais.instagrabber.models.enums.BroadcastItemType
class StoryReplyBroadcastOptions(
clientContext: String,
threadIdOrUserIds: ThreadIdOrUserIds,
threadIdsOrUserIds: ThreadIdsOrUserIds,
val text: String,
val mediaId: String,
val reelId: String // or user id, usually same
) : BroadcastOptions(clientContext, threadIdOrUserIds, BroadcastItemType.REELSHARE) {
) : BroadcastOptions(clientContext, threadIdsOrUserIds, BroadcastItemType.REELSHARE) {
override val formMap: Map<String, String>
get() = mapOf(
"text" to text,

View File

@ -4,11 +4,11 @@ import awais.instagrabber.models.enums.BroadcastItemType
class TextBroadcastOptions(
clientContext: String,
threadIdOrUserIds: ThreadIdOrUserIds,
threadIdsOrUserIds: ThreadIdsOrUserIds,
val text: String
) : BroadcastOptions(
clientContext,
threadIdOrUserIds,
threadIdsOrUserIds,
BroadcastItemType.TEXT
) {
override val formMap: Map<String, String>

View File

@ -0,0 +1,14 @@
package awais.instagrabber.repositories.requests.directmessages
data class ThreadIdsOrUserIds(val threadIds: List<String>? = null, val userIds: List<List<String>>? = null) {
companion object {
@JvmStatic
fun of(threadId: String): ThreadIdsOrUserIds {
return ThreadIdsOrUserIds(listOf(threadId), null)
}
fun ofOneUser(userId: String): ThreadIdsOrUserIds {
return ThreadIdsOrUserIds(null, listOf(listOf(userId)))
}
}
}

View File

@ -4,13 +4,13 @@ import awais.instagrabber.models.enums.BroadcastItemType
class VideoBroadcastOptions(
clientContext: String,
threadIdOrUserIds: ThreadIdOrUserIds,
threadIdsOrUserIds: ThreadIdsOrUserIds,
val videoResult: String,
val uploadId: String,
val sampled: Boolean
) : BroadcastOptions(
clientContext,
threadIdOrUserIds,
threadIdsOrUserIds,
BroadcastItemType.VIDEO
) {
override val formMap: Map<String, String>

View File

@ -5,11 +5,11 @@ import org.json.JSONArray
class VoiceBroadcastOptions(
clientContext: String,
threadIdOrUserIds: ThreadIdOrUserIds,
threadIdsOrUserIds: ThreadIdsOrUserIds,
val uploadId: String,
val waveform: List<Float>,
val waveformSamplingFrequencyHz: Int
) : BroadcastOptions(clientContext, threadIdOrUserIds, BroadcastItemType.VOICE) {
) : BroadcastOptions(clientContext, threadIdsOrUserIds, BroadcastItemType.VOICE) {
override val formMap: Map<String, String>
get() = mapOf(
"waveform" to JSONArray(waveform).toString(),

View File

@ -54,16 +54,16 @@ object DirectMessagesService {
userId: Long,
deviceUuid: String,
clientContext: String,
threadIdOrUserIds: ThreadIdOrUserIds,
threadIdsOrUserIds: ThreadIdsOrUserIds,
text: String,
repliedToItemId: String?,
repliedToClientContext: String?,
): DirectThreadBroadcastResponse {
val urls = extractUrls(text)
if (urls.isNotEmpty()) {
return broadcastLink(csrfToken, userId, deviceUuid, clientContext, threadIdOrUserIds, text, urls, repliedToItemId, repliedToClientContext)
return broadcastLink(csrfToken, userId, deviceUuid, clientContext, threadIdsOrUserIds, text, urls, repliedToItemId, repliedToClientContext)
}
val broadcastOptions = TextBroadcastOptions(clientContext, threadIdOrUserIds, text)
val broadcastOptions = TextBroadcastOptions(clientContext, threadIdsOrUserIds, text)
if (!repliedToItemId.isNullOrBlank() && !repliedToClientContext.isNullOrBlank()) {
broadcastOptions.repliedToItemId = repliedToItemId
broadcastOptions.repliedToClientContext = repliedToClientContext
@ -76,13 +76,13 @@ object DirectMessagesService {
userId: Long,
deviceUuid: String,
clientContext: String,
threadIdOrUserIds: ThreadIdOrUserIds,
threadIdsOrUserIds: ThreadIdsOrUserIds,
linkText: String,
urls: List<String>,
repliedToItemId: String?,
repliedToClientContext: String?,
): DirectThreadBroadcastResponse {
val broadcastOptions = LinkBroadcastOptions(clientContext, threadIdOrUserIds, linkText, urls)
val broadcastOptions = LinkBroadcastOptions(clientContext, threadIdsOrUserIds, linkText, urls)
if (!repliedToItemId.isNullOrBlank() && !repliedToClientContext.isNullOrBlank()) {
broadcastOptions.repliedToItemId = repliedToItemId
broadcastOptions.repliedToClientContext = repliedToClientContext
@ -95,77 +95,77 @@ object DirectMessagesService {
userId: Long,
deviceUuid: String,
clientContext: String,
threadIdOrUserIds: ThreadIdOrUserIds,
threadIdsOrUserIds: ThreadIdsOrUserIds,
uploadId: String,
): DirectThreadBroadcastResponse =
broadcast(csrfToken, userId, deviceUuid, PhotoBroadcastOptions(clientContext, threadIdOrUserIds, true, uploadId))
broadcast(csrfToken, userId, deviceUuid, PhotoBroadcastOptions(clientContext, threadIdsOrUserIds, true, uploadId))
suspend fun broadcastVideo(
csrfToken: String,
userId: Long,
deviceUuid: String,
clientContext: String,
threadIdOrUserIds: ThreadIdOrUserIds,
threadIdsOrUserIds: ThreadIdsOrUserIds,
uploadId: String,
videoResult: String,
sampled: Boolean,
): DirectThreadBroadcastResponse =
broadcast(csrfToken, userId, deviceUuid, VideoBroadcastOptions(clientContext, threadIdOrUserIds, videoResult, uploadId, sampled))
broadcast(csrfToken, userId, deviceUuid, VideoBroadcastOptions(clientContext, threadIdsOrUserIds, videoResult, uploadId, sampled))
suspend fun broadcastVoice(
csrfToken: String,
userId: Long,
deviceUuid: String,
clientContext: String,
threadIdOrUserIds: ThreadIdOrUserIds,
threadIdsOrUserIds: ThreadIdsOrUserIds,
uploadId: String,
waveform: List<Float>,
samplingFreq: Int,
): DirectThreadBroadcastResponse =
broadcast(csrfToken, userId, deviceUuid, VoiceBroadcastOptions(clientContext, threadIdOrUserIds, uploadId, waveform, samplingFreq))
broadcast(csrfToken, userId, deviceUuid, VoiceBroadcastOptions(clientContext, threadIdsOrUserIds, uploadId, waveform, samplingFreq))
suspend fun broadcastStoryReply(
csrfToken: String,
userId: Long,
deviceUuid: String,
threadIdOrUserIds: ThreadIdOrUserIds,
threadIdsOrUserIds: ThreadIdsOrUserIds,
text: String,
mediaId: String,
reelId: String,
): DirectThreadBroadcastResponse =
broadcast(csrfToken, userId, deviceUuid, StoryReplyBroadcastOptions(UUID.randomUUID().toString(), threadIdOrUserIds, text, mediaId, reelId))
broadcast(csrfToken, userId, deviceUuid, StoryReplyBroadcastOptions(UUID.randomUUID().toString(), threadIdsOrUserIds, text, mediaId, reelId))
suspend fun broadcastReaction(
csrfToken: String,
userId: Long,
deviceUuid: String,
clientContext: String,
threadIdOrUserIds: ThreadIdOrUserIds,
threadIdsOrUserIds: ThreadIdsOrUserIds,
itemId: String,
emoji: String?,
delete: Boolean,
): DirectThreadBroadcastResponse =
broadcast(csrfToken, userId, deviceUuid, ReactionBroadcastOptions(clientContext, threadIdOrUserIds, itemId, emoji, delete))
broadcast(csrfToken, userId, deviceUuid, ReactionBroadcastOptions(clientContext, threadIdsOrUserIds, itemId, emoji, delete))
suspend fun broadcastAnimatedMedia(
csrfToken: String,
userId: Long,
deviceUuid: String,
clientContext: String,
threadIdOrUserIds: ThreadIdOrUserIds,
threadIdsOrUserIds: ThreadIdsOrUserIds,
giphyGif: GiphyGif,
): DirectThreadBroadcastResponse =
broadcast(csrfToken, userId, deviceUuid, AnimatedMediaBroadcastOptions(clientContext, threadIdOrUserIds, giphyGif))
broadcast(csrfToken, userId, deviceUuid, AnimatedMediaBroadcastOptions(clientContext, threadIdsOrUserIds, giphyGif))
suspend fun broadcastMediaShare(
csrfToken: String,
userId: Long,
deviceUuid: String,
clientContext: String,
threadIdOrUserIds: ThreadIdOrUserIds,
threadIdsOrUserIds: ThreadIdsOrUserIds,
mediaId: String,
): DirectThreadBroadcastResponse =
broadcast(csrfToken, userId, deviceUuid, MediaShareBroadcastOptions(clientContext, threadIdOrUserIds, mediaId))
broadcast(csrfToken, userId, deviceUuid, MediaShareBroadcastOptions(clientContext, threadIdsOrUserIds, mediaId))
private suspend fun broadcast(
csrfToken: String,
@ -181,9 +181,9 @@ object DirectMessagesService {
"client_context" to broadcastOptions.clientContext,
"mutation_token" to broadcastOptions.clientContext,
)
val threadId = broadcastOptions.threadId
if (!threadId.isNullOrBlank()) {
form["thread_id"] = threadId
val threadIds = broadcastOptions.threadIds
if (!threadIds.isNullOrEmpty()) {
form["thread_ids"] = JSONArray(threadIds).toString()
} else {
val userIds = broadcastOptions.userIds
require(!userIds.isNullOrEmpty()) {