Skip to content

Commit

Permalink
Уведомление о возможности просмотра приватных видосов
Browse files Browse the repository at this point in the history
  • Loading branch information
Spliterash committed Mar 30, 2024
1 parent 6c68f71 commit 196110a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ru.spliterash.vkVideoUnlocker.group

import io.micronaut.context.annotation.Value
import jakarta.inject.Singleton
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
Expand All @@ -14,9 +13,7 @@ import ru.spliterash.vkVideoUnlocker.vk.api.VkApi

@Singleton
class WorkUserGroupService(
@WorkUser private val user: VkApi,
@Value("\${vk-unlocker.private-groups:false}") private val privateGroupWork: Boolean

@WorkUser private val user: VkApi
) {
private val groups = hashMapOf<Int, GroupInfo>()
private val lock = Mutex()
Expand Down Expand Up @@ -49,7 +46,6 @@ class WorkUserGroupService(
try {
when (actualInfo.groupStatus) {
GroupStatus.CLOSE -> {
if (!privateGroupWork) return GroupStatus.CLOSE
when (actualInfo.memberStatus) {
MemberStatus.NO -> {
user.groups.join(groupId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import ru.spliterash.vkVideoUnlocker.longpoll.message.isPersonalChat
import ru.spliterash.vkVideoUnlocker.message.editableMessage.EditableMessage
import ru.spliterash.vkVideoUnlocker.message.utils.MessageUtils
import ru.spliterash.vkVideoUnlocker.messageChain.MessageHandler
import ru.spliterash.vkVideoUnlocker.video.DownloadUrlSupplier
import ru.spliterash.vkVideoUnlocker.video.exceptions.PrivateVideoDisabledException
import ru.spliterash.vkVideoUnlocker.video.service.VideoReUploadService
import ru.spliterash.vkVideoUnlocker.vk.actor.GroupUser
import ru.spliterash.vkVideoUnlocker.vk.api.VkApi
Expand All @@ -21,6 +23,7 @@ class DefaultVideoChain(
@GroupUser private val client: VkApi,
private val utils: MessageUtils,
private val reUploadService: VideoReUploadService,
private val downloadUrlSupplier: DownloadUrlSupplier,
) : MessageHandler {
override suspend fun handle(message: RootMessage, editableMessage: EditableMessage): Boolean = coroutineScope {
val video = try {
Expand All @@ -46,6 +49,10 @@ class DefaultVideoChain(
}
val unlockedId: String = try {
reUploadService.getUnlockedId(video).id
} catch (ex: PrivateVideoDisabledException) {
val url = downloadUrlSupplier.downloadUrl(video.attachmentId)
editableMessage.sendOrUpdate("Перезалив видео из закрытых групп временно отключён, но если очень хочется посмотреть, то вот\n$url")
return@coroutineScope true
} catch (ex: VkUnlockerException) {
handleException(ex, message)
return@coroutineScope true
Expand Down

0 comments on commit 196110a

Please sign in to comment.