1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-22 06: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)) data.postValue(loading(null))
scope.launch(Dispatchers.IO) { scope.launch(Dispatchers.IO) {
try { try {
if (itemType == BroadcastItemType.MEDIA_SHARE) when (itemType) {
directMessagesRepository.broadcastMediaShare( BroadcastItemType.MEDIA_SHARE -> directMessagesRepository.broadcastMediaShare(
csrfToken, csrfToken,
viewerId, viewerId,
deviceUuid, deviceUuid,
@ -112,8 +112,7 @@ object DirectMessagesManager {
mediaId, mediaId,
secondId secondId
) )
if (itemType == BroadcastItemType.PROFILE) BroadcastItemType.PROFILE -> directMessagesRepository.broadcastProfile(
directMessagesRepository.broadcastProfile(
csrfToken, csrfToken,
viewerId, viewerId,
deviceUuid, deviceUuid,
@ -121,6 +120,16 @@ object DirectMessagesManager {
ThreadIdsOrUserIds(threadIds, userIds), ThreadIdsOrUserIds(threadIds, userIds),
mediaId mediaId
) )
BroadcastItemType.STORY -> directMessagesRepository.broadcastStory(
csrfToken,
viewerId,
deviceUuid,
UUID.randomUUID().toString(),
ThreadIdsOrUserIds(threadIds, userIds),
mediaId,
secondId!!
)
}
data.postValue(success(Any())) data.postValue(success(Any()))
callback?.invoke() callback?.invoke()
} catch (e: Exception) { } catch (e: Exception) {
@ -132,6 +141,42 @@ object DirectMessagesManager {
return data 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 { init {
val cookie = Utils.settingsHelper.getString(Constants.COOKIE) val cookie = Utils.settingsHelper.getString(Constants.COOKIE)
viewerId = getUserIdFromCookie(cookie) viewerId = getUserIdFromCookie(cookie)

View File

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

View File

@ -187,6 +187,17 @@ open class DirectMessagesRepository(private val service: DirectMessagesService)
): DirectThreadBroadcastResponse = ): DirectThreadBroadcastResponse =
broadcast(csrfToken, userId, deviceUuid, ProfileBroadcastOptions(clientContext, threadIdsOrUserIds, profileId)) 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( private suspend fun broadcast(
csrfToken: String, csrfToken: String,
userId: Long, userId: Long,