1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-14 02:37:30 +00:00

share story via dm (backend)

This commit is contained in:
Austin Huang 2021-07-05 16:31:47 -04:00
parent 06f679608c
commit 1bba8dc065
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
3 changed files with 61 additions and 5 deletions

View File

@ -102,8 +102,8 @@ object DirectMessagesManager {
data.postValue(loading(null))
scope.launch(Dispatchers.IO) {
try {
if (itemType == BroadcastItemType.MEDIA_SHARE)
directMessagesRepository.broadcastMediaShare(
when (itemType) {
BroadcastItemType.MEDIA_SHARE -> directMessagesRepository.broadcastMediaShare(
csrfToken,
viewerId,
deviceUuid,
@ -112,8 +112,7 @@ object DirectMessagesManager {
mediaId,
secondId
)
if (itemType == BroadcastItemType.PROFILE)
directMessagesRepository.broadcastProfile(
BroadcastItemType.PROFILE -> directMessagesRepository.broadcastProfile(
csrfToken,
viewerId,
deviceUuid,
@ -121,6 +120,16 @@ object DirectMessagesManager {
ThreadIdsOrUserIds(threadIds, userIds),
mediaId
)
BroadcastItemType.STORY -> directMessagesRepository.broadcastStory(
csrfToken,
viewerId,
deviceUuid,
UUID.randomUUID().toString(),
ThreadIdsOrUserIds(threadIds, userIds),
mediaId,
secondId!!
)
}
data.postValue(success(Any()))
callback?.invoke()
} catch (e: Exception) {
@ -132,6 +141,42 @@ object DirectMessagesManager {
return data
}
fun replyToStory(
recipientId: Long?,
reelId: String?,
mediaId: String?,
text: String,
scope: CoroutineScope
): LiveData<Resource<Any?>> {
Log.d("austin_debug", "replying")
val data = MutableLiveData<Resource<Any?>>()
data.postValue(loading(null))
if (recipientId == null || reelId == null || mediaId == null) {
data.postValue(error("arguments are null", null))
return data
}
scope.launch(Dispatchers.IO) {
try {
directMessagesRepository.broadcastStoryReply(
csrfToken,
viewerId,
deviceUuid,
ThreadIdsOrUserIds.Companion.ofOneUser(recipientId.toString(10)),
text,
mediaId,
reelId
)
inboxManager.refresh(scope)
data.postValue(success(null))
}
catch (e: Exception) {
Log.e(TAG, "story reply: ", e)
data.postValue(error(e.message, null))
}
}
return data
}
init {
val cookie = Utils.settingsHelper.getString(Constants.COOKIE)
viewerId = getUserIdFromCookie(cookie)

View File

@ -7,7 +7,7 @@ class StoryReplyBroadcastOptions(
threadIdsOrUserIds: ThreadIdsOrUserIds,
val text: String,
val mediaId: String,
val reelId: String // or user id, usually same
val reelId: String
) : BroadcastOptions(clientContext, threadIdsOrUserIds, BroadcastItemType.REELSHARE) {
override val formMap: Map<String, String>
get() = mapOf(

View File

@ -187,6 +187,17 @@ open class DirectMessagesRepository(private val service: DirectMessagesService)
): DirectThreadBroadcastResponse =
broadcast(csrfToken, userId, deviceUuid, ProfileBroadcastOptions(clientContext, threadIdsOrUserIds, profileId))
suspend fun broadcastStory(
csrfToken: String,
userId: Long,
deviceUuid: String,
clientContext: String,
threadIdsOrUserIds: ThreadIdsOrUserIds,
mediaId: String,
reelId: String,
): DirectThreadBroadcastResponse =
broadcast(csrfToken, userId, deviceUuid, StoryBroadcastOptions(clientContext, threadIdsOrUserIds, mediaId, reelId))
private suspend fun broadcast(
csrfToken: String,
userId: Long,