Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a4feb8978f | |||
| 79f539a27b | |||
| 4cc6ec6b5d | |||
| 36a119ffa9 | |||
| 1a78a51017 | |||
| cbe3313b87 |
+14
-14
@@ -2,9 +2,9 @@ name: Android CI Build
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ "master", "hotfix/*", "feature/*" ]
|
branches: [ "dev", "release/*", "hotfix/*" ]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ "master", "hotfix/*", "feature/*" ]
|
branches: [ "dev", "release/*", "hotfix/*" ]
|
||||||
|
|
||||||
env:
|
env:
|
||||||
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
|
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
|
||||||
@@ -12,32 +12,23 @@ env:
|
|||||||
RELEASE_SIGN_KEY_PASSWORD: ${{ secrets.RELEASE_SIGN_KEY_PASSWORD }}
|
RELEASE_SIGN_KEY_PASSWORD: ${{ secrets.RELEASE_SIGN_KEY_PASSWORD }}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build_apks:
|
build_apk_aab:
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
name: Build artifacts
|
name: Build artifacts
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: set up JDK 21
|
- name: set up JDK 17
|
||||||
uses: actions/setup-java@v4
|
uses: actions/setup-java@v4
|
||||||
with:
|
with:
|
||||||
java-version: '21'
|
java-version: '17'
|
||||||
distribution: 'temurin'
|
distribution: 'temurin'
|
||||||
cache: gradle
|
cache: gradle
|
||||||
|
|
||||||
- name: Grant execute permission for gradlew
|
- name: Grant execute permission for gradlew
|
||||||
run: chmod +x gradlew
|
run: chmod +x gradlew
|
||||||
|
|
||||||
- name: Build and sign release APK
|
|
||||||
run: ./gradlew assembleRelease
|
|
||||||
|
|
||||||
- name: Upload release APK
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: app-release.apk
|
|
||||||
path: app/build/outputs/apk/release/app-release.apk
|
|
||||||
|
|
||||||
- name: Build and sign debug APK
|
- name: Build and sign debug APK
|
||||||
run: ./gradlew assembleDebug
|
run: ./gradlew assembleDebug
|
||||||
|
|
||||||
@@ -46,3 +37,12 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
name: app-debug.apk
|
name: app-debug.apk
|
||||||
path: app/build/outputs/apk/debug/app-debug.apk
|
path: app/build/outputs/apk/debug/app-debug.apk
|
||||||
|
|
||||||
|
- name: Build and sign release APK
|
||||||
|
run: ./gradlew assembleRelease
|
||||||
|
|
||||||
|
- name: Upload release APK
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: app-release.apk
|
||||||
|
path: app/build/outputs/apk/release/app-release.apk
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
name: Android CI Release
|
name: Android CI Release
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
pull_request:
|
||||||
branches: [ "release/*"]
|
branches: [ "master" ]
|
||||||
|
|
||||||
env:
|
env:
|
||||||
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
|
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
|
||||||
@@ -17,16 +17,25 @@ jobs:
|
|||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: set up JDK 21
|
- name: set up JDK 17
|
||||||
uses: actions/setup-java@v4
|
uses: actions/setup-java@v4
|
||||||
with:
|
with:
|
||||||
java-version: '21'
|
java-version: '17'
|
||||||
distribution: 'temurin'
|
distribution: 'temurin'
|
||||||
cache: gradle
|
cache: gradle
|
||||||
|
|
||||||
- name: Grant execute permission for gradlew
|
- name: Grant execute permission for gradlew
|
||||||
run: chmod +x gradlew
|
run: chmod +x gradlew
|
||||||
|
|
||||||
|
- name: Build and sign debug APK
|
||||||
|
run: ./gradlew assembleDebug
|
||||||
|
|
||||||
|
- name: Upload debug APK
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: app-debug.apk
|
||||||
|
path: app/build/outputs/apk/debug/app-debug.apk
|
||||||
|
|
||||||
- name: Build and sign release APK
|
- name: Build and sign release APK
|
||||||
run: ./gradlew assembleRelease
|
run: ./gradlew assembleRelease
|
||||||
|
|
||||||
@@ -36,6 +45,15 @@ jobs:
|
|||||||
name: app-release.apk
|
name: app-release.apk
|
||||||
path: app/build/outputs/apk/release/app-release.apk
|
path: app/build/outputs/apk/release/app-release.apk
|
||||||
|
|
||||||
|
- name: Build and sign debug Bundle
|
||||||
|
run: ./gradlew bundleDebug
|
||||||
|
|
||||||
|
- name: Upload debug Bundle
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: app-debug.aab
|
||||||
|
path: app/build/outputs/bundle/debug/app-debug.aab
|
||||||
|
|
||||||
- name: Build and sign release Bundle
|
- name: Build and sign release Bundle
|
||||||
run: ./gradlew bundleRelease
|
run: ./gradlew bundleRelease
|
||||||
|
|
||||||
|
|||||||
@@ -17,19 +17,16 @@ Unofficial messenger for russian social network VKontakte
|
|||||||
- [ ] View archived conversations
|
- [ ] View archived conversations
|
||||||
- [ ] Archive & unarchive conversations
|
- [ ] Archive & unarchive conversations
|
||||||
- [x] Friends list
|
- [x] Friends list
|
||||||
- [x] Sort alphabetically, by priority or random
|
- [ ] Sort alphabetically, by priority or random
|
||||||
- [x] Separate tab with only friends who are online
|
- [ ] Separate tab with only friends who are online
|
||||||
- [x] Settings screen
|
- [x] Settings screen
|
||||||
- [ ] TODO
|
- [ ] TODO
|
||||||
- [x] Chat screen
|
- [x] Chat screen
|
||||||
- [x] Pagination
|
- [ ] Pagination
|
||||||
- [x] Manual refresh
|
- [x] Manual refresh
|
||||||
- [x] Message bubbles
|
- [x] Message bubbles
|
||||||
- [x] Text
|
- [x] Text
|
||||||
- [x] Date
|
- [ ] Date
|
||||||
- [x] Read status
|
|
||||||
- [x] Edit status
|
|
||||||
- [x] Sending status
|
|
||||||
- [ ] Message's attachments
|
- [ ] Message's attachments
|
||||||
- [ ] Photo
|
- [ ] Photo
|
||||||
- [ ] Video
|
- [ ] Video
|
||||||
@@ -38,19 +35,19 @@ Unofficial messenger for russian social network VKontakte
|
|||||||
- [ ] Link
|
- [ ] Link
|
||||||
- [ ] TODO
|
- [ ] TODO
|
||||||
- [x] Send messages
|
- [x] Send messages
|
||||||
- [x] Pinned message
|
- [ ] Pinned message
|
||||||
- [x] Pin & unpin messages
|
- [ ] Pin & unpin messages
|
||||||
- [ ] Reply to message
|
- [ ] Reply to message
|
||||||
- [x] Delete message
|
- [ ] Delete message
|
||||||
- [x] Select multiple messages
|
- [ ] Select multiple messages
|
||||||
- [x] Delete
|
- [ ] Delete
|
||||||
- [ ] Forward
|
- [ ] Forward
|
||||||
- [ ] Forward in current chat
|
- [ ] Forward in current chat
|
||||||
- [ ] Send attachments to chat
|
- [ ] Send attachments to chat
|
||||||
- [ ] TODO
|
- [ ] TODO
|
||||||
- [x] Chat materials (attachments)
|
- [x] Chat materials (attachments)
|
||||||
- [x] Separate tabs for each attachment type
|
- [x] Separate tabs for each attachment type
|
||||||
- [x] Pagination
|
- [ ] Pagination
|
||||||
- [x] Manual refresh
|
- [x] Manual refresh
|
||||||
- [x] View attachments
|
- [x] View attachments
|
||||||
- [x] Open photo
|
- [x] Open photo
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import dev.meloda.fast.datastore.UserSettings
|
|||||||
import dev.meloda.fast.domain.GetCurrentAccountUseCase
|
import dev.meloda.fast.domain.GetCurrentAccountUseCase
|
||||||
import dev.meloda.fast.domain.LoadUserByIdUseCase
|
import dev.meloda.fast.domain.LoadUserByIdUseCase
|
||||||
import dev.meloda.fast.model.BaseError
|
import dev.meloda.fast.model.BaseError
|
||||||
import dev.meloda.fast.model.api.domain.VkUser
|
|
||||||
import dev.meloda.fast.navigation.Main
|
import dev.meloda.fast.navigation.Main
|
||||||
import dev.meloda.fast.settings.navigation.Settings
|
import dev.meloda.fast.settings.navigation.Settings
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@@ -37,13 +36,14 @@ interface MainViewModel {
|
|||||||
|
|
||||||
val startDestination: StateFlow<Any?>
|
val startDestination: StateFlow<Any?>
|
||||||
val isNeedToReplaceWithAuth: StateFlow<Boolean>
|
val isNeedToReplaceWithAuth: StateFlow<Boolean>
|
||||||
val currentUser: StateFlow<VkUser?>
|
|
||||||
|
|
||||||
val isNeedToShowNotificationsDeniedDialog: StateFlow<Boolean>
|
val isNeedToShowNotificationsDeniedDialog: StateFlow<Boolean>
|
||||||
val isNeedToShowNotificationsRationaleDialog: StateFlow<Boolean>
|
val isNeedToShowNotificationsRationaleDialog: StateFlow<Boolean>
|
||||||
val isNeedToCheckNotificationsPermission: StateFlow<Boolean>
|
val isNeedToCheckNotificationsPermission: StateFlow<Boolean>
|
||||||
val isNeedToRequestNotifications: StateFlow<Boolean>
|
val isNeedToRequestNotifications: StateFlow<Boolean>
|
||||||
|
|
||||||
|
val profileImageUrl: StateFlow<String?>
|
||||||
|
|
||||||
fun onError(error: BaseError)
|
fun onError(error: BaseError)
|
||||||
|
|
||||||
fun onNavigatedToAuth()
|
fun onNavigatedToAuth()
|
||||||
@@ -59,8 +59,6 @@ interface MainViewModel {
|
|||||||
fun onNotificationsDeniedDialogDismissed()
|
fun onNotificationsDeniedDialogDismissed()
|
||||||
fun onNotificationsRationaleDialogDismissed()
|
fun onNotificationsRationaleDialogDismissed()
|
||||||
fun onNotificationsRationaleDialogCancelClicked()
|
fun onNotificationsRationaleDialogCancelClicked()
|
||||||
|
|
||||||
fun onUserAuthenticated()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class MainViewModelImpl(
|
class MainViewModelImpl(
|
||||||
@@ -72,24 +70,24 @@ class MainViewModelImpl(
|
|||||||
|
|
||||||
override val startDestination = MutableStateFlow<Any?>(null)
|
override val startDestination = MutableStateFlow<Any?>(null)
|
||||||
override val isNeedToReplaceWithAuth = MutableStateFlow(false)
|
override val isNeedToReplaceWithAuth = MutableStateFlow(false)
|
||||||
override val currentUser = MutableStateFlow<VkUser?>(null)
|
|
||||||
|
|
||||||
override val isNeedToShowNotificationsDeniedDialog = MutableStateFlow(false)
|
override val isNeedToShowNotificationsDeniedDialog = MutableStateFlow(false)
|
||||||
override val isNeedToShowNotificationsRationaleDialog = MutableStateFlow(false)
|
override val isNeedToShowNotificationsRationaleDialog = MutableStateFlow(false)
|
||||||
override val isNeedToCheckNotificationsPermission = MutableStateFlow(false)
|
override val isNeedToCheckNotificationsPermission = MutableStateFlow(false)
|
||||||
override val isNeedToRequestNotifications = MutableStateFlow(false)
|
override val isNeedToRequestNotifications = MutableStateFlow(false)
|
||||||
|
|
||||||
|
override val profileImageUrl = MutableStateFlow<String?>(null)
|
||||||
|
|
||||||
private var openNotificationsSettings = false
|
private var openNotificationsSettings = false
|
||||||
private var openAppSettings = false
|
private var openAppSettings = false
|
||||||
|
|
||||||
override fun onError(error: BaseError) {
|
override fun onError(error: BaseError) {
|
||||||
when (error) {
|
when (error) {
|
||||||
BaseError.SessionExpired,
|
BaseError.SessionExpired -> {
|
||||||
BaseError.AccountBlocked -> {
|
|
||||||
isNeedToReplaceWithAuth.update { true }
|
isNeedToReplaceWithAuth.update { true }
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> Unit // TODO: 21-Mar-25, Danil Nikolaev: show error in ui
|
is BaseError.SimpleError -> Unit // TODO: 21-Mar-25, Danil Nikolaev: show error in ui
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,20 +170,17 @@ class MainViewModelImpl(
|
|||||||
disableBackgroundLongPoll()
|
disableBackgroundLongPoll()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onUserAuthenticated() {
|
|
||||||
loadProfile()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun loadProfile() {
|
private fun loadProfile() {
|
||||||
loadUserByIdUseCase(userId = null)
|
loadUserByIdUseCase(userId = null)
|
||||||
.listenValue(viewModelScope) { state ->
|
.listenValue(viewModelScope) { state ->
|
||||||
state.processState(
|
state.processState(
|
||||||
error = { error ->
|
error = { error ->
|
||||||
currentUser.emit(null)
|
profileImageUrl.emit(null)
|
||||||
},
|
},
|
||||||
success = { response ->
|
success = { response ->
|
||||||
val user = response ?: return@listenValue
|
val user = response ?: return@listenValue
|
||||||
currentUser.emit(user)
|
|
||||||
|
profileImageUrl.emit(user.photo100)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ val applicationModule = module {
|
|||||||
createChatModule
|
createChatModule
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TODO: 14/05/2024, Danil Nikolaev: research on memory leaks and potentials errors
|
||||||
// TODO: 14/05/2024, Danil Nikolaev: extract all operations with preferences to standalone class
|
// TODO: 14/05/2024, Danil Nikolaev: extract all operations with preferences to standalone class
|
||||||
singleOf(PreferenceManager::getDefaultSharedPreferences)
|
singleOf(PreferenceManager::getDefaultSharedPreferences)
|
||||||
single<Resources> { androidContext().resources }
|
single<Resources> { androidContext().resources }
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ package dev.meloda.fast.navigation
|
|||||||
|
|
||||||
import androidx.navigation.NavGraphBuilder
|
import androidx.navigation.NavGraphBuilder
|
||||||
import androidx.navigation.compose.composable
|
import androidx.navigation.compose.composable
|
||||||
import dev.meloda.fast.conversations.navigation.ConversationsGraph
|
import dev.meloda.fast.MainViewModel
|
||||||
|
import dev.meloda.fast.conversations.navigation.Conversations
|
||||||
import dev.meloda.fast.friends.navigation.Friends
|
import dev.meloda.fast.friends.navigation.Friends
|
||||||
import dev.meloda.fast.model.BaseError
|
import dev.meloda.fast.model.BaseError
|
||||||
import dev.meloda.fast.model.BottomNavigationItem
|
import dev.meloda.fast.model.BottomNavigationItem
|
||||||
@@ -21,10 +22,11 @@ object Main
|
|||||||
fun NavGraphBuilder.mainScreen(
|
fun NavGraphBuilder.mainScreen(
|
||||||
onError: (BaseError) -> Unit,
|
onError: (BaseError) -> Unit,
|
||||||
onSettingsButtonClicked: () -> Unit,
|
onSettingsButtonClicked: () -> Unit,
|
||||||
onNavigateToMessagesHistory: (conversationId: Long) -> Unit,
|
onConversationClicked: (conversationId: Int) -> Unit,
|
||||||
onPhotoClicked: (url: String) -> Unit,
|
onPhotoClicked: (url: String) -> Unit,
|
||||||
onMessageClicked: (userid: Long) -> Unit,
|
onMessageClicked: (userId: Int) -> Unit,
|
||||||
onNavigateToCreateChat: () -> Unit
|
onCreateChatClicked: () -> Unit,
|
||||||
|
viewModel: MainViewModel
|
||||||
) {
|
) {
|
||||||
val navigationItems = ImmutableList.of(
|
val navigationItems = ImmutableList.of(
|
||||||
BottomNavigationItem(
|
BottomNavigationItem(
|
||||||
@@ -37,7 +39,7 @@ fun NavGraphBuilder.mainScreen(
|
|||||||
titleResId = UiR.string.title_conversations,
|
titleResId = UiR.string.title_conversations,
|
||||||
selectedIconResId = UiR.drawable.baseline_chat_24,
|
selectedIconResId = UiR.drawable.baseline_chat_24,
|
||||||
unselectedIconResId = UiR.drawable.outline_chat_24,
|
unselectedIconResId = UiR.drawable.outline_chat_24,
|
||||||
route = ConversationsGraph
|
route = Conversations
|
||||||
),
|
),
|
||||||
BottomNavigationItem(
|
BottomNavigationItem(
|
||||||
titleResId = UiR.string.title_profile,
|
titleResId = UiR.string.title_profile,
|
||||||
@@ -52,10 +54,11 @@ fun NavGraphBuilder.mainScreen(
|
|||||||
navigationItems = navigationItems,
|
navigationItems = navigationItems,
|
||||||
onError = onError,
|
onError = onError,
|
||||||
onSettingsButtonClicked = onSettingsButtonClicked,
|
onSettingsButtonClicked = onSettingsButtonClicked,
|
||||||
onNavigateToMessagesHistory = onNavigateToMessagesHistory,
|
onConversationItemClicked = onConversationClicked,
|
||||||
onPhotoClicked = onPhotoClicked,
|
onPhotoClicked = onPhotoClicked,
|
||||||
onMessageClicked = onMessageClicked,
|
onMessageClicked = onMessageClicked,
|
||||||
onNavigateToCreateChat = onNavigateToCreateChat
|
onCreateChatClicked = onCreateChatClicked,
|
||||||
|
viewModel = viewModel
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ import dev.meloda.fast.common.LongPollController
|
|||||||
import dev.meloda.fast.common.model.LongPollState
|
import dev.meloda.fast.common.model.LongPollState
|
||||||
import dev.meloda.fast.datastore.AppSettings
|
import dev.meloda.fast.datastore.AppSettings
|
||||||
import dev.meloda.fast.datastore.UserSettings
|
import dev.meloda.fast.datastore.UserSettings
|
||||||
import dev.meloda.fast.model.api.domain.VkUser
|
|
||||||
import dev.meloda.fast.service.OnlineService
|
import dev.meloda.fast.service.OnlineService
|
||||||
import dev.meloda.fast.service.longpolling.LongPollingService
|
import dev.meloda.fast.service.longpolling.LongPollingService
|
||||||
import dev.meloda.fast.ui.model.DeviceSize
|
import dev.meloda.fast.ui.model.DeviceSize
|
||||||
@@ -47,7 +46,6 @@ import dev.meloda.fast.ui.model.ThemeConfig
|
|||||||
import dev.meloda.fast.ui.theme.AppTheme
|
import dev.meloda.fast.ui.theme.AppTheme
|
||||||
import dev.meloda.fast.ui.theme.LocalSizeConfig
|
import dev.meloda.fast.ui.theme.LocalSizeConfig
|
||||||
import dev.meloda.fast.ui.theme.LocalThemeConfig
|
import dev.meloda.fast.ui.theme.LocalThemeConfig
|
||||||
import dev.meloda.fast.ui.theme.LocalUser
|
|
||||||
import dev.meloda.fast.ui.util.isNeedToEnableDarkMode
|
import dev.meloda.fast.ui.util.isNeedToEnableDarkMode
|
||||||
import org.koin.androidx.compose.koinViewModel
|
import org.koin.androidx.compose.koinViewModel
|
||||||
import org.koin.compose.KoinContext
|
import org.koin.compose.KoinContext
|
||||||
@@ -100,8 +98,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
val viewModel: MainViewModel = koinViewModel<MainViewModelImpl>()
|
val viewModel: MainViewModel = koinViewModel<MainViewModelImpl>()
|
||||||
|
|
||||||
val currentUser: VkUser? by viewModel.currentUser.collectAsStateWithLifecycle()
|
|
||||||
|
|
||||||
LifecycleResumeEffect(true) {
|
LifecycleResumeEffect(true) {
|
||||||
viewModel.onAppResumed(intent)
|
viewModel.onAppResumed(intent)
|
||||||
onPauseOrDispose {}
|
onPauseOrDispose {}
|
||||||
@@ -137,8 +133,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LifecycleResumeEffect(longPollStateToApply) {
|
LaunchedEffect(longPollStateToApply) {
|
||||||
Log.d("LongPollMainActivity", "longPollStateToApply: $longPollStateToApply")
|
|
||||||
if (longPollStateToApply != LongPollState.Background) {
|
if (longPollStateToApply != LongPollState.Background) {
|
||||||
if (longPollStateToApply.isLaunched() && longPollCurrentState.isLaunched()
|
if (longPollStateToApply.isLaunched() && longPollCurrentState.isLaunched()
|
||||||
&& longPollCurrentState != longPollStateToApply
|
&& longPollCurrentState != longPollStateToApply
|
||||||
@@ -152,8 +147,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
inBackground = longPollStateToApply == LongPollState.Background
|
inBackground = longPollStateToApply == LongPollState.Background
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
onPauseOrDispose {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val sendOnline by userSettings.sendOnlineStatus.collectAsStateWithLifecycle()
|
val sendOnline by userSettings.sendOnlineStatus.collectAsStateWithLifecycle()
|
||||||
@@ -209,7 +202,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
val enableBlur by userSettings.useBlur.collectAsStateWithLifecycle()
|
val enableBlur by userSettings.useBlur.collectAsStateWithLifecycle()
|
||||||
val enableMultiline by userSettings.enableMultiline.collectAsStateWithLifecycle()
|
val enableMultiline by userSettings.enableMultiline.collectAsStateWithLifecycle()
|
||||||
val useSystemFont by userSettings.useSystemFont.collectAsStateWithLifecycle()
|
val useSystemFont by userSettings.useSystemFont.collectAsStateWithLifecycle()
|
||||||
val enableAnimations by userSettings.enableAnimations.collectAsStateWithLifecycle()
|
|
||||||
|
|
||||||
val setDarkMode = isNeedToEnableDarkMode(darkMode = darkMode)
|
val setDarkMode = isNeedToEnableDarkMode(darkMode = darkMode)
|
||||||
|
|
||||||
@@ -222,7 +214,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
setDarkMode,
|
setDarkMode,
|
||||||
useSystemFont
|
useSystemFont
|
||||||
) {
|
) {
|
||||||
derivedStateOf {
|
mutableStateOf(
|
||||||
ThemeConfig(
|
ThemeConfig(
|
||||||
darkMode = setDarkMode,
|
darkMode = setDarkMode,
|
||||||
dynamicColors = dynamicColors,
|
dynamicColors = dynamicColors,
|
||||||
@@ -230,16 +222,14 @@ class MainActivity : AppCompatActivity() {
|
|||||||
amoledDark = amoledDark,
|
amoledDark = amoledDark,
|
||||||
enableBlur = enableBlur,
|
enableBlur = enableBlur,
|
||||||
enableMultiline = enableMultiline,
|
enableMultiline = enableMultiline,
|
||||||
useSystemFont = useSystemFont,
|
useSystemFont = useSystemFont
|
||||||
enableAnimations = enableAnimations
|
)
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CompositionLocalProvider(
|
CompositionLocalProvider(
|
||||||
LocalThemeConfig provides themeConfig,
|
LocalThemeConfig provides themeConfig,
|
||||||
LocalSizeConfig provides sizeConfig,
|
LocalSizeConfig provides sizeConfig
|
||||||
LocalUser provides currentUser
|
|
||||||
) {
|
) {
|
||||||
AppTheme(
|
AppTheme(
|
||||||
useDarkTheme = themeConfig.darkMode,
|
useDarkTheme = themeConfig.darkMode,
|
||||||
@@ -302,19 +292,12 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val longPollingServiceIntent by lazy {
|
|
||||||
Intent(this, LongPollingService::class.java)
|
|
||||||
}
|
|
||||||
private val onlineServiceIntent by lazy {
|
|
||||||
Intent(this, OnlineService::class.java)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun toggleLongPollService(
|
private fun toggleLongPollService(
|
||||||
enable: Boolean,
|
enable: Boolean,
|
||||||
inBackground: Boolean = AppSettings.Experimental.longPollInBackground
|
inBackground: Boolean = AppSettings.Experimental.longPollInBackground
|
||||||
) {
|
) {
|
||||||
if (enable) {
|
if (enable) {
|
||||||
val longPollIntent = longPollingServiceIntent
|
val longPollIntent = Intent(this, LongPollingService::class.java)
|
||||||
|
|
||||||
if (inBackground) {
|
if (inBackground) {
|
||||||
ContextCompat.startForegroundService(this, longPollIntent)
|
ContextCompat.startForegroundService(this, longPollIntent)
|
||||||
@@ -322,15 +305,15 @@ class MainActivity : AppCompatActivity() {
|
|||||||
startService(longPollIntent)
|
startService(longPollIntent)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
stopService(longPollingServiceIntent)
|
stopService(Intent(this, LongPollingService::class.java))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun toggleOnlineService(enable: Boolean) {
|
private fun toggleOnlineService(enable: Boolean) {
|
||||||
if (enable) {
|
if (enable) {
|
||||||
startService(onlineServiceIntent)
|
startService(Intent(this, OnlineService::class.java))
|
||||||
} else {
|
} else {
|
||||||
stopService(onlineServiceIntent)
|
stopService(Intent(this, OnlineService::class.java))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package dev.meloda.fast.presentation
|
package dev.meloda.fast.presentation
|
||||||
|
|
||||||
import androidx.activity.compose.BackHandler
|
|
||||||
import androidx.compose.animation.core.tween
|
import androidx.compose.animation.core.tween
|
||||||
import androidx.compose.animation.fadeIn
|
import androidx.compose.animation.fadeIn
|
||||||
import androidx.compose.animation.fadeOut
|
import androidx.compose.animation.fadeOut
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.foundation.shape.CircleShape
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
@@ -16,7 +16,6 @@ import androidx.compose.material3.NavigationBarItem
|
|||||||
import androidx.compose.material3.Scaffold
|
import androidx.compose.material3.Scaffold
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.CompositionLocalProvider
|
import androidx.compose.runtime.CompositionLocalProvider
|
||||||
import androidx.compose.runtime.derivedStateOf
|
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableIntStateOf
|
import androidx.compose.runtime.mutableIntStateOf
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
@@ -26,9 +25,9 @@ import androidx.compose.runtime.setValue
|
|||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.alpha
|
import androidx.compose.ui.draw.alpha
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.graphics.Color
|
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import androidx.navigation.compose.NavHost
|
import androidx.navigation.compose.NavHost
|
||||||
import androidx.navigation.compose.navigation
|
import androidx.navigation.compose.navigation
|
||||||
import androidx.navigation.compose.rememberNavController
|
import androidx.navigation.compose.rememberNavController
|
||||||
@@ -37,10 +36,8 @@ import dev.chrisbanes.haze.HazeState
|
|||||||
import dev.chrisbanes.haze.hazeEffect
|
import dev.chrisbanes.haze.hazeEffect
|
||||||
import dev.chrisbanes.haze.materials.ExperimentalHazeMaterialsApi
|
import dev.chrisbanes.haze.materials.ExperimentalHazeMaterialsApi
|
||||||
import dev.chrisbanes.haze.materials.HazeMaterials
|
import dev.chrisbanes.haze.materials.HazeMaterials
|
||||||
import dev.meloda.fast.conversations.navigation.Conversations
|
import dev.meloda.fast.MainViewModel
|
||||||
import dev.meloda.fast.conversations.navigation.ConversationsGraph
|
import dev.meloda.fast.conversations.navigation.conversationsScreen
|
||||||
import dev.meloda.fast.conversations.navigation.conversationsGraph
|
|
||||||
import dev.meloda.fast.friends.navigation.Friends
|
|
||||||
import dev.meloda.fast.friends.navigation.friendsScreen
|
import dev.meloda.fast.friends.navigation.friendsScreen
|
||||||
import dev.meloda.fast.model.BaseError
|
import dev.meloda.fast.model.BaseError
|
||||||
import dev.meloda.fast.model.BottomNavigationItem
|
import dev.meloda.fast.model.BottomNavigationItem
|
||||||
@@ -48,10 +45,7 @@ import dev.meloda.fast.navigation.MainGraph
|
|||||||
import dev.meloda.fast.profile.navigation.profileScreen
|
import dev.meloda.fast.profile.navigation.profileScreen
|
||||||
import dev.meloda.fast.ui.theme.LocalBottomPadding
|
import dev.meloda.fast.ui.theme.LocalBottomPadding
|
||||||
import dev.meloda.fast.ui.theme.LocalHazeState
|
import dev.meloda.fast.ui.theme.LocalHazeState
|
||||||
import dev.meloda.fast.ui.theme.LocalNavController
|
|
||||||
import dev.meloda.fast.ui.theme.LocalReselectedTab
|
|
||||||
import dev.meloda.fast.ui.theme.LocalThemeConfig
|
import dev.meloda.fast.ui.theme.LocalThemeConfig
|
||||||
import dev.meloda.fast.ui.theme.LocalUser
|
|
||||||
import dev.meloda.fast.ui.util.ImmutableList
|
import dev.meloda.fast.ui.util.ImmutableList
|
||||||
|
|
||||||
@OptIn(ExperimentalHazeMaterialsApi::class)
|
@OptIn(ExperimentalHazeMaterialsApi::class)
|
||||||
@@ -60,59 +54,38 @@ fun MainScreen(
|
|||||||
navigationItems: ImmutableList<BottomNavigationItem>,
|
navigationItems: ImmutableList<BottomNavigationItem>,
|
||||||
onError: (BaseError) -> Unit = {},
|
onError: (BaseError) -> Unit = {},
|
||||||
onSettingsButtonClicked: () -> Unit = {},
|
onSettingsButtonClicked: () -> Unit = {},
|
||||||
onNavigateToMessagesHistory: (conversationId: Long) -> Unit = {},
|
onConversationItemClicked: (conversationId: Int) -> Unit = {},
|
||||||
onPhotoClicked: (url: String) -> Unit = {},
|
onPhotoClicked: (url: String) -> Unit = {},
|
||||||
onMessageClicked: (userid: Long) -> Unit = {},
|
onMessageClicked: (userId: Int) -> Unit = {},
|
||||||
onNavigateToCreateChat: () -> Unit = {}
|
onCreateChatClicked: () -> Unit = {},
|
||||||
|
viewModel: MainViewModel
|
||||||
) {
|
) {
|
||||||
val theme = LocalThemeConfig.current
|
val currentTheme = LocalThemeConfig.current
|
||||||
val hazeState = remember { HazeState() }
|
val hazeState = remember { HazeState() }
|
||||||
val navController = rememberNavController()
|
val navController = rememberNavController()
|
||||||
|
|
||||||
|
val profileImageUrl by viewModel.profileImageUrl.collectAsStateWithLifecycle()
|
||||||
|
|
||||||
var selectedItemIndex by rememberSaveable {
|
var selectedItemIndex by rememberSaveable {
|
||||||
mutableIntStateOf(1)
|
mutableIntStateOf(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
BackHandler(enabled = selectedItemIndex != 1) {
|
|
||||||
val index = 1
|
|
||||||
val currentRoute = navigationItems[selectedItemIndex].route
|
|
||||||
|
|
||||||
selectedItemIndex = 1
|
|
||||||
navController.navigate(navigationItems[index].route) {
|
|
||||||
popUpTo(route = currentRoute) {
|
|
||||||
inclusive = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val user = LocalUser.current
|
|
||||||
val profileImageUrl by remember(user) {
|
|
||||||
derivedStateOf { user?.photo100 }
|
|
||||||
}
|
|
||||||
|
|
||||||
var tabReselected by remember {
|
|
||||||
mutableStateOf(
|
|
||||||
navigationItems.associate {
|
|
||||||
it.route to false
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
bottomBar = {
|
bottomBar = {
|
||||||
NavigationBar(
|
NavigationBar(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
|
||||||
.then(
|
.then(
|
||||||
if (theme.enableBlur) {
|
if (currentTheme.enableBlur) {
|
||||||
Modifier.hazeEffect(
|
Modifier.hazeEffect(
|
||||||
state = hazeState,
|
state = hazeState,
|
||||||
style = HazeMaterials.thick()
|
style = HazeMaterials.thick()
|
||||||
)
|
)
|
||||||
} else Modifier
|
} else Modifier
|
||||||
),
|
)
|
||||||
containerColor = if (theme.enableBlur) Color.Transparent
|
.fillMaxWidth(),
|
||||||
else NavigationBarDefaults.containerColor
|
containerColor = NavigationBarDefaults.containerColor.copy(
|
||||||
|
alpha = if (currentTheme.enableBlur) 0f else 1f
|
||||||
|
)
|
||||||
) {
|
) {
|
||||||
navigationItems.forEachIndexed { index, item ->
|
navigationItems.forEachIndexed { index, item ->
|
||||||
NavigationBarItem(
|
NavigationBarItem(
|
||||||
@@ -127,10 +100,6 @@ fun MainScreen(
|
|||||||
inclusive = true
|
inclusive = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
tabReselected = tabReselected.toMutableMap().also {
|
|
||||||
it[navigationItems[index].route] = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
icon = {
|
icon = {
|
||||||
@@ -154,7 +123,9 @@ fun MainScreen(
|
|||||||
.size(24.dp)
|
.size(24.dp)
|
||||||
.clip(CircleShape)
|
.clip(CircleShape)
|
||||||
.alpha(if (isLoading) 0f else 1f),
|
.alpha(if (isLoading) 0f else 1f),
|
||||||
onSuccess = { isLoading = false }
|
onSuccess = {
|
||||||
|
isLoading = false
|
||||||
|
}
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
Icon(
|
Icon(
|
||||||
@@ -175,12 +146,11 @@ fun MainScreen(
|
|||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
|
.padding(bottom = if (currentTheme.enableBlur) 0.dp else padding.calculateBottomPadding())
|
||||||
) {
|
) {
|
||||||
CompositionLocalProvider(
|
CompositionLocalProvider(
|
||||||
LocalHazeState provides hazeState,
|
LocalHazeState provides hazeState,
|
||||||
LocalBottomPadding provides padding.calculateBottomPadding(),
|
LocalBottomPadding provides if (currentTheme.enableBlur) padding.calculateBottomPadding() else 0.dp
|
||||||
LocalReselectedTab provides tabReselected,
|
|
||||||
LocalNavController provides navController
|
|
||||||
) {
|
) {
|
||||||
NavHost(
|
NavHost(
|
||||||
navController = navController,
|
navController = navController,
|
||||||
@@ -195,28 +165,22 @@ fun MainScreen(
|
|||||||
) {
|
) {
|
||||||
friendsScreen(
|
friendsScreen(
|
||||||
onError = onError,
|
onError = onError,
|
||||||
|
navController = navController,
|
||||||
onPhotoClicked = onPhotoClicked,
|
onPhotoClicked = onPhotoClicked,
|
||||||
onMessageClicked = onMessageClicked,
|
onMessageClicked = onMessageClicked
|
||||||
onScrolledToTop = {
|
|
||||||
tabReselected = tabReselected.toMutableMap().also {
|
|
||||||
it[Friends] = false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
conversationsGraph(
|
conversationsScreen(
|
||||||
onError = onError,
|
onError = onError,
|
||||||
onNavigateToMessagesHistory = onNavigateToMessagesHistory,
|
onConversationItemClicked = onConversationItemClicked,
|
||||||
onNavigateToCreateChat = onNavigateToCreateChat,
|
onPhotoClicked = onPhotoClicked,
|
||||||
onScrolledToTop = {
|
onCreateChatClicked = onCreateChatClicked,
|
||||||
tabReselected = tabReselected.toMutableMap().also {
|
navController = navController,
|
||||||
it[ConversationsGraph] = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
profileScreen(
|
profileScreen(
|
||||||
onError = onError,
|
onError = onError,
|
||||||
onSettingsButtonClicked = onSettingsButtonClicked,
|
onSettingsButtonClicked = onSettingsButtonClicked,
|
||||||
onPhotoClicked = onPhotoClicked
|
onPhotoClicked = onPhotoClicked,
|
||||||
|
navController = navController
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import androidx.compose.material3.AlertDialog
|
|||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TextButton
|
import androidx.compose.material3.TextButton
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.CompositionLocalProvider
|
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
@@ -39,8 +38,6 @@ import dev.meloda.fast.photoviewer.navigation.photoViewScreen
|
|||||||
import dev.meloda.fast.settings.navigation.navigateToSettings
|
import dev.meloda.fast.settings.navigation.navigateToSettings
|
||||||
import dev.meloda.fast.settings.navigation.settingsScreen
|
import dev.meloda.fast.settings.navigation.settingsScreen
|
||||||
import dev.meloda.fast.ui.R
|
import dev.meloda.fast.ui.R
|
||||||
import dev.meloda.fast.ui.theme.LocalNavController
|
|
||||||
import dev.meloda.fast.ui.theme.LocalNavRootController
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun RootScreen(
|
fun RootScreen(
|
||||||
@@ -114,10 +111,6 @@ fun RootScreen(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (startDestination != null) {
|
if (startDestination != null) {
|
||||||
CompositionLocalProvider(
|
|
||||||
LocalNavRootController provides navController,
|
|
||||||
LocalNavController provides navController
|
|
||||||
) {
|
|
||||||
NavHost(
|
NavHost(
|
||||||
navController = navController,
|
navController = navController,
|
||||||
startDestination = requireNotNull(startDestination),
|
startDestination = requireNotNull(startDestination),
|
||||||
@@ -125,26 +118,23 @@ fun RootScreen(
|
|||||||
exitTransition = { fadeOut(animationSpec = tween(200)) }
|
exitTransition = { fadeOut(animationSpec = tween(200)) }
|
||||||
) {
|
) {
|
||||||
authNavGraph(
|
authNavGraph(
|
||||||
onNavigateToMain = {
|
onNavigateToMain = navController::navigateToMain,
|
||||||
viewModel.onUserAuthenticated()
|
|
||||||
navController.navigateToMain()
|
|
||||||
},
|
|
||||||
navController = navController
|
navController = navController
|
||||||
)
|
)
|
||||||
|
|
||||||
mainScreen(
|
mainScreen(
|
||||||
onError = viewModel::onError,
|
onError = viewModel::onError,
|
||||||
onSettingsButtonClicked = navController::navigateToSettings,
|
onSettingsButtonClicked = navController::navigateToSettings,
|
||||||
onNavigateToMessagesHistory = navController::navigateToMessagesHistory,
|
onConversationClicked = navController::navigateToMessagesHistory,
|
||||||
onPhotoClicked = { url -> navController.navigateToPhotoView(listOf(url)) },
|
onPhotoClicked = { url -> navController.navigateToPhotoView(listOf(url)) },
|
||||||
onMessageClicked = navController::navigateToMessagesHistory,
|
onMessageClicked = navController::navigateToMessagesHistory,
|
||||||
onNavigateToCreateChat = navController::navigateToCreateChat
|
onCreateChatClicked = navController::navigateToCreateChat,
|
||||||
|
viewModel = viewModel
|
||||||
)
|
)
|
||||||
|
|
||||||
messagesHistoryScreen(
|
messagesHistoryScreen(
|
||||||
onError = viewModel::onError,
|
onError = viewModel::onError,
|
||||||
onBack = navController::navigateUp,
|
onBack = navController::navigateUp,
|
||||||
onNavigateToChatMaterials = navController::navigateToChatMaterials
|
onChatMaterialsDropdownItemClicked = navController::navigateToChatMaterials
|
||||||
)
|
)
|
||||||
chatMaterialsScreen(
|
chatMaterialsScreen(
|
||||||
onBack = navController::navigateUp,
|
onBack = navController::navigateUp,
|
||||||
@@ -168,7 +158,6 @@ fun RootScreen(
|
|||||||
photoViewScreen(onBack = navController::navigateUp)
|
photoViewScreen(onBack = navController::navigateUp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun NavController.navigateToMain() {
|
fun NavController.navigateToMain() {
|
||||||
|
|||||||
@@ -16,11 +16,11 @@ import dev.meloda.fast.common.LongPollController
|
|||||||
import dev.meloda.fast.common.VkConstants
|
import dev.meloda.fast.common.VkConstants
|
||||||
import dev.meloda.fast.common.extensions.listenValue
|
import dev.meloda.fast.common.extensions.listenValue
|
||||||
import dev.meloda.fast.common.model.LongPollState
|
import dev.meloda.fast.common.model.LongPollState
|
||||||
|
import dev.meloda.fast.domain.LongPollUpdatesParser
|
||||||
|
import dev.meloda.fast.domain.LongPollUseCase
|
||||||
import dev.meloda.fast.data.UserConfig
|
import dev.meloda.fast.data.UserConfig
|
||||||
import dev.meloda.fast.data.processState
|
import dev.meloda.fast.data.processState
|
||||||
import dev.meloda.fast.datastore.AppSettings
|
import dev.meloda.fast.datastore.AppSettings
|
||||||
import dev.meloda.fast.domain.LongPollUpdatesParser
|
|
||||||
import dev.meloda.fast.domain.LongPollUseCase
|
|
||||||
import dev.meloda.fast.model.api.data.LongPollUpdates
|
import dev.meloda.fast.model.api.data.LongPollUpdates
|
||||||
import dev.meloda.fast.model.api.data.VkLongPollData
|
import dev.meloda.fast.model.api.data.VkLongPollData
|
||||||
import dev.meloda.fast.ui.R
|
import dev.meloda.fast.ui.R
|
||||||
@@ -30,13 +30,11 @@ import kotlinx.coroutines.CoroutineScope
|
|||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.SupervisorJob
|
import kotlinx.coroutines.SupervisorJob
|
||||||
import kotlinx.coroutines.delay
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.koin.android.ext.android.inject
|
import org.koin.android.ext.android.inject
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlin.coroutines.CoroutineContext
|
||||||
import kotlin.coroutines.resume
|
import kotlin.coroutines.resume
|
||||||
import kotlin.coroutines.suspendCoroutine
|
import kotlin.coroutines.suspendCoroutine
|
||||||
import kotlin.time.Duration.Companion.seconds
|
|
||||||
|
|
||||||
class LongPollingService : Service() {
|
class LongPollingService : Service() {
|
||||||
|
|
||||||
@@ -44,9 +42,15 @@ class LongPollingService : Service() {
|
|||||||
|
|
||||||
private val job = SupervisorJob()
|
private val job = SupervisorJob()
|
||||||
|
|
||||||
private val exceptionHandler =
|
private val exceptionHandler = CoroutineExceptionHandler { _, throwable ->
|
||||||
CoroutineExceptionHandler { _, throwable ->
|
Log.e(TAG, "error: $throwable")
|
||||||
handleError(throwable)
|
|
||||||
|
if (throwable !is NoAccessTokenException) {
|
||||||
|
throwable.printStackTrace()
|
||||||
|
}
|
||||||
|
|
||||||
|
longPollController.updateCurrentState(LongPollState.Exception)
|
||||||
|
longPollController.setStateToApply(LongPollState.Exception)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val coroutineContext: CoroutineContext
|
private val coroutineContext: CoroutineContext
|
||||||
@@ -59,8 +63,6 @@ class LongPollingService : Service() {
|
|||||||
|
|
||||||
private var currentJob: Job? = null
|
private var currentJob: Job? = null
|
||||||
|
|
||||||
private val inBackground get() = AppSettings.Experimental.longPollInBackground
|
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
Log.d(STATE_TAG, "onCreate()")
|
Log.d(STATE_TAG, "onCreate()")
|
||||||
@@ -74,12 +76,21 @@ class LongPollingService : Service() {
|
|||||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
if (startId > 1) return START_STICKY
|
if (startId > 1) return START_STICKY
|
||||||
|
|
||||||
|
val inBackground = AppSettings.Experimental.longPollInBackground
|
||||||
|
|
||||||
Log.d(
|
Log.d(
|
||||||
STATE_TAG,
|
STATE_TAG,
|
||||||
"onStartCommand: asForeground: $inBackground; flags: $flags; startId: $startId;\ninstance: $this"
|
"onStartCommand: asForeground: $inBackground; flags: $flags; startId: $startId;\ninstance: $this"
|
||||||
)
|
)
|
||||||
|
|
||||||
startJob()
|
if (currentJob != null) {
|
||||||
|
currentJob?.cancel()
|
||||||
|
currentJob = null
|
||||||
|
}
|
||||||
|
|
||||||
|
coroutineScope.launch {
|
||||||
|
currentJob = startPolling().also { it.join() }
|
||||||
|
}
|
||||||
|
|
||||||
val openCategorySettingsIntent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
val openCategorySettingsIntent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
|
Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
|
||||||
@@ -97,6 +108,11 @@ class LongPollingService : Service() {
|
|||||||
PendingIntent.FLAG_IMMUTABLE
|
PendingIntent.FLAG_IMMUTABLE
|
||||||
)
|
)
|
||||||
|
|
||||||
|
longPollController.updateCurrentState(
|
||||||
|
if (inBackground) LongPollState.Background
|
||||||
|
else LongPollState.InApp
|
||||||
|
)
|
||||||
|
|
||||||
if (inBackground) {
|
if (inBackground) {
|
||||||
val notification =
|
val notification =
|
||||||
NotificationsUtils.createNotification(
|
NotificationsUtils.createNotification(
|
||||||
@@ -118,33 +134,17 @@ class LongPollingService : Service() {
|
|||||||
return START_STICKY
|
return START_STICKY
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun startJob() {
|
|
||||||
if (currentJob != null) {
|
|
||||||
currentJob?.cancel()
|
|
||||||
currentJob = null
|
|
||||||
}
|
|
||||||
|
|
||||||
coroutineScope.launch {
|
|
||||||
currentJob = startPolling().also { it.join() }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun startPolling(): Job {
|
private fun startPolling(): Job {
|
||||||
if (job.isCompleted || job.isCancelled) {
|
if (job.isCompleted || job.isCancelled) {
|
||||||
Log.d(STATE_TAG, "Job is completed or cancelled")
|
Log.d(STATE_TAG, "job is completed or cancelled")
|
||||||
throw Exception("Job is over")
|
throw Exception("Job is over")
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.d(STATE_TAG, "Starting job...")
|
Log.d(STATE_TAG, "job started")
|
||||||
|
|
||||||
return coroutineScope.launch(coroutineContext) {
|
|
||||||
longPollController.updateCurrentState(
|
|
||||||
if (inBackground) LongPollState.Background
|
|
||||||
else LongPollState.InApp
|
|
||||||
)
|
|
||||||
|
|
||||||
|
return coroutineScope.launch {
|
||||||
if (UserConfig.accessToken.isEmpty()) {
|
if (UserConfig.accessToken.isEmpty()) {
|
||||||
throw NoAccessTokenException()
|
throw NoAccessTokenException
|
||||||
}
|
}
|
||||||
|
|
||||||
var serverInfo = getServerInfo()
|
var serverInfo = getServerInfo()
|
||||||
@@ -246,21 +246,6 @@ class LongPollingService : Service() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleError(throwable: Throwable) {
|
|
||||||
Log.e(TAG, "error: $throwable")
|
|
||||||
|
|
||||||
if (throwable !is NoAccessTokenException) {
|
|
||||||
throwable.printStackTrace()
|
|
||||||
}
|
|
||||||
|
|
||||||
coroutineScope.launch {
|
|
||||||
delay(5.seconds)
|
|
||||||
startJob()
|
|
||||||
}
|
|
||||||
|
|
||||||
longPollController.updateCurrentState(LongPollState.Exception)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
Log.d(STATE_TAG, "onDestroy")
|
Log.d(STATE_TAG, "onDestroy")
|
||||||
longPollController.updateCurrentState(LongPollState.Stopped)
|
longPollController.updateCurrentState(LongPollState.Stopped)
|
||||||
@@ -274,7 +259,8 @@ class LongPollingService : Service() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onTrimMemory(level: Int) {
|
override fun onTrimMemory(level: Int) {
|
||||||
Log.d(STATE_TAG, "onTrimMemory. Level: $level")
|
Log.d(STATE_TAG, "onTrimMemory")
|
||||||
|
longPollController.updateCurrentState(LongPollState.Stopped)
|
||||||
super.onTrimMemory(level)
|
super.onTrimMemory(level)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -290,4 +276,4 @@ class LongPollingService : Service() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private data class LongPollException(override val message: String) : Throwable()
|
private data class LongPollException(override val message: String) : Throwable()
|
||||||
private class NoAccessTokenException : Throwable()
|
private data object NoAccessTokenException : Throwable()
|
||||||
|
|||||||
@@ -7,13 +7,13 @@ plugins {
|
|||||||
group = "dev.meloda.fast.buildlogic"
|
group = "dev.meloda.fast.buildlogic"
|
||||||
|
|
||||||
java {
|
java {
|
||||||
sourceCompatibility = JavaVersion.VERSION_21
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
targetCompatibility = JavaVersion.VERSION_21
|
targetCompatibility = JavaVersion.VERSION_17
|
||||||
}
|
}
|
||||||
|
|
||||||
kotlin {
|
kotlin {
|
||||||
compilerOptions {
|
compilerOptions {
|
||||||
jvmTarget = JvmTarget.JVM_21
|
jvmTarget = JvmTarget.JVM_17
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ internal fun Project.configureKotlinAndroid(
|
|||||||
}
|
}
|
||||||
|
|
||||||
compileOptions {
|
compileOptions {
|
||||||
sourceCompatibility = JavaVersion.VERSION_21
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
targetCompatibility = JavaVersion.VERSION_21
|
targetCompatibility = JavaVersion.VERSION_17
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,8 +33,8 @@ internal fun Project.configureKotlinAndroid(
|
|||||||
|
|
||||||
internal fun Project.configureKotlinJvm() {
|
internal fun Project.configureKotlinJvm() {
|
||||||
extensions.configure<JavaPluginExtension> {
|
extensions.configure<JavaPluginExtension> {
|
||||||
sourceCompatibility = JavaVersion.VERSION_21
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
targetCompatibility = JavaVersion.VERSION_21
|
targetCompatibility = JavaVersion.VERSION_17
|
||||||
}
|
}
|
||||||
|
|
||||||
configureKotlin<KotlinJvmProjectExtension>()
|
configureKotlin<KotlinJvmProjectExtension>()
|
||||||
@@ -49,7 +49,7 @@ private inline fun <reified T : KotlinBaseExtension> Project.configureKotlin() =
|
|||||||
is KotlinJvmProjectExtension -> compilerOptions
|
is KotlinJvmProjectExtension -> compilerOptions
|
||||||
else -> TODO("Unsupported project extension $this ${T::class}")
|
else -> TODO("Unsupported project extension $this ${T::class}")
|
||||||
}.apply {
|
}.apply {
|
||||||
jvmTarget = JvmTarget.JVM_21
|
jvmTarget = JvmTarget.JVM_17
|
||||||
allWarningsAsErrors = warningsAsErrors.toBoolean()
|
allWarningsAsErrors = warningsAsErrors.toBoolean()
|
||||||
freeCompilerArgs.addAll(
|
freeCompilerArgs.addAll(
|
||||||
"-opt-in=kotlin.RequiresOptIn",
|
"-opt-in=kotlin.RequiresOptIn",
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ object AppConstants {
|
|||||||
|
|
||||||
const val INSTALL_APP_MIME_TYPE = "application/vnd.android.package-archive"
|
const val INSTALL_APP_MIME_TYPE = "application/vnd.android.package-archive"
|
||||||
|
|
||||||
const val API_VERSION = "5.238"
|
const val API_VERSION = "5.173"
|
||||||
const val URL_OAUTH = "https://oauth.vk.com"
|
const val URL_OAUTH = "https://oauth.vk.com"
|
||||||
const val URL_API = "https://api.vk.com/method"
|
const val URL_API = "https://api.vk.com/method"
|
||||||
|
|
||||||
|
|||||||
@@ -5,12 +5,12 @@ object VkConstants {
|
|||||||
const val GROUP_FIELDS = "description,members_count,counters,status,verified"
|
const val GROUP_FIELDS = "description,members_count,counters,status,verified"
|
||||||
|
|
||||||
const val USER_FIELDS =
|
const val USER_FIELDS =
|
||||||
"photo_50,photo_100,photo_200,photo_400_orig,status,screen_name,online_info,last_seen,verified,sex,bdate"
|
"photo_50,photo_100,photo_200,photo_400_orig,status,screen_name,online,online_mobile,last_seen,verified,sex,online_info,bdate"
|
||||||
|
|
||||||
const val ALL_FIELDS =
|
const val ALL_FIELDS =
|
||||||
"$USER_FIELDS,$GROUP_FIELDS"
|
"$USER_FIELDS,$GROUP_FIELDS"
|
||||||
|
|
||||||
const val LP_VERSION = 19
|
const val LP_VERSION = 10
|
||||||
|
|
||||||
const val VK_APP_ID = "2274003"
|
const val VK_APP_ID = "2274003"
|
||||||
const val VK_SECRET = "hHbZxrka2uZ6jB1inYsH"
|
const val VK_SECRET = "hHbZxrka2uZ6jB1inYsH"
|
||||||
@@ -18,11 +18,6 @@ object VkConstants {
|
|||||||
const val FAST_GROUP_ID = -119516304
|
const val FAST_GROUP_ID = -119516304
|
||||||
const val FAST_APP_ID = "6964679"
|
const val FAST_APP_ID = "6964679"
|
||||||
|
|
||||||
const val MESSENGER_APP_ID = 51453752
|
|
||||||
const val MESSENGER_APP_SECRET = "4UyuCUsdK8pVCNoeQuGi"
|
|
||||||
|
|
||||||
const val MESSENGER_APP_SCOPE = 1454174
|
|
||||||
|
|
||||||
object Auth {
|
object Auth {
|
||||||
const val SCOPE = "notify," +
|
const val SCOPE = "notify," +
|
||||||
"friends," +
|
"friends," +
|
||||||
|
|||||||
@@ -23,20 +23,6 @@ fun <T> MutableList<T>.addIf(element: T, condition: () -> Boolean) {
|
|||||||
if (condition.invoke()) add(element)
|
if (condition.invoke()) add(element)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T> MutableList<T>.removeIfCompat(condition: (T) -> Boolean): Boolean {
|
|
||||||
var removed = false
|
|
||||||
|
|
||||||
val each = iterator()
|
|
||||||
while (each.hasNext()) {
|
|
||||||
if (condition(each.next())) {
|
|
||||||
each.remove()
|
|
||||||
removed = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return removed
|
|
||||||
}
|
|
||||||
|
|
||||||
fun <T> Flow<T>.listenValue(
|
fun <T> Flow<T>.listenValue(
|
||||||
coroutineScope: CoroutineScope,
|
coroutineScope: CoroutineScope,
|
||||||
action: suspend (T) -> Unit
|
action: suspend (T) -> Unit
|
||||||
@@ -89,11 +75,6 @@ fun <T> MutableStateFlow<T>.setValue(function: (T) -> T) {
|
|||||||
update { newValue }
|
update { newValue }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T> MutableStateFlow<T>.updateValue(block: T.() -> T) {
|
|
||||||
val newValue = block(value)
|
|
||||||
update { newValue }
|
|
||||||
}
|
|
||||||
|
|
||||||
fun Any.asInt(): Int {
|
fun Any.asInt(): Int {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
is Number -> this.toInt()
|
is Number -> this.toInt()
|
||||||
@@ -102,14 +83,6 @@ fun Any.asInt(): Int {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Any.asLong(): Long {
|
|
||||||
return when(this) {
|
|
||||||
is Number -> this.toLong()
|
|
||||||
|
|
||||||
else -> throw IllegalArgumentException("Object is not numeric")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun <T> Any.toList(mapper: (old: Any) -> T): List<T> {
|
fun <T> Any.toList(mapper: (old: Any) -> T): List<T> {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
is List<*> -> this.mapNotNull { it?.run(mapper) }
|
is List<*> -> this.mapNotNull { it?.run(mapper) }
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ sealed class State<out T> {
|
|||||||
data object InternalError : Error()
|
data object InternalError : Error()
|
||||||
|
|
||||||
data class OAuthError(val error: OAuthErrorDomain) : Error()
|
data class OAuthError(val error: OAuthErrorDomain) : Error()
|
||||||
|
|
||||||
|
data class TestError(val message: String) : Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isLoading(): Boolean = this is Loading
|
fun isLoading(): Boolean = this is Loading
|
||||||
@@ -36,16 +38,16 @@ sealed class State<out T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline fun <T> State<T>.processState(
|
inline fun <T> State<T>.processState(
|
||||||
error: (error: State.Error) -> Unit,
|
error: (error: State.Error) -> (Unit),
|
||||||
success: (data: T) -> Unit,
|
success: (data: T) -> (Unit),
|
||||||
idle: (() -> (Unit)) = {},
|
idle: (() -> (Unit)) = {},
|
||||||
loading: (() -> (Unit)) = {},
|
loading: (() -> (Unit)) = {},
|
||||||
any: () -> Unit = {}
|
any: () -> Unit = {}
|
||||||
) {
|
) {
|
||||||
when (this) {
|
when (this) {
|
||||||
is State.Error -> {
|
is State.Error -> {
|
||||||
any()
|
|
||||||
error(this)
|
error(this)
|
||||||
|
any()
|
||||||
}
|
}
|
||||||
|
|
||||||
State.Idle -> idle()
|
State.Idle -> idle()
|
||||||
@@ -53,47 +55,17 @@ inline fun <T> State<T>.processState(
|
|||||||
State.Loading -> loading()
|
State.Loading -> loading()
|
||||||
|
|
||||||
is State.Success -> {
|
is State.Success -> {
|
||||||
any()
|
|
||||||
success(data)
|
success(data)
|
||||||
|
any()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun OAuthErrorDomain?.toStateApiError(): State.Error {
|
|
||||||
if (this == null) return State.Error.ConnectionError
|
|
||||||
return State.Error.OAuthError(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun RestApiErrorDomain?.toStateApiError(): State.Error = when (this) {
|
fun RestApiErrorDomain?.toStateApiError(): State.Error = when (this) {
|
||||||
null -> State.Error.ConnectionError
|
null -> State.Error.ConnectionError
|
||||||
else -> State.Error.ApiError(VkErrorCode.parse(code), message)
|
else -> State.Error.ApiError(VkErrorCode.parse(code), message)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T : Any> ApiResult<T, OAuthErrorDomain>.asState() = when (this) {
|
|
||||||
is ApiResult.Success -> State.Success(this.value)
|
|
||||||
|
|
||||||
is ApiResult.Failure.NetworkFailure -> State.Error.ConnectionError
|
|
||||||
is ApiResult.Failure.UnknownFailure -> State.UNKNOWN_ERROR
|
|
||||||
is ApiResult.Failure.HttpFailure -> this.error.toStateApiError()
|
|
||||||
is ApiResult.Failure.ApiFailure -> this.error.toStateApiError()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun <T : Any, N> ApiResult<T, OAuthErrorDomain>.asState(successMapper: (T) -> N) =
|
|
||||||
when (this) {
|
|
||||||
is ApiResult.Success -> State.Success(successMapper(this.value))
|
|
||||||
|
|
||||||
is ApiResult.Failure.NetworkFailure -> State.Error.ConnectionError
|
|
||||||
is ApiResult.Failure.UnknownFailure -> State.UNKNOWN_ERROR
|
|
||||||
is ApiResult.Failure.HttpFailure -> this.error.toStateApiError()
|
|
||||||
is ApiResult.Failure.ApiFailure -> this.error.toStateApiError()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun <T : Any, E : Any> ApiResult<T, E>.success(): T =
|
|
||||||
when (this) {
|
|
||||||
is ApiResult.Success -> value
|
|
||||||
else -> throw IllegalArgumentException()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun <T : Any> ApiResult<T, RestApiErrorDomain>.mapToState() = when (this) {
|
fun <T : Any> ApiResult<T, RestApiErrorDomain>.mapToState() = when (this) {
|
||||||
is ApiResult.Success -> State.Success(this.value)
|
is ApiResult.Success -> State.Success(this.value)
|
||||||
|
|
||||||
|
|||||||
@@ -6,18 +6,17 @@ object UserConfig {
|
|||||||
|
|
||||||
private const val ARG_CURRENT_USER_ID = "current_user_id"
|
private const val ARG_CURRENT_USER_ID = "current_user_id"
|
||||||
|
|
||||||
var currentUserId: Long = -1
|
var currentUserId: Int = -1
|
||||||
get() = AppSettings.getLong(ARG_CURRENT_USER_ID, -1)
|
get() = AppSettings.getInt(ARG_CURRENT_USER_ID, -1)
|
||||||
set(value) {
|
set(value) {
|
||||||
field = value
|
field = value
|
||||||
AppSettings.edit { putLong(ARG_CURRENT_USER_ID, value) }
|
AppSettings.edit { putInt(ARG_CURRENT_USER_ID, value) }
|
||||||
}
|
}
|
||||||
|
|
||||||
var userId: Long = -1
|
var userId: Int = -1
|
||||||
var accessToken: String = ""
|
var accessToken: String = ""
|
||||||
var fastToken: String? = ""
|
var fastToken: String? = ""
|
||||||
var trustedHash: String? = null
|
var trustedHash: String? = null
|
||||||
var exchangeToken: String? = null
|
|
||||||
|
|
||||||
fun clear() {
|
fun clear() {
|
||||||
currentUserId = -1
|
currentUserId = -1
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ class VkGroupsMap(
|
|||||||
private val groups: List<VkGroupDomain>
|
private val groups: List<VkGroupDomain>
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private val map: HashMap<Long, VkGroupDomain> by lazy {
|
private val map: HashMap<Int, VkGroupDomain> by lazy {
|
||||||
HashMap(groups.associateBy(VkGroupDomain::id))
|
HashMap(groups.associateBy(VkGroupDomain::id))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ class VkGroupsMap(
|
|||||||
if (message.fromId >= 0) null
|
if (message.fromId >= 0) null
|
||||||
else map[abs(message.fromId)]
|
else map[abs(message.fromId)]
|
||||||
|
|
||||||
fun group(groupId: Long): VkGroupDomain? = map[abs(groupId)]
|
fun group(groupId: Int): VkGroupDomain? = map[abs(groupId)]
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package dev.meloda.fast.data
|
package dev.meloda.fast.data
|
||||||
|
|
||||||
import dev.meloda.fast.data.UserConfig.userId
|
|
||||||
import dev.meloda.fast.model.api.domain.VkContactDomain
|
import dev.meloda.fast.model.api.domain.VkContactDomain
|
||||||
import dev.meloda.fast.model.api.domain.VkConversation
|
import dev.meloda.fast.model.api.domain.VkConversation
|
||||||
import dev.meloda.fast.model.api.domain.VkGroupDomain
|
import dev.meloda.fast.model.api.domain.VkGroupDomain
|
||||||
@@ -10,11 +9,11 @@ import kotlin.math.abs
|
|||||||
|
|
||||||
object VkMemoryCache {
|
object VkMemoryCache {
|
||||||
|
|
||||||
private val users: HashMap<Long, VkUser> = hashMapOf()
|
private val users: HashMap<Int, VkUser> = hashMapOf()
|
||||||
private val groups: HashMap<Long, VkGroupDomain> = hashMapOf()
|
private val groups: HashMap<Int, VkGroupDomain> = hashMapOf()
|
||||||
private val messages: HashMap<Long, VkMessage> = hashMapOf()
|
private val messages: HashMap<Int, VkMessage> = hashMapOf()
|
||||||
private val conversations: HashMap<Long, VkConversation> = hashMapOf()
|
private val conversations: HashMap<Int, VkConversation> = hashMapOf()
|
||||||
private val contacts: HashMap<Long, VkContactDomain> = hashMapOf()
|
private val contacts: HashMap<Int, VkContactDomain> = hashMapOf()
|
||||||
|
|
||||||
fun appendUsers(users: List<VkUser>) {
|
fun appendUsers(users: List<VkUser>) {
|
||||||
users.forEach { user -> VkMemoryCache.users[user.id] = user }
|
users.forEach { user -> VkMemoryCache.users[user.id] = user }
|
||||||
@@ -38,83 +37,83 @@ object VkMemoryCache {
|
|||||||
contacts.forEach { contact -> VkMemoryCache.contacts[contact.userId] = contact }
|
contacts.forEach { contact -> VkMemoryCache.contacts[contact.userId] = contact }
|
||||||
}
|
}
|
||||||
|
|
||||||
operator fun set(userid: Long, user: VkUser) {
|
operator fun set(userId: Int, user: VkUser) {
|
||||||
users[userId] = user
|
users[userId] = user
|
||||||
}
|
}
|
||||||
|
|
||||||
operator fun set(groupId: Long, group: VkGroupDomain) {
|
operator fun set(groupId: Int, group: VkGroupDomain) {
|
||||||
groups[groupId] = group
|
groups[groupId] = group
|
||||||
}
|
}
|
||||||
|
|
||||||
operator fun set(messageId: Long, message: VkMessage) {
|
operator fun set(messageId: Int, message: VkMessage) {
|
||||||
messages[messageId] = message
|
messages[messageId] = message
|
||||||
}
|
}
|
||||||
|
|
||||||
operator fun set(conversationId: Long, conversation: VkConversation) {
|
operator fun set(conversationId: Int, conversation: VkConversation) {
|
||||||
conversations[conversationId] = conversation
|
conversations[conversationId] = conversation
|
||||||
}
|
}
|
||||||
|
|
||||||
operator fun set(contactId: Long, contact: VkContactDomain) {
|
operator fun set(contactId: Int, contact: VkContactDomain) {
|
||||||
contacts[contactId] = contact
|
contacts[contactId] = contact
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getUser(id: Long): VkUser? {
|
fun getUser(id: Int): VkUser? {
|
||||||
return getUsers(id).firstOrNull()
|
return getUsers(id).firstOrNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getUsers(vararg ids: Long): List<VkUser> {
|
fun getUsers(vararg ids: Int): List<VkUser> {
|
||||||
return getUsers(ids.toList())
|
return getUsers(ids.toList())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getUsers(ids: List<Long>): List<VkUser> {
|
fun getUsers(ids: List<Int>): List<VkUser> {
|
||||||
return ids.mapNotNull { id -> users[id] }
|
return ids.mapNotNull { id -> users[id] }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getGroup(id: Long): VkGroupDomain? {
|
fun getGroup(id: Int): VkGroupDomain? {
|
||||||
return getGroups(id).firstOrNull()
|
return getGroups(id).firstOrNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getGroups(vararg ids: Long): List<VkGroupDomain> {
|
fun getGroups(vararg ids: Int): List<VkGroupDomain> {
|
||||||
return getGroups(ids.toList())
|
return getGroups(ids.toList())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getGroups(ids: List<Long>): List<VkGroupDomain> {
|
fun getGroups(ids: List<Int>): List<VkGroupDomain> {
|
||||||
return ids.mapNotNull { id -> groups[id] }
|
return ids.mapNotNull { id -> groups[id] }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getMessage(id: Long): VkMessage? {
|
fun getMessage(id: Int): VkMessage? {
|
||||||
return getMessages(id).firstOrNull()
|
return getMessages(id).firstOrNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getMessages(vararg ids: Long): List<VkMessage> {
|
fun getMessages(vararg ids: Int): List<VkMessage> {
|
||||||
return getMessages(ids.toList())
|
return getMessages(ids.toList())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getMessages(ids: List<Long>): List<VkMessage> {
|
fun getMessages(ids: List<Int>): List<VkMessage> {
|
||||||
return ids.mapNotNull { id -> messages[id] }
|
return ids.mapNotNull { id -> messages[id] }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getConversation(id: Long): VkConversation? {
|
fun getConversation(id: Int): VkConversation? {
|
||||||
return getConversations(id).firstOrNull()
|
return getConversations(id).firstOrNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getConversations(vararg ids: Long): List<VkConversation> {
|
fun getConversations(vararg ids: Int): List<VkConversation> {
|
||||||
return getConversations(ids.toList())
|
return getConversations(ids.toList())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getConversations(ids: List<Long>): List<VkConversation> {
|
fun getConversations(ids: List<Int>): List<VkConversation> {
|
||||||
return ids.mapNotNull { id -> conversations[id] }
|
return ids.mapNotNull { id -> conversations[id] }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getContact(id: Long): VkContactDomain? {
|
fun getContact(id: Int): VkContactDomain? {
|
||||||
return getContacts(id).firstOrNull()
|
return getContacts(id).firstOrNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getContacts(vararg ids: Long): List<VkContactDomain> {
|
fun getContacts(vararg ids: Int): List<VkContactDomain> {
|
||||||
return getContacts(ids.toList())
|
return getContacts(ids.toList())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getContacts(ids: List<Long>): List<VkContactDomain> {
|
fun getContacts(ids: List<Int>): List<VkContactDomain> {
|
||||||
return ids.mapNotNull { id -> contacts[id] }
|
return ids.mapNotNull { id -> contacts[id] }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package dev.meloda.fast.data
|
package dev.meloda.fast.data
|
||||||
|
|
||||||
import dev.meloda.fast.data.UserConfig.userId
|
|
||||||
import dev.meloda.fast.model.api.data.VkMessageData
|
import dev.meloda.fast.model.api.data.VkMessageData
|
||||||
import dev.meloda.fast.model.api.domain.VkConversation
|
import dev.meloda.fast.model.api.domain.VkConversation
|
||||||
import dev.meloda.fast.model.api.domain.VkMessage
|
import dev.meloda.fast.model.api.domain.VkMessage
|
||||||
@@ -10,7 +9,7 @@ class VkUsersMap(
|
|||||||
private val users: List<VkUser>
|
private val users: List<VkUser>
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private val map: HashMap<Long, VkUser> by lazy {
|
private val map: HashMap<Int, VkUser> by lazy {
|
||||||
HashMap(users.associateBy(VkUser::id))
|
HashMap(users.associateBy(VkUser::id))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,7 +35,7 @@ class VkUsersMap(
|
|||||||
if (message.fromId > 0) map[message.fromId]
|
if (message.fromId > 0) map[message.fromId]
|
||||||
else null
|
else null
|
||||||
|
|
||||||
fun user(userid: Long): VkUser? = map[userId]
|
fun user(userId: Int): VkUser? = map[userId]
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
package dev.meloda.fast.data
|
|
||||||
|
|
||||||
import dev.meloda.fast.model.BaseError
|
|
||||||
import dev.meloda.fast.network.VkErrorCode
|
|
||||||
|
|
||||||
object VkUtils {
|
|
||||||
|
|
||||||
fun parseError(error: State.Error): BaseError? {
|
|
||||||
return when (error) {
|
|
||||||
is State.Error.ApiError -> {
|
|
||||||
when (error.errorCode) {
|
|
||||||
VkErrorCode.USER_AUTHORIZATION_FAILED -> {
|
|
||||||
if (error.errorMessage.startsWith(
|
|
||||||
"User authorization failed: user is blocked."
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
BaseError.AccountBlocked
|
|
||||||
} else {
|
|
||||||
BaseError.SessionExpired
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> BaseError.SimpleError(message = error.errorMessage)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
State.Error.ConnectionError -> BaseError.ConnectionError
|
|
||||||
State.Error.InternalError -> BaseError.InternalError
|
|
||||||
State.Error.UnknownError -> BaseError.UnknownError
|
|
||||||
|
|
||||||
else -> null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,32 +1,12 @@
|
|||||||
package dev.meloda.fast.data.api.auth
|
package dev.meloda.fast.data.api.auth
|
||||||
|
|
||||||
import com.slack.eithernet.ApiResult
|
|
||||||
import dev.meloda.fast.model.api.responses.ExchangeSilentTokenResponse
|
|
||||||
import dev.meloda.fast.model.api.responses.GetAnonymTokenResponse
|
|
||||||
import dev.meloda.fast.model.api.responses.GetExchangeTokenResponse
|
|
||||||
import dev.meloda.fast.model.api.responses.ValidatePhoneResponse
|
import dev.meloda.fast.model.api.responses.ValidatePhoneResponse
|
||||||
import dev.meloda.fast.network.RestApiErrorDomain
|
import dev.meloda.fast.network.RestApiErrorDomain
|
||||||
|
import com.slack.eithernet.ApiResult
|
||||||
|
|
||||||
interface AuthRepository {
|
interface AuthRepository {
|
||||||
|
|
||||||
suspend fun logout(): ApiResult<Int, RestApiErrorDomain>
|
|
||||||
|
|
||||||
suspend fun validatePhone(
|
suspend fun validatePhone(
|
||||||
validationSid: String
|
validationSid: String
|
||||||
): ApiResult<ValidatePhoneResponse, RestApiErrorDomain>
|
): ApiResult<ValidatePhoneResponse, RestApiErrorDomain>
|
||||||
|
|
||||||
suspend fun getAnonymToken(
|
|
||||||
clientId: String,
|
|
||||||
clientSecret: String
|
|
||||||
): ApiResult<GetAnonymTokenResponse, RestApiErrorDomain>
|
|
||||||
|
|
||||||
suspend fun exchangeSilentToken(
|
|
||||||
anonymToken: String,
|
|
||||||
silentToken: String,
|
|
||||||
silentUuid: String
|
|
||||||
): ApiResult<ExchangeSilentTokenResponse, RestApiErrorDomain>
|
|
||||||
|
|
||||||
suspend fun getExchangeToken(
|
|
||||||
accessToken: String
|
|
||||||
): ApiResult<GetExchangeTokenResponse, RestApiErrorDomain>
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,10 @@
|
|||||||
package dev.meloda.fast.data.api.auth
|
package dev.meloda.fast.data.api.auth
|
||||||
|
|
||||||
import com.slack.eithernet.ApiResult
|
|
||||||
import dev.meloda.fast.common.VkConstants
|
|
||||||
import dev.meloda.fast.model.api.requests.ExchangeSilentTokenRequest
|
|
||||||
import dev.meloda.fast.model.api.requests.GetAnonymTokenRequest
|
|
||||||
import dev.meloda.fast.model.api.requests.GetExchangeTokenRequest
|
|
||||||
import dev.meloda.fast.model.api.responses.ExchangeSilentTokenResponse
|
|
||||||
import dev.meloda.fast.model.api.responses.GetAnonymTokenResponse
|
|
||||||
import dev.meloda.fast.model.api.responses.GetExchangeTokenResponse
|
|
||||||
import dev.meloda.fast.model.api.responses.ValidatePhoneResponse
|
import dev.meloda.fast.model.api.responses.ValidatePhoneResponse
|
||||||
import dev.meloda.fast.network.RestApiErrorDomain
|
import dev.meloda.fast.network.RestApiErrorDomain
|
||||||
import dev.meloda.fast.network.mapApiDefault
|
import dev.meloda.fast.network.mapApiDefault
|
||||||
import dev.meloda.fast.network.service.auth.AuthService
|
import dev.meloda.fast.network.service.auth.AuthService
|
||||||
|
import com.slack.eithernet.ApiResult
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
@@ -19,50 +12,9 @@ class AuthRepositoryImpl(
|
|||||||
private val service: AuthService
|
private val service: AuthService
|
||||||
) : AuthRepository {
|
) : AuthRepository {
|
||||||
|
|
||||||
override suspend fun logout(): ApiResult<Int, RestApiErrorDomain> =
|
|
||||||
withContext(Dispatchers.IO) {
|
|
||||||
service.logout(
|
|
||||||
clientId = VkConstants.MESSENGER_APP_ID.toString(),
|
|
||||||
clientSecret = VkConstants.MESSENGER_APP_SECRET
|
|
||||||
).mapApiDefault()
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun validatePhone(
|
override suspend fun validatePhone(
|
||||||
validationSid: String
|
validationSid: String
|
||||||
): ApiResult<ValidatePhoneResponse, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
): ApiResult<ValidatePhoneResponse, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
||||||
service.validatePhone(validationSid).mapApiDefault()
|
service.validatePhone(validationSid).mapApiDefault()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getAnonymToken(
|
|
||||||
clientId: String,
|
|
||||||
clientSecret: String
|
|
||||||
): ApiResult<GetAnonymTokenResponse, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
|
||||||
val requestModel = GetAnonymTokenRequest(
|
|
||||||
clientId = clientId,
|
|
||||||
clientSecret = clientSecret
|
|
||||||
)
|
|
||||||
|
|
||||||
service.getAnonymToken(requestModel.map).mapApiDefault()
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun exchangeSilentToken(
|
|
||||||
anonymToken: String,
|
|
||||||
silentToken: String,
|
|
||||||
silentUuid: String
|
|
||||||
): ApiResult<ExchangeSilentTokenResponse, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
|
||||||
val requestModel = ExchangeSilentTokenRequest(
|
|
||||||
anonymToken = anonymToken,
|
|
||||||
silentToken = silentToken,
|
|
||||||
silentUuid = silentUuid
|
|
||||||
)
|
|
||||||
|
|
||||||
service.exchangeSilentToken(requestModel.map).mapApiDefault()
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getExchangeToken(
|
|
||||||
accessToken: String
|
|
||||||
): ApiResult<GetExchangeTokenResponse, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
|
||||||
val requestModel = GetExchangeTokenRequest(accessToken = accessToken)
|
|
||||||
service.getExchangeToken(requestModel.map).mapApiDefault()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-14
@@ -1,30 +1,22 @@
|
|||||||
package dev.meloda.fast.data.api.conversations
|
package dev.meloda.fast.data.api.conversations
|
||||||
|
|
||||||
import com.slack.eithernet.ApiResult
|
import com.slack.eithernet.ApiResult
|
||||||
import dev.meloda.fast.model.ConversationsFilter
|
|
||||||
import dev.meloda.fast.model.api.domain.VkConversation
|
import dev.meloda.fast.model.api.domain.VkConversation
|
||||||
import dev.meloda.fast.network.RestApiErrorDomain
|
import dev.meloda.fast.network.RestApiErrorDomain
|
||||||
|
|
||||||
interface ConversationsRepository {
|
interface ConversationsRepository {
|
||||||
|
|
||||||
suspend fun storeConversations(conversations: List<VkConversation>)
|
|
||||||
|
|
||||||
suspend fun getConversations(
|
suspend fun getConversations(
|
||||||
count: Int?,
|
count: Int?,
|
||||||
offset: Int?,
|
offset: Int?
|
||||||
filter: ConversationsFilter
|
|
||||||
): ApiResult<List<VkConversation>, RestApiErrorDomain>
|
): ApiResult<List<VkConversation>, RestApiErrorDomain>
|
||||||
|
|
||||||
suspend fun getConversationsById(
|
suspend fun getConversationsById(
|
||||||
peerIds: List<Long>,
|
peerIds: List<Int>
|
||||||
extended: Boolean? = null,
|
|
||||||
fields: String? = null
|
|
||||||
): ApiResult<List<VkConversation>, RestApiErrorDomain>
|
): ApiResult<List<VkConversation>, RestApiErrorDomain>
|
||||||
|
|
||||||
suspend fun delete(peerId: Long): ApiResult<Long, RestApiErrorDomain>
|
suspend fun storeConversations(conversations: List<VkConversation>)
|
||||||
suspend fun pin(peerId: Long): ApiResult<Int, RestApiErrorDomain>
|
suspend fun delete(peerId: Int): ApiResult<Int, RestApiErrorDomain>
|
||||||
suspend fun unpin(peerId: Long): ApiResult<Int, RestApiErrorDomain>
|
suspend fun pin(peerId: Int): ApiResult<Int, RestApiErrorDomain>
|
||||||
suspend fun reorderPinned(peerIds: List<Long>): ApiResult<Int, RestApiErrorDomain>
|
suspend fun unpin(peerId: Int): ApiResult<Int, RestApiErrorDomain>
|
||||||
suspend fun archive(peerId: Long): ApiResult<Int, RestApiErrorDomain>
|
|
||||||
suspend fun unarchive(peerId: Long): ApiResult<Int, RestApiErrorDomain>
|
|
||||||
}
|
}
|
||||||
|
|||||||
+31
-78
@@ -6,50 +6,37 @@ import dev.meloda.fast.data.VkGroupsMap
|
|||||||
import dev.meloda.fast.data.VkMemoryCache
|
import dev.meloda.fast.data.VkMemoryCache
|
||||||
import dev.meloda.fast.data.VkUsersMap
|
import dev.meloda.fast.data.VkUsersMap
|
||||||
import dev.meloda.fast.database.dao.ConversationDao
|
import dev.meloda.fast.database.dao.ConversationDao
|
||||||
import dev.meloda.fast.database.dao.GroupDao
|
|
||||||
import dev.meloda.fast.database.dao.MessageDao
|
|
||||||
import dev.meloda.fast.database.dao.UserDao
|
|
||||||
import dev.meloda.fast.model.ConversationsFilter
|
|
||||||
import dev.meloda.fast.model.api.data.VkContactData
|
import dev.meloda.fast.model.api.data.VkContactData
|
||||||
import dev.meloda.fast.model.api.data.VkGroupData
|
import dev.meloda.fast.model.api.data.VkGroupData
|
||||||
import dev.meloda.fast.model.api.data.VkUserData
|
import dev.meloda.fast.model.api.data.VkUserData
|
||||||
import dev.meloda.fast.model.api.data.asDomain
|
import dev.meloda.fast.model.api.data.asDomain
|
||||||
import dev.meloda.fast.model.api.domain.VkConversation
|
import dev.meloda.fast.model.api.domain.VkConversation
|
||||||
import dev.meloda.fast.model.api.domain.VkGroupDomain
|
|
||||||
import dev.meloda.fast.model.api.domain.VkMessage
|
|
||||||
import dev.meloda.fast.model.api.domain.VkUser
|
|
||||||
import dev.meloda.fast.model.api.domain.asEntity
|
import dev.meloda.fast.model.api.domain.asEntity
|
||||||
|
import dev.meloda.fast.model.api.requests.ConversationsDeleteRequest
|
||||||
import dev.meloda.fast.model.api.requests.ConversationsGetRequest
|
import dev.meloda.fast.model.api.requests.ConversationsGetRequest
|
||||||
|
import dev.meloda.fast.model.api.requests.ConversationsPinRequest
|
||||||
|
import dev.meloda.fast.model.api.requests.ConversationsUnpinRequest
|
||||||
import dev.meloda.fast.network.RestApiErrorDomain
|
import dev.meloda.fast.network.RestApiErrorDomain
|
||||||
import dev.meloda.fast.network.mapApiDefault
|
import dev.meloda.fast.network.mapApiDefault
|
||||||
import dev.meloda.fast.network.mapApiResult
|
import dev.meloda.fast.network.mapApiResult
|
||||||
import dev.meloda.fast.network.service.conversations.ConversationsService
|
import dev.meloda.fast.network.service.conversations.ConversationsService
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
class ConversationsRepositoryImpl(
|
class ConversationsRepositoryImpl(
|
||||||
private val conversationsService: ConversationsService,
|
private val conversationsService: ConversationsService,
|
||||||
private val messageDao: MessageDao,
|
|
||||||
private val userDao: UserDao,
|
|
||||||
private val groupDao: GroupDao,
|
|
||||||
private val conversationDao: ConversationDao
|
private val conversationDao: ConversationDao
|
||||||
) : ConversationsRepository {
|
) : ConversationsRepository {
|
||||||
|
|
||||||
override suspend fun storeConversations(conversations: List<VkConversation>) {
|
|
||||||
conversationDao.insertAll(conversations.map(VkConversation::asEntity))
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getConversations(
|
override suspend fun getConversations(
|
||||||
count: Int?,
|
count: Int?,
|
||||||
offset: Int?,
|
offset: Int?
|
||||||
filter: ConversationsFilter
|
|
||||||
): ApiResult<List<VkConversation>, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
): ApiResult<List<VkConversation>, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
||||||
val requestModel = ConversationsGetRequest(
|
val requestModel = ConversationsGetRequest(
|
||||||
count = count,
|
count = count,
|
||||||
offset = offset,
|
offset = offset,
|
||||||
fields = VkConstants.ALL_FIELDS,
|
fields = VkConstants.ALL_FIELDS,
|
||||||
filter = filter,
|
filter = "all",
|
||||||
extended = true,
|
extended = true,
|
||||||
startMessageId = null
|
startMessageId = null
|
||||||
)
|
)
|
||||||
@@ -69,7 +56,7 @@ class ConversationsRepositoryImpl(
|
|||||||
VkMemoryCache.appendGroups(groupsList)
|
VkMemoryCache.appendGroups(groupsList)
|
||||||
VkMemoryCache.appendContacts(contactsList)
|
VkMemoryCache.appendContacts(contactsList)
|
||||||
|
|
||||||
val conversations = response.items.map { item ->
|
response.items.map { item ->
|
||||||
val lastMessage = item.lastMessage?.asDomain()?.let { message ->
|
val lastMessage = item.lastMessage?.asDomain()?.let { message ->
|
||||||
message.copy(
|
message.copy(
|
||||||
user = usersMap.messageUser(message),
|
user = usersMap.messageUser(message),
|
||||||
@@ -85,17 +72,6 @@ class ConversationsRepositoryImpl(
|
|||||||
).also { VkMemoryCache[conversation.id] = it }
|
).also { VkMemoryCache[conversation.id] = it }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val messages = conversations.mapNotNull(VkConversation::lastMessage)
|
|
||||||
|
|
||||||
launch(Dispatchers.IO) {
|
|
||||||
conversationDao.insertAll(conversations.map(VkConversation::asEntity))
|
|
||||||
messageDao.insertAll(messages.map(VkMessage::asEntity))
|
|
||||||
userDao.insertAll(profilesList.map(VkUser::asEntity))
|
|
||||||
groupDao.insertAll(groupsList.map(VkGroupDomain::asEntity))
|
|
||||||
}
|
|
||||||
|
|
||||||
conversations
|
|
||||||
},
|
},
|
||||||
errorMapper = { error ->
|
errorMapper = { error ->
|
||||||
error?.toDomain()
|
error?.toDomain()
|
||||||
@@ -104,16 +80,13 @@ class ConversationsRepositoryImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getConversationsById(
|
override suspend fun getConversationsById(
|
||||||
peerIds: List<Long>,
|
peerIds: List<Int>
|
||||||
extended: Boolean?,
|
|
||||||
fields: String?
|
|
||||||
): ApiResult<List<VkConversation>, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
): ApiResult<List<VkConversation>, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
||||||
val requestParams = mutableMapOf(
|
val requestParams = mapOf(
|
||||||
"peer_ids" to peerIds.joinToString(separator = ",")
|
"peer_ids" to peerIds.joinToString(separator = ","),
|
||||||
).apply {
|
"extended" to "1",
|
||||||
extended?.let { this["extended"] = if (it) "1" else "0" }
|
"fields" to VkConstants.ALL_FIELDS
|
||||||
fields?.let { this["fields"] = it }
|
)
|
||||||
}
|
|
||||||
|
|
||||||
conversationsService.getConversationsById(requestParams).mapApiResult(
|
conversationsService.getConversationsById(requestParams).mapApiResult(
|
||||||
successMapper = { apiResponse ->
|
successMapper = { apiResponse ->
|
||||||
@@ -126,7 +99,11 @@ class ConversationsRepositoryImpl(
|
|||||||
val usersMap = VkUsersMap.forUsers(profilesList)
|
val usersMap = VkUsersMap.forUsers(profilesList)
|
||||||
val groupsMap = VkGroupsMap.forGroups(groupsList)
|
val groupsMap = VkGroupsMap.forGroups(groupsList)
|
||||||
|
|
||||||
val conversations = response.items.map { item ->
|
VkMemoryCache.appendUsers(profilesList)
|
||||||
|
VkMemoryCache.appendGroups(groupsList)
|
||||||
|
VkMemoryCache.appendContacts(contactsList)
|
||||||
|
|
||||||
|
response.items.map { item ->
|
||||||
item.asDomain().let { conversation ->
|
item.asDomain().let { conversation ->
|
||||||
conversation.copy(
|
conversation.copy(
|
||||||
user = usersMap.conversationUser(conversation),
|
user = usersMap.conversationUser(conversation),
|
||||||
@@ -134,18 +111,6 @@ class ConversationsRepositoryImpl(
|
|||||||
).also { VkMemoryCache[conversation.id] = it }
|
).also { VkMemoryCache[conversation.id] = it }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
launch(Dispatchers.IO) {
|
|
||||||
conversationDao.insertAll(conversations.map(VkConversation::asEntity))
|
|
||||||
userDao.insertAll(profilesList.map(VkUser::asEntity))
|
|
||||||
groupDao.insertAll(groupsList.map(VkGroupDomain::asEntity))
|
|
||||||
}
|
|
||||||
|
|
||||||
VkMemoryCache.appendUsers(profilesList)
|
|
||||||
VkMemoryCache.appendGroups(groupsList)
|
|
||||||
VkMemoryCache.appendContacts(contactsList)
|
|
||||||
|
|
||||||
conversations
|
|
||||||
},
|
},
|
||||||
errorMapper = { error ->
|
errorMapper = { error ->
|
||||||
error?.toDomain()
|
error?.toDomain()
|
||||||
@@ -153,43 +118,31 @@ class ConversationsRepositoryImpl(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun delete(peerId: Long): ApiResult<Long, RestApiErrorDomain> =
|
override suspend fun storeConversations(conversations: List<VkConversation>) {
|
||||||
|
conversationDao.insertAll(conversations.map(VkConversation::asEntity))
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun delete(peerId: Int): ApiResult<Int, RestApiErrorDomain> =
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
conversationsService.delete(mapOf("peer_id" to peerId.toString())).mapApiResult(
|
val requestModel = ConversationsDeleteRequest(peerId = peerId)
|
||||||
|
|
||||||
|
conversationsService.delete(requestModel.map).mapApiResult(
|
||||||
successMapper = { response -> response.requireResponse().lastDeletedId },
|
successMapper = { response -> response.requireResponse().lastDeletedId },
|
||||||
errorMapper = { error -> error?.toDomain() }
|
errorMapper = { error -> error?.toDomain() }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun pin(
|
override suspend fun pin(
|
||||||
peerId: Long
|
peerId: Int
|
||||||
): ApiResult<Int, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
): ApiResult<Int, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
||||||
conversationsService.pin(mapOf("peer_id" to peerId.toString())).mapApiDefault()
|
val requestModel = ConversationsPinRequest(peerId = peerId)
|
||||||
|
conversationsService.pin(requestModel.map).mapApiDefault()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun unpin(
|
override suspend fun unpin(
|
||||||
peerId: Long
|
peerId: Int
|
||||||
): ApiResult<Int, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
): ApiResult<Int, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
||||||
conversationsService.unpin(mapOf("peer_id" to peerId.toString())).mapApiDefault()
|
val requestModel = ConversationsUnpinRequest(peerId = peerId)
|
||||||
}
|
conversationsService.unpin(requestModel.map).mapApiDefault()
|
||||||
|
|
||||||
override suspend fun reorderPinned(
|
|
||||||
peerIds: List<Long>
|
|
||||||
): ApiResult<Int, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
|
||||||
conversationsService
|
|
||||||
.reorderPinned(mapOf("peer_ids" to peerIds.joinToString(",")))
|
|
||||||
.mapApiDefault()
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun archive(
|
|
||||||
peerId: Long
|
|
||||||
): ApiResult<Int, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
|
||||||
conversationsService.archive(mapOf("peer_id" to peerId.toString())).mapApiDefault()
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun unarchive(
|
|
||||||
peerId: Long
|
|
||||||
): ApiResult<Int, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
|
||||||
conversationsService.unarchive(mapOf("peer_id" to peerId.toString())).mapApiDefault()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ class FilesRepository(
|
|||||||
// AUDIO_MESSAGE("audio_message")
|
// AUDIO_MESSAGE("audio_message")
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// suspend fun getMessagesUploadServer(peerid: Long, type: FileType) =
|
// suspend fun getMessagesUploadServer(peerId: Int, type: FileType) =
|
||||||
// filesService.getUploadServer(
|
// filesService.getUploadServer(
|
||||||
// mapOf(
|
// mapOf(
|
||||||
// "peer_id" to peerId.toString(),
|
// "peer_id" to peerId.toString(),
|
||||||
|
|||||||
@@ -8,13 +8,11 @@ import com.slack.eithernet.ApiResult
|
|||||||
interface FriendsRepository {
|
interface FriendsRepository {
|
||||||
|
|
||||||
suspend fun getAllFriends(
|
suspend fun getAllFriends(
|
||||||
order: String,
|
|
||||||
count: Int?,
|
count: Int?,
|
||||||
offset: Int?
|
offset: Int?
|
||||||
): ApiResult<FriendsInfo, RestApiErrorDomain>
|
): ApiResult<FriendsInfo, RestApiErrorDomain>
|
||||||
|
|
||||||
suspend fun getFriends(
|
suspend fun getFriends(
|
||||||
order: String,
|
|
||||||
count: Int?,
|
count: Int?,
|
||||||
offset: Int?
|
offset: Int?
|
||||||
): ApiResult<List<VkUser>, RestApiErrorDomain>
|
): ApiResult<List<VkUser>, RestApiErrorDomain>
|
||||||
@@ -22,7 +20,7 @@ interface FriendsRepository {
|
|||||||
suspend fun getOnlineFriends(
|
suspend fun getOnlineFriends(
|
||||||
count: Int?,
|
count: Int?,
|
||||||
offset: Int?
|
offset: Int?
|
||||||
): ApiResult<List<Long>, RestApiErrorDomain>
|
): ApiResult<List<Int>, RestApiErrorDomain>
|
||||||
|
|
||||||
suspend fun storeUsers(users: List<VkUser>)
|
suspend fun storeUsers(users: List<VkUser>)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package dev.meloda.fast.data.api.friends
|
|||||||
|
|
||||||
import dev.meloda.fast.common.VkConstants
|
import dev.meloda.fast.common.VkConstants
|
||||||
import dev.meloda.fast.data.VkMemoryCache
|
import dev.meloda.fast.data.VkMemoryCache
|
||||||
import dev.meloda.fast.database.dao.UserDao
|
import dev.meloda.fast.database.dao.UsersDao
|
||||||
import dev.meloda.fast.model.FriendsInfo
|
import dev.meloda.fast.model.FriendsInfo
|
||||||
import dev.meloda.fast.model.api.data.VkUserData
|
import dev.meloda.fast.model.api.data.VkUserData
|
||||||
import dev.meloda.fast.model.api.domain.VkUser
|
import dev.meloda.fast.model.api.domain.VkUser
|
||||||
@@ -21,15 +21,14 @@ import kotlinx.coroutines.withContext
|
|||||||
|
|
||||||
class FriendsRepositoryImpl(
|
class FriendsRepositoryImpl(
|
||||||
private val service: FriendsService,
|
private val service: FriendsService,
|
||||||
private val dao: UserDao
|
private val dao: UsersDao
|
||||||
) : FriendsRepository {
|
) : FriendsRepository {
|
||||||
|
|
||||||
override suspend fun getAllFriends(
|
override suspend fun getAllFriends(
|
||||||
order: String,
|
|
||||||
count: Int?,
|
count: Int?,
|
||||||
offset: Int?
|
offset: Int?
|
||||||
): ApiResult<FriendsInfo, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
): ApiResult<FriendsInfo, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
||||||
val friends = async { getFriends(order, count, offset) }.await()
|
val friends = async { getFriends(count, offset) }.await()
|
||||||
.successOrElse { failure ->
|
.successOrElse { failure ->
|
||||||
return@withContext failure
|
return@withContext failure
|
||||||
}
|
}
|
||||||
@@ -43,12 +42,11 @@ class FriendsRepositoryImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getFriends(
|
override suspend fun getFriends(
|
||||||
order: String,
|
|
||||||
count: Int?,
|
count: Int?,
|
||||||
offset: Int?
|
offset: Int?
|
||||||
): ApiResult<List<VkUser>, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
): ApiResult<List<VkUser>, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
||||||
val requestModel = GetFriendsRequest(
|
val requestModel = GetFriendsRequest(
|
||||||
order = order,
|
order = "hints",
|
||||||
count = count,
|
count = count,
|
||||||
offset = offset,
|
offset = offset,
|
||||||
fields = VkConstants.USER_FIELDS
|
fields = VkConstants.USER_FIELDS
|
||||||
@@ -69,7 +67,7 @@ class FriendsRepositoryImpl(
|
|||||||
override suspend fun getOnlineFriends(
|
override suspend fun getOnlineFriends(
|
||||||
count: Int?,
|
count: Int?,
|
||||||
offset: Int?
|
offset: Int?
|
||||||
): ApiResult<List<Long>, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
): ApiResult<List<Int>, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
||||||
val requestModel = GetOnlineFriendsRequest(
|
val requestModel = GetOnlineFriendsRequest(
|
||||||
order = "hints",
|
order = "hints",
|
||||||
count = count,
|
count = count,
|
||||||
|
|||||||
@@ -1,113 +1,82 @@
|
|||||||
package dev.meloda.fast.data.api.messages
|
package dev.meloda.fast.data.api.messages
|
||||||
|
|
||||||
import com.slack.eithernet.ApiResult
|
import com.slack.eithernet.ApiResult
|
||||||
import dev.meloda.fast.model.api.data.VkChatData
|
|
||||||
import dev.meloda.fast.model.api.domain.VkAttachment
|
import dev.meloda.fast.model.api.domain.VkAttachment
|
||||||
import dev.meloda.fast.model.api.domain.VkAttachmentHistoryMessage
|
import dev.meloda.fast.model.api.domain.VkAttachmentHistoryMessage
|
||||||
import dev.meloda.fast.model.api.domain.VkMessage
|
import dev.meloda.fast.model.api.domain.VkMessage
|
||||||
import dev.meloda.fast.model.api.responses.MessagesGetConversationMembersResponse
|
|
||||||
import dev.meloda.fast.model.api.responses.MessagesSendResponse
|
|
||||||
import dev.meloda.fast.network.RestApiErrorDomain
|
import dev.meloda.fast.network.RestApiErrorDomain
|
||||||
|
|
||||||
interface MessagesRepository {
|
interface MessagesRepository {
|
||||||
|
|
||||||
suspend fun storeMessages(messages: List<VkMessage>)
|
|
||||||
|
|
||||||
suspend fun getHistory(
|
suspend fun getHistory(
|
||||||
conversationId: Long,
|
conversationId: Int,
|
||||||
offset: Int?,
|
offset: Int?,
|
||||||
count: Int?
|
count: Int?
|
||||||
): ApiResult<MessagesHistoryInfo, RestApiErrorDomain>
|
): ApiResult<MessagesHistoryInfo, RestApiErrorDomain>
|
||||||
|
|
||||||
suspend fun getById(
|
suspend fun getById(
|
||||||
peerCmIds: List<Long>?,
|
messagesIds: List<Int>,
|
||||||
peerId: Long?,
|
|
||||||
messagesIds: List<Long>?,
|
|
||||||
cmIds: List<Long>?,
|
|
||||||
extended: Boolean?,
|
extended: Boolean?,
|
||||||
fields: String?
|
fields: String?
|
||||||
): ApiResult<List<VkMessage>, RestApiErrorDomain>
|
): ApiResult<List<VkMessage>, RestApiErrorDomain>
|
||||||
|
|
||||||
suspend fun send(
|
suspend fun send(
|
||||||
peerId: Long,
|
peerId: Int,
|
||||||
randomId: Long,
|
randomId: Int,
|
||||||
message: String?,
|
message: String?,
|
||||||
replyTo: Long?,
|
replyTo: Int?,
|
||||||
attachments: List<VkAttachment>?,
|
attachments: List<VkAttachment>?
|
||||||
formatData: VkMessage.FormatData?
|
): ApiResult<Int, RestApiErrorDomain>
|
||||||
): ApiResult<MessagesSendResponse, RestApiErrorDomain>
|
|
||||||
|
|
||||||
suspend fun markAsRead(
|
suspend fun markAsRead(
|
||||||
peerId: Long,
|
peerId: Int,
|
||||||
startMessageId: Long?
|
startMessageId: Int?
|
||||||
): ApiResult<Int, RestApiErrorDomain>
|
): ApiResult<Int, RestApiErrorDomain>
|
||||||
|
|
||||||
suspend fun getHistoryAttachments(
|
suspend fun getHistoryAttachments(
|
||||||
peerId: Long,
|
peerId: Int,
|
||||||
count: Int?,
|
count: Int?,
|
||||||
offset: Int?,
|
offset: Int?,
|
||||||
attachmentTypes: List<String>,
|
attachmentTypes: List<String>,
|
||||||
cmId: Long
|
conversationMessageId: Int
|
||||||
): ApiResult<List<VkAttachmentHistoryMessage>, RestApiErrorDomain>
|
): ApiResult<List<VkAttachmentHistoryMessage>, RestApiErrorDomain>
|
||||||
|
|
||||||
suspend fun createChat(
|
suspend fun createChat(
|
||||||
userIds: List<Long>?,
|
userIds: List<Int>?,
|
||||||
title: String?
|
title: String?
|
||||||
): ApiResult<Long, RestApiErrorDomain>
|
|
||||||
|
|
||||||
suspend fun pin(
|
|
||||||
peerId: Long,
|
|
||||||
messageId: Long? = null,
|
|
||||||
cmId: Long? = null
|
|
||||||
): ApiResult<VkMessage, RestApiErrorDomain>
|
|
||||||
|
|
||||||
suspend fun unpin(
|
|
||||||
peerId: Long
|
|
||||||
): ApiResult<Int, RestApiErrorDomain>
|
): ApiResult<Int, RestApiErrorDomain>
|
||||||
|
|
||||||
suspend fun markAsImportant(
|
suspend fun storeMessages(messages: List<VkMessage>)
|
||||||
peerId: Long,
|
|
||||||
messageIds: List<Long>? = null,
|
|
||||||
cmIds: List<Long>? = null,
|
|
||||||
important: Boolean
|
|
||||||
): ApiResult<List<Long>, RestApiErrorDomain>
|
|
||||||
|
|
||||||
suspend fun delete(
|
// suspend fun markAsImportant(
|
||||||
peerId: Long,
|
// params: MessagesMarkAsImportantRequest
|
||||||
messageIds: List<Long>?,
|
// ): ApiResult<List<Int>, RestApiErrorDomain>
|
||||||
cmIds: List<Long>?,
|
//
|
||||||
spam: Boolean,
|
// suspend fun pin(
|
||||||
deleteForAll: Boolean
|
// params: MessagesPinMessageRequest
|
||||||
): ApiResult<List<Any>, RestApiErrorDomain>
|
// ): ApiResult<VkMessageData, RestApiErrorDomain>
|
||||||
|
//
|
||||||
suspend fun edit(
|
// suspend fun unpin(
|
||||||
peerId: Long,
|
// params: MessagesUnPinMessageRequest
|
||||||
messageId: Long? = null,
|
// ): ApiResult<Unit, RestApiErrorDomain>
|
||||||
cmId: Long? = null,
|
//
|
||||||
message: String? = null,
|
// suspend fun delete(
|
||||||
lat: Float? = null,
|
// params: MessagesDeleteRequest
|
||||||
long: Float? = null,
|
// ): ApiResult<Unit, RestApiErrorDomain>
|
||||||
attachments: List<VkAttachment>? = null,
|
//
|
||||||
notParseLinks: Boolean = false,
|
// suspend fun edit(
|
||||||
keepSnippets: Boolean = true,
|
// params: MessagesEditRequest
|
||||||
keepForwardedMessages: Boolean = true
|
// ): ApiResult<Int, RestApiErrorDomain>
|
||||||
): ApiResult<Int, RestApiErrorDomain>
|
//
|
||||||
|
// suspend fun getChat(
|
||||||
suspend fun getChat(
|
// params: MessagesGetChatRequest
|
||||||
chatId: Long,
|
// ): ApiResult<VkChatData, RestApiErrorDomain>
|
||||||
fields: String? = null
|
//
|
||||||
): ApiResult<VkChatData, RestApiErrorDomain>
|
// suspend fun getConversationMembers(
|
||||||
|
// params: MessagesGetConversationMembersRequest
|
||||||
suspend fun getConversationMembers(
|
// ): ApiResult<MessagesGetConversationMembersResponse, RestApiErrorDomain>
|
||||||
peerId: Long,
|
//
|
||||||
offset: Int? = null,
|
// suspend fun removeChatUser(
|
||||||
count: Int? = null,
|
// params: MessagesRemoveChatUserRequest
|
||||||
extended: Boolean? = null,
|
// ): ApiResult<Int, RestApiErrorDomain>
|
||||||
fields: String? = null
|
|
||||||
): ApiResult<MessagesGetConversationMembersResponse, RestApiErrorDomain>
|
|
||||||
|
|
||||||
suspend fun removeChatUser(
|
|
||||||
chatId: Long,
|
|
||||||
memberId: Long
|
|
||||||
): ApiResult<Int, RestApiErrorDomain>
|
|
||||||
}
|
}
|
||||||
|
|||||||
+93
-202
@@ -5,57 +5,36 @@ import dev.meloda.fast.common.VkConstants
|
|||||||
import dev.meloda.fast.data.VkGroupsMap
|
import dev.meloda.fast.data.VkGroupsMap
|
||||||
import dev.meloda.fast.data.VkMemoryCache
|
import dev.meloda.fast.data.VkMemoryCache
|
||||||
import dev.meloda.fast.data.VkUsersMap
|
import dev.meloda.fast.data.VkUsersMap
|
||||||
import dev.meloda.fast.database.dao.ConversationDao
|
|
||||||
import dev.meloda.fast.database.dao.GroupDao
|
|
||||||
import dev.meloda.fast.database.dao.MessageDao
|
import dev.meloda.fast.database.dao.MessageDao
|
||||||
import dev.meloda.fast.database.dao.UserDao
|
|
||||||
import dev.meloda.fast.model.api.data.VkAttachmentHistoryMessageData
|
import dev.meloda.fast.model.api.data.VkAttachmentHistoryMessageData
|
||||||
import dev.meloda.fast.model.api.data.VkChatData
|
|
||||||
import dev.meloda.fast.model.api.data.VkContactData
|
import dev.meloda.fast.model.api.data.VkContactData
|
||||||
import dev.meloda.fast.model.api.data.VkGroupData
|
import dev.meloda.fast.model.api.data.VkGroupData
|
||||||
import dev.meloda.fast.model.api.data.VkUserData
|
import dev.meloda.fast.model.api.data.VkUserData
|
||||||
import dev.meloda.fast.model.api.data.asDomain
|
import dev.meloda.fast.model.api.data.asDomain
|
||||||
import dev.meloda.fast.model.api.domain.VkAttachment
|
import dev.meloda.fast.model.api.domain.VkAttachment
|
||||||
import dev.meloda.fast.model.api.domain.VkAttachmentHistoryMessage
|
import dev.meloda.fast.model.api.domain.VkAttachmentHistoryMessage
|
||||||
import dev.meloda.fast.model.api.domain.VkConversation
|
|
||||||
import dev.meloda.fast.model.api.domain.VkGroupDomain
|
|
||||||
import dev.meloda.fast.model.api.domain.VkMessage
|
import dev.meloda.fast.model.api.domain.VkMessage
|
||||||
import dev.meloda.fast.model.api.domain.VkUser
|
|
||||||
import dev.meloda.fast.model.api.domain.asEntity
|
import dev.meloda.fast.model.api.domain.asEntity
|
||||||
import dev.meloda.fast.model.api.requests.MessagesCreateChatRequest
|
import dev.meloda.fast.model.api.requests.MessagesCreateChatRequest
|
||||||
import dev.meloda.fast.model.api.requests.MessagesDeleteRequest
|
|
||||||
import dev.meloda.fast.model.api.requests.MessagesEditRequest
|
|
||||||
import dev.meloda.fast.model.api.requests.MessagesGetByIdRequest
|
import dev.meloda.fast.model.api.requests.MessagesGetByIdRequest
|
||||||
import dev.meloda.fast.model.api.requests.MessagesGetChatRequest
|
|
||||||
import dev.meloda.fast.model.api.requests.MessagesGetConversationMembersRequest
|
|
||||||
import dev.meloda.fast.model.api.requests.MessagesGetHistoryAttachmentsRequest
|
import dev.meloda.fast.model.api.requests.MessagesGetHistoryAttachmentsRequest
|
||||||
import dev.meloda.fast.model.api.requests.MessagesGetHistoryRequest
|
import dev.meloda.fast.model.api.requests.MessagesGetHistoryRequest
|
||||||
import dev.meloda.fast.model.api.requests.MessagesMarkAsImportantRequest
|
|
||||||
import dev.meloda.fast.model.api.requests.MessagesMarkAsReadRequest
|
import dev.meloda.fast.model.api.requests.MessagesMarkAsReadRequest
|
||||||
import dev.meloda.fast.model.api.requests.MessagesPinMessageRequest
|
|
||||||
import dev.meloda.fast.model.api.requests.MessagesRemoveChatUserRequest
|
|
||||||
import dev.meloda.fast.model.api.requests.MessagesSendRequest
|
import dev.meloda.fast.model.api.requests.MessagesSendRequest
|
||||||
import dev.meloda.fast.model.api.requests.MessagesUnpinMessageRequest
|
|
||||||
import dev.meloda.fast.model.api.responses.MessagesGetConversationMembersResponse
|
|
||||||
import dev.meloda.fast.model.api.responses.MessagesSendResponse
|
|
||||||
import dev.meloda.fast.network.RestApiErrorDomain
|
import dev.meloda.fast.network.RestApiErrorDomain
|
||||||
import dev.meloda.fast.network.mapApiDefault
|
import dev.meloda.fast.network.mapApiDefault
|
||||||
import dev.meloda.fast.network.mapApiResult
|
import dev.meloda.fast.network.mapApiResult
|
||||||
import dev.meloda.fast.network.service.messages.MessagesService
|
import dev.meloda.fast.network.service.messages.MessagesService
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
class MessagesRepositoryImpl(
|
class MessagesRepositoryImpl(
|
||||||
private val messagesService: MessagesService,
|
private val messagesService: MessagesService,
|
||||||
private val messageDao: MessageDao,
|
private val messageDao: MessageDao,
|
||||||
private val userDao: UserDao,
|
|
||||||
private val groupDao: GroupDao,
|
|
||||||
private val conversationDao: ConversationDao
|
|
||||||
) : MessagesRepository {
|
) : MessagesRepository {
|
||||||
|
|
||||||
override suspend fun getHistory(
|
override suspend fun getHistory(
|
||||||
conversationId: Long,
|
conversationId: Int,
|
||||||
offset: Int?,
|
offset: Int?,
|
||||||
count: Int?
|
count: Int?
|
||||||
): ApiResult<MessagesHistoryInfo, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
): ApiResult<MessagesHistoryInfo, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
||||||
@@ -106,13 +85,6 @@ class MessagesRepositoryImpl(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
launch(Dispatchers.IO) {
|
|
||||||
conversationDao.insertAll(conversations.map(VkConversation::asEntity))
|
|
||||||
messageDao.insertAll(messages.map(VkMessage::asEntity))
|
|
||||||
userDao.insertAll(profilesList.map(VkUser::asEntity))
|
|
||||||
groupDao.insertAll(groupsList.map(VkGroupDomain::asEntity))
|
|
||||||
}
|
|
||||||
|
|
||||||
MessagesHistoryInfo(
|
MessagesHistoryInfo(
|
||||||
messages = messages,
|
messages = messages,
|
||||||
conversations = conversations
|
conversations = conversations
|
||||||
@@ -125,18 +97,12 @@ class MessagesRepositoryImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getById(
|
override suspend fun getById(
|
||||||
peerCmIds: List<Long>?,
|
messagesIds: List<Int>,
|
||||||
peerId: Long?,
|
|
||||||
messagesIds: List<Long>?,
|
|
||||||
cmIds: List<Long>?,
|
|
||||||
extended: Boolean?,
|
extended: Boolean?,
|
||||||
fields: String?
|
fields: String?
|
||||||
): ApiResult<List<VkMessage>, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
): ApiResult<List<VkMessage>, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
||||||
val requestModel = MessagesGetByIdRequest(
|
val requestModel = MessagesGetByIdRequest(
|
||||||
peerCmIds = peerCmIds,
|
|
||||||
peerId = peerId,
|
|
||||||
messagesIds = messagesIds,
|
messagesIds = messagesIds,
|
||||||
cmIds = cmIds,
|
|
||||||
extended = extended,
|
extended = extended,
|
||||||
fields = fields
|
fields = fields
|
||||||
)
|
)
|
||||||
@@ -146,15 +112,12 @@ class MessagesRepositoryImpl(
|
|||||||
val response = apiResponse.requireResponse()
|
val response = apiResponse.requireResponse()
|
||||||
|
|
||||||
val messages = response.items
|
val messages = response.items
|
||||||
|
val usersMap =
|
||||||
|
VkUsersMap.forUsers(response.profiles.orEmpty().map(VkUserData::mapToDomain))
|
||||||
|
val groupsMap =
|
||||||
|
VkGroupsMap.forGroups(response.groups.orEmpty().map(VkGroupData::mapToDomain))
|
||||||
|
|
||||||
val profilesList = response.profiles.orEmpty().map(VkUserData::mapToDomain)
|
messages.map { message ->
|
||||||
val groupsList = response.groups.orEmpty().map(VkGroupData::mapToDomain)
|
|
||||||
val contactsList = response.contacts.orEmpty().map(VkContactData::mapToDomain)
|
|
||||||
|
|
||||||
val usersMap = VkUsersMap.forUsers(profilesList)
|
|
||||||
val groupsMap = VkGroupsMap.forGroups(groupsList)
|
|
||||||
|
|
||||||
val domainMessages = messages.map { message ->
|
|
||||||
message.asDomain().copy(
|
message.asDomain().copy(
|
||||||
user = usersMap.messageUser(message),
|
user = usersMap.messageUser(message),
|
||||||
group = groupsMap.messageGroup(message),
|
group = groupsMap.messageGroup(message),
|
||||||
@@ -162,46 +125,32 @@ class MessagesRepositoryImpl(
|
|||||||
actionGroup = groupsMap.messageActionGroup(message)
|
actionGroup = groupsMap.messageActionGroup(message)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
launch(Dispatchers.IO) {
|
|
||||||
messageDao.insertAll(domainMessages.map(VkMessage::asEntity))
|
|
||||||
userDao.insertAll(profilesList.map(VkUser::asEntity))
|
|
||||||
groupDao.insertAll(groupsList.map(VkGroupDomain::asEntity))
|
|
||||||
}
|
|
||||||
|
|
||||||
VkMemoryCache.appendUsers(profilesList)
|
|
||||||
VkMemoryCache.appendGroups(groupsList)
|
|
||||||
VkMemoryCache.appendContacts(contactsList)
|
|
||||||
|
|
||||||
domainMessages
|
|
||||||
},
|
},
|
||||||
errorMapper = { error -> error?.toDomain() }
|
errorMapper = { error -> error?.toDomain() }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun send(
|
override suspend fun send(
|
||||||
peerId: Long,
|
peerId: Int,
|
||||||
randomId: Long,
|
randomId: Int,
|
||||||
message: String?,
|
message: String?,
|
||||||
replyTo: Long?,
|
replyTo: Int?,
|
||||||
attachments: List<VkAttachment>?,
|
attachments: List<VkAttachment>?
|
||||||
formatData: VkMessage.FormatData?
|
): ApiResult<Int, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
||||||
): ApiResult<MessagesSendResponse, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
|
||||||
val requestModel = MessagesSendRequest(
|
val requestModel = MessagesSendRequest(
|
||||||
peerId = peerId,
|
peerId = peerId,
|
||||||
randomId = randomId,
|
randomId = randomId,
|
||||||
message = message,
|
message = message,
|
||||||
replyTo = replyTo,
|
replyTo = replyTo,
|
||||||
attachments = attachments,
|
attachments = attachments
|
||||||
formatData = formatData
|
|
||||||
)
|
)
|
||||||
|
|
||||||
messagesService.send(requestModel.map).mapApiDefault()
|
messagesService.send(requestModel.map).mapApiDefault()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun markAsRead(
|
override suspend fun markAsRead(
|
||||||
peerId: Long,
|
peerId: Int,
|
||||||
startMessageId: Long?
|
startMessageId: Int?
|
||||||
): ApiResult<Int, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
): ApiResult<Int, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
||||||
val requestModel = MessagesMarkAsReadRequest(
|
val requestModel = MessagesMarkAsReadRequest(
|
||||||
peerId = peerId,
|
peerId = peerId,
|
||||||
@@ -212,11 +161,11 @@ class MessagesRepositoryImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getHistoryAttachments(
|
override suspend fun getHistoryAttachments(
|
||||||
peerId: Long,
|
peerId: Int,
|
||||||
count: Int?,
|
count: Int?,
|
||||||
offset: Int?,
|
offset: Int?,
|
||||||
attachmentTypes: List<String>,
|
attachmentTypes: List<String>,
|
||||||
cmId: Long
|
conversationMessageId: Int
|
||||||
): ApiResult<List<VkAttachmentHistoryMessage>, RestApiErrorDomain> =
|
): ApiResult<List<VkAttachmentHistoryMessage>, RestApiErrorDomain> =
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
val requestModel = MessagesGetHistoryAttachmentsRequest(
|
val requestModel = MessagesGetHistoryAttachmentsRequest(
|
||||||
@@ -226,7 +175,7 @@ class MessagesRepositoryImpl(
|
|||||||
offset = offset,
|
offset = offset,
|
||||||
preserveOrder = true,
|
preserveOrder = true,
|
||||||
attachmentTypes = attachmentTypes,
|
attachmentTypes = attachmentTypes,
|
||||||
conversationMessageId = cmId,
|
conversationMessageId = conversationMessageId,
|
||||||
fields = VkConstants.ALL_FIELDS
|
fields = VkConstants.ALL_FIELDS
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -242,11 +191,6 @@ class MessagesRepositoryImpl(
|
|||||||
VkMemoryCache.appendGroups(groupsList)
|
VkMemoryCache.appendGroups(groupsList)
|
||||||
VkMemoryCache.appendContacts(contactsList)
|
VkMemoryCache.appendContacts(contactsList)
|
||||||
|
|
||||||
launch(Dispatchers.IO) {
|
|
||||||
userDao.insertAll(profilesList.map(VkUser::asEntity))
|
|
||||||
groupDao.insertAll(groupsList.map(VkGroupDomain::asEntity))
|
|
||||||
}
|
|
||||||
|
|
||||||
response.items.map(VkAttachmentHistoryMessageData::toDomain)
|
response.items.map(VkAttachmentHistoryMessageData::toDomain)
|
||||||
},
|
},
|
||||||
errorMapper = { error ->
|
errorMapper = { error ->
|
||||||
@@ -256,9 +200,9 @@ class MessagesRepositoryImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun createChat(
|
override suspend fun createChat(
|
||||||
userIds: List<Long>?,
|
userIds: List<Int>?,
|
||||||
title: String?
|
title: String?
|
||||||
): ApiResult<Long, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
): ApiResult<Int, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
||||||
val requestModel = MessagesCreateChatRequest(
|
val requestModel = MessagesCreateChatRequest(
|
||||||
userIds = userIds,
|
userIds = userIds,
|
||||||
title = title
|
title = title
|
||||||
@@ -272,134 +216,81 @@ class MessagesRepositoryImpl(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun pin(
|
|
||||||
peerId: Long,
|
|
||||||
messageId: Long?,
|
|
||||||
cmId: Long?
|
|
||||||
): ApiResult<VkMessage, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
|
||||||
val requestModel = MessagesPinMessageRequest(
|
|
||||||
peerId = peerId,
|
|
||||||
messageId = messageId,
|
|
||||||
conversationMessageId = cmId
|
|
||||||
)
|
|
||||||
|
|
||||||
messagesService.pin(requestModel.map).mapApiResult(
|
|
||||||
successMapper = { apiResponse ->
|
|
||||||
apiResponse.requireResponse().asDomain()
|
|
||||||
},
|
|
||||||
errorMapper = { error -> error?.toDomain() }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun unpin(
|
|
||||||
peerId: Long
|
|
||||||
): ApiResult<Int, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
|
||||||
val requestModel = MessagesUnpinMessageRequest(peerId = peerId)
|
|
||||||
messagesService.unpin(requestModel.map).mapApiDefault()
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun markAsImportant(
|
|
||||||
peerId: Long,
|
|
||||||
messageIds: List<Long>?,
|
|
||||||
cmIds: List<Long>?,
|
|
||||||
important: Boolean
|
|
||||||
): ApiResult<List<Long>, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
|
||||||
val requestModel = MessagesMarkAsImportantRequest(
|
|
||||||
messagesIds = messageIds.orEmpty(),
|
|
||||||
important = important
|
|
||||||
)
|
|
||||||
messagesService.markAsImportant(requestModel.map).mapApiDefault()
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun delete(
|
|
||||||
peerId: Long,
|
|
||||||
messageIds: List<Long>?,
|
|
||||||
cmIds: List<Long>?,
|
|
||||||
spam: Boolean,
|
|
||||||
deleteForAll: Boolean
|
|
||||||
): ApiResult<List<Any>, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
|
||||||
val requestModel = MessagesDeleteRequest(
|
|
||||||
peerId = peerId,
|
|
||||||
messagesIds = messageIds,
|
|
||||||
conversationsMessagesIds = cmIds,
|
|
||||||
isSpam = spam,
|
|
||||||
deleteForAll = deleteForAll
|
|
||||||
)
|
|
||||||
messagesService.delete(requestModel.map).mapApiDefault()
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun storeMessages(messages: List<VkMessage>) {
|
override suspend fun storeMessages(messages: List<VkMessage>) {
|
||||||
messageDao.insertAll(messages.map(VkMessage::asEntity))
|
messageDao.insertAll(messages.map(VkMessage::asEntity))
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun edit(
|
// override suspend fun markAsImportant(
|
||||||
peerId: Long,
|
// params: MessagesMarkAsImportantRequest
|
||||||
messageId: Long?,
|
// ): ApiResult<List<Int>, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
||||||
cmId: Long?,
|
// messagesService.markAsImportant(params.map).mapResult(
|
||||||
message: String?,
|
// successMapper = { response -> response.requireResponse() },
|
||||||
lat: Float?,
|
// errorMapper = { error -> error?.toDomain() }
|
||||||
long: Float?,
|
// )
|
||||||
attachments: List<VkAttachment>?,
|
// }
|
||||||
notParseLinks: Boolean,
|
//
|
||||||
keepSnippets: Boolean,
|
// override suspend fun pin(
|
||||||
keepForwardedMessages: Boolean
|
// params: MessagesPinMessageRequest
|
||||||
): ApiResult<Int, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
// ): ApiResult<VkMessageData, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
||||||
val requestModel = MessagesEditRequest(
|
// messagesService.pin(params.map).mapResult(
|
||||||
peerId = peerId,
|
// successMapper = { response -> response.requireResponse() },
|
||||||
messageId = messageId,
|
// errorMapper = { error -> error?.toDomain() }
|
||||||
cmId = cmId,
|
// )
|
||||||
message = message,
|
// }
|
||||||
lat = lat,
|
//
|
||||||
long = long,
|
// override suspend fun unpin(
|
||||||
attachments = attachments,
|
// params: MessagesUnPinMessageRequest
|
||||||
notParseLinks = notParseLinks,
|
// ): ApiResult<Unit, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
||||||
keepSnippets = keepSnippets,
|
// messagesService.unpin(params.map).mapResult(
|
||||||
keepForwardedMessages = keepForwardedMessages
|
// successMapper = {},
|
||||||
)
|
// errorMapper = { error -> error?.toDomain() }
|
||||||
|
// )
|
||||||
messagesService.edit(requestModel.map).mapApiDefault()
|
// }
|
||||||
}
|
//
|
||||||
|
// override suspend fun delete(
|
||||||
override suspend fun getChat(
|
// params: MessagesDeleteRequest
|
||||||
chatId: Long,
|
// ): ApiResult<Unit, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
||||||
fields: String?
|
// messagesService.delete(params.map).mapResult(
|
||||||
): ApiResult<VkChatData, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
// successMapper = {},
|
||||||
val requestModel = MessagesGetChatRequest(
|
// errorMapper = { error -> error?.toDomain() }
|
||||||
chatId = chatId,
|
// )
|
||||||
fields = fields
|
// }
|
||||||
)
|
//
|
||||||
|
// override suspend fun edit(
|
||||||
messagesService.getChat(requestModel.map).mapApiDefault()
|
// params: MessagesEditRequest
|
||||||
}
|
// ): ApiResult<Int, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
||||||
|
// messagesService.edit(params.map).mapResult(
|
||||||
override suspend fun getConversationMembers(
|
// successMapper = { response -> response.requireResponse() },
|
||||||
peerId: Long,
|
// errorMapper = { error -> error?.toDomain() }
|
||||||
offset: Int?,
|
// )
|
||||||
count: Int?,
|
// }
|
||||||
extended: Boolean?,
|
//
|
||||||
fields: String?
|
// override suspend fun getChat(
|
||||||
): ApiResult<MessagesGetConversationMembersResponse, RestApiErrorDomain> =
|
// params: MessagesGetChatRequest
|
||||||
withContext(Dispatchers.IO) {
|
// ): ApiResult<VkChatData, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
||||||
val requestModel = MessagesGetConversationMembersRequest(
|
// messagesService.getChat(params.map).mapResult(
|
||||||
peerId = peerId,
|
// successMapper = { response -> response.requireResponse() },
|
||||||
offset = offset,
|
// errorMapper = { error -> error?.toDomain() }
|
||||||
count = count,
|
// )
|
||||||
extended = extended,
|
// }
|
||||||
fields = fields
|
//
|
||||||
)
|
// override suspend fun getConversationMembers(
|
||||||
|
// params: MessagesGetConversationMembersRequest
|
||||||
messagesService.getConversationMembers(requestModel.map).mapApiDefault()
|
// ): ApiResult<MessagesGetConversationMembersResponse, RestApiErrorDomain> =
|
||||||
}
|
// withContext(Dispatchers.IO) {
|
||||||
|
// messagesService.getConversationMembers(params.map).mapResult(
|
||||||
override suspend fun removeChatUser(
|
// successMapper = { response -> response.requireResponse() },
|
||||||
chatId: Long,
|
// errorMapper = { error -> error?.toDomain() }
|
||||||
memberId: Long
|
// )
|
||||||
): ApiResult<Int, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
// }
|
||||||
val requestModel = MessagesRemoveChatUserRequest(
|
//
|
||||||
chatId = chatId,
|
// override suspend fun removeChatUser(
|
||||||
memberId = memberId
|
// params: MessagesRemoveChatUserRequest
|
||||||
)
|
// ): ApiResult<Int, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
||||||
|
// messagesService.removeChatUser(params.map).mapResult(
|
||||||
messagesService.removeChatUser(requestModel.map).mapApiDefault()
|
// successMapper = { response -> response.requireResponse() },
|
||||||
}
|
// errorMapper = { error -> error?.toDomain() }
|
||||||
|
// )
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
package dev.meloda.fast.data.api.oauth
|
package dev.meloda.fast.data.api.oauth
|
||||||
|
|
||||||
import com.slack.eithernet.ApiResult
|
|
||||||
import dev.meloda.fast.model.api.responses.AuthDirectResponse
|
import dev.meloda.fast.model.api.responses.AuthDirectResponse
|
||||||
import dev.meloda.fast.model.api.responses.GetSilentTokenResponse
|
|
||||||
import dev.meloda.fast.network.OAuthErrorDomain
|
|
||||||
|
|
||||||
interface OAuthRepository {
|
interface OAuthRepository {
|
||||||
|
|
||||||
@@ -14,14 +11,5 @@ interface OAuthRepository {
|
|||||||
validationCode: String?,
|
validationCode: String?,
|
||||||
captchaSid: String?,
|
captchaSid: String?,
|
||||||
captchaKey: String?
|
captchaKey: String?
|
||||||
): ApiResult<AuthDirectResponse, OAuthErrorDomain>
|
): AuthDirectResponse
|
||||||
|
|
||||||
suspend fun getSilentToken(
|
|
||||||
login: String,
|
|
||||||
password: String,
|
|
||||||
forceSms: Boolean,
|
|
||||||
validationCode: String?,
|
|
||||||
captchaSid: String?,
|
|
||||||
captchaKey: String?,
|
|
||||||
): ApiResult<GetSilentTokenResponse, OAuthErrorDomain>
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,10 @@
|
|||||||
package dev.meloda.fast.data.api.oauth
|
package dev.meloda.fast.data.api.oauth
|
||||||
|
|
||||||
import com.slack.eithernet.ApiResult
|
|
||||||
import dev.meloda.fast.common.VkConstants
|
import dev.meloda.fast.common.VkConstants
|
||||||
import dev.meloda.fast.model.api.requests.AuthDirectRequest
|
import dev.meloda.fast.model.api.requests.AuthDirectRequest
|
||||||
import dev.meloda.fast.model.api.responses.AuthDirectResponse
|
import dev.meloda.fast.model.api.responses.AuthDirectResponse
|
||||||
import dev.meloda.fast.model.api.responses.GetSilentTokenResponse
|
|
||||||
import dev.meloda.fast.network.OAuthErrorDomain
|
|
||||||
import dev.meloda.fast.network.ValidationType
|
|
||||||
import dev.meloda.fast.network.VkOAuthError
|
|
||||||
import dev.meloda.fast.network.VkOAuthErrorType
|
|
||||||
import dev.meloda.fast.network.mapResult
|
|
||||||
import dev.meloda.fast.network.service.oauth.OAuthService
|
import dev.meloda.fast.network.service.oauth.OAuthService
|
||||||
|
import com.slack.eithernet.ApiResult
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
@@ -24,190 +18,37 @@ class OAuthRepositoryImpl(
|
|||||||
forceSms: Boolean,
|
forceSms: Boolean,
|
||||||
validationCode: String?,
|
validationCode: String?,
|
||||||
captchaSid: String?,
|
captchaSid: String?,
|
||||||
captchaKey: String?,
|
captchaKey: String?
|
||||||
): ApiResult<AuthDirectResponse, OAuthErrorDomain> = withContext(Dispatchers.IO) {
|
): AuthDirectResponse = withContext(Dispatchers.IO) {
|
||||||
val requestModel = AuthDirectRequest(
|
val requestModel = AuthDirectRequest(
|
||||||
grantType = VkConstants.Auth.GrantType.PASSWORD,
|
grantType = VkConstants.Auth.GrantType.PASSWORD,
|
||||||
clientId = VkConstants.MESSENGER_APP_ID.toString(),
|
clientId = VkConstants.VK_APP_ID,
|
||||||
clientSecret = VkConstants.MESSENGER_APP_SECRET,
|
clientSecret = VkConstants.VK_SECRET,
|
||||||
username = login,
|
username = login,
|
||||||
password = password,
|
password = password,
|
||||||
scope = VkConstants.MESSENGER_APP_SCOPE.toString(),
|
scope = VkConstants.Auth.SCOPE,
|
||||||
validationForceSms = forceSms,
|
validationForceSms = forceSms,
|
||||||
validationCode = validationCode,
|
validationCode = validationCode,
|
||||||
captchaSid = captchaSid,
|
captchaSid = captchaSid,
|
||||||
captchaKey = captchaKey,
|
captchaKey = captchaKey,
|
||||||
)
|
)
|
||||||
|
|
||||||
oAuthService.auth(requestModel.map).mapResult(
|
when (val result = oAuthService.auth(requestModel.map)) {
|
||||||
successMapper = {
|
is ApiResult.Success -> result.value
|
||||||
it
|
|
||||||
},
|
|
||||||
errorMapper = { response ->
|
|
||||||
val error = response?.error?.let(VkOAuthError::parse)
|
|
||||||
val errorType = response?.errorType?.let(VkOAuthErrorType::parse)
|
|
||||||
|
|
||||||
when (error) {
|
is ApiResult.Failure.HttpFailure -> {
|
||||||
null -> OAuthErrorDomain.UnknownError
|
requireNotNull(result.error)
|
||||||
|
|
||||||
VkOAuthError.FLOOD_CONTROL -> OAuthErrorDomain.TooManyTriesError
|
|
||||||
|
|
||||||
VkOAuthError.NEED_VALIDATION -> {
|
|
||||||
if (response.banInfo != null) {
|
|
||||||
val info = requireNotNull(response.banInfo)
|
|
||||||
|
|
||||||
OAuthErrorDomain.UserBannedError(
|
|
||||||
memberName = info.memberName,
|
|
||||||
message = info.message,
|
|
||||||
accessToken = info.accessToken,
|
|
||||||
restoreUrl = info.restoreUrl
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
OAuthErrorDomain.ValidationRequiredError(
|
|
||||||
description = response.errorDescription.orEmpty(),
|
|
||||||
validationType = response.validationType.orEmpty()
|
|
||||||
.let(ValidationType::parse),
|
|
||||||
validationSid = response.validationSid.orEmpty(),
|
|
||||||
phoneMask = response.phoneMask.orEmpty(),
|
|
||||||
redirectUri = response.redirectUri.orEmpty(),
|
|
||||||
validationResend = response.validationResend,
|
|
||||||
restoreIfCannotGetCode = response.restoreIfCannotGetCode
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VkOAuthError.NEED_CAPTCHA -> {
|
is ApiResult.Failure.ApiFailure -> TODO()
|
||||||
OAuthErrorDomain.CaptchaRequiredError(
|
|
||||||
captchaSid = response.captchaSid.orEmpty(),
|
|
||||||
captchaImageUrl = response.captchaImage.orEmpty()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
VkOAuthError.INVALID_CLIENT -> {
|
is ApiResult.Failure.NetworkFailure -> {
|
||||||
OAuthErrorDomain.InvalidCredentialsError
|
// TODO: 13/07/2024, Danil Nikolaev: implement showing network error
|
||||||
|
TODO()
|
||||||
}
|
}
|
||||||
|
is ApiResult.Failure.UnknownFailure -> TODO()
|
||||||
|
|
||||||
VkOAuthError.INVALID_REQUEST -> {
|
else -> throw IllegalStateException("Unknown result")
|
||||||
when (errorType) {
|
|
||||||
null -> OAuthErrorDomain.UnknownError
|
|
||||||
|
|
||||||
VkOAuthErrorType.WRONG_OTP -> {
|
|
||||||
OAuthErrorDomain.WrongValidationCode
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VkOAuthErrorType.WRONG_OTP_FORMAT -> {
|
|
||||||
OAuthErrorDomain.WrongValidationCodeFormat
|
|
||||||
}
|
|
||||||
|
|
||||||
VkOAuthErrorType.PASSWORD_BRUTEFORCE_ATTEMPT -> {
|
|
||||||
OAuthErrorDomain.TooManyTriesError
|
|
||||||
}
|
|
||||||
|
|
||||||
VkOAuthErrorType.USERNAME_OR_PASSWORD_IS_INCORRECT -> {
|
|
||||||
OAuthErrorDomain.InvalidCredentialsError
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
VkOAuthError.UNKNOWN -> OAuthErrorDomain.UnknownError
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getSilentToken(
|
|
||||||
login: String,
|
|
||||||
password: String,
|
|
||||||
forceSms: Boolean,
|
|
||||||
validationCode: String?,
|
|
||||||
captchaSid: String?,
|
|
||||||
captchaKey: String?,
|
|
||||||
): ApiResult<GetSilentTokenResponse, OAuthErrorDomain> =
|
|
||||||
withContext(Dispatchers.IO) {
|
|
||||||
val requestModel = AuthDirectRequest(
|
|
||||||
grantType = VkConstants.Auth.GrantType.PASSWORD,
|
|
||||||
clientId = VkConstants.MESSENGER_APP_ID.toString(),
|
|
||||||
clientSecret = VkConstants.MESSENGER_APP_SECRET,
|
|
||||||
username = login,
|
|
||||||
password = password,
|
|
||||||
scope = VkConstants.MESSENGER_APP_SCOPE.toString(),
|
|
||||||
validationForceSms = forceSms,
|
|
||||||
validationCode = validationCode,
|
|
||||||
captchaSid = captchaSid,
|
|
||||||
captchaKey = captchaKey,
|
|
||||||
)
|
|
||||||
|
|
||||||
oAuthService.getSilentToken(requestModel.map).mapResult(
|
|
||||||
successMapper = { it },
|
|
||||||
errorMapper = { response ->
|
|
||||||
val error = response?.error?.let(VkOAuthError::parse)
|
|
||||||
val errorType = response?.errorType?.let(VkOAuthErrorType::parse)
|
|
||||||
|
|
||||||
when (error) {
|
|
||||||
null -> OAuthErrorDomain.UnknownError
|
|
||||||
|
|
||||||
VkOAuthError.FLOOD_CONTROL -> OAuthErrorDomain.TooManyTriesError
|
|
||||||
|
|
||||||
VkOAuthError.NEED_VALIDATION -> {
|
|
||||||
if (response.banInfo != null) {
|
|
||||||
val info = requireNotNull(response.banInfo)
|
|
||||||
|
|
||||||
OAuthErrorDomain.UserBannedError(
|
|
||||||
memberName = info.memberName,
|
|
||||||
message = info.message,
|
|
||||||
accessToken = info.accessToken,
|
|
||||||
restoreUrl = info.restoreUrl
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
OAuthErrorDomain.ValidationRequiredError(
|
|
||||||
description = response.errorDescription.orEmpty(),
|
|
||||||
validationType = response.validationType.orEmpty()
|
|
||||||
.let(ValidationType::parse),
|
|
||||||
validationSid = response.validationSid.orEmpty(),
|
|
||||||
phoneMask = response.phoneMask.orEmpty(),
|
|
||||||
redirectUri = response.redirectUri.orEmpty(),
|
|
||||||
validationResend = response.validationResend,
|
|
||||||
restoreIfCannotGetCode = response.restoreIfCannotGetCode
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
VkOAuthError.NEED_CAPTCHA -> {
|
|
||||||
OAuthErrorDomain.CaptchaRequiredError(
|
|
||||||
captchaSid = response.captchaSid.orEmpty(),
|
|
||||||
captchaImageUrl = response.captchaImage.orEmpty()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
VkOAuthError.INVALID_CLIENT -> {
|
|
||||||
OAuthErrorDomain.InvalidCredentialsError
|
|
||||||
}
|
|
||||||
|
|
||||||
VkOAuthError.INVALID_REQUEST -> {
|
|
||||||
when (errorType) {
|
|
||||||
null -> OAuthErrorDomain.UnknownError
|
|
||||||
|
|
||||||
VkOAuthErrorType.WRONG_OTP -> {
|
|
||||||
OAuthErrorDomain.WrongValidationCode
|
|
||||||
}
|
|
||||||
|
|
||||||
VkOAuthErrorType.WRONG_OTP_FORMAT -> {
|
|
||||||
OAuthErrorDomain.WrongValidationCodeFormat
|
|
||||||
}
|
|
||||||
|
|
||||||
VkOAuthErrorType.PASSWORD_BRUTEFORCE_ATTEMPT -> {
|
|
||||||
OAuthErrorDomain.TooManyTriesError
|
|
||||||
}
|
|
||||||
|
|
||||||
VkOAuthErrorType.USERNAME_OR_PASSWORD_IS_INCORRECT -> {
|
|
||||||
OAuthErrorDomain.InvalidCredentialsError
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
VkOAuthError.UNKNOWN -> OAuthErrorDomain.UnknownError
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ class PhotosRepository(
|
|||||||
private val photosService: PhotosService
|
private val photosService: PhotosService
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend fun getMessagesUploadServer(peerId: Long) =
|
suspend fun getMessagesUploadServer(peerId: Int) =
|
||||||
photosService.getUploadServer(mapOf("peer_id" to peerId.toString()))
|
photosService.getUploadServer(mapOf("peer_id" to peerId.toString()))
|
||||||
|
|
||||||
suspend fun uploadPhoto(url: String, photo: MultipartBody.Part) =
|
suspend fun uploadPhoto(url: String, photo: MultipartBody.Part) =
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
package dev.meloda.fast.data.api.users
|
package dev.meloda.fast.data.api.users
|
||||||
|
|
||||||
import com.slack.eithernet.ApiResult
|
|
||||||
import dev.meloda.fast.model.api.domain.VkUser
|
import dev.meloda.fast.model.api.domain.VkUser
|
||||||
import dev.meloda.fast.network.RestApiErrorDomain
|
import dev.meloda.fast.network.RestApiErrorDomain
|
||||||
|
import com.slack.eithernet.ApiResult
|
||||||
|
|
||||||
interface UsersRepository {
|
interface UsersRepository {
|
||||||
|
|
||||||
suspend fun get(
|
suspend fun get(
|
||||||
userIds: List<Long>?,
|
userIds: List<Int>?,
|
||||||
fields: String?,
|
fields: String?,
|
||||||
nomCase: String?
|
nomCase: String?
|
||||||
): ApiResult<List<VkUser>, RestApiErrorDomain>
|
): ApiResult<List<VkUser>, RestApiErrorDomain>
|
||||||
|
|
||||||
suspend fun getLocalUsers(userIds: List<Long>): List<VkUser>
|
suspend fun getLocalUsers(userIds: List<Int>): List<VkUser>
|
||||||
|
|
||||||
suspend fun storeUsers(users: List<VkUser>)
|
suspend fun storeUsers(users: List<VkUser>)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
package dev.meloda.fast.data.api.users
|
package dev.meloda.fast.data.api.users
|
||||||
|
|
||||||
import com.slack.eithernet.ApiResult
|
|
||||||
import dev.meloda.fast.data.VkMemoryCache
|
import dev.meloda.fast.data.VkMemoryCache
|
||||||
import dev.meloda.fast.database.dao.UserDao
|
import dev.meloda.fast.database.dao.UsersDao
|
||||||
import dev.meloda.fast.model.api.data.VkUserData
|
import dev.meloda.fast.model.api.data.VkUserData
|
||||||
import dev.meloda.fast.model.api.domain.VkUser
|
import dev.meloda.fast.model.api.domain.VkUser
|
||||||
import dev.meloda.fast.model.api.domain.asEntity
|
import dev.meloda.fast.model.api.domain.asEntity
|
||||||
@@ -12,17 +11,18 @@ import dev.meloda.fast.model.database.asExternalModel
|
|||||||
import dev.meloda.fast.network.RestApiErrorDomain
|
import dev.meloda.fast.network.RestApiErrorDomain
|
||||||
import dev.meloda.fast.network.mapApiResult
|
import dev.meloda.fast.network.mapApiResult
|
||||||
import dev.meloda.fast.network.service.users.UsersService
|
import dev.meloda.fast.network.service.users.UsersService
|
||||||
|
import com.slack.eithernet.ApiResult
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
class UsersRepositoryImpl(
|
class UsersRepositoryImpl(
|
||||||
private val service: UsersService,
|
private val service: UsersService,
|
||||||
private val dao: UserDao
|
private val dao: UsersDao
|
||||||
) : UsersRepository {
|
) : UsersRepository {
|
||||||
|
|
||||||
override suspend fun get(
|
override suspend fun get(
|
||||||
userIds: List<Long>?,
|
userIds: List<Int>?,
|
||||||
fields: String?,
|
fields: String?,
|
||||||
nomCase: String?
|
nomCase: String?
|
||||||
): ApiResult<List<VkUser>, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
): ApiResult<List<VkUser>, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
||||||
@@ -38,9 +38,7 @@ class UsersRepositoryImpl(
|
|||||||
|
|
||||||
val users = response.map(VkUserData::mapToDomain)
|
val users = response.map(VkUserData::mapToDomain)
|
||||||
|
|
||||||
launch(Dispatchers.IO) {
|
launch { storeUsers(users) }
|
||||||
storeUsers(users)
|
|
||||||
}
|
|
||||||
|
|
||||||
VkMemoryCache.appendUsers(users)
|
VkMemoryCache.appendUsers(users)
|
||||||
|
|
||||||
@@ -53,7 +51,7 @@ class UsersRepositoryImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getLocalUsers(
|
override suspend fun getLocalUsers(
|
||||||
userIds: List<Long>
|
userIds: List<Int>
|
||||||
): List<VkUser> = withContext(Dispatchers.IO) {
|
): List<VkUser> = withContext(Dispatchers.IO) {
|
||||||
dao.getAllByIds(userIds).map(VkUserEntity::asExternalModel)
|
dao.getAllByIds(userIds).map(VkUserEntity::asExternalModel)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ interface AccountsRepository {
|
|||||||
|
|
||||||
suspend fun getAccounts(): List<AccountEntity>
|
suspend fun getAccounts(): List<AccountEntity>
|
||||||
|
|
||||||
suspend fun getAccountById(userId: Long): AccountEntity?
|
suspend fun getAccountById(userId: Int): AccountEntity?
|
||||||
|
|
||||||
suspend fun storeAccounts(accounts: List<AccountEntity>)
|
suspend fun storeAccounts(accounts: List<AccountEntity>)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class AccountsRepositoryImpl(
|
|||||||
|
|
||||||
override suspend fun getAccounts(): List<AccountEntity> = accountDao.getAll()
|
override suspend fun getAccounts(): List<AccountEntity> = accountDao.getAll()
|
||||||
|
|
||||||
override suspend fun getAccountById(userId: Long): AccountEntity? =
|
override suspend fun getAccountById(userId: Int): AccountEntity? =
|
||||||
accountDao.getById(userId)
|
accountDao.getById(userId)
|
||||||
|
|
||||||
override suspend fun storeAccounts(
|
override suspend fun storeAccounts(
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ val dataModule = module {
|
|||||||
|
|
||||||
singleOf(::FriendsRepositoryImpl) bind FriendsRepository::class
|
singleOf(::FriendsRepositoryImpl) bind FriendsRepository::class
|
||||||
|
|
||||||
|
// TODO: 11/08/2024, Danil Nikolaev: find a better solution
|
||||||
single<Interceptor>(named("token_interceptor")) {
|
single<Interceptor>(named("token_interceptor")) {
|
||||||
AccessTokenInterceptor()
|
AccessTokenInterceptor()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,11 @@
|
|||||||
"formatVersion": 1,
|
"formatVersion": 1,
|
||||||
"database": {
|
"database": {
|
||||||
"version": 2,
|
"version": 2,
|
||||||
"identityHash": "ca007bca2ab4a9b901662792042770ad",
|
"identityHash": "3ebd234270e36902d3d461af38664869",
|
||||||
"entities": [
|
"entities": [
|
||||||
{
|
{
|
||||||
"tableName": "accounts",
|
"tableName": "accounts",
|
||||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`userId` INTEGER NOT NULL, `accessToken` TEXT NOT NULL, `fastToken` TEXT, `trustedHash` TEXT, `exchangeToken` TEXT, PRIMARY KEY(`userId`))",
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`userId` INTEGER NOT NULL, `accessToken` TEXT NOT NULL, `fastToken` TEXT, `trustedHash` TEXT, PRIMARY KEY(`userId`))",
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
"fieldPath": "userId",
|
"fieldPath": "userId",
|
||||||
@@ -31,12 +31,6 @@
|
|||||||
"columnName": "trustedHash",
|
"columnName": "trustedHash",
|
||||||
"affinity": "TEXT",
|
"affinity": "TEXT",
|
||||||
"notNull": false
|
"notNull": false
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "exchangeToken",
|
|
||||||
"columnName": "exchangeToken",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": false
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"primaryKey": {
|
"primaryKey": {
|
||||||
@@ -52,7 +46,7 @@
|
|||||||
"views": [],
|
"views": [],
|
||||||
"setupQueries": [
|
"setupQueries": [
|
||||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'ca007bca2ab4a9b901662792042770ad')"
|
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '3ebd234270e36902d3d461af38664869')"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
{
|
|
||||||
"formatVersion": 1,
|
|
||||||
"database": {
|
|
||||||
"version": 3,
|
|
||||||
"identityHash": "ca007bca2ab4a9b901662792042770ad",
|
|
||||||
"entities": [
|
|
||||||
{
|
|
||||||
"tableName": "accounts",
|
|
||||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`userId` INTEGER NOT NULL, `accessToken` TEXT NOT NULL, `fastToken` TEXT, `trustedHash` TEXT, `exchangeToken` TEXT, PRIMARY KEY(`userId`))",
|
|
||||||
"fields": [
|
|
||||||
{
|
|
||||||
"fieldPath": "userId",
|
|
||||||
"columnName": "userId",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "accessToken",
|
|
||||||
"columnName": "accessToken",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "fastToken",
|
|
||||||
"columnName": "fastToken",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "trustedHash",
|
|
||||||
"columnName": "trustedHash",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "exchangeToken",
|
|
||||||
"columnName": "exchangeToken",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": false
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"primaryKey": {
|
|
||||||
"autoGenerate": false,
|
|
||||||
"columnNames": [
|
|
||||||
"userId"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"indices": [],
|
|
||||||
"foreignKeys": []
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"views": [],
|
|
||||||
"setupQueries": [
|
|
||||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
|
||||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'ca007bca2ab4a9b901662792042770ad')"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,454 +0,0 @@
|
|||||||
{
|
|
||||||
"formatVersion": 1,
|
|
||||||
"database": {
|
|
||||||
"version": 10,
|
|
||||||
"identityHash": "fa307a5eb2e1f7d601bd1374174635cd",
|
|
||||||
"entities": [
|
|
||||||
{
|
|
||||||
"tableName": "users",
|
|
||||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `firstName` TEXT NOT NULL, `lastName` TEXT NOT NULL, `isOnline` INTEGER NOT NULL, `isOnlineMobile` INTEGER NOT NULL, `onlineAppId` INTEGER, `lastSeen` INTEGER, `lastSeenStatus` TEXT, `birthday` TEXT, `photo50` TEXT, `photo100` TEXT, `photo200` TEXT, `photo400Orig` TEXT, PRIMARY KEY(`id`))",
|
|
||||||
"fields": [
|
|
||||||
{
|
|
||||||
"fieldPath": "id",
|
|
||||||
"columnName": "id",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "firstName",
|
|
||||||
"columnName": "firstName",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "lastName",
|
|
||||||
"columnName": "lastName",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isOnline",
|
|
||||||
"columnName": "isOnline",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isOnlineMobile",
|
|
||||||
"columnName": "isOnlineMobile",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "onlineAppId",
|
|
||||||
"columnName": "onlineAppId",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "lastSeen",
|
|
||||||
"columnName": "lastSeen",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "lastSeenStatus",
|
|
||||||
"columnName": "lastSeenStatus",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "birthday",
|
|
||||||
"columnName": "birthday",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "photo50",
|
|
||||||
"columnName": "photo50",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "photo100",
|
|
||||||
"columnName": "photo100",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "photo200",
|
|
||||||
"columnName": "photo200",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "photo400Orig",
|
|
||||||
"columnName": "photo400Orig",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": false
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"primaryKey": {
|
|
||||||
"autoGenerate": false,
|
|
||||||
"columnNames": [
|
|
||||||
"id"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"indices": [],
|
|
||||||
"foreignKeys": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"tableName": "groups",
|
|
||||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `name` TEXT NOT NULL, `screenName` TEXT NOT NULL, `photo50` TEXT, `photo100` TEXT, `photo200` TEXT, `membersCount` INTEGER, PRIMARY KEY(`id`))",
|
|
||||||
"fields": [
|
|
||||||
{
|
|
||||||
"fieldPath": "id",
|
|
||||||
"columnName": "id",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "name",
|
|
||||||
"columnName": "name",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "screenName",
|
|
||||||
"columnName": "screenName",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "photo50",
|
|
||||||
"columnName": "photo50",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "photo100",
|
|
||||||
"columnName": "photo100",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "photo200",
|
|
||||||
"columnName": "photo200",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "membersCount",
|
|
||||||
"columnName": "membersCount",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": false
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"primaryKey": {
|
|
||||||
"autoGenerate": false,
|
|
||||||
"columnNames": [
|
|
||||||
"id"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"indices": [],
|
|
||||||
"foreignKeys": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"tableName": "messages",
|
|
||||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `conversationMessageId` INTEGER NOT NULL, `text` TEXT, `isOut` INTEGER NOT NULL, `peerId` INTEGER NOT NULL, `fromId` INTEGER NOT NULL, `date` INTEGER NOT NULL, `randomId` INTEGER NOT NULL, `action` TEXT, `actionMemberId` INTEGER, `actionText` TEXT, `actionConversationMessageId` INTEGER, `actionMessage` TEXT, `updateTime` INTEGER, `important` INTEGER NOT NULL, `forwardIds` TEXT, `attachments` TEXT, `replyMessageId` INTEGER, `geoType` TEXT, `pinnedAt` INTEGER, `isPinned` INTEGER NOT NULL, PRIMARY KEY(`id`))",
|
|
||||||
"fields": [
|
|
||||||
{
|
|
||||||
"fieldPath": "id",
|
|
||||||
"columnName": "id",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "conversationMessageId",
|
|
||||||
"columnName": "conversationMessageId",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "text",
|
|
||||||
"columnName": "text",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isOut",
|
|
||||||
"columnName": "isOut",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "peerId",
|
|
||||||
"columnName": "peerId",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "fromId",
|
|
||||||
"columnName": "fromId",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "date",
|
|
||||||
"columnName": "date",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "randomId",
|
|
||||||
"columnName": "randomId",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "action",
|
|
||||||
"columnName": "action",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "actionMemberId",
|
|
||||||
"columnName": "actionMemberId",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "actionText",
|
|
||||||
"columnName": "actionText",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "actionConversationMessageId",
|
|
||||||
"columnName": "actionConversationMessageId",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "actionMessage",
|
|
||||||
"columnName": "actionMessage",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "updateTime",
|
|
||||||
"columnName": "updateTime",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "important",
|
|
||||||
"columnName": "important",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "forwardIds",
|
|
||||||
"columnName": "forwardIds",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "attachments",
|
|
||||||
"columnName": "attachments",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "replyMessageId",
|
|
||||||
"columnName": "replyMessageId",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "geoType",
|
|
||||||
"columnName": "geoType",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "pinnedAt",
|
|
||||||
"columnName": "pinnedAt",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isPinned",
|
|
||||||
"columnName": "isPinned",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"primaryKey": {
|
|
||||||
"autoGenerate": false,
|
|
||||||
"columnNames": [
|
|
||||||
"id"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"indices": [],
|
|
||||||
"foreignKeys": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"tableName": "conversations",
|
|
||||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `localId` INTEGER NOT NULL, `ownerId` INTEGER, `title` TEXT, `photo50` TEXT, `photo100` TEXT, `photo200` TEXT, `isPhantom` INTEGER NOT NULL, `lastConversationMessageId` INTEGER NOT NULL, `inReadCmId` INTEGER NOT NULL, `outReadCmId` INTEGER NOT NULL, `inRead` INTEGER NOT NULL, `outRead` INTEGER NOT NULL, `lastMessageId` INTEGER, `unreadCount` INTEGER NOT NULL, `membersCount` INTEGER, `canChangePin` INTEGER NOT NULL, `canChangeInfo` INTEGER NOT NULL, `majorId` INTEGER NOT NULL, `minorId` INTEGER NOT NULL, `pinnedMessageId` INTEGER, `peerType` TEXT NOT NULL, `isArchived` INTEGER NOT NULL, PRIMARY KEY(`id`))",
|
|
||||||
"fields": [
|
|
||||||
{
|
|
||||||
"fieldPath": "id",
|
|
||||||
"columnName": "id",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "localId",
|
|
||||||
"columnName": "localId",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "ownerId",
|
|
||||||
"columnName": "ownerId",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "title",
|
|
||||||
"columnName": "title",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "photo50",
|
|
||||||
"columnName": "photo50",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "photo100",
|
|
||||||
"columnName": "photo100",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "photo200",
|
|
||||||
"columnName": "photo200",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isPhantom",
|
|
||||||
"columnName": "isPhantom",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "lastConversationMessageId",
|
|
||||||
"columnName": "lastConversationMessageId",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "inReadCmId",
|
|
||||||
"columnName": "inReadCmId",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "outReadCmId",
|
|
||||||
"columnName": "outReadCmId",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "inRead",
|
|
||||||
"columnName": "inRead",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "outRead",
|
|
||||||
"columnName": "outRead",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "lastMessageId",
|
|
||||||
"columnName": "lastMessageId",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "unreadCount",
|
|
||||||
"columnName": "unreadCount",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "membersCount",
|
|
||||||
"columnName": "membersCount",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "canChangePin",
|
|
||||||
"columnName": "canChangePin",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "canChangeInfo",
|
|
||||||
"columnName": "canChangeInfo",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "majorId",
|
|
||||||
"columnName": "majorId",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "minorId",
|
|
||||||
"columnName": "minorId",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "pinnedMessageId",
|
|
||||||
"columnName": "pinnedMessageId",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "peerType",
|
|
||||||
"columnName": "peerType",
|
|
||||||
"affinity": "TEXT",
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldPath": "isArchived",
|
|
||||||
"columnName": "isArchived",
|
|
||||||
"affinity": "INTEGER",
|
|
||||||
"notNull": true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"primaryKey": {
|
|
||||||
"autoGenerate": false,
|
|
||||||
"columnNames": [
|
|
||||||
"id"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"indices": [],
|
|
||||||
"foreignKeys": []
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"views": [],
|
|
||||||
"setupQueries": [
|
|
||||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
|
||||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'fa307a5eb2e1f7d601bd1374174635cd')"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -7,7 +7,7 @@ import dev.meloda.fast.model.database.AccountEntity
|
|||||||
|
|
||||||
@Database(
|
@Database(
|
||||||
entities = [AccountEntity::class],
|
entities = [AccountEntity::class],
|
||||||
version = 3
|
version = 2
|
||||||
)
|
)
|
||||||
abstract class AccountsDatabase : RoomDatabase() {
|
abstract class AccountsDatabase : RoomDatabase() {
|
||||||
abstract fun accountDao(): AccountDao
|
abstract fun accountDao(): AccountDao
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import androidx.room.TypeConverters
|
|||||||
import dev.meloda.fast.database.dao.ConversationDao
|
import dev.meloda.fast.database.dao.ConversationDao
|
||||||
import dev.meloda.fast.database.dao.GroupDao
|
import dev.meloda.fast.database.dao.GroupDao
|
||||||
import dev.meloda.fast.database.dao.MessageDao
|
import dev.meloda.fast.database.dao.MessageDao
|
||||||
import dev.meloda.fast.database.dao.UserDao
|
import dev.meloda.fast.database.dao.UsersDao
|
||||||
import dev.meloda.fast.database.typeconverters.Converters
|
import dev.meloda.fast.database.typeconverters.Converters
|
||||||
import dev.meloda.fast.model.database.VkConversationEntity
|
import dev.meloda.fast.model.database.VkConversationEntity
|
||||||
import dev.meloda.fast.model.database.VkGroupEntity
|
import dev.meloda.fast.model.database.VkGroupEntity
|
||||||
@@ -21,11 +21,11 @@ import dev.meloda.fast.model.database.VkUserEntity
|
|||||||
VkConversationEntity::class
|
VkConversationEntity::class
|
||||||
],
|
],
|
||||||
|
|
||||||
version = 10
|
version = 7
|
||||||
)
|
)
|
||||||
@TypeConverters(Converters::class)
|
@TypeConverters(Converters::class)
|
||||||
abstract class CacheDatabase : RoomDatabase() {
|
abstract class CacheDatabase : RoomDatabase() {
|
||||||
abstract fun userDao(): UserDao
|
abstract fun userDao(): UsersDao
|
||||||
abstract fun groupDao(): GroupDao
|
abstract fun groupDao(): GroupDao
|
||||||
abstract fun messageDao(): MessageDao
|
abstract fun messageDao(): MessageDao
|
||||||
abstract fun conversationDao(): ConversationDao
|
abstract fun conversationDao(): ConversationDao
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ abstract class AccountDao : EntityDao<AccountEntity> {
|
|||||||
abstract suspend fun getAll(): List<AccountEntity>
|
abstract suspend fun getAll(): List<AccountEntity>
|
||||||
|
|
||||||
@Query("SELECT * FROM accounts WHERE userId = :userId")
|
@Query("SELECT * FROM accounts WHERE userId = :userId")
|
||||||
abstract suspend fun getById(userId: Long): AccountEntity?
|
abstract suspend fun getById(userId: Int): AccountEntity?
|
||||||
|
|
||||||
@Query("DELETE FROM accounts WHERE userId = :userId")
|
@Query("DELETE FROM accounts WHERE userId = :userId")
|
||||||
abstract suspend fun deleteById(userId: Long)
|
abstract suspend fun deleteById(userId: Int)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,11 +16,11 @@ abstract class ConversationDao : EntityDao<VkConversationEntity> {
|
|||||||
abstract suspend fun getAllByIds(ids: List<Int>): List<VkConversationEntity>
|
abstract suspend fun getAllByIds(ids: List<Int>): List<VkConversationEntity>
|
||||||
|
|
||||||
@Query("SELECT * FROM conversations WHERE id IS (:id)")
|
@Query("SELECT * FROM conversations WHERE id IS (:id)")
|
||||||
abstract suspend fun getById(id: Long): VkConversationEntity?
|
abstract suspend fun getById(id: Int): VkConversationEntity?
|
||||||
|
|
||||||
@Transaction
|
@Transaction
|
||||||
@Query("SELECT * FROM conversations WHERE id IS (:id)")
|
@Query("SELECT * FROM conversations WHERE id IS (:id)")
|
||||||
abstract suspend fun getByIdWithMessage(id: Long): ConversationWithMessage?
|
abstract suspend fun getByIdWithMessage(id: Int): ConversationWithMessage?
|
||||||
|
|
||||||
@Query("DELETE FROM conversations WHERE rowid IN (:ids)")
|
@Query("DELETE FROM conversations WHERE rowid IN (:ids)")
|
||||||
abstract suspend fun deleteByIds(ids: List<Int>): Int
|
abstract suspend fun deleteByIds(ids: List<Int>): Int
|
||||||
|
|||||||
@@ -11,13 +11,13 @@ abstract class MessageDao : EntityDao<VkMessageEntity> {
|
|||||||
abstract suspend fun getAll(): List<VkMessageEntity>
|
abstract suspend fun getAll(): List<VkMessageEntity>
|
||||||
|
|
||||||
@Query("SELECT * FROM messages WHERE peerId IS (:conversationId)")
|
@Query("SELECT * FROM messages WHERE peerId IS (:conversationId)")
|
||||||
abstract suspend fun getAll(conversationId: Long): List<VkMessageEntity>
|
abstract suspend fun getAll(conversationId: Int): List<VkMessageEntity>
|
||||||
|
|
||||||
@Query("SELECT * FROM messages WHERE id IN (:ids)")
|
@Query("SELECT * FROM messages WHERE id IN (:ids)")
|
||||||
abstract suspend fun getAllByIds(ids: List<Int>): List<VkMessageEntity>
|
abstract suspend fun getAllByIds(ids: List<Int>): List<VkMessageEntity>
|
||||||
|
|
||||||
@Query("SELECT * FROM messages WHERE id IS (:messageId)")
|
@Query("SELECT * FROM messages WHERE id IS (:messageId)")
|
||||||
abstract suspend fun getById(messageId: Long): VkMessageEntity?
|
abstract suspend fun getById(messageId: Int): VkMessageEntity?
|
||||||
|
|
||||||
@Query("DELETE FROM messages WHERE id IN (:ids)")
|
@Query("DELETE FROM messages WHERE id IN (:ids)")
|
||||||
abstract suspend fun deleteByIds(ids: List<Int>): Int
|
abstract suspend fun deleteByIds(ids: List<Int>): Int
|
||||||
|
|||||||
+3
-3
@@ -5,14 +5,14 @@ import androidx.room.Query
|
|||||||
import dev.meloda.fast.model.database.VkUserEntity
|
import dev.meloda.fast.model.database.VkUserEntity
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
abstract class UserDao : EntityDao<VkUserEntity> {
|
abstract class UsersDao : EntityDao<VkUserEntity> {
|
||||||
|
|
||||||
@Query("SELECT * FROM users")
|
@Query("SELECT * FROM users")
|
||||||
abstract suspend fun getAll(): List<VkUserEntity>
|
abstract suspend fun getAll(): List<VkUserEntity>
|
||||||
|
|
||||||
@Query("SELECT * FROM users WHERE id IN (:ids)")
|
@Query("SELECT * FROM users WHERE id IN (:ids)")
|
||||||
abstract suspend fun getAllByIds(ids: List<Long>): List<VkUserEntity>
|
abstract suspend fun getAllByIds(ids: List<Int>): List<VkUserEntity>
|
||||||
|
|
||||||
@Query("DELETE FROM users WHERE id IN (:ids)")
|
@Query("DELETE FROM users WHERE id IN (:ids)")
|
||||||
abstract suspend fun deleteByIds(ids: List<Long>): Int
|
abstract suspend fun deleteByIds(ids: List<Int>): Int
|
||||||
}
|
}
|
||||||
@@ -2,21 +2,17 @@ package dev.meloda.fast.database.di
|
|||||||
|
|
||||||
import androidx.room.Room
|
import androidx.room.Room
|
||||||
import dev.meloda.fast.database.AccountsDatabase
|
import dev.meloda.fast.database.AccountsDatabase
|
||||||
import dev.meloda.fast.database.CacheDatabase
|
|
||||||
import dev.meloda.fast.database.di.migration.migrationFrom2To3
|
|
||||||
import org.koin.core.scope.Scope
|
import org.koin.core.scope.Scope
|
||||||
import org.koin.dsl.module
|
import org.koin.dsl.module
|
||||||
|
|
||||||
val databaseModule = module {
|
val databaseModule = module {
|
||||||
single {
|
single {
|
||||||
Room.databaseBuilder(get(), AccountsDatabase::class.java, "accounts")
|
Room.databaseBuilder(get(), AccountsDatabase::class.java, "accounts").build()
|
||||||
.addMigrations(migrationFrom2To3)
|
|
||||||
.build()
|
|
||||||
}
|
}
|
||||||
single { get<AccountsDatabase>().accountDao() }
|
single { get<AccountsDatabase>().accountDao() }
|
||||||
|
|
||||||
single {
|
single {
|
||||||
Room.databaseBuilder(get(), CacheDatabase::class.java, "cache")
|
Room.databaseBuilder(get(), dev.meloda.fast.database.CacheDatabase::class.java, "cache")
|
||||||
.fallbackToDestructiveMigration()
|
.fallbackToDestructiveMigration()
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
@@ -26,4 +22,4 @@ val databaseModule = module {
|
|||||||
single { cacheDB().conversationDao() }
|
single { cacheDB().conversationDao() }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Scope.cacheDB(): CacheDatabase = get()
|
private fun Scope.cacheDB(): dev.meloda.fast.database.CacheDatabase = get()
|
||||||
|
|||||||
-14
@@ -1,14 +0,0 @@
|
|||||||
package dev.meloda.fast.database.di.migration
|
|
||||||
|
|
||||||
import androidx.room.migration.Migration
|
|
||||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
|
||||||
|
|
||||||
val migrationFrom2To3 = object : Migration(
|
|
||||||
startVersion = 2,
|
|
||||||
endVersion = 3
|
|
||||||
) {
|
|
||||||
|
|
||||||
override fun migrate(db: SupportSQLiteDatabase) {
|
|
||||||
db.execSQL("ALTER TABLE accounts ADD COLUMN exchangeToken TEXT DEFAULT null")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -13,15 +13,6 @@ class Converters {
|
|||||||
.split(", ")
|
.split(", ")
|
||||||
.mapNotNull(String::toIntOrNull)
|
.mapNotNull(String::toIntOrNull)
|
||||||
|
|
||||||
@TypeConverter
|
|
||||||
fun longListToString(list: List<Long>): String = list.joinToString()
|
|
||||||
|
|
||||||
@TypeConverter
|
|
||||||
fun stringToLongList(string: String): List<Long> =
|
|
||||||
string
|
|
||||||
.split(", ")
|
|
||||||
.mapNotNull(String::toLongOrNull)
|
|
||||||
|
|
||||||
@TypeConverter
|
@TypeConverter
|
||||||
fun stringListToString(list: List<String>): String = list.joinToString()
|
fun stringListToString(list: List<String>): String = list.joinToString()
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ object SettingsKeys {
|
|||||||
const val KEY_ENABLE_HAPTIC = "enable_haptic"
|
const val KEY_ENABLE_HAPTIC = "enable_haptic"
|
||||||
const val DEFAULT_ENABLE_HAPTIC = true
|
const val DEFAULT_ENABLE_HAPTIC = true
|
||||||
const val KEY_DEBUG_NETWORK_LOG_LEVEL = "debug_network_log_level"
|
const val KEY_DEBUG_NETWORK_LOG_LEVEL = "debug_network_log_level"
|
||||||
const val DEFAULT_NETWORK_LOG_LEVEL = 3
|
const val DEFAULT_NETWORK_LOG_LEVEL = 0
|
||||||
const val KEY_USE_SYSTEM_FONT = "use_system_font"
|
const val KEY_USE_SYSTEM_FONT = "use_system_font"
|
||||||
const val DEFAULT_USE_SYSTEM_FONT = false
|
const val DEFAULT_USE_SYSTEM_FONT = false
|
||||||
const val KEY_MORE_ANIMATIONS = "more_animations"
|
const val KEY_MORE_ANIMATIONS = "more_animations"
|
||||||
@@ -53,5 +53,5 @@ object SettingsKeys {
|
|||||||
|
|
||||||
|
|
||||||
const val KEY_SHOW_DEBUG_CATEGORY = "show_debug_category"
|
const val KEY_SHOW_DEBUG_CATEGORY = "show_debug_category"
|
||||||
const val ID_DMITRY = 37610580L
|
const val ID_DMITRY = 37610580
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ interface UserSettings {
|
|||||||
val showEmojiButton: StateFlow<Boolean>
|
val showEmojiButton: StateFlow<Boolean>
|
||||||
val showTimeInActionMessages: StateFlow<Boolean>
|
val showTimeInActionMessages: StateFlow<Boolean>
|
||||||
val useSystemFont: StateFlow<Boolean>
|
val useSystemFont: StateFlow<Boolean>
|
||||||
val enableAnimations: StateFlow<Boolean>
|
|
||||||
val showDebugCategory: StateFlow<Boolean>
|
val showDebugCategory: StateFlow<Boolean>
|
||||||
|
|
||||||
fun onUseContactNamesChanged(use: Boolean)
|
fun onUseContactNamesChanged(use: Boolean)
|
||||||
@@ -69,7 +68,6 @@ class UserSettingsImpl : UserSettings {
|
|||||||
override val showTimeInActionMessages =
|
override val showTimeInActionMessages =
|
||||||
MutableStateFlow(AppSettings.Experimental.showTimeInActionMessages)
|
MutableStateFlow(AppSettings.Experimental.showTimeInActionMessages)
|
||||||
override val useSystemFont = MutableStateFlow(AppSettings.Appearance.useSystemFont)
|
override val useSystemFont = MutableStateFlow(AppSettings.Appearance.useSystemFont)
|
||||||
override val enableAnimations = MutableStateFlow(AppSettings.Experimental.moreAnimations)
|
|
||||||
override val showDebugCategory = MutableStateFlow(AppSettings.Debug.showDebugCategory)
|
override val showDebugCategory = MutableStateFlow(AppSettings.Debug.showDebugCategory)
|
||||||
|
|
||||||
override fun onUseContactNamesChanged(use: Boolean) {
|
override fun onUseContactNamesChanged(use: Boolean) {
|
||||||
|
|||||||
@@ -1,32 +1,12 @@
|
|||||||
package dev.meloda.fast.domain
|
package dev.meloda.fast.domain
|
||||||
|
|
||||||
import dev.meloda.fast.data.State
|
import dev.meloda.fast.data.State
|
||||||
import dev.meloda.fast.model.api.responses.ExchangeSilentTokenResponse
|
|
||||||
import dev.meloda.fast.model.api.responses.GetAnonymTokenResponse
|
|
||||||
import dev.meloda.fast.model.api.responses.GetExchangeTokenResponse
|
|
||||||
import dev.meloda.fast.model.api.responses.ValidatePhoneResponse
|
import dev.meloda.fast.model.api.responses.ValidatePhoneResponse
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
interface AuthUseCase : BaseUseCase {
|
interface AuthUseCase {
|
||||||
|
|
||||||
fun logout(): Flow<State<Int>>
|
|
||||||
|
|
||||||
fun validatePhone(
|
fun validatePhone(
|
||||||
validationSid: String
|
validationSid: String
|
||||||
): Flow<State<ValidatePhoneResponse>>
|
): Flow<State<ValidatePhoneResponse>>
|
||||||
|
|
||||||
suspend fun getAnonymToken(
|
|
||||||
clientId: String,
|
|
||||||
clientSecret: String
|
|
||||||
): Flow<State<GetAnonymTokenResponse>>
|
|
||||||
|
|
||||||
suspend fun exchangeSilentToken(
|
|
||||||
anonymToken: String,
|
|
||||||
silentToken: String,
|
|
||||||
silentUuid: String
|
|
||||||
): Flow<State<ExchangeSilentTokenResponse>>
|
|
||||||
|
|
||||||
suspend fun getExchangeToken(
|
|
||||||
accessToken: String
|
|
||||||
): Flow<State<GetExchangeTokenResponse>>
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,44 +3,16 @@ package dev.meloda.fast.domain
|
|||||||
import dev.meloda.fast.data.State
|
import dev.meloda.fast.data.State
|
||||||
import dev.meloda.fast.data.api.auth.AuthRepository
|
import dev.meloda.fast.data.api.auth.AuthRepository
|
||||||
import dev.meloda.fast.data.mapToState
|
import dev.meloda.fast.data.mapToState
|
||||||
import dev.meloda.fast.model.api.responses.ExchangeSilentTokenResponse
|
|
||||||
import dev.meloda.fast.model.api.responses.GetAnonymTokenResponse
|
|
||||||
import dev.meloda.fast.model.api.responses.GetExchangeTokenResponse
|
|
||||||
import dev.meloda.fast.model.api.responses.ValidatePhoneResponse
|
import dev.meloda.fast.model.api.responses.ValidatePhoneResponse
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.flow
|
||||||
|
|
||||||
class AuthUseCaseImpl(private val repository: AuthRepository) : AuthUseCase {
|
class AuthUseCaseImpl(private val repository: AuthRepository) : AuthUseCase {
|
||||||
|
|
||||||
override fun logout(): Flow<State<Int>> = flowNewState { repository.logout().mapToState() }
|
override fun validatePhone(validationSid: String): Flow<State<ValidatePhoneResponse>> = flow {
|
||||||
|
emit(State.Loading)
|
||||||
|
|
||||||
override fun validatePhone(validationSid: String): Flow<State<ValidatePhoneResponse>> =
|
val newState = repository.validatePhone(validationSid).mapToState()
|
||||||
flowNewState { repository.validatePhone(validationSid = validationSid).mapToState() }
|
emit(newState)
|
||||||
|
|
||||||
override suspend fun getAnonymToken(
|
|
||||||
clientId: String,
|
|
||||||
clientSecret: String
|
|
||||||
): Flow<State<GetAnonymTokenResponse>> = flowNewState {
|
|
||||||
repository.getAnonymToken(
|
|
||||||
clientId = clientId,
|
|
||||||
clientSecret = clientSecret
|
|
||||||
).mapToState()
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun exchangeSilentToken(
|
|
||||||
anonymToken: String,
|
|
||||||
silentToken: String,
|
|
||||||
silentUuid: String
|
|
||||||
): Flow<State<ExchangeSilentTokenResponse>> = flowNewState {
|
|
||||||
repository.exchangeSilentToken(
|
|
||||||
anonymToken = anonymToken,
|
|
||||||
silentToken = silentToken,
|
|
||||||
silentUuid = silentUuid
|
|
||||||
).mapToState()
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getExchangeToken(
|
|
||||||
accessToken: String
|
|
||||||
): Flow<State<GetExchangeTokenResponse>> = flowNewState {
|
|
||||||
repository.getExchangeToken(accessToken = accessToken).mapToState()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
package dev.meloda.fast.domain
|
|
||||||
|
|
||||||
import dev.meloda.fast.data.State
|
|
||||||
import kotlinx.coroutines.flow.FlowCollector
|
|
||||||
import kotlinx.coroutines.flow.flow
|
|
||||||
|
|
||||||
interface BaseUseCase {
|
|
||||||
|
|
||||||
suspend fun <T> FlowCollector<State<T>>.emitState(stateBlock: suspend () -> State<T>) {
|
|
||||||
emit(State.Loading)
|
|
||||||
emit(stateBlock())
|
|
||||||
}
|
|
||||||
|
|
||||||
fun <T> flowNewState(stateBlock: suspend () -> State<T>) =
|
|
||||||
flow { emitState(stateBlock) }
|
|
||||||
}
|
|
||||||
@@ -1,29 +1,19 @@
|
|||||||
package dev.meloda.fast.domain
|
package dev.meloda.fast.domain
|
||||||
|
|
||||||
import dev.meloda.fast.data.State
|
import dev.meloda.fast.data.State
|
||||||
import dev.meloda.fast.model.ConversationsFilter
|
|
||||||
import dev.meloda.fast.model.api.domain.VkConversation
|
import dev.meloda.fast.model.api.domain.VkConversation
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
interface ConversationsUseCase : BaseUseCase {
|
interface ConversationsUseCase {
|
||||||
|
|
||||||
suspend fun storeConversations(conversations: List<VkConversation>)
|
|
||||||
|
|
||||||
fun getConversations(
|
fun getConversations(
|
||||||
count: Int? = null,
|
count: Int?,
|
||||||
offset: Int? = null,
|
offset: Int?,
|
||||||
filter: ConversationsFilter
|
|
||||||
): Flow<State<List<VkConversation>>>
|
): Flow<State<List<VkConversation>>>
|
||||||
|
|
||||||
fun getById(
|
fun delete(peerId: Int): Flow<State<Int>>
|
||||||
peerIds: List<Long>,
|
|
||||||
extended: Boolean? = null,
|
|
||||||
fields: String? = null
|
|
||||||
): Flow<State<List<VkConversation>>>
|
|
||||||
|
|
||||||
fun delete(peerId: Long): Flow<State<Long>>
|
fun changePinState(peerId: Int, pin: Boolean): Flow<State<Int>>
|
||||||
|
|
||||||
fun changePinState(peerId: Long, pin: Boolean): Flow<State<Int>>
|
suspend fun storeConversations(conversations: List<VkConversation>)
|
||||||
|
|
||||||
fun changeArchivedState(peerId: Long, archive: Boolean): Flow<State<Int>>
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,69 +3,116 @@ package dev.meloda.fast.domain
|
|||||||
import dev.meloda.fast.data.State
|
import dev.meloda.fast.data.State
|
||||||
import dev.meloda.fast.data.api.conversations.ConversationsRepository
|
import dev.meloda.fast.data.api.conversations.ConversationsRepository
|
||||||
import dev.meloda.fast.data.mapToState
|
import dev.meloda.fast.data.mapToState
|
||||||
import dev.meloda.fast.model.ConversationsFilter
|
|
||||||
import dev.meloda.fast.model.api.domain.VkConversation
|
import dev.meloda.fast.model.api.domain.VkConversation
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.flow
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
class ConversationsUseCaseImpl(
|
class ConversationsUseCaseImpl(
|
||||||
private val repository: ConversationsRepository,
|
private val repository: ConversationsRepository,
|
||||||
) : ConversationsUseCase {
|
) : ConversationsUseCase {
|
||||||
|
|
||||||
|
// override fun getConversations(
|
||||||
|
// count: Int?,
|
||||||
|
// offset: Int?,
|
||||||
|
// fields: String,
|
||||||
|
// filter: String,
|
||||||
|
// extended: Boolean?,
|
||||||
|
// startMessageId: Int?
|
||||||
|
// ): Flow<dev.meloda.fast.network.State<ConversationsResponseDomain>> = flow {
|
||||||
|
// emit(dev.meloda.fast.network.State.Loading)
|
||||||
|
//
|
||||||
|
// val newState = conversationsRepository.getConversations(
|
||||||
|
// params = ConversationsGetRequest(
|
||||||
|
// count = count,
|
||||||
|
// offset = offset,
|
||||||
|
// fields = fields,
|
||||||
|
// filter = filter,
|
||||||
|
// extended = extended,
|
||||||
|
// startMessageId = startMessageId
|
||||||
|
// )
|
||||||
|
// ).fold(
|
||||||
|
// onSuccess = { response -> dev.meloda.fast.network.State.Success(response.toDomain()) },
|
||||||
|
// onNetworkFailure = { dev.meloda.fast.network.State.Error.ConnectionError },
|
||||||
|
// onUnknownFailure = { dev.meloda.fast.network.State.UNKNOWN_ERROR },
|
||||||
|
// onHttpFailure = { result -> result.error.toStateApiError() },
|
||||||
|
// onApiFailure = { result -> result.error.toStateApiError() }
|
||||||
|
// )
|
||||||
|
// emit(newState)
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// override fun pin(peerId: Int): Flow<dev.meloda.fast.network.State<Unit>> = flow {
|
||||||
|
// emit(dev.meloda.fast.network.State.Loading)
|
||||||
|
//
|
||||||
|
// val newState = conversationsRepository.pin(
|
||||||
|
// ConversationsPinRequest(peerId = peerId)
|
||||||
|
// ).fold(
|
||||||
|
// onSuccess = { dev.meloda.fast.network.State.Success(Unit) },
|
||||||
|
// onNetworkFailure = { dev.meloda.fast.network.State.Error.ConnectionError },
|
||||||
|
// onUnknownFailure = { dev.meloda.fast.network.State.UNKNOWN_ERROR },
|
||||||
|
// onHttpFailure = { result -> result.error.toStateApiError() },
|
||||||
|
// onApiFailure = { result -> result.error.toStateApiError() }
|
||||||
|
// )
|
||||||
|
// emit(newState)
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// override fun unpin(peerId: Int): Flow<dev.meloda.fast.network.State<Unit>> = flow {
|
||||||
|
// emit(dev.meloda.fast.network.State.Loading)
|
||||||
|
//
|
||||||
|
// val newState = conversationsRepository.unpin(
|
||||||
|
// ConversationsUnpinRequest(peerId = peerId)
|
||||||
|
// ).fold(
|
||||||
|
// onSuccess = { dev.meloda.fast.network.State.Success(Unit) },
|
||||||
|
// onNetworkFailure = { dev.meloda.fast.network.State.Error.ConnectionError },
|
||||||
|
// onUnknownFailure = { dev.meloda.fast.network.State.UNKNOWN_ERROR },
|
||||||
|
// onHttpFailure = { result -> result.error.toStateApiError() },
|
||||||
|
// onApiFailure = { result -> result.error.toStateApiError() }
|
||||||
|
// )
|
||||||
|
// emit(newState)
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// override suspend fun storeConversations(conversations: List<VkConversationDomain>) {
|
||||||
|
// conversationsDao.insertAll(conversations.map(VkConversationDomain::mapToDb))
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// override suspend fun storeGroups(groups: List<VkGroupDomain>) {
|
||||||
|
// groupsDao.insertAll(groups.map(VkGroupDomain::mapToDB))
|
||||||
|
// }
|
||||||
|
override fun getConversations(
|
||||||
|
count: Int?,
|
||||||
|
offset: Int?
|
||||||
|
): Flow<State<List<VkConversation>>> = flow {
|
||||||
|
emit(State.Loading)
|
||||||
|
|
||||||
|
val newState = repository.getConversations(count, offset).mapToState()
|
||||||
|
emit(newState)
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun storeConversations(
|
override suspend fun storeConversations(
|
||||||
conversations: List<VkConversation>
|
conversations: List<VkConversation>
|
||||||
) = withContext(Dispatchers.IO) {
|
) = withContext(Dispatchers.IO) {
|
||||||
repository.storeConversations(conversations)
|
repository.storeConversations(conversations)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getConversations(
|
override fun delete(peerId: Int): Flow<State<Int>> = flow {
|
||||||
count: Int?,
|
emit(State.Loading)
|
||||||
offset: Int?,
|
|
||||||
filter: ConversationsFilter
|
val newState = repository.delete(peerId = peerId).mapToState()
|
||||||
): Flow<State<List<VkConversation>>> = flowNewState {
|
emit(newState)
|
||||||
repository.getConversations(
|
|
||||||
count = count,
|
|
||||||
offset = offset,
|
|
||||||
filter = filter
|
|
||||||
).mapToState()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getById(
|
override fun changePinState(peerId: Int, pin: Boolean): Flow<State<Int>> = flow {
|
||||||
peerIds: List<Long>,
|
emit(State.Loading)
|
||||||
extended: Boolean?,
|
|
||||||
fields: String?
|
|
||||||
): Flow<State<List<VkConversation>>> = flowNewState {
|
|
||||||
repository.getConversationsById(
|
|
||||||
peerIds = peerIds,
|
|
||||||
extended = extended,
|
|
||||||
fields = fields
|
|
||||||
).mapToState()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun delete(peerId: Long): Flow<State<Long>> = flowNewState {
|
val newState = if (pin) {
|
||||||
repository.delete(peerId = peerId).mapToState()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun changePinState(
|
|
||||||
peerId: Long,
|
|
||||||
pin: Boolean
|
|
||||||
): Flow<State<Int>> = flowNewState {
|
|
||||||
if (pin) {
|
|
||||||
repository.pin(peerId)
|
repository.pin(peerId)
|
||||||
} else {
|
} else {
|
||||||
repository.unpin(peerId)
|
repository.unpin(peerId)
|
||||||
}.mapToState()
|
}.mapToState()
|
||||||
}
|
|
||||||
|
|
||||||
override fun changeArchivedState(
|
emit(newState)
|
||||||
peerId: Long,
|
|
||||||
archive: Boolean
|
|
||||||
): Flow<State<Int>> = flowNewState {
|
|
||||||
if (archive) {
|
|
||||||
repository.archive(peerId)
|
|
||||||
} else {
|
|
||||||
repository.unarchive(peerId)
|
|
||||||
}.mapToState()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,13 +8,11 @@ import kotlinx.coroutines.flow.Flow
|
|||||||
interface FriendsUseCase {
|
interface FriendsUseCase {
|
||||||
|
|
||||||
fun getAllFriends(
|
fun getAllFriends(
|
||||||
order: String = "hints",
|
|
||||||
count: Int?,
|
count: Int?,
|
||||||
offset: Int?
|
offset: Int?
|
||||||
): Flow<State<FriendsInfo>>
|
): Flow<State<FriendsInfo>>
|
||||||
|
|
||||||
fun getFriends(
|
fun getFriends(
|
||||||
order: String = "hints",
|
|
||||||
count: Int?,
|
count: Int?,
|
||||||
offset: Int?
|
offset: Int?
|
||||||
): Flow<State<List<VkUser>>>
|
): Flow<State<List<VkUser>>>
|
||||||
@@ -22,7 +20,7 @@ interface FriendsUseCase {
|
|||||||
fun getOnlineFriends(
|
fun getOnlineFriends(
|
||||||
count: Int?,
|
count: Int?,
|
||||||
offset: Int?
|
offset: Int?
|
||||||
): Flow<State<List<Long>>>
|
): Flow<State<List<Int>>>
|
||||||
|
|
||||||
suspend fun storeUsers(users: List<VkUser>)
|
suspend fun storeUsers(users: List<VkUser>)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,32 +11,25 @@ import kotlinx.coroutines.flow.flow
|
|||||||
class FriendsUseCaseImpl(private val repository: FriendsRepository) :
|
class FriendsUseCaseImpl(private val repository: FriendsRepository) :
|
||||||
FriendsUseCase {
|
FriendsUseCase {
|
||||||
|
|
||||||
override fun getAllFriends(order: String, count: Int?, offset: Int?): Flow<State<FriendsInfo>> = flow {
|
override fun getAllFriends(count: Int?, offset: Int?): Flow<State<FriendsInfo>> = flow {
|
||||||
emit(State.Loading)
|
emit(State.Loading)
|
||||||
|
|
||||||
val newState = repository.getAllFriends(order, count, offset).mapToState()
|
val newState = repository.getAllFriends(count, offset).mapToState()
|
||||||
emit(newState)
|
emit(newState)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getFriends(
|
override fun getFriends(
|
||||||
order: String,
|
count: Int?, offset: Int?
|
||||||
count: Int?,
|
|
||||||
offset: Int?
|
|
||||||
): Flow<State<List<VkUser>>> = flow {
|
): Flow<State<List<VkUser>>> = flow {
|
||||||
emit(State.Loading)
|
emit(State.Loading)
|
||||||
|
|
||||||
val newState = repository.getFriends(
|
val newState = repository.getFriends(count, offset).mapToState()
|
||||||
order = order,
|
|
||||||
count = count,
|
|
||||||
offset = offset
|
|
||||||
).mapToState()
|
|
||||||
|
|
||||||
emit(newState)
|
emit(newState)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getOnlineFriends(
|
override fun getOnlineFriends(
|
||||||
count: Int?, offset: Int?
|
count: Int?, offset: Int?
|
||||||
): Flow<State<List<Long>>> = flow {
|
): Flow<State<List<Int>>> = flow {
|
||||||
emit(State.Loading)
|
emit(State.Loading)
|
||||||
|
|
||||||
val newState = repository.getOnlineFriends(count, offset).mapToState()
|
val newState = repository.getOnlineFriends(count, offset).mapToState()
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import kotlinx.coroutines.flow.flow
|
|||||||
|
|
||||||
class GetLocalUserByIdUseCase(private val repository: UsersRepository) {
|
class GetLocalUserByIdUseCase(private val repository: UsersRepository) {
|
||||||
|
|
||||||
operator fun invoke(userId: Long): Flow<State<VkUser?>> = flow {
|
operator fun invoke(userId: Int): Flow<State<VkUser?>> = flow {
|
||||||
emit(State.Loading)
|
emit(State.Loading)
|
||||||
|
|
||||||
val newState = kotlin.runCatching {
|
val newState = kotlin.runCatching {
|
||||||
@@ -21,7 +21,7 @@ class GetLocalUserByIdUseCase(private val repository: UsersRepository) {
|
|||||||
emit(newState)
|
emit(newState)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun proceed(userId: Long): VkUser? {
|
suspend fun proceed(userId: Int): VkUser? {
|
||||||
return repository.getLocalUsers(userIds = listOf(userId)).singleOrNull()
|
return repository.getLocalUsers(userIds = listOf(userId)).singleOrNull()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import kotlinx.coroutines.flow.flow
|
|||||||
|
|
||||||
class GetLocalUsersByIdsUseCase(private val repository: UsersRepository) {
|
class GetLocalUsersByIdsUseCase(private val repository: UsersRepository) {
|
||||||
|
|
||||||
operator fun invoke(userIds: List<Long>): Flow<State<List<VkUser>>> = flow {
|
operator fun invoke(userIds: List<Int>): Flow<State<List<VkUser>>> = flow {
|
||||||
emit(State.Loading)
|
emit(State.Loading)
|
||||||
|
|
||||||
val newState = kotlin.runCatching {
|
val newState = kotlin.runCatching {
|
||||||
|
|||||||
+10
-12
@@ -5,21 +5,19 @@ import dev.meloda.fast.data.api.conversations.ConversationsRepository
|
|||||||
import dev.meloda.fast.data.mapToState
|
import dev.meloda.fast.data.mapToState
|
||||||
import dev.meloda.fast.model.api.domain.VkConversation
|
import dev.meloda.fast.model.api.domain.VkConversation
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.flow
|
||||||
|
|
||||||
class LoadConversationsByIdUseCase(
|
class LoadConversationsByIdUseCase(
|
||||||
private val conversationsRepository: ConversationsRepository
|
private val conversationsRepository: ConversationsRepository
|
||||||
) : BaseUseCase {
|
) {
|
||||||
|
|
||||||
operator fun invoke(
|
operator fun invoke(peerIds: List<Int>): Flow<State<List<VkConversation>>> = flow {
|
||||||
peerIds: List<Long>,
|
emit(State.Loading)
|
||||||
extended: Boolean? = null,
|
|
||||||
fields: String? = null
|
val newState = conversationsRepository
|
||||||
): Flow<State<List<VkConversation>>> = flowNewState {
|
.getConversationsById(peerIds = peerIds)
|
||||||
conversationsRepository
|
.mapToState()
|
||||||
.getConversationsById(
|
|
||||||
peerIds = peerIds,
|
emit(newState)
|
||||||
extended = extended,
|
|
||||||
fields = fields,
|
|
||||||
).mapToState()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import kotlinx.coroutines.flow.flow
|
|||||||
class LoadUserByIdUseCase(private val repository: UsersRepository) {
|
class LoadUserByIdUseCase(private val repository: UsersRepository) {
|
||||||
|
|
||||||
operator fun invoke(
|
operator fun invoke(
|
||||||
userId: Long?,
|
userId: Int?,
|
||||||
fields: String = VkConstants.USER_FIELDS,
|
fields: String = VkConstants.USER_FIELDS,
|
||||||
nomCase: String? = null
|
nomCase: String? = null
|
||||||
): Flow<State<VkUser?>> = flow {
|
): Flow<State<VkUser?>> = flow {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import kotlinx.coroutines.flow.flow
|
|||||||
class LoadUsersByIdsUseCase(private val repository: UsersRepository) {
|
class LoadUsersByIdsUseCase(private val repository: UsersRepository) {
|
||||||
|
|
||||||
operator fun invoke(
|
operator fun invoke(
|
||||||
userIds: List<Long>?,
|
userIds: List<Int>?,
|
||||||
fields: String = VkConstants.USER_FIELDS,
|
fields: String = VkConstants.USER_FIELDS,
|
||||||
nomCase: String? = null
|
nomCase: String? = null
|
||||||
): Flow<State<List<VkUser>>> = flow {
|
): Flow<State<List<VkUser>>> = flow {
|
||||||
|
|||||||
@@ -3,39 +3,30 @@ package dev.meloda.fast.domain
|
|||||||
import android.util.Log
|
import android.util.Log
|
||||||
import dev.meloda.fast.common.VkConstants
|
import dev.meloda.fast.common.VkConstants
|
||||||
import dev.meloda.fast.common.extensions.asInt
|
import dev.meloda.fast.common.extensions.asInt
|
||||||
import dev.meloda.fast.common.extensions.asLong
|
|
||||||
import dev.meloda.fast.common.extensions.listenValue
|
import dev.meloda.fast.common.extensions.listenValue
|
||||||
import dev.meloda.fast.common.extensions.toList
|
import dev.meloda.fast.common.extensions.toList
|
||||||
import dev.meloda.fast.data.UserConfig
|
import dev.meloda.fast.data.UserConfig
|
||||||
|
import dev.meloda.fast.data.VkMemoryCache
|
||||||
import dev.meloda.fast.data.processState
|
import dev.meloda.fast.data.processState
|
||||||
import dev.meloda.fast.model.ApiEvent
|
import dev.meloda.fast.model.ApiEvent
|
||||||
import dev.meloda.fast.model.ConversationFlags
|
|
||||||
import dev.meloda.fast.model.InteractionType
|
import dev.meloda.fast.model.InteractionType
|
||||||
import dev.meloda.fast.model.LongPollEvent
|
import dev.meloda.fast.model.LongPollEvent
|
||||||
import dev.meloda.fast.model.LongPollParsedEvent
|
|
||||||
import dev.meloda.fast.model.MessageFlags
|
|
||||||
import dev.meloda.fast.model.api.domain.VkConversation
|
|
||||||
import dev.meloda.fast.model.api.domain.VkMessage
|
|
||||||
import kotlinx.coroutines.CoroutineExceptionHandler
|
import kotlinx.coroutines.CoroutineExceptionHandler
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.SupervisorJob
|
import kotlinx.coroutines.SupervisorJob
|
||||||
import kotlinx.coroutines.async
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlin.coroutines.CoroutineContext
|
||||||
import kotlin.coroutines.resume
|
import kotlin.coroutines.resume
|
||||||
import kotlin.coroutines.suspendCoroutine
|
import kotlin.coroutines.suspendCoroutine
|
||||||
|
|
||||||
class LongPollUpdatesParser(
|
class LongPollUpdatesParser(
|
||||||
private val conversationsUseCase: ConversationsUseCase,
|
|
||||||
private val messagesUseCase: MessagesUseCase
|
private val messagesUseCase: MessagesUseCase
|
||||||
) {
|
) {
|
||||||
private val job = SupervisorJob()
|
private val job = SupervisorJob()
|
||||||
|
|
||||||
private val exceptionHandler =
|
private val exceptionHandler = CoroutineExceptionHandler { _, throwable ->
|
||||||
CoroutineExceptionHandler { _, throwable ->
|
Log.d("LongPollUpdatesParser", "error: $throwable")
|
||||||
Log.e("LongPollUpdatesParser", "error: $throwable")
|
|
||||||
throwable.printStackTrace()
|
throwable.printStackTrace()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,7 +35,7 @@ class LongPollUpdatesParser(
|
|||||||
|
|
||||||
private val coroutineScope = CoroutineScope(coroutineContext)
|
private val coroutineScope = CoroutineScope(coroutineContext)
|
||||||
|
|
||||||
private val listenersMap: MutableMap<LongPollEvent, MutableList<VkEventCallback<LongPollParsedEvent>>> =
|
private val listenersMap: MutableMap<ApiEvent, MutableCollection<VkEventCallback<*>>> =
|
||||||
mutableMapOf()
|
mutableMapOf()
|
||||||
|
|
||||||
fun parseNextUpdate(event: List<Any>) {
|
fun parseNextUpdate(event: List<Any>) {
|
||||||
@@ -59,11 +50,8 @@ class LongPollUpdatesParser(
|
|||||||
ApiEvent.MESSAGE_EDIT -> parseMessageEdit(eventType, event)
|
ApiEvent.MESSAGE_EDIT -> parseMessageEdit(eventType, event)
|
||||||
ApiEvent.MESSAGE_READ_INCOMING -> parseMessageReadIncoming(eventType, event)
|
ApiEvent.MESSAGE_READ_INCOMING -> parseMessageReadIncoming(eventType, event)
|
||||||
ApiEvent.MESSAGE_READ_OUTGOING -> parseMessageReadOutgoing(eventType, event)
|
ApiEvent.MESSAGE_READ_OUTGOING -> parseMessageReadOutgoing(eventType, event)
|
||||||
ApiEvent.CHAT_CLEAR_FLAGS -> parseChatClearFlags(eventType, event)
|
|
||||||
ApiEvent.CHAT_SET_FLAGS -> parseChatSetFlags(eventType, event)
|
|
||||||
ApiEvent.MESSAGES_DELETED -> parseMessagesDeleted(eventType, event)
|
ApiEvent.MESSAGES_DELETED -> parseMessagesDeleted(eventType, event)
|
||||||
ApiEvent.CHAT_MAJOR_CHANGED -> parseChatMajorChanged(eventType, event)
|
ApiEvent.PIN_UNPIN_CONVERSATION -> parseConversationPinStateChanged(eventType, event)
|
||||||
ApiEvent.CHAT_MINOR_CHANGED -> parseChatMinorChanged(eventType, event)
|
|
||||||
|
|
||||||
ApiEvent.TYPING,
|
ApiEvent.TYPING,
|
||||||
ApiEvent.AUDIO_MESSAGE_RECORDING,
|
ApiEvent.AUDIO_MESSAGE_RECORDING,
|
||||||
@@ -71,460 +59,12 @@ class LongPollUpdatesParser(
|
|||||||
ApiEvent.VIDEO_UPLOADING,
|
ApiEvent.VIDEO_UPLOADING,
|
||||||
ApiEvent.FILE_UPLOADING -> parseInteraction(eventType, event)
|
ApiEvent.FILE_UPLOADING -> parseInteraction(eventType, event)
|
||||||
|
|
||||||
ApiEvent.UNREAD_COUNT_UPDATE -> parseUnreadCounterUpdate(eventType, event)
|
ApiEvent.UNREAD_COUNT_UPDATE -> onNewEvent(eventType, event)
|
||||||
ApiEvent.MESSAGE_UPDATED -> parseMessageUpdated(eventType, event)
|
|
||||||
ApiEvent.MESSAGE_CACHE_CLEAR -> parseMessageCacheClear(eventType, event)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun parseMessageSetFlags(eventType: ApiEvent, event: List<Any>) {
|
private fun onNewEvent(eventType: ApiEvent, event: List<Any>) {
|
||||||
Log.d("LongPollUpdatesParser", "$eventType: $event")
|
Log.d("LongPollUpdatesParser", "newEvent: $eventType: $event")
|
||||||
|
|
||||||
val cmId = event[1].asLong()
|
|
||||||
val flags = event[2].asInt()
|
|
||||||
val peerId = event[3].asLong()
|
|
||||||
|
|
||||||
val eventsToSend = mutableListOf<LongPollParsedEvent>()
|
|
||||||
|
|
||||||
val parsedFlags = MessageFlags.parse(flags)
|
|
||||||
parsedFlags.forEach { flag ->
|
|
||||||
when (flag) {
|
|
||||||
MessageFlags.IMPORTANT -> {
|
|
||||||
val eventToSend = LongPollParsedEvent.MessageMarkedAsImportant(
|
|
||||||
peerId = peerId,
|
|
||||||
cmId = cmId,
|
|
||||||
marked = true
|
|
||||||
)
|
|
||||||
eventsToSend += eventToSend
|
|
||||||
|
|
||||||
listenersMap[LongPollEvent.MARKED_AS_IMPORTANT]?.let { listeners ->
|
|
||||||
listeners.map { vkEventCallback ->
|
|
||||||
(vkEventCallback as? VkEventCallback<LongPollParsedEvent.MessageMarkedAsImportant>)
|
|
||||||
?.onEvent(eventToSend)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MessageFlags.SPAM -> {
|
|
||||||
val eventToSend = LongPollParsedEvent.MessageMarkedAsSpam(
|
|
||||||
peerId = peerId,
|
|
||||||
cmId = cmId
|
|
||||||
)
|
|
||||||
eventsToSend += eventToSend
|
|
||||||
|
|
||||||
listenersMap[LongPollEvent.MARKED_AS_SPAM]?.let { listeners ->
|
|
||||||
listeners.map { vkEventCallback ->
|
|
||||||
(vkEventCallback as? VkEventCallback<LongPollParsedEvent.MessageMarkedAsSpam>)
|
|
||||||
?.onEvent(eventToSend)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MessageFlags.DELETED -> {
|
|
||||||
val eventToSend =
|
|
||||||
if (parsedFlags.contains(MessageFlags.DELETED_FOR_ALL)) {
|
|
||||||
LongPollParsedEvent.MessageDeleted(
|
|
||||||
peerId = peerId,
|
|
||||||
cmId = cmId,
|
|
||||||
forAll = true
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
LongPollParsedEvent.MessageDeleted(
|
|
||||||
peerId = peerId,
|
|
||||||
cmId = cmId,
|
|
||||||
forAll = false
|
|
||||||
)
|
|
||||||
}
|
|
||||||
eventsToSend += eventToSend
|
|
||||||
|
|
||||||
listenersMap[LongPollEvent.MESSAGE_DELETED]?.let { listeners ->
|
|
||||||
listeners.map { vkEventCallback ->
|
|
||||||
(vkEventCallback as? VkEventCallback<LongPollParsedEvent.MessageDeleted>)
|
|
||||||
?.onEvent(eventToSend)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MessageFlags.AUDIO_LISTENED -> {
|
|
||||||
val eventToSend = LongPollParsedEvent.AudioMessageListened(
|
|
||||||
peerId = peerId,
|
|
||||||
cmId = cmId
|
|
||||||
)
|
|
||||||
eventsToSend += eventToSend
|
|
||||||
|
|
||||||
listenersMap[LongPollEvent.AUDIO_MESSAGE_LISTENED]?.let { listeners ->
|
|
||||||
listeners.map { vkEventCallback ->
|
|
||||||
(vkEventCallback as? VkEventCallback<LongPollParsedEvent.AudioMessageListened>)
|
|
||||||
?.onEvent(eventToSend)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> Unit
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
eventsToSend.forEach { eventToSend ->
|
|
||||||
listenersMap[LongPollEvent.MESSAGE_SET_FLAGS]?.let { listeners ->
|
|
||||||
listeners.map { vkEventCallback ->
|
|
||||||
(vkEventCallback as? VkEventCallback<LongPollParsedEvent>)?.onEvent(eventToSend)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun parseMessageClearFlags(eventType: ApiEvent, event: List<Any>) {
|
|
||||||
Log.d("LongPollUpdatesParser", "$eventType: $event")
|
|
||||||
|
|
||||||
val cmId = event[1].asLong()
|
|
||||||
val flags = event[2].asInt()
|
|
||||||
val peerId = event[3].asLong()
|
|
||||||
|
|
||||||
val eventsToSend = mutableListOf<LongPollParsedEvent>()
|
|
||||||
|
|
||||||
val parsedFlags = MessageFlags.parse(flags)
|
|
||||||
|
|
||||||
coroutineScope.launch {
|
|
||||||
parsedFlags.forEach { flag ->
|
|
||||||
when (flag) {
|
|
||||||
MessageFlags.IMPORTANT -> {
|
|
||||||
val eventToSend = LongPollParsedEvent.MessageMarkedAsImportant(
|
|
||||||
peerId = peerId,
|
|
||||||
cmId = cmId,
|
|
||||||
marked = false
|
|
||||||
)
|
|
||||||
eventsToSend += eventToSend
|
|
||||||
|
|
||||||
listenersMap[LongPollEvent.MARKED_AS_IMPORTANT]?.let { listeners ->
|
|
||||||
listeners.map { vkEventCallback ->
|
|
||||||
(vkEventCallback as? VkEventCallback<LongPollParsedEvent.MessageMarkedAsImportant>)
|
|
||||||
?.onEvent(eventToSend)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MessageFlags.SPAM -> {
|
|
||||||
if (parsedFlags.contains(MessageFlags.CANCEL_SPAM)) {
|
|
||||||
withContext(Dispatchers.IO) {
|
|
||||||
val message = loadMessage(
|
|
||||||
peerId = peerId,
|
|
||||||
cmId = cmId
|
|
||||||
)
|
|
||||||
message?.let {
|
|
||||||
val eventToSend =
|
|
||||||
LongPollParsedEvent.MessageMarkedAsNotSpam(message = message)
|
|
||||||
eventsToSend += eventToSend
|
|
||||||
|
|
||||||
listenersMap[LongPollEvent.MARKED_AS_NOT_SPAM]?.let { listeners ->
|
|
||||||
listeners.map { vkEventCallback ->
|
|
||||||
(vkEventCallback as? VkEventCallback<LongPollParsedEvent.MessageMarkedAsNotSpam>)
|
|
||||||
?.onEvent(eventToSend)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MessageFlags.DELETED -> {
|
|
||||||
withContext(Dispatchers.IO) {
|
|
||||||
val message = loadMessage(
|
|
||||||
peerId = peerId,
|
|
||||||
cmId = cmId
|
|
||||||
)
|
|
||||||
message?.let {
|
|
||||||
val eventToSend =
|
|
||||||
LongPollParsedEvent.MessageRestored(message = message)
|
|
||||||
eventsToSend += eventToSend
|
|
||||||
|
|
||||||
listenersMap[LongPollEvent.MESSAGE_RESTORED]?.let { listeners ->
|
|
||||||
listeners.map { vkEventCallback ->
|
|
||||||
(vkEventCallback as? VkEventCallback<LongPollParsedEvent.MessageRestored>)
|
|
||||||
?.onEvent(eventToSend)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> Unit
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
eventsToSend.forEach { eventToSend ->
|
|
||||||
listenersMap[LongPollEvent.MESSAGE_CLEAR_FLAGS]?.let { listeners ->
|
|
||||||
listeners.map { vkEventCallback ->
|
|
||||||
vkEventCallback.onEvent(eventToSend)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun parseMessageNew(eventType: ApiEvent, event: List<Any>) {
|
|
||||||
Log.d("LongPollUpdatesParser", "$eventType: $event")
|
|
||||||
|
|
||||||
val cmId = event[1].asLong()
|
|
||||||
val peerId = event[4].asLong()
|
|
||||||
|
|
||||||
coroutineScope.launch(Dispatchers.IO) {
|
|
||||||
val message =
|
|
||||||
async { loadMessage(peerId = peerId, cmId = cmId) }.await()
|
|
||||||
|
|
||||||
val conversation =
|
|
||||||
async {
|
|
||||||
loadConversation(
|
|
||||||
peerId = peerId,
|
|
||||||
extended = true,
|
|
||||||
fields = VkConstants.ALL_FIELDS
|
|
||||||
)
|
|
||||||
}.await()
|
|
||||||
|
|
||||||
message?.let {
|
|
||||||
listenersMap[LongPollEvent.MESSAGE_NEW]?.let {
|
|
||||||
it.map { vkEventCallback ->
|
|
||||||
(vkEventCallback as VkEventCallback<LongPollParsedEvent.NewMessage>)
|
|
||||||
.onEvent(
|
|
||||||
LongPollParsedEvent.NewMessage(
|
|
||||||
message = message,
|
|
||||||
inArchive = conversation?.isArchived == true
|
|
||||||
// TODO: 03-Apr-25, Danil Nikolaev:
|
|
||||||
// load user settings about restoring chats with
|
|
||||||
// enabled notifications from archive
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun parseMessageEdit(eventType: ApiEvent, event: List<Any>) {
|
|
||||||
Log.d("LongPollUpdatesParser", "$eventType: $event")
|
|
||||||
|
|
||||||
val cmId = event[1].asLong()
|
|
||||||
val peerId = event[3].asLong()
|
|
||||||
|
|
||||||
coroutineScope.launch(Dispatchers.IO) {
|
|
||||||
loadMessage(
|
|
||||||
peerId = peerId,
|
|
||||||
cmId = cmId
|
|
||||||
)?.let { message ->
|
|
||||||
listenersMap[LongPollEvent.MESSAGE_EDITED]?.let {
|
|
||||||
it.map { vkEventCallback ->
|
|
||||||
(vkEventCallback as VkEventCallback<LongPollParsedEvent.MessageEdited>)
|
|
||||||
.onEvent(LongPollParsedEvent.MessageEdited(message))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun parseMessageReadIncoming(eventType: ApiEvent, event: List<Any>) {
|
|
||||||
Log.d("LongPollUpdatesParser", "$eventType: $event")
|
|
||||||
val peerId = event[1].asLong()
|
|
||||||
val cmId = event[2].asLong()
|
|
||||||
val unreadCount = event[3].asInt()
|
|
||||||
|
|
||||||
listenersMap[LongPollEvent.INCOMING_MESSAGE_READ]?.let { listeners ->
|
|
||||||
listeners.map { vkEventCallback ->
|
|
||||||
(vkEventCallback as VkEventCallback<LongPollParsedEvent.IncomingMessageRead>)
|
|
||||||
.onEvent(
|
|
||||||
LongPollParsedEvent.IncomingMessageRead(
|
|
||||||
peerId = peerId,
|
|
||||||
cmId = cmId,
|
|
||||||
unreadCount = unreadCount
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun parseMessageReadOutgoing(eventType: ApiEvent, event: List<Any>) {
|
|
||||||
Log.d("LongPollUpdatesParser", "$eventType: $event")
|
|
||||||
val peerId = event[1].asLong()
|
|
||||||
val cmId = event[2].asLong()
|
|
||||||
val unreadCount = event[3].asInt()
|
|
||||||
|
|
||||||
listenersMap[LongPollEvent.OUTGOING_MESSAGE_READ]?.let { listeners ->
|
|
||||||
listeners.map { vkEventCallback ->
|
|
||||||
(vkEventCallback as VkEventCallback<LongPollParsedEvent.OutgoingMessageRead>)
|
|
||||||
.onEvent(
|
|
||||||
LongPollParsedEvent.OutgoingMessageRead(
|
|
||||||
peerId = peerId,
|
|
||||||
cmId = cmId,
|
|
||||||
unreadCount = unreadCount
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun parseChatClearFlags(eventType: ApiEvent, event: List<Any>) {
|
|
||||||
Log.d("LongPollUpdatesParser", "$eventType: $event")
|
|
||||||
|
|
||||||
val peerId = event[1].asLong()
|
|
||||||
val flags = event[2].asInt()
|
|
||||||
|
|
||||||
val eventsToSend = mutableListOf<LongPollParsedEvent>()
|
|
||||||
|
|
||||||
val parsedFlags = ConversationFlags.parse(flags)
|
|
||||||
|
|
||||||
coroutineScope.launch(Dispatchers.IO) {
|
|
||||||
parsedFlags.forEach { flag ->
|
|
||||||
when (flag) {
|
|
||||||
ConversationFlags.ARCHIVED -> {
|
|
||||||
val conversation = loadConversation(
|
|
||||||
peerId = peerId,
|
|
||||||
extended = true,
|
|
||||||
fields = VkConstants.ALL_FIELDS
|
|
||||||
) ?: return@forEach
|
|
||||||
|
|
||||||
val message = loadMessage(
|
|
||||||
peerId = peerId,
|
|
||||||
cmId = conversation.lastCmId
|
|
||||||
)
|
|
||||||
|
|
||||||
val eventToSend = LongPollParsedEvent.ChatArchived(
|
|
||||||
conversation = conversation.copy(lastMessage = message),
|
|
||||||
archived = false
|
|
||||||
)
|
|
||||||
eventsToSend += eventToSend
|
|
||||||
|
|
||||||
listenersMap[LongPollEvent.CHAT_ARCHIVED]?.let { listeners ->
|
|
||||||
listeners.map { vkEventCallback ->
|
|
||||||
(vkEventCallback as? VkEventCallback<LongPollParsedEvent.ChatArchived>)
|
|
||||||
?.onEvent(eventToSend)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> Unit
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
eventsToSend.forEach { eventToSend ->
|
|
||||||
listenersMap[LongPollEvent.CHAT_CLEAR_FLAGS]?.let { listeners ->
|
|
||||||
listeners.map { vkEventCallback ->
|
|
||||||
(vkEventCallback as? VkEventCallback<LongPollParsedEvent>)?.onEvent(
|
|
||||||
eventToSend
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun parseChatSetFlags(eventType: ApiEvent, event: List<Any>) {
|
|
||||||
Log.d("LongPollUpdatesParser", "$eventType: $event")
|
|
||||||
|
|
||||||
val peerId = event[1].asLong()
|
|
||||||
val flags = event[2].asInt()
|
|
||||||
|
|
||||||
val eventsToSend = mutableListOf<LongPollParsedEvent>()
|
|
||||||
|
|
||||||
val parsedFlags = ConversationFlags.parse(flags)
|
|
||||||
|
|
||||||
coroutineScope.launch(Dispatchers.IO) {
|
|
||||||
parsedFlags.forEach { flag ->
|
|
||||||
when (flag) {
|
|
||||||
ConversationFlags.ARCHIVED -> {
|
|
||||||
val conversation = loadConversation(
|
|
||||||
peerId = peerId,
|
|
||||||
extended = true,
|
|
||||||
fields = VkConstants.ALL_FIELDS
|
|
||||||
) ?: return@forEach
|
|
||||||
|
|
||||||
val message = loadMessage(
|
|
||||||
peerId = peerId,
|
|
||||||
cmId = conversation.lastCmId
|
|
||||||
)
|
|
||||||
|
|
||||||
val eventToSend = LongPollParsedEvent.ChatArchived(
|
|
||||||
conversation = conversation.copy(lastMessage = message),
|
|
||||||
archived = true
|
|
||||||
)
|
|
||||||
eventsToSend += eventToSend
|
|
||||||
|
|
||||||
listenersMap[LongPollEvent.CHAT_ARCHIVED]?.let { listeners ->
|
|
||||||
listeners.map { vkEventCallback ->
|
|
||||||
(vkEventCallback as? VkEventCallback<LongPollParsedEvent.ChatArchived>)
|
|
||||||
?.onEvent(eventToSend)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> Unit
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
eventsToSend.forEach { eventToSend ->
|
|
||||||
listenersMap[LongPollEvent.CHAT_SET_FLAGS]?.let { listeners ->
|
|
||||||
listeners.map { vkEventCallback ->
|
|
||||||
(vkEventCallback as? VkEventCallback<LongPollParsedEvent>)?.onEvent(
|
|
||||||
eventToSend
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun parseMessagesDeleted(eventType: ApiEvent, event: List<Any>) {
|
|
||||||
Log.d("LongPollUpdatesParser", "$eventType: $event")
|
|
||||||
|
|
||||||
val peerId = event[1].asLong()
|
|
||||||
val cmId = event[2].asLong()
|
|
||||||
|
|
||||||
listenersMap[LongPollEvent.CHAT_CLEARED]?.let { listeners ->
|
|
||||||
listeners.forEach { vkEventCallback ->
|
|
||||||
(vkEventCallback as VkEventCallback<LongPollParsedEvent.ChatCleared>)
|
|
||||||
.onEvent(
|
|
||||||
LongPollParsedEvent.ChatCleared(
|
|
||||||
peerId = peerId,
|
|
||||||
toCmId = cmId
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun parseChatMajorChanged(eventType: ApiEvent, event: List<Any>) {
|
|
||||||
Log.d("LongPollUpdatesParser", "$eventType: $event")
|
|
||||||
|
|
||||||
val peerId = event[1].asLong()
|
|
||||||
val majorId = event[2].asInt()
|
|
||||||
|
|
||||||
listenersMap[LongPollEvent.CHAT_MAJOR_CHANGED]?.let { listeners ->
|
|
||||||
listeners.forEach { vkEventCallback ->
|
|
||||||
(vkEventCallback as VkEventCallback<LongPollParsedEvent.ChatMajorChanged>)
|
|
||||||
.onEvent(
|
|
||||||
LongPollParsedEvent.ChatMajorChanged(
|
|
||||||
peerId = peerId,
|
|
||||||
majorId = majorId,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun parseChatMinorChanged(eventType: ApiEvent, event: List<Any>) {
|
|
||||||
Log.d("LongPollUpdatesParser", "$eventType: $event")
|
|
||||||
|
|
||||||
val peerId = event[1].asLong()
|
|
||||||
val minorId = event[2].asInt()
|
|
||||||
|
|
||||||
listenersMap[LongPollEvent.CHAT_MINOR_CHANGED]?.let { listeners ->
|
|
||||||
listeners.forEach { vkEventCallback ->
|
|
||||||
(vkEventCallback as VkEventCallback<LongPollParsedEvent.ChatMinorChanged>)
|
|
||||||
.onEvent(
|
|
||||||
LongPollParsedEvent.ChatMinorChanged(
|
|
||||||
peerId = peerId,
|
|
||||||
minorId = minorId,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun parseInteraction(eventType: ApiEvent, event: List<Any>) {
|
private fun parseInteraction(eventType: ApiEvent, event: List<Any>) {
|
||||||
@@ -539,28 +79,20 @@ class LongPollUpdatesParser(
|
|||||||
else -> return
|
else -> return
|
||||||
}
|
}
|
||||||
|
|
||||||
val longPollEvent: LongPollEvent = when (eventType) {
|
val peerId = event[1].asInt()
|
||||||
ApiEvent.TYPING -> LongPollEvent.TYPING
|
val userIds = event[2].toList(Any::asInt).filter { it != UserConfig.userId }
|
||||||
ApiEvent.AUDIO_MESSAGE_RECORDING -> LongPollEvent.AUDIO_MESSAGE_RECORDING
|
|
||||||
ApiEvent.PHOTO_UPLOADING -> LongPollEvent.PHOTO_UPLOADING
|
|
||||||
ApiEvent.VIDEO_UPLOADING -> LongPollEvent.VIDEO_UPLOADING
|
|
||||||
ApiEvent.FILE_UPLOADING -> LongPollEvent.FILE_UPLOADING
|
|
||||||
else -> return
|
|
||||||
}
|
|
||||||
|
|
||||||
val peerId = event[1].asLong()
|
|
||||||
val userIds = event[2].toList(Any::asLong).filter { it != UserConfig.userId }
|
|
||||||
val totalCount = event[3].asInt()
|
val totalCount = event[3].asInt()
|
||||||
val timestamp = event[4].asInt()
|
val timestamp = event[4].asInt()
|
||||||
|
|
||||||
// if userIds contains only account's id, then we don't need to show our status
|
// if userIds contains only account's id, then we don't need to show our status
|
||||||
if (userIds.isEmpty()) return
|
if (userIds.isEmpty()) return
|
||||||
|
|
||||||
listenersMap[longPollEvent]?.let { listeners ->
|
coroutineScope.launch {
|
||||||
|
listenersMap[eventType]?.let { listeners ->
|
||||||
listeners.forEach { vkEventCallback ->
|
listeners.forEach { vkEventCallback ->
|
||||||
(vkEventCallback as VkEventCallback<LongPollParsedEvent.Interaction>)
|
(vkEventCallback as VkEventCallback<LongPollEvent.Interaction>)
|
||||||
.onEvent(
|
.onEvent(
|
||||||
LongPollParsedEvent.Interaction(
|
LongPollEvent.Interaction(
|
||||||
interactionType = interactionType,
|
interactionType = interactionType,
|
||||||
peerId = peerId,
|
peerId = peerId,
|
||||||
userIds = userIds,
|
userIds = userIds,
|
||||||
@@ -571,237 +103,253 @@ class LongPollUpdatesParser(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun parseUnreadCounterUpdate(eventType: ApiEvent, event: List<Any>) {
|
private fun parseConversationPinStateChanged(eventType: ApiEvent, event: List<Any>) {
|
||||||
Log.d("LongPollUpdatesParser", "$eventType $event")
|
Log.d("LongPollUpdatesParser", "$eventType: $event")
|
||||||
|
|
||||||
val unreadCount = event[1].asInt()
|
val peerId = event[1].asInt()
|
||||||
val unreadUnmutedCount = event[2].asInt()
|
val majorId = event[2].asInt()
|
||||||
val showOnlyMuted = event[3].asInt() == 1
|
|
||||||
val businessNotifyUnreadCount = event[4].asInt()
|
|
||||||
val archiveUnreadCount = event[7].asInt()
|
|
||||||
val archiveUnreadUnmutedCount = event[8].asInt()
|
|
||||||
val archiveMentionsCount = event[9].asInt()
|
|
||||||
|
|
||||||
listenersMap[LongPollEvent.UNREAD_COUNTER_UPDATE]?.let { listeners ->
|
coroutineScope.launch {
|
||||||
|
listenersMap[ApiEvent.PIN_UNPIN_CONVERSATION]?.let { listeners ->
|
||||||
listeners.forEach { vkEventCallback ->
|
listeners.forEach { vkEventCallback ->
|
||||||
(vkEventCallback as VkEventCallback<LongPollParsedEvent.UnreadCounter>)
|
(vkEventCallback as VkEventCallback<LongPollEvent.VkConversationPinStateChangedEvent>)
|
||||||
.onEvent(
|
.onEvent(
|
||||||
LongPollParsedEvent.UnreadCounter(
|
LongPollEvent.VkConversationPinStateChangedEvent(
|
||||||
unread = unreadCount,
|
|
||||||
unreadUnmuted = unreadUnmutedCount,
|
|
||||||
showOnlyMuted = showOnlyMuted,
|
|
||||||
business = businessNotifyUnreadCount,
|
|
||||||
archive = archiveUnreadCount,
|
|
||||||
archiveUnmuted = archiveUnreadUnmutedCount,
|
|
||||||
archiveMentions = archiveMentionsCount
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun parseMessageUpdated(eventType: ApiEvent, event: List<Any>) {
|
|
||||||
Log.d("LongPollUpdatesParser", "$eventType $event")
|
|
||||||
|
|
||||||
val cmId = event[1].asLong()
|
|
||||||
val peerId = event[4].asLong()
|
|
||||||
|
|
||||||
coroutineScope.launch(Dispatchers.IO) {
|
|
||||||
loadMessage(
|
|
||||||
peerId = peerId,
|
peerId = peerId,
|
||||||
cmId = cmId
|
majorId = majorId
|
||||||
)?.let { message ->
|
)
|
||||||
listenersMap[LongPollEvent.MESSAGE_UPDATED]?.let {
|
)
|
||||||
it.map { vkEventCallback ->
|
|
||||||
(vkEventCallback as VkEventCallback<LongPollParsedEvent.MessageUpdated>)
|
|
||||||
.onEvent(LongPollParsedEvent.MessageUpdated(message))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun parseMessageCacheClear(eventType: ApiEvent, event: List<Any>) {
|
private fun parseMessageSetFlags(eventType: ApiEvent, event: List<Any>) {
|
||||||
Log.d("LongPollUpdatesParser", "$eventType $event")
|
Log.d("LongPollUpdatesParser", "$eventType: $event")
|
||||||
|
}
|
||||||
|
|
||||||
val messageId = event[1].asLong()
|
private fun parseMessageClearFlags(eventType: ApiEvent, event: List<Any>) {
|
||||||
|
Log.d("LongPollUpdatesParser", "$eventType: $event")
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun parseMessageNew(eventType: ApiEvent, event: List<Any>) {
|
||||||
|
Log.d("LongPollUpdatesParser", "$eventType: $event")
|
||||||
|
val messageId = event[1].asInt()
|
||||||
|
|
||||||
coroutineScope.launch(Dispatchers.IO) {
|
coroutineScope.launch(Dispatchers.IO) {
|
||||||
loadMessage(messageId = messageId)?.let { message ->
|
val newMessageEvent: LongPollEvent.VkMessageNewEvent? =
|
||||||
listenersMap[LongPollEvent.MESSAGE_CACHE_CLEAR]?.let {
|
loadNormalMessage(
|
||||||
|
eventType,
|
||||||
|
messageId
|
||||||
|
)
|
||||||
|
|
||||||
|
newMessageEvent?.let { event ->
|
||||||
|
listenersMap[ApiEvent.MESSAGE_NEW]?.let {
|
||||||
it.map { vkEventCallback ->
|
it.map { vkEventCallback ->
|
||||||
(vkEventCallback as VkEventCallback<LongPollParsedEvent.MessageCacheClear>)
|
(vkEventCallback as VkEventCallback<LongPollEvent.VkMessageNewEvent>)
|
||||||
.onEvent(LongPollParsedEvent.MessageCacheClear(message))
|
.onEvent(event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun loadMessage(
|
private fun parseMessageEdit(eventType: ApiEvent, event: List<Any>) {
|
||||||
peerId: Long? = null,
|
Log.d("LongPollUpdatesParser", "$eventType: $event")
|
||||||
cmId: Long? = null,
|
val messageId = event[1].asInt()
|
||||||
messageId: Long? = null
|
|
||||||
): VkMessage? = suspendCoroutine { continuation ->
|
|
||||||
require((peerId != null && cmId != null) || messageId != null)
|
|
||||||
|
|
||||||
|
coroutineScope.launch {
|
||||||
|
val editedMessageEvent: LongPollEvent.VkMessageEditEvent? =
|
||||||
|
loadNormalMessage(
|
||||||
|
eventType,
|
||||||
|
messageId
|
||||||
|
)
|
||||||
|
|
||||||
|
editedMessageEvent?.let { event ->
|
||||||
|
listenersMap[ApiEvent.MESSAGE_EDIT]?.let {
|
||||||
|
it.map { vkEventCallback ->
|
||||||
|
(vkEventCallback as VkEventCallback<LongPollEvent.VkMessageEditEvent>)
|
||||||
|
.onEvent(event)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun parseMessageReadIncoming(eventType: ApiEvent, event: List<Any>) {
|
||||||
|
Log.d("LongPollUpdatesParser", "$eventType: $event")
|
||||||
|
val peerId = event[1].asInt()
|
||||||
|
val messageId = event[2].asInt()
|
||||||
|
val unreadCount = event[3].asInt()
|
||||||
|
|
||||||
|
coroutineScope.launch {
|
||||||
|
listenersMap[ApiEvent.MESSAGE_READ_INCOMING]?.let { listeners ->
|
||||||
|
listeners.map { vkEventCallback ->
|
||||||
|
(vkEventCallback as VkEventCallback<LongPollEvent.VkMessageReadIncomingEvent>)
|
||||||
|
.onEvent(
|
||||||
|
LongPollEvent.VkMessageReadIncomingEvent(
|
||||||
|
peerId = peerId,
|
||||||
|
messageId = messageId,
|
||||||
|
unreadCount = unreadCount
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun parseMessageReadOutgoing(eventType: ApiEvent, event: List<Any>) {
|
||||||
|
Log.d("LongPollUpdatesParser", "$eventType: $event")
|
||||||
|
val peerId = event[1].asInt()
|
||||||
|
val messageId = event[2].asInt()
|
||||||
|
val unreadCount = event[3].asInt()
|
||||||
|
|
||||||
|
coroutineScope.launch {
|
||||||
|
listenersMap[ApiEvent.MESSAGE_READ_OUTGOING]?.let { listeners ->
|
||||||
|
listeners.map { vkEventCallback ->
|
||||||
|
(vkEventCallback as VkEventCallback<LongPollEvent.VkMessageReadOutgoingEvent>)
|
||||||
|
.onEvent(
|
||||||
|
LongPollEvent.VkMessageReadOutgoingEvent(
|
||||||
|
peerId = peerId,
|
||||||
|
messageId = messageId,
|
||||||
|
unreadCount = unreadCount
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun parseMessagesDeleted(eventType: ApiEvent, event: List<Any>) {
|
||||||
|
Log.d("LongPollUpdatesParser", "$eventType: $event")
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend inline fun <reified T : LongPollEvent> loadNormalMessage(
|
||||||
|
eventType: ApiEvent,
|
||||||
|
messageId: Int
|
||||||
|
): T? = suspendCoroutine { continuation ->
|
||||||
coroutineScope.launch(Dispatchers.IO) {
|
coroutineScope.launch(Dispatchers.IO) {
|
||||||
messagesUseCase.getById(
|
messagesUseCase.getById(
|
||||||
peerCmIds = null,
|
messageIds = listOf(messageId),
|
||||||
peerId = peerId,
|
|
||||||
messageIds = messageId?.let(::listOf),
|
|
||||||
cmIds = cmId?.let(::listOf),
|
|
||||||
extended = true,
|
extended = true,
|
||||||
fields = VkConstants.ALL_FIELDS
|
fields = VkConstants.ALL_FIELDS
|
||||||
).listenValue(this) { state ->
|
).listenValue(this) { state ->
|
||||||
state.processState(
|
state.processState(
|
||||||
error = { error ->
|
error = { error ->
|
||||||
Log.e("LongPollUpdatesParser", "loadMessage: error: $error")
|
Log.e("LongPollUpdatesParser", "loadNormalMessage: error: $error")
|
||||||
continuation.resume(null)
|
|
||||||
},
|
},
|
||||||
success = { response ->
|
success = { messages ->
|
||||||
val message = response.singleOrNull() ?: run {
|
val message = messages.singleOrNull() ?: run {
|
||||||
continuation.resume(null)
|
continuation.resume(null)
|
||||||
return@listenValue
|
return@listenValue
|
||||||
}
|
}
|
||||||
|
|
||||||
continuation.resume(message)
|
VkMemoryCache[message.id] = message
|
||||||
|
messagesUseCase.storeMessage(message)
|
||||||
|
|
||||||
|
val resumeValue: LongPollEvent? = when (eventType) {
|
||||||
|
ApiEvent.MESSAGE_NEW -> LongPollEvent.VkMessageNewEvent(message)
|
||||||
|
ApiEvent.MESSAGE_EDIT -> LongPollEvent.VkMessageEditEvent(message)
|
||||||
|
|
||||||
|
else -> {
|
||||||
|
continuation.resume(null)
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resumeValue?.let { value -> continuation.resume(value as T) }
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun loadConversation(
|
private fun <T : Any> registerListener(
|
||||||
peerId: Long,
|
eventType: ApiEvent,
|
||||||
extended: Boolean = false,
|
|
||||||
fields: String? = null
|
|
||||||
): VkConversation? = suspendCoroutine { continuation ->
|
|
||||||
coroutineScope.launch(Dispatchers.IO) {
|
|
||||||
conversationsUseCase.getById(
|
|
||||||
peerIds = listOf(peerId),
|
|
||||||
extended = extended,
|
|
||||||
fields = fields
|
|
||||||
).listenValue(coroutineScope) { state ->
|
|
||||||
state.processState(
|
|
||||||
error = { error ->
|
|
||||||
Log.e("LongPollUpdatesParser", "loadConversation: error: $error")
|
|
||||||
continuation.resume(null)
|
|
||||||
},
|
|
||||||
success = { response ->
|
|
||||||
val conversation = response.singleOrNull() ?: run {
|
|
||||||
continuation.resume(null)
|
|
||||||
return@listenValue
|
|
||||||
}
|
|
||||||
|
|
||||||
continuation.resume(conversation)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
private fun <T : LongPollParsedEvent> registerListener(
|
|
||||||
eventType: LongPollEvent,
|
|
||||||
listener: VkEventCallback<T>
|
listener: VkEventCallback<T>
|
||||||
) {
|
) {
|
||||||
listenersMap.let { map ->
|
listenersMap.let { map ->
|
||||||
map[eventType] = (map[eventType] ?: mutableListOf())
|
map[eventType] = (map[eventType] ?: mutableListOf()).also { it.add(listener) }
|
||||||
.also {
|
|
||||||
it.add(listener as VkEventCallback<LongPollParsedEvent>)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun <T : LongPollParsedEvent> registerListeners(
|
private fun <T : Any> registerListeners(
|
||||||
eventTypes: List<LongPollEvent>,
|
eventTypes: List<ApiEvent>,
|
||||||
listener: VkEventCallback<T>
|
listener: VkEventCallback<T>
|
||||||
) {
|
) {
|
||||||
eventTypes.forEach { eventType -> registerListener(eventType, listener) }
|
eventTypes.forEach { eventType -> registerListener(eventType, listener) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onMessageSetFlags(block: (LongPollParsedEvent) -> Unit) {
|
fun onConversationPinStateChanged(listener: VkEventCallback<LongPollEvent.VkConversationPinStateChangedEvent>) {
|
||||||
registerListener(LongPollEvent.MESSAGE_SET_FLAGS, assembleEventCallback(block))
|
registerListener(ApiEvent.PIN_UNPIN_CONVERSATION, listener)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onMessageMarkedAsImportant(block: (LongPollParsedEvent.MessageMarkedAsImportant) -> Unit) {
|
fun onConversationPinStateChanged(block: (LongPollEvent.VkConversationPinStateChangedEvent) -> Unit) {
|
||||||
registerListener(LongPollEvent.MARKED_AS_IMPORTANT, assembleEventCallback(block))
|
onConversationPinStateChanged(assembleEventCallback(block))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onMessageMarkedAsSpam(block: (LongPollParsedEvent.MessageMarkedAsSpam) -> Unit) {
|
fun onMessageIncomingRead(listener: VkEventCallback<LongPollEvent.VkMessageReadIncomingEvent>) {
|
||||||
registerListener(LongPollEvent.MARKED_AS_SPAM, assembleEventCallback(block))
|
registerListener(ApiEvent.MESSAGE_READ_INCOMING, listener)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onMessageDeleted(block: (LongPollParsedEvent.MessageDeleted) -> Unit) {
|
fun onMessageIncomingRead(block: (LongPollEvent.VkMessageReadIncomingEvent) -> Unit) {
|
||||||
registerListener(LongPollEvent.MESSAGE_DELETED, assembleEventCallback(block))
|
onMessageIncomingRead(assembleEventCallback(block))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onMessageClearFlags(block: (LongPollParsedEvent) -> Unit) {
|
fun onMessageOutgoingRead(listener: VkEventCallback<LongPollEvent.VkMessageReadOutgoingEvent>) {
|
||||||
registerListener(LongPollEvent.MESSAGE_CLEAR_FLAGS, assembleEventCallback(block))
|
registerListener(ApiEvent.MESSAGE_READ_OUTGOING, listener)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onMessageMarkedAsNotSpam(block: (LongPollParsedEvent.MessageMarkedAsNotSpam) -> Unit) {
|
fun onMessageOutgoingRead(block: (LongPollEvent.VkMessageReadOutgoingEvent) -> Unit) {
|
||||||
registerListener(LongPollEvent.MARKED_AS_NOT_SPAM, assembleEventCallback(block))
|
onMessageOutgoingRead(assembleEventCallback(block))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onMessageRestored(block: (LongPollParsedEvent.MessageRestored) -> Unit) {
|
fun onNewMessage(listener: VkEventCallback<LongPollEvent.VkMessageNewEvent>) {
|
||||||
registerListener(LongPollEvent.MESSAGE_RESTORED, assembleEventCallback(block))
|
registerListener(ApiEvent.MESSAGE_NEW, listener)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onNewMessage(block: (LongPollParsedEvent.NewMessage) -> Unit) {
|
fun onNewMessage(block: (LongPollEvent.VkMessageNewEvent) -> Unit) {
|
||||||
registerListener(LongPollEvent.MESSAGE_NEW, assembleEventCallback(block))
|
onNewMessage(assembleEventCallback(block))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onMessageEdited(block: (LongPollParsedEvent.MessageEdited) -> Unit) {
|
fun onMessageEdited(listener: VkEventCallback<LongPollEvent.VkMessageEditEvent>) {
|
||||||
registerListener(LongPollEvent.MESSAGE_EDITED, assembleEventCallback(block))
|
registerListener(ApiEvent.MESSAGE_EDIT, listener)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onMessageIncomingRead(block: (LongPollParsedEvent.IncomingMessageRead) -> Unit) {
|
fun onMessageEdited(block: (LongPollEvent.VkMessageEditEvent) -> Unit) {
|
||||||
registerListener(LongPollEvent.INCOMING_MESSAGE_READ, assembleEventCallback(block))
|
onMessageEdited(assembleEventCallback(block))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onMessageOutgoingRead(block: (LongPollParsedEvent.OutgoingMessageRead) -> Unit) {
|
fun onInteractions(listener: VkEventCallback<LongPollEvent.Interaction>) {
|
||||||
registerListener(LongPollEvent.OUTGOING_MESSAGE_READ, assembleEventCallback(block))
|
|
||||||
}
|
|
||||||
|
|
||||||
fun onChatCleared(block: (LongPollParsedEvent.ChatCleared) -> Unit) {
|
|
||||||
registerListener(LongPollEvent.CHAT_CLEARED, assembleEventCallback(block))
|
|
||||||
}
|
|
||||||
|
|
||||||
fun onChatMajorChanged(block: (LongPollParsedEvent.ChatMajorChanged) -> Unit) {
|
|
||||||
registerListener(LongPollEvent.CHAT_MAJOR_CHANGED, assembleEventCallback(block))
|
|
||||||
}
|
|
||||||
|
|
||||||
fun onChatMinorChanged(block: (LongPollParsedEvent.ChatMinorChanged) -> Unit) {
|
|
||||||
registerListener(LongPollEvent.CHAT_MINOR_CHANGED, assembleEventCallback(block))
|
|
||||||
}
|
|
||||||
|
|
||||||
fun onChatArchived(block: (LongPollParsedEvent.ChatArchived) -> Unit) {
|
|
||||||
registerListener(LongPollEvent.CHAT_ARCHIVED, assembleEventCallback(block))
|
|
||||||
}
|
|
||||||
|
|
||||||
fun onInteractions(block: (LongPollParsedEvent.Interaction) -> Unit) {
|
|
||||||
registerListeners(
|
registerListeners(
|
||||||
eventTypes = listOf(
|
eventTypes = listOf(
|
||||||
LongPollEvent.TYPING,
|
ApiEvent.TYPING,
|
||||||
LongPollEvent.AUDIO_MESSAGE_RECORDING,
|
ApiEvent.AUDIO_MESSAGE_RECORDING,
|
||||||
LongPollEvent.PHOTO_UPLOADING,
|
ApiEvent.PHOTO_UPLOADING,
|
||||||
LongPollEvent.VIDEO_UPLOADING,
|
ApiEvent.VIDEO_UPLOADING,
|
||||||
LongPollEvent.FILE_UPLOADING
|
ApiEvent.FILE_UPLOADING
|
||||||
),
|
),
|
||||||
listener = assembleEventCallback(block)
|
listener = listener
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun onInteractions(block: (LongPollEvent.Interaction) -> Unit) {
|
||||||
|
onInteractions(assembleEventCallback(block))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun clearListeners() {
|
||||||
|
listenersMap.clear()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal inline fun <R : LongPollParsedEvent> assembleEventCallback(
|
internal inline fun <R : Any> assembleEventCallback(
|
||||||
crossinline block: (R) -> Unit,
|
crossinline block: (R) -> Unit,
|
||||||
): VkEventCallback<R> {
|
): VkEventCallback<R> {
|
||||||
return VkEventCallback { event -> block.invoke(event) }
|
return VkEventCallback { event -> block.invoke(event) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun interface VkEventCallback<in T : LongPollParsedEvent> {
|
fun interface VkEventCallback<in T : Any> {
|
||||||
fun onEvent(event: T)
|
fun onEvent(event: T)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,78 +5,48 @@ import dev.meloda.fast.data.api.messages.MessagesHistoryInfo
|
|||||||
import dev.meloda.fast.model.api.domain.VkAttachment
|
import dev.meloda.fast.model.api.domain.VkAttachment
|
||||||
import dev.meloda.fast.model.api.domain.VkAttachmentHistoryMessage
|
import dev.meloda.fast.model.api.domain.VkAttachmentHistoryMessage
|
||||||
import dev.meloda.fast.model.api.domain.VkMessage
|
import dev.meloda.fast.model.api.domain.VkMessage
|
||||||
import dev.meloda.fast.model.api.responses.MessagesSendResponse
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
interface MessagesUseCase : BaseUseCase {
|
interface MessagesUseCase {
|
||||||
|
|
||||||
suspend fun storeMessage(message: VkMessage)
|
|
||||||
suspend fun storeMessages(messages: List<VkMessage>)
|
|
||||||
|
|
||||||
fun getMessagesHistory(
|
fun getMessagesHistory(
|
||||||
conversationId: Long,
|
conversationId: Int,
|
||||||
count: Int?,
|
count: Int?,
|
||||||
offset: Int?
|
offset: Int?
|
||||||
): Flow<State<MessagesHistoryInfo>>
|
): Flow<State<MessagesHistoryInfo>>
|
||||||
|
|
||||||
fun getById(
|
fun getById(
|
||||||
peerCmIds: List<Long>?,
|
messageIds: List<Int>,
|
||||||
peerId: Long?,
|
|
||||||
messageIds: List<Long>?,
|
|
||||||
cmIds: List<Long>?,
|
|
||||||
extended: Boolean?,
|
extended: Boolean?,
|
||||||
fields: String?
|
fields: String?
|
||||||
): Flow<State<List<VkMessage>>>
|
): Flow<State<List<VkMessage>>>
|
||||||
|
|
||||||
fun sendMessage(
|
fun sendMessage(
|
||||||
peerId: Long,
|
peerId: Int,
|
||||||
randomId: Long,
|
randomId: Int,
|
||||||
message: String?,
|
message: String?,
|
||||||
replyTo: Long?,
|
replyTo: Int?,
|
||||||
attachments: List<VkAttachment>?,
|
attachments: List<VkAttachment>?
|
||||||
formatData: VkMessage.FormatData?
|
): Flow<State<Int>>
|
||||||
): Flow<State<MessagesSendResponse>>
|
|
||||||
|
|
||||||
fun markAsRead(
|
fun markAsRead(
|
||||||
peerId: Long,
|
peerId: Int,
|
||||||
startMessageId: Long
|
startMessageId: Int
|
||||||
): Flow<State<Int>>
|
): Flow<State<Int>>
|
||||||
|
|
||||||
fun getHistoryAttachments(
|
fun getHistoryAttachments(
|
||||||
peerId: Long,
|
peerId: Int,
|
||||||
count: Int? = null,
|
count: Int?,
|
||||||
offset: Int? = null,
|
offset: Int?,
|
||||||
attachmentTypes: List<String>,
|
attachmentTypes: List<String>,
|
||||||
cmId: Long
|
conversationMessageId: Int
|
||||||
): Flow<State<List<VkAttachmentHistoryMessage>>>
|
): Flow<State<List<VkAttachmentHistoryMessage>>>
|
||||||
|
|
||||||
fun createChat(
|
fun createChat(
|
||||||
userIds: List<Long>? = null,
|
userIds: List<Int>?,
|
||||||
title: String
|
title: String?
|
||||||
): Flow<State<Long>>
|
|
||||||
|
|
||||||
fun pin(
|
|
||||||
peerId: Long,
|
|
||||||
messageId: Long? = null,
|
|
||||||
cmId: Long? = null
|
|
||||||
): Flow<State<VkMessage>>
|
|
||||||
|
|
||||||
fun unpin(
|
|
||||||
peerId: Long
|
|
||||||
): Flow<State<Int>>
|
): Flow<State<Int>>
|
||||||
|
|
||||||
fun markAsImportant(
|
suspend fun storeMessage(message: VkMessage)
|
||||||
peerId: Long,
|
suspend fun storeMessages(messages: List<VkMessage>)
|
||||||
messageIds: List<Long>? = null,
|
|
||||||
cmIds: List<Long>? = null,
|
|
||||||
important: Boolean
|
|
||||||
): Flow<State<List<Long>>>
|
|
||||||
|
|
||||||
fun delete(
|
|
||||||
peerId: Long,
|
|
||||||
messageIds: List<Long>? = null,
|
|
||||||
cmIds: List<Long>? = null,
|
|
||||||
spam: Boolean = false,
|
|
||||||
deleteForAll: Boolean = false
|
|
||||||
): Flow<State<List<Any>>>
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,13 +7,107 @@ import dev.meloda.fast.data.mapToState
|
|||||||
import dev.meloda.fast.model.api.domain.VkAttachment
|
import dev.meloda.fast.model.api.domain.VkAttachment
|
||||||
import dev.meloda.fast.model.api.domain.VkAttachmentHistoryMessage
|
import dev.meloda.fast.model.api.domain.VkAttachmentHistoryMessage
|
||||||
import dev.meloda.fast.model.api.domain.VkMessage
|
import dev.meloda.fast.model.api.domain.VkMessage
|
||||||
import dev.meloda.fast.model.api.responses.MessagesSendResponse
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.flow
|
||||||
|
|
||||||
class MessagesUseCaseImpl(
|
class MessagesUseCaseImpl(
|
||||||
private val repository: MessagesRepository,
|
private val repository: MessagesRepository
|
||||||
) : MessagesUseCase {
|
) : MessagesUseCase {
|
||||||
|
|
||||||
|
override fun getMessagesHistory(
|
||||||
|
conversationId: Int,
|
||||||
|
count: Int?,
|
||||||
|
offset: Int?
|
||||||
|
): Flow<State<MessagesHistoryInfo>> = flow {
|
||||||
|
emit(State.Loading)
|
||||||
|
|
||||||
|
val newState = repository.getHistory(
|
||||||
|
conversationId = conversationId,
|
||||||
|
offset = offset,
|
||||||
|
count = count
|
||||||
|
).mapToState()
|
||||||
|
|
||||||
|
emit(newState)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getById(
|
||||||
|
messageIds: List<Int>,
|
||||||
|
extended: Boolean?,
|
||||||
|
fields: String?
|
||||||
|
): Flow<State<List<VkMessage>>> = flow {
|
||||||
|
emit(State.Loading)
|
||||||
|
|
||||||
|
val newState = repository.getById(
|
||||||
|
messagesIds = messageIds,
|
||||||
|
extended = extended,
|
||||||
|
fields = fields
|
||||||
|
).mapToState()
|
||||||
|
|
||||||
|
emit(newState)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun sendMessage(
|
||||||
|
peerId: Int,
|
||||||
|
randomId: Int,
|
||||||
|
message: String?,
|
||||||
|
replyTo: Int?,
|
||||||
|
attachments: List<VkAttachment>?
|
||||||
|
): Flow<State<Int>> = flow {
|
||||||
|
emit(State.Loading)
|
||||||
|
|
||||||
|
val newState = repository.send(
|
||||||
|
peerId = peerId,
|
||||||
|
randomId = randomId,
|
||||||
|
message = message,
|
||||||
|
replyTo = replyTo,
|
||||||
|
attachments = attachments
|
||||||
|
).mapToState()
|
||||||
|
|
||||||
|
emit(newState)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun markAsRead(
|
||||||
|
peerId: Int,
|
||||||
|
startMessageId: Int
|
||||||
|
): Flow<State<Int>> = flow {
|
||||||
|
emit(State.Loading)
|
||||||
|
|
||||||
|
val newState = repository.markAsRead(
|
||||||
|
peerId = peerId,
|
||||||
|
startMessageId = startMessageId
|
||||||
|
).mapToState()
|
||||||
|
|
||||||
|
emit(newState)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getHistoryAttachments(
|
||||||
|
peerId: Int,
|
||||||
|
count: Int?,
|
||||||
|
offset: Int?,
|
||||||
|
attachmentTypes: List<String>,
|
||||||
|
conversationMessageId: Int
|
||||||
|
): Flow<State<List<VkAttachmentHistoryMessage>>> = flow {
|
||||||
|
emit(State.Loading)
|
||||||
|
|
||||||
|
val newState = repository.getHistoryAttachments(
|
||||||
|
peerId = peerId,
|
||||||
|
count = count,
|
||||||
|
offset = offset,
|
||||||
|
attachmentTypes = attachmentTypes,
|
||||||
|
conversationMessageId = conversationMessageId
|
||||||
|
).mapToState()
|
||||||
|
|
||||||
|
emit(newState)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun createChat(userIds: List<Int>?, title: String?): Flow<State<Int>> = flow {
|
||||||
|
emit(State.Loading)
|
||||||
|
|
||||||
|
val newState = repository.createChat(userIds, title).mapToState()
|
||||||
|
|
||||||
|
emit(newState)
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun storeMessage(message: VkMessage) {
|
override suspend fun storeMessage(message: VkMessage) {
|
||||||
repository.storeMessages(listOf(message))
|
repository.storeMessages(listOf(message))
|
||||||
}
|
}
|
||||||
@@ -21,131 +115,4 @@ class MessagesUseCaseImpl(
|
|||||||
override suspend fun storeMessages(messages: List<VkMessage>) {
|
override suspend fun storeMessages(messages: List<VkMessage>) {
|
||||||
repository.storeMessages(messages)
|
repository.storeMessages(messages)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getMessagesHistory(
|
|
||||||
conversationId: Long,
|
|
||||||
count: Int?,
|
|
||||||
offset: Int?
|
|
||||||
): Flow<State<MessagesHistoryInfo>> = flowNewState {
|
|
||||||
repository.getHistory(
|
|
||||||
conversationId = conversationId,
|
|
||||||
offset = offset,
|
|
||||||
count = count
|
|
||||||
).mapToState()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getById(
|
|
||||||
peerCmIds: List<Long>?,
|
|
||||||
peerId: Long?,
|
|
||||||
messageIds: List<Long>?,
|
|
||||||
cmIds: List<Long>?,
|
|
||||||
extended: Boolean?,
|
|
||||||
fields: String?
|
|
||||||
): Flow<State<List<VkMessage>>> = flowNewState {
|
|
||||||
repository.getById(
|
|
||||||
peerCmIds = peerCmIds,
|
|
||||||
peerId = peerId,
|
|
||||||
messagesIds = messageIds,
|
|
||||||
cmIds = cmIds,
|
|
||||||
extended = extended,
|
|
||||||
fields = fields
|
|
||||||
).mapToState()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun sendMessage(
|
|
||||||
peerId: Long,
|
|
||||||
randomId: Long,
|
|
||||||
message: String?,
|
|
||||||
replyTo: Long?,
|
|
||||||
attachments: List<VkAttachment>?,
|
|
||||||
formatData: VkMessage.FormatData?
|
|
||||||
): Flow<State<MessagesSendResponse>> = flowNewState {
|
|
||||||
repository.send(
|
|
||||||
peerId = peerId,
|
|
||||||
randomId = randomId,
|
|
||||||
message = message,
|
|
||||||
replyTo = replyTo,
|
|
||||||
attachments = attachments,
|
|
||||||
formatData = formatData
|
|
||||||
).mapToState()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun markAsRead(
|
|
||||||
peerId: Long,
|
|
||||||
startMessageId: Long
|
|
||||||
): Flow<State<Int>> = flowNewState {
|
|
||||||
repository.markAsRead(
|
|
||||||
peerId = peerId,
|
|
||||||
startMessageId = startMessageId
|
|
||||||
).mapToState()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getHistoryAttachments(
|
|
||||||
peerId: Long,
|
|
||||||
count: Int?,
|
|
||||||
offset: Int?,
|
|
||||||
attachmentTypes: List<String>,
|
|
||||||
cmId: Long
|
|
||||||
): Flow<State<List<VkAttachmentHistoryMessage>>> = flowNewState {
|
|
||||||
repository.getHistoryAttachments(
|
|
||||||
peerId = peerId,
|
|
||||||
count = count,
|
|
||||||
offset = offset,
|
|
||||||
attachmentTypes = attachmentTypes,
|
|
||||||
cmId = cmId
|
|
||||||
).mapToState()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun createChat(
|
|
||||||
userIds: List<Long>?,
|
|
||||||
title: String
|
|
||||||
): Flow<State<Long>> = flowNewState {
|
|
||||||
repository.createChat(userIds, title).mapToState()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun pin(
|
|
||||||
peerId: Long,
|
|
||||||
messageId: Long?,
|
|
||||||
cmId: Long?
|
|
||||||
): Flow<State<VkMessage>> = flowNewState {
|
|
||||||
repository.pin(
|
|
||||||
peerId = peerId,
|
|
||||||
messageId = messageId,
|
|
||||||
cmId = cmId
|
|
||||||
).mapToState()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun unpin(peerId: Long): Flow<State<Int>> = flowNewState {
|
|
||||||
repository.unpin(peerId = peerId).mapToState()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun markAsImportant(
|
|
||||||
peerId: Long,
|
|
||||||
messageIds: List<Long>?,
|
|
||||||
cmIds: List<Long>?,
|
|
||||||
important: Boolean
|
|
||||||
): Flow<State<List<Long>>> = flowNewState {
|
|
||||||
repository.markAsImportant(
|
|
||||||
peerId = peerId,
|
|
||||||
messageIds = messageIds,
|
|
||||||
cmIds = cmIds,
|
|
||||||
important = important
|
|
||||||
).mapToState()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun delete(
|
|
||||||
peerId: Long,
|
|
||||||
messageIds: List<Long>?,
|
|
||||||
cmIds: List<Long>?,
|
|
||||||
spam: Boolean,
|
|
||||||
deleteForAll: Boolean
|
|
||||||
): Flow<State<List<Any>>> = flowNewState {
|
|
||||||
repository.delete(
|
|
||||||
peerId = peerId,
|
|
||||||
messageIds = messageIds,
|
|
||||||
cmIds = cmIds,
|
|
||||||
spam = spam,
|
|
||||||
deleteForAll = deleteForAll
|
|
||||||
).mapToState()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package dev.meloda.fast.domain
|
|||||||
|
|
||||||
import dev.meloda.fast.data.State
|
import dev.meloda.fast.data.State
|
||||||
import dev.meloda.fast.model.AuthInfo
|
import dev.meloda.fast.model.AuthInfo
|
||||||
import dev.meloda.fast.model.api.responses.GetSilentTokenResponse
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
interface OAuthUseCase {
|
interface OAuthUseCase {
|
||||||
@@ -15,13 +14,4 @@ interface OAuthUseCase {
|
|||||||
captchaSid: String?,
|
captchaSid: String?,
|
||||||
captchaKey: String?
|
captchaKey: String?
|
||||||
): Flow<State<AuthInfo>>
|
): Flow<State<AuthInfo>>
|
||||||
|
|
||||||
fun getSilentToken(
|
|
||||||
login: String,
|
|
||||||
password: String,
|
|
||||||
forceSms: Boolean,
|
|
||||||
validationCode: String?,
|
|
||||||
captchaSid: String?,
|
|
||||||
captchaKey: String?
|
|
||||||
): Flow<State<GetSilentTokenResponse>>
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,11 @@ package dev.meloda.fast.domain
|
|||||||
|
|
||||||
import dev.meloda.fast.data.State
|
import dev.meloda.fast.data.State
|
||||||
import dev.meloda.fast.data.api.oauth.OAuthRepository
|
import dev.meloda.fast.data.api.oauth.OAuthRepository
|
||||||
import dev.meloda.fast.data.asState
|
|
||||||
import dev.meloda.fast.model.AuthInfo
|
import dev.meloda.fast.model.AuthInfo
|
||||||
import dev.meloda.fast.model.api.responses.GetSilentTokenResponse
|
import dev.meloda.fast.network.OAuthErrorDomain
|
||||||
|
import dev.meloda.fast.network.ValidationType
|
||||||
|
import dev.meloda.fast.network.VkOAuthError
|
||||||
|
import dev.meloda.fast.network.VkOAuthErrorType
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.flow
|
import kotlinx.coroutines.flow.flow
|
||||||
|
|
||||||
@@ -22,45 +24,109 @@ class OAuthUseCaseImpl(
|
|||||||
): Flow<State<AuthInfo>> = flow {
|
): Flow<State<AuthInfo>> = flow {
|
||||||
emit(State.Loading)
|
emit(State.Loading)
|
||||||
|
|
||||||
val newState = oAuthRepository.auth(
|
val response = oAuthRepository.auth(
|
||||||
login = login,
|
login = login,
|
||||||
password = password,
|
password = password,
|
||||||
forceSms = forceSms,
|
|
||||||
validationCode = validationCode,
|
validationCode = validationCode,
|
||||||
captchaSid = captchaSid,
|
captchaSid = captchaSid,
|
||||||
captchaKey = captchaKey
|
captchaKey = captchaKey,
|
||||||
).asState(
|
forceSms = forceSms
|
||||||
successMapper = {
|
)
|
||||||
|
|
||||||
|
kotlin.runCatching {
|
||||||
|
val error = response.error?.let(VkOAuthError::parse)
|
||||||
|
val errorType = response.errorType?.let(VkOAuthErrorType::parse)
|
||||||
|
|
||||||
|
val newState = when (error) {
|
||||||
|
null -> {
|
||||||
|
State.Success(
|
||||||
AuthInfo(
|
AuthInfo(
|
||||||
userId = it.userId!!,
|
userId = response.userId,
|
||||||
accessToken = it.accessToken!!,
|
accessToken = response.accessToken,
|
||||||
validationHash = it.validationHash!!
|
validationHash = response.validationHash
|
||||||
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
|
||||||
|
|
||||||
emit(newState)
|
VkOAuthError.FLOOD_CONTROL -> {
|
||||||
|
State.Error.OAuthError(OAuthErrorDomain.TooManyTriesError)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getSilentToken(
|
VkOAuthError.NEED_VALIDATION -> {
|
||||||
login: String,
|
if (response.banInfo != null) {
|
||||||
password: String,
|
val info = requireNotNull(response.banInfo)
|
||||||
forceSms: Boolean,
|
|
||||||
validationCode: String?,
|
|
||||||
captchaSid: String?,
|
|
||||||
captchaKey: String?
|
|
||||||
): Flow<State<GetSilentTokenResponse>> = flow {
|
|
||||||
emit(State.Loading)
|
|
||||||
|
|
||||||
val newState = oAuthRepository.getSilentToken(
|
State.Error.OAuthError(
|
||||||
login = login,
|
OAuthErrorDomain.UserBannedError(
|
||||||
password = password,
|
memberName = info.memberName,
|
||||||
forceSms = forceSms,
|
message = info.message,
|
||||||
validationCode = validationCode,
|
accessToken = info.accessToken,
|
||||||
captchaSid = captchaSid,
|
restoreUrl = info.restoreUrl
|
||||||
captchaKey = captchaKey
|
)
|
||||||
).asState()
|
)
|
||||||
|
} else {
|
||||||
|
State.Error.OAuthError(
|
||||||
|
OAuthErrorDomain.ValidationRequiredError(
|
||||||
|
description = response.errorDescription.orEmpty(),
|
||||||
|
validationType = response.validationType.orEmpty()
|
||||||
|
.let(ValidationType::parse),
|
||||||
|
validationSid = response.validationSid.orEmpty(),
|
||||||
|
phoneMask = response.phoneMask.orEmpty(),
|
||||||
|
redirectUri = response.redirectUri.orEmpty(),
|
||||||
|
validationResend = response.validationResend,
|
||||||
|
restoreIfCannotGetCode = response.restoreIfCannotGetCode
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
VkOAuthError.NEED_CAPTCHA -> {
|
||||||
|
State.Error.OAuthError(
|
||||||
|
OAuthErrorDomain.CaptchaRequiredError(
|
||||||
|
captchaSid = response.captchaSid.orEmpty(),
|
||||||
|
captchaImageUrl = response.captchaImage.orEmpty()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
VkOAuthError.INVALID_CLIENT -> {
|
||||||
|
State.Error.OAuthError(OAuthErrorDomain.InvalidCredentialsError)
|
||||||
|
}
|
||||||
|
|
||||||
|
VkOAuthError.INVALID_REQUEST -> {
|
||||||
|
when (errorType) {
|
||||||
|
null -> State.Error.OAuthError(OAuthErrorDomain.UnknownError)
|
||||||
|
|
||||||
|
VkOAuthErrorType.WRONG_OTP -> {
|
||||||
|
State.Error.OAuthError(OAuthErrorDomain.WrongValidationCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
VkOAuthErrorType.WRONG_OTP_FORMAT -> {
|
||||||
|
State.Error.OAuthError(OAuthErrorDomain.WrongValidationCodeFormat)
|
||||||
|
}
|
||||||
|
|
||||||
|
VkOAuthErrorType.PASSWORD_BRUTEFORCE_ATTEMPT -> {
|
||||||
|
State.Error.OAuthError(OAuthErrorDomain.TooManyTriesError)
|
||||||
|
}
|
||||||
|
|
||||||
|
VkOAuthErrorType.USERNAME_OR_PASSWORD_IS_INCORRECT -> {
|
||||||
|
State.Error.OAuthError(OAuthErrorDomain.InvalidCredentialsError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
VkOAuthError.UNKNOWN -> {
|
||||||
|
State.Error.OAuthError(OAuthErrorDomain.UnknownError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
emit(newState)
|
emit(newState)
|
||||||
|
}.fold(
|
||||||
|
onSuccess = {
|
||||||
|
},
|
||||||
|
onFailure = {
|
||||||
|
emit(State.Error.TestError(it.stackTraceToString()))
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,14 @@
|
|||||||
package dev.meloda.fast.model
|
package dev.meloda.fast.model
|
||||||
|
|
||||||
enum class ApiEvent(val value: Int) {
|
enum class ApiEvent(val value: Int) {
|
||||||
MESSAGE_SET_FLAGS(10002),
|
MESSAGE_SET_FLAGS(2),
|
||||||
MESSAGE_CLEAR_FLAGS(10003),
|
MESSAGE_CLEAR_FLAGS(3),
|
||||||
MESSAGE_NEW(10004),
|
MESSAGE_NEW(4),
|
||||||
MESSAGE_EDIT(10005),
|
MESSAGE_EDIT(5),
|
||||||
MESSAGE_READ_INCOMING(10006),
|
MESSAGE_READ_INCOMING(6),
|
||||||
MESSAGE_READ_OUTGOING(10007),
|
MESSAGE_READ_OUTGOING(7),
|
||||||
CHAT_CLEAR_FLAGS(10),
|
MESSAGES_DELETED(13),
|
||||||
CHAT_SET_FLAGS(12),
|
PIN_UNPIN_CONVERSATION(20),
|
||||||
MESSAGES_DELETED(10013),
|
|
||||||
MESSAGE_UPDATED(10018),
|
|
||||||
MESSAGE_CACHE_CLEAR(10019),
|
|
||||||
CHAT_MAJOR_CHANGED(20),
|
|
||||||
CHAT_MINOR_CHANGED(21),
|
|
||||||
TYPING(63),
|
TYPING(63),
|
||||||
AUDIO_MESSAGE_RECORDING(64),
|
AUDIO_MESSAGE_RECORDING(64),
|
||||||
PHOTO_UPLOADING(65),
|
PHOTO_UPLOADING(65),
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package dev.meloda.fast.model
|
package dev.meloda.fast.model
|
||||||
|
|
||||||
data class AuthInfo(
|
data class AuthInfo(
|
||||||
val userId: Long,
|
val userId: Int?,
|
||||||
val accessToken: String,
|
val accessToken: String?,
|
||||||
val validationHash: String
|
val validationHash: String?
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,10 +6,6 @@ import androidx.compose.runtime.Immutable
|
|||||||
sealed class BaseError {
|
sealed class BaseError {
|
||||||
|
|
||||||
data object SessionExpired : BaseError()
|
data object SessionExpired : BaseError()
|
||||||
data object AccountBlocked : BaseError()
|
|
||||||
data object ConnectionError : BaseError()
|
|
||||||
data object InternalError : BaseError()
|
|
||||||
data object UnknownError : BaseError()
|
|
||||||
|
|
||||||
data class SimpleError(val message: String) : BaseError()
|
data class SimpleError(val message: String) : BaseError()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
package dev.meloda.fast.model
|
|
||||||
|
|
||||||
enum class ConversationFlags(val value: Int) {
|
|
||||||
DISABLE_PUSH(16),
|
|
||||||
DISABLE_SOUND(32),
|
|
||||||
INCOMING_CHAT_REQUEST(256),
|
|
||||||
DECLINED_CHAT_REQUEST(512),
|
|
||||||
MENTION(1024),
|
|
||||||
HIDE_CHAT_FROM_SEARCH(2048),
|
|
||||||
BUSINESS_CHAT(8192),
|
|
||||||
MARKED_MESSAGE(16384), // mention or disappearing message
|
|
||||||
DO_NOT_NOTIFY_MENTIONS_ALL_ONLINE(262144),
|
|
||||||
DO_NOT_NOTIFY_ALL_MENTIONS(524288),
|
|
||||||
MARKED_AS_UNREAD(1048576),
|
|
||||||
ARCHIVED(8388608),
|
|
||||||
CALL_IN_PROGRESS(16777216);
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
|
|
||||||
fun parse(mask: Int): List<ConversationFlags> {
|
|
||||||
val flags = mutableListOf<ConversationFlags>()
|
|
||||||
|
|
||||||
ConversationFlags.entries.forEach { flag ->
|
|
||||||
if (mask and flag.value > 0) {
|
|
||||||
flags.add(flag)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return flags
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package dev.meloda.fast.model
|
|
||||||
|
|
||||||
enum class ConversationsFilter {
|
|
||||||
ALL, UNREAD, ARCHIVE, BUSINESS_NOTIFY
|
|
||||||
}
|
|
||||||
@@ -4,5 +4,5 @@ import dev.meloda.fast.model.api.domain.VkUser
|
|||||||
|
|
||||||
data class FriendsInfo(
|
data class FriendsInfo(
|
||||||
val friends: List<VkUser>,
|
val friends: List<VkUser>,
|
||||||
val onlineFriendsIds: List<Long>
|
val onlineFriendsIds: List<Int>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,30 +1,35 @@
|
|||||||
package dev.meloda.fast.model
|
package dev.meloda.fast.model
|
||||||
|
|
||||||
enum class LongPollEvent {
|
import dev.meloda.fast.model.api.domain.VkMessage
|
||||||
MESSAGE_SET_FLAGS,
|
|
||||||
MESSAGE_CLEAR_FLAGS,
|
sealed interface LongPollEvent {
|
||||||
MESSAGE_NEW,
|
|
||||||
MESSAGE_EDITED,
|
data class VkMessageNewEvent(val message: VkMessage) : LongPollEvent
|
||||||
INCOMING_MESSAGE_READ,
|
|
||||||
OUTGOING_MESSAGE_READ,
|
data class VkMessageEditEvent(val message: VkMessage) : LongPollEvent
|
||||||
CHAT_SET_FLAGS,
|
|
||||||
CHAT_CLEAR_FLAGS,
|
data class VkMessageReadIncomingEvent(
|
||||||
CHAT_MAJOR_CHANGED,
|
val peerId: Int,
|
||||||
CHAT_MINOR_CHANGED,
|
val messageId: Int,
|
||||||
TYPING,
|
val unreadCount: Int,
|
||||||
AUDIO_MESSAGE_RECORDING,
|
) : LongPollEvent
|
||||||
PHOTO_UPLOADING,
|
|
||||||
VIDEO_UPLOADING,
|
data class VkMessageReadOutgoingEvent(
|
||||||
FILE_UPLOADING,
|
val peerId: Int,
|
||||||
UNREAD_COUNTER_UPDATE,
|
val messageId: Int,
|
||||||
MARKED_AS_IMPORTANT,
|
val unreadCount: Int,
|
||||||
MARKED_AS_SPAM,
|
) : LongPollEvent
|
||||||
MARKED_AS_NOT_SPAM,
|
|
||||||
MESSAGE_DELETED,
|
data class VkConversationPinStateChangedEvent(
|
||||||
MESSAGE_UPDATED,
|
val peerId: Int,
|
||||||
MESSAGE_CACHE_CLEAR,
|
val majorId: Int,
|
||||||
MESSAGE_RESTORED,
|
) : LongPollEvent
|
||||||
AUDIO_MESSAGE_LISTENED,
|
|
||||||
CHAT_CLEARED,
|
data class Interaction(
|
||||||
CHAT_ARCHIVED
|
val interactionType: InteractionType,
|
||||||
|
val peerId: Int,
|
||||||
|
val userIds: List<Int>,
|
||||||
|
val totalCount: Int,
|
||||||
|
val timestamp: Int
|
||||||
|
) : LongPollEvent
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,98 +0,0 @@
|
|||||||
package dev.meloda.fast.model
|
|
||||||
|
|
||||||
import dev.meloda.fast.model.api.domain.VkConversation
|
|
||||||
import dev.meloda.fast.model.api.domain.VkMessage
|
|
||||||
|
|
||||||
sealed interface LongPollParsedEvent {
|
|
||||||
|
|
||||||
data class NewMessage(
|
|
||||||
val message: VkMessage,
|
|
||||||
val inArchive: Boolean
|
|
||||||
) : LongPollParsedEvent
|
|
||||||
|
|
||||||
data class MessageEdited(val message: VkMessage) : LongPollParsedEvent
|
|
||||||
|
|
||||||
data class MessageUpdated(val message: VkMessage) : LongPollParsedEvent
|
|
||||||
|
|
||||||
data class MessageCacheClear(val message: VkMessage) : LongPollParsedEvent
|
|
||||||
|
|
||||||
data class IncomingMessageRead(
|
|
||||||
val peerId: Long,
|
|
||||||
val cmId: Long,
|
|
||||||
val unreadCount: Int,
|
|
||||||
) : LongPollParsedEvent
|
|
||||||
|
|
||||||
data class OutgoingMessageRead(
|
|
||||||
val peerId: Long,
|
|
||||||
val cmId: Long,
|
|
||||||
val unreadCount: Int,
|
|
||||||
) : LongPollParsedEvent
|
|
||||||
|
|
||||||
data class ChatMajorChanged(
|
|
||||||
val peerId: Long,
|
|
||||||
val majorId: Int,
|
|
||||||
) : LongPollParsedEvent
|
|
||||||
|
|
||||||
data class ChatMinorChanged(
|
|
||||||
val peerId: Long,
|
|
||||||
val minorId: Int
|
|
||||||
) : LongPollParsedEvent
|
|
||||||
|
|
||||||
data class Interaction(
|
|
||||||
val interactionType: InteractionType,
|
|
||||||
val peerId: Long,
|
|
||||||
val userIds: List<Long>,
|
|
||||||
val totalCount: Int,
|
|
||||||
val timestamp: Int
|
|
||||||
) : LongPollParsedEvent
|
|
||||||
|
|
||||||
data class UnreadCounter(
|
|
||||||
val unread: Int,
|
|
||||||
val unreadUnmuted: Int,
|
|
||||||
val showOnlyMuted: Boolean,
|
|
||||||
val business: Int,
|
|
||||||
val archive: Int,
|
|
||||||
val archiveUnmuted: Int,
|
|
||||||
val archiveMentions: Int
|
|
||||||
) : LongPollParsedEvent
|
|
||||||
|
|
||||||
data class MessageMarkedAsImportant(
|
|
||||||
val peerId: Long,
|
|
||||||
val cmId: Long,
|
|
||||||
val marked: Boolean
|
|
||||||
) : LongPollParsedEvent
|
|
||||||
|
|
||||||
data class MessageMarkedAsSpam(
|
|
||||||
val peerId: Long,
|
|
||||||
val cmId: Long
|
|
||||||
) : LongPollParsedEvent
|
|
||||||
|
|
||||||
data class MessageMarkedAsNotSpam(
|
|
||||||
val message: VkMessage
|
|
||||||
) : LongPollParsedEvent
|
|
||||||
|
|
||||||
data class MessageDeleted(
|
|
||||||
val peerId: Long,
|
|
||||||
val cmId: Long,
|
|
||||||
val forAll: Boolean
|
|
||||||
) : LongPollParsedEvent
|
|
||||||
|
|
||||||
data class MessageRestored(
|
|
||||||
val message: VkMessage
|
|
||||||
) : LongPollParsedEvent
|
|
||||||
|
|
||||||
data class AudioMessageListened(
|
|
||||||
val peerId: Long,
|
|
||||||
val cmId: Long
|
|
||||||
) : LongPollParsedEvent
|
|
||||||
|
|
||||||
data class ChatCleared(
|
|
||||||
val peerId: Long,
|
|
||||||
val toCmId: Long
|
|
||||||
) : LongPollParsedEvent
|
|
||||||
|
|
||||||
data class ChatArchived(
|
|
||||||
val conversation: VkConversation,
|
|
||||||
val archived: Boolean
|
|
||||||
) : LongPollParsedEvent
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
package dev.meloda.fast.model
|
|
||||||
|
|
||||||
enum class MessageFlags(val value: Int) {
|
|
||||||
UNREAD(1),
|
|
||||||
OUTGOING(2),
|
|
||||||
IMPORTANT(8),
|
|
||||||
SPAM(64),
|
|
||||||
DELETED(128),
|
|
||||||
AUDIO_LISTENED(4096),
|
|
||||||
FROM_GROUP_CHAT(8192),
|
|
||||||
CANCEL_SPAM(32768),
|
|
||||||
DELETED_FOR_ALL(131072),
|
|
||||||
DO_NOT_SHOW_NOTIFICATION(1048576),
|
|
||||||
MESSAGE_WITH_REPLY(2097152),
|
|
||||||
REACTION(16777216);
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
|
|
||||||
fun parse(mask: Int): List<MessageFlags> {
|
|
||||||
val flags = mutableListOf<MessageFlags>()
|
|
||||||
|
|
||||||
entries.forEach { flag ->
|
|
||||||
if (mask and flag.value > 0) {
|
|
||||||
flags.add(flag)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return flags
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
package dev.meloda.fast.model
|
|
||||||
|
|
||||||
data class PhotoSize(
|
|
||||||
val height: Int,
|
|
||||||
val width: Int,
|
|
||||||
val type: String,
|
|
||||||
val url: String
|
|
||||||
)
|
|
||||||
@@ -6,8 +6,8 @@ enum class AttachmentType(var value: String) {
|
|||||||
UNKNOWN("unknown"),
|
UNKNOWN("unknown"),
|
||||||
PHOTO("photo"),
|
PHOTO("photo"),
|
||||||
VIDEO("video"),
|
VIDEO("video"),
|
||||||
FILE("doc"),
|
|
||||||
AUDIO("audio"),
|
AUDIO("audio"),
|
||||||
|
FILE("doc"),
|
||||||
LINK("link"),
|
LINK("link"),
|
||||||
AUDIO_MESSAGE("audio_message"),
|
AUDIO_MESSAGE("audio_message"),
|
||||||
MINI_APP("mini_app"),
|
MINI_APP("mini_app"),
|
||||||
@@ -27,11 +27,7 @@ enum class AttachmentType(var value: String) {
|
|||||||
AUDIO_PLAYLIST("audio_playlist"),
|
AUDIO_PLAYLIST("audio_playlist"),
|
||||||
PODCAST("podcast"),
|
PODCAST("podcast"),
|
||||||
NARRATIVE("narrative"),
|
NARRATIVE("narrative"),
|
||||||
ARTICLE("article"),
|
ARTICLE("article");
|
||||||
VIDEO_MESSAGE("video_message"),
|
|
||||||
GROUP_CHAT_STICKER("ugc_sticker"),
|
|
||||||
STICKER_PACK_PREVIEW("sticker_pack_preview")
|
|
||||||
;
|
|
||||||
|
|
||||||
fun isMultiple(): Boolean = this in listOf(PHOTO, VIDEO, AUDIO, FILE)
|
fun isMultiple(): Boolean = this in listOf(PHOTO, VIDEO, AUDIO, FILE)
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import com.squareup.moshi.JsonClass
|
|||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
data class VkArticleData(
|
data class VkArticleData(
|
||||||
@Json(name = "id") val id: Long
|
@Json(name = "id") val id: Int
|
||||||
) : VkAttachmentData {
|
) : VkAttachmentData {
|
||||||
|
|
||||||
fun toDomain(): VkArticleDomain = VkArticleDomain(
|
fun toDomain(): VkArticleDomain = VkArticleDomain(
|
||||||
|
|||||||
+4
-4
@@ -1,15 +1,15 @@
|
|||||||
package dev.meloda.fast.model.api.data
|
package dev.meloda.fast.model.api.data
|
||||||
|
|
||||||
|
import dev.meloda.fast.model.api.domain.VkAttachmentHistoryMessage
|
||||||
import com.squareup.moshi.Json
|
import com.squareup.moshi.Json
|
||||||
import com.squareup.moshi.JsonClass
|
import com.squareup.moshi.JsonClass
|
||||||
import dev.meloda.fast.model.api.domain.VkAttachmentHistoryMessage
|
|
||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
data class VkAttachmentHistoryMessageData(
|
data class VkAttachmentHistoryMessageData(
|
||||||
@Json(name = "message_id") val messageId: Long,
|
@Json(name = "message_id") val messageId: Int,
|
||||||
@Json(name = "date") val date: Int,
|
@Json(name = "date") val date: Int,
|
||||||
@Json(name = "cmid") val conversationMessageId: Long,
|
@Json(name = "cmid") val conversationMessageId: Int,
|
||||||
@Json(name = "from_id") val fromId: Long,
|
@Json(name = "from_id") val fromId: Int,
|
||||||
@Json(name = "position") val position: Int,
|
@Json(name = "position") val position: Int,
|
||||||
@Json(name = "attachment") val attachment: VkAttachmentItemData
|
@Json(name = "attachment") val attachment: VkAttachmentItemData
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package dev.meloda.fast.model.api.data
|
package dev.meloda.fast.model.api.data
|
||||||
|
|
||||||
import com.squareup.moshi.Json
|
|
||||||
import com.squareup.moshi.JsonClass
|
|
||||||
import dev.meloda.fast.model.api.domain.VkAttachment
|
import dev.meloda.fast.model.api.domain.VkAttachment
|
||||||
import dev.meloda.fast.model.api.domain.VkUnknownAttachment
|
import dev.meloda.fast.model.api.domain.VkUnknownAttachment
|
||||||
|
import com.squareup.moshi.Json
|
||||||
|
import com.squareup.moshi.JsonClass
|
||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
data class VkAttachmentItemData(
|
data class VkAttachmentItemData(
|
||||||
@@ -32,10 +32,7 @@ data class VkAttachmentItemData(
|
|||||||
@Json(name = "audio_playlist") val audioPlaylist: VkAudioPlaylistData?,
|
@Json(name = "audio_playlist") val audioPlaylist: VkAudioPlaylistData?,
|
||||||
@Json(name = "podcast") val podcast: VkPodcastData?,
|
@Json(name = "podcast") val podcast: VkPodcastData?,
|
||||||
@Json(name = "narrative") val narrative: VkNarrativeData?,
|
@Json(name = "narrative") val narrative: VkNarrativeData?,
|
||||||
@Json(name = "article") val article: VkArticleData?,
|
@Json(name = "article") val article: VkArticleData?
|
||||||
@Json(name = "video_message") val videoMessage: VkVideoMessageData?,
|
|
||||||
@Json(name = "ugc_sticker") val groupSticker: VkGroupStickerData?,
|
|
||||||
@Json(name = "sticker_pack_preview") val stickerPackPreview: VkStickerPackPreviewData?
|
|
||||||
) {
|
) {
|
||||||
fun toDomain(): VkAttachment = when (AttachmentType.parse(type)) {
|
fun toDomain(): VkAttachment = when (AttachmentType.parse(type)) {
|
||||||
AttachmentType.UNKNOWN -> VkUnknownAttachment
|
AttachmentType.UNKNOWN -> VkUnknownAttachment
|
||||||
@@ -63,8 +60,5 @@ data class VkAttachmentItemData(
|
|||||||
AttachmentType.PODCAST -> podcast?.toDomain()
|
AttachmentType.PODCAST -> podcast?.toDomain()
|
||||||
AttachmentType.NARRATIVE -> narrative?.toDomain()
|
AttachmentType.NARRATIVE -> narrative?.toDomain()
|
||||||
AttachmentType.ARTICLE -> article?.toDomain()
|
AttachmentType.ARTICLE -> article?.toDomain()
|
||||||
AttachmentType.VIDEO_MESSAGE -> videoMessage?.toDomain()
|
|
||||||
AttachmentType.GROUP_CHAT_STICKER -> groupSticker?.toDomain()
|
|
||||||
AttachmentType.STICKER_PACK_PREVIEW -> stickerPackPreview?.toDomain()
|
|
||||||
} ?: VkUnknownAttachment
|
} ?: VkUnknownAttachment
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,33 +1,33 @@
|
|||||||
package dev.meloda.fast.model.api.data
|
package dev.meloda.fast.model.api.data
|
||||||
|
|
||||||
|
import dev.meloda.fast.model.api.domain.VkAudioDomain
|
||||||
import com.squareup.moshi.Json
|
import com.squareup.moshi.Json
|
||||||
import com.squareup.moshi.JsonClass
|
import com.squareup.moshi.JsonClass
|
||||||
import dev.meloda.fast.model.api.domain.VkAudioDomain
|
|
||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
data class VkAudioData(
|
data class VkAudioData(
|
||||||
@Json(name = "id") val id: Long,
|
@Json(name = "id") val id: Int,
|
||||||
@Json(name = "title") val title: String,
|
@Json(name = "title") val title: String,
|
||||||
@Json(name = "artist") val artist: String,
|
@Json(name = "artist") val artist: String,
|
||||||
@Json(name = "duration") val duration: Int,
|
@Json(name = "duration") val duration: Int,
|
||||||
@Json(name = "url") val url: String,
|
@Json(name = "url") val url: String,
|
||||||
@Json(name = "date") val date: Int,
|
@Json(name = "date") val date: Int,
|
||||||
@Json(name = "owner_id") val ownerId: Long,
|
@Json(name = "owner_id") val ownerId: Int,
|
||||||
@Json(name = "access_key") val accessKey: String?,
|
@Json(name = "access_key") val accessKey: String?,
|
||||||
@Json(name = "is_explicit") val isExplicit: Boolean,
|
@Json(name = "is_explicit") val isExplicit: Boolean,
|
||||||
@Json(name = "is_focus_track") val isFocusTrack: Boolean,
|
@Json(name = "is_focus_track") val isFocusTrack: Boolean,
|
||||||
@Json(name = "is_licensed") val isLicensed: Boolean?,
|
@Json(name = "is_licensed") val isLicensed: Boolean?,
|
||||||
@Json(name = "genre_id") val genreId: Long?,
|
@Json(name = "genre_id") val genreId: Int?,
|
||||||
@Json(name = "album") val album: Album?,
|
@Json(name = "album") val album: Album?,
|
||||||
) : VkAttachmentData {
|
) : VkAttachmentData {
|
||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
data class Album(
|
data class Album(
|
||||||
@Json(name = "id") val id: Long,
|
@Json(name = "id") val id: Int,
|
||||||
@Json(name = "title") val title: String,
|
@Json(name = "title") val title: String,
|
||||||
@Json(name = "owner_id") val ownerId: Long,
|
@Json(name = "owner_id") val ownerId: Int,
|
||||||
@Json(name = "access_key") val accessKey: String,
|
@Json(name = "access_key") val accessKey: String,
|
||||||
@Json(name = "thumb") val thumb: Thumb?
|
@Json(name = "thumb") val thumb: Thumb
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import com.squareup.moshi.JsonClass
|
|||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
data class VkAudioMessageData(
|
data class VkAudioMessageData(
|
||||||
@Json(name = "id") val id: Long,
|
@Json(name = "id") val id: Int,
|
||||||
@Json(name = "owner_id") val ownerId: Long,
|
@Json(name = "owner_id") val ownerId: Int,
|
||||||
@Json(name = "duration") val duration: Int,
|
@Json(name = "duration") val duration: Int,
|
||||||
@Json(name = "waveform") val waveform: List<Int>,
|
@Json(name = "waveform") val waveform: List<Int>,
|
||||||
@Json(name = "link_ogg") val linkOgg: String,
|
@Json(name = "link_ogg") val linkOgg: String,
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import com.squareup.moshi.JsonClass
|
|||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
data class VkAudioPlaylistData(
|
data class VkAudioPlaylistData(
|
||||||
@Json(name = "id") val id: Long,
|
@Json(name = "id") val id: Int,
|
||||||
@Json(name = "owner_id") val ownerId: Long,
|
@Json(name = "owner_id") val ownerId: Int,
|
||||||
@Json(name = "type") val type: Int,
|
@Json(name = "type") val type: Int,
|
||||||
@Json(name = "title") val title: String,
|
@Json(name = "title") val title: String,
|
||||||
@Json(name = "description") val description: String,
|
@Json(name = "description") val description: String,
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import com.squareup.moshi.JsonClass
|
|||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
data class VkCallData(
|
data class VkCallData(
|
||||||
@Json(name = "initiator_id") val initiatorId: Long,
|
@Json(name = "initiator_id") val initiatorId: Int,
|
||||||
@Json(name = "receiver_id") val receiverId: Long,
|
@Json(name = "receiver_id") val receiverId: Int,
|
||||||
@Json(name = "state") val state: String,
|
@Json(name = "state") val state: String,
|
||||||
@Json(name = "time") val time: Int,
|
@Json(name = "time") val time: Int,
|
||||||
@Json(name = "duration") val duration: Int,
|
@Json(name = "duration") val duration: Int,
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ import com.squareup.moshi.JsonClass
|
|||||||
data class VkChatData(
|
data class VkChatData(
|
||||||
@Json(name = "type") val type: String,
|
@Json(name = "type") val type: String,
|
||||||
@Json(name = "val title") val title: String,
|
@Json(name = "val title") val title: String,
|
||||||
@Json(name = "admin_id") val adminId: Long,
|
@Json(name = "admin_id") val adminId: Int,
|
||||||
@Json(name = "members_count") val membersCount: Int,
|
@Json(name = "members_count") val membersCount: Int,
|
||||||
@Json(name = "id") val id: Long,
|
@Json(name = "id") val id: Int,
|
||||||
@Json(name = "photo_50") val photo50: String,
|
@Json(name = "photo_50") val photo50: String,
|
||||||
@Json(name = "photo_100") val photo100: String,
|
@Json(name = "photo_100") val photo100: String,
|
||||||
@Json(name = "photo_200") val photo200: String,
|
@Json(name = "photo_200") val photo200: String,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import com.squareup.moshi.JsonClass
|
|||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
data class VkChatMemberData(
|
data class VkChatMemberData(
|
||||||
@Json(name = "member_id") val memberId: Long,
|
@Json(name = "member_id") val memberId: Int,
|
||||||
@Json(name = "invited_by") val invitedBy: Int,
|
@Json(name = "invited_by") val invitedBy: Int,
|
||||||
@Json(name = "join_date") val joinDate: Int,
|
@Json(name = "join_date") val joinDate: Int,
|
||||||
@Json(name = "is_admin") val isAdmin: Boolean?,
|
@Json(name = "is_admin") val isAdmin: Boolean?,
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ import com.squareup.moshi.JsonClass
|
|||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
data class VkContactData(
|
data class VkContactData(
|
||||||
@Json(name = "id") val id: Long,
|
@Json(name = "id") val id: Int,
|
||||||
@Json(name = "name") val name: String,
|
@Json(name = "name") val name: String,
|
||||||
@Json(name = "can_write") val canWrite: Boolean,
|
@Json(name = "can_write") val canWrite: Boolean,
|
||||||
@Json(name = "user_id") val userId: Long,
|
@Json(name = "user_id") val userId: Int,
|
||||||
@Json(name = "last_seen_status") val lastSeenStatus: String?,
|
@Json(name = "last_seen_status") val lastSeenStatus: String?,
|
||||||
@Json(name = "photo_50") val photo50: String?,
|
@Json(name = "photo_50") val photo50: String?,
|
||||||
@Json(name = "calls_id") val callsId: String
|
@Json(name = "calls_id") val callsId: String
|
||||||
|
|||||||
@@ -1,21 +1,21 @@
|
|||||||
package dev.meloda.fast.model.api.data
|
package dev.meloda.fast.model.api.data
|
||||||
|
|
||||||
import com.squareup.moshi.Json
|
|
||||||
import com.squareup.moshi.JsonClass
|
|
||||||
import dev.meloda.fast.model.api.PeerType
|
import dev.meloda.fast.model.api.PeerType
|
||||||
import dev.meloda.fast.model.api.domain.VkConversation
|
import dev.meloda.fast.model.api.domain.VkConversation
|
||||||
import dev.meloda.fast.model.api.domain.VkMessage
|
import dev.meloda.fast.model.api.domain.VkMessage
|
||||||
|
import com.squareup.moshi.Json
|
||||||
|
import com.squareup.moshi.JsonClass
|
||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
data class VkConversationData(
|
data class VkConversationData(
|
||||||
@Json(name = "peer") val peer: Peer,
|
@Json(name = "peer") val peer: Peer,
|
||||||
@Json(name = "last_message_id") val lastMessageId: Long?,
|
@Json(name = "last_message_id") val lastMessageId: Int?,
|
||||||
@Json(name = "in_read") val inRead: Long,
|
@Json(name = "in_read") val inRead: Int,
|
||||||
@Json(name = "out_read") val outRead: Long,
|
@Json(name = "out_read") val outRead: Int,
|
||||||
@Json(name = "in_read_cmid") val inReadConversationMessageId: Long,
|
@Json(name = "in_read_cmid") val inReadConversationMessageId: Int,
|
||||||
@Json(name = "out_read_cmid") val outReadConversationMessageId: Long,
|
@Json(name = "out_read_cmid") val outReadConversationMessageId: Int,
|
||||||
@Json(name = "sort_id") val sortId: SortId,
|
@Json(name = "sort_id") val sortId: SortId,
|
||||||
@Json(name = "last_conversation_message_id") val lastConversationMessageId: Long,
|
@Json(name = "last_conversation_message_id") val lastConversationMessageId: Int,
|
||||||
@Json(name = "is_marked_unread") val isMarkedUnread: Boolean,
|
@Json(name = "is_marked_unread") val isMarkedUnread: Boolean,
|
||||||
@Json(name = "important") val important: Boolean,
|
@Json(name = "important") val important: Boolean,
|
||||||
@Json(name = "push_settings") val pushSettings: PushSettings?,
|
@Json(name = "push_settings") val pushSettings: PushSettings?,
|
||||||
@@ -25,14 +25,13 @@ data class VkConversationData(
|
|||||||
@Json(name = "chat_settings") val chatSettings: ChatSettings?,
|
@Json(name = "chat_settings") val chatSettings: ChatSettings?,
|
||||||
@Json(name = "call_in_progress") val callInProgress: CallInProgress?,
|
@Json(name = "call_in_progress") val callInProgress: CallInProgress?,
|
||||||
@Json(name = "unread_count") val unreadCount: Int?,
|
@Json(name = "unread_count") val unreadCount: Int?,
|
||||||
@Json(name = "is_archived") val isArchived: Boolean?
|
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
data class Peer(
|
data class Peer(
|
||||||
@Json(name = "id") val id: Long,
|
@Json(name = "id") val id: Int,
|
||||||
@Json(name = "type") val type: String,
|
@Json(name = "type") val type: String,
|
||||||
@Json(name = "local_id") val localId: Long,
|
@Json(name = "local_id") val localId: Int,
|
||||||
)
|
)
|
||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
@@ -56,7 +55,7 @@ data class VkConversationData(
|
|||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
data class ChatSettings(
|
data class ChatSettings(
|
||||||
@Json(name = "owner_id") val ownerId: Long,
|
@Json(name = "owner_id") val ownerId: Int,
|
||||||
@Json(name = "title") val title: String,
|
@Json(name = "title") val title: String,
|
||||||
@Json(name = "state") val state: String,
|
@Json(name = "state") val state: String,
|
||||||
@Json(name = "acl") val acl: Acl,
|
@Json(name = "acl") val acl: Acl,
|
||||||
@@ -120,7 +119,7 @@ data class VkConversationData(
|
|||||||
photo200 = chatSettings?.photo?.photo200,
|
photo200 = chatSettings?.photo?.photo200,
|
||||||
isCallInProgress = callInProgress != null,
|
isCallInProgress = callInProgress != null,
|
||||||
isPhantom = chatSettings?.isDisappearing == true,
|
isPhantom = chatSettings?.isDisappearing == true,
|
||||||
lastCmId = lastConversationMessageId,
|
lastConversationMessageId = lastConversationMessageId,
|
||||||
inRead = inRead,
|
inRead = inRead,
|
||||||
outRead = outRead,
|
outRead = outRead,
|
||||||
lastMessageId = lastMessageId,
|
lastMessageId = lastMessageId,
|
||||||
@@ -141,6 +140,5 @@ data class VkConversationData(
|
|||||||
pinnedMessage = chatSettings?.pinnedMessage?.mapToDomain(),
|
pinnedMessage = chatSettings?.pinnedMessage?.mapToDomain(),
|
||||||
user = null,
|
user = null,
|
||||||
group = null,
|
group = null,
|
||||||
isArchived = isArchived == true
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import com.squareup.moshi.JsonClass
|
|||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
data class VkCuratorData(
|
data class VkCuratorData(
|
||||||
val id: Long,
|
val id: Int,
|
||||||
val name: String,
|
val name: String,
|
||||||
val description: String,
|
val description: String,
|
||||||
val url: String,
|
val url: String,
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import com.squareup.moshi.JsonClass
|
|||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
data class VkEventData(
|
data class VkEventData(
|
||||||
@Json(name = "button_text") val buttonText: String,
|
@Json(name = "button_text") val buttonText: String,
|
||||||
@Json(name = "id") val id: Long,
|
@Json(name = "id") val id: Int,
|
||||||
@Json(name = "is_favorite") val isFavorite: Boolean,
|
@Json(name = "is_favorite") val isFavorite: Boolean,
|
||||||
@Json(name = "text") val text: String,
|
@Json(name = "text") val text: String,
|
||||||
@Json(name = "address") val address: String,
|
@Json(name = "address") val address: String,
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
package dev.meloda.fast.model.api.data
|
package dev.meloda.fast.model.api.data
|
||||||
|
|
||||||
|
import dev.meloda.fast.model.api.domain.VkFileDomain
|
||||||
import com.squareup.moshi.Json
|
import com.squareup.moshi.Json
|
||||||
import com.squareup.moshi.JsonClass
|
import com.squareup.moshi.JsonClass
|
||||||
import dev.meloda.fast.model.api.domain.VkFileDomain
|
|
||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
data class VkFileData(
|
data class VkFileData(
|
||||||
@Json(name = "id") val id: Long,
|
@Json(name = "id") val id: Int,
|
||||||
@Json(name = "owner_id") val ownerId: Long,
|
@Json(name = "owner_id") val ownerId: Int,
|
||||||
@Json(name = "title") val title: String,
|
@Json(name = "title") val title: String,
|
||||||
@Json(name = "size") val size: Int,
|
@Json(name = "size") val size: Int,
|
||||||
@Json(name = "ext") val extension: String,
|
@Json(name = "ext") val extension: String,
|
||||||
@@ -27,9 +27,7 @@ data class VkFileData(
|
|||||||
) {
|
) {
|
||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
data class Photo(
|
data class Photo(val sizes: List<Size>) {
|
||||||
val sizes: List<Size>
|
|
||||||
) {
|
|
||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
data class Size(
|
data class Size(
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import com.squareup.moshi.JsonClass
|
|||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
data class VkGiftData(
|
data class VkGiftData(
|
||||||
@Json(name = "id") val id: Long,
|
@Json(name = "id") val id: Int,
|
||||||
@Json(name = "thumb_256") val thumb256: String?,
|
@Json(name = "thumb_256") val thumb256: String?,
|
||||||
@Json(name = "thumb_96") val thumb96: String?,
|
@Json(name = "thumb_96") val thumb96: String?,
|
||||||
@Json(name = "thumb_48") val thumb48: String
|
@Json(name = "thumb_48") val thumb48: String
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
package dev.meloda.fast.model.api.data
|
package dev.meloda.fast.model.api.data
|
||||||
|
|
||||||
|
import dev.meloda.fast.model.api.domain.VkGraffitiDomain
|
||||||
import com.squareup.moshi.Json
|
import com.squareup.moshi.Json
|
||||||
import com.squareup.moshi.JsonClass
|
import com.squareup.moshi.JsonClass
|
||||||
import dev.meloda.fast.model.api.domain.VkGraffitiDomain
|
|
||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
data class VkGraffitiData(
|
data class VkGraffitiData(
|
||||||
@Json(name = "id") val id: Long,
|
@Json(name = "id") val id: Int,
|
||||||
@Json(name = "owner_id") val ownerId: Long,
|
@Json(name = "owner_id") val ownerId: Int,
|
||||||
@Json(name = "url") val url: String,
|
@Json(name = "url") val url: String,
|
||||||
@Json(name = "width") val width: Int,
|
@Json(name = "width") val width: Int,
|
||||||
@Json(name = "height") val height: Int,
|
@Json(name = "height") val height: Int,
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package dev.meloda.fast.model.api.data
|
package dev.meloda.fast.model.api.data
|
||||||
|
|
||||||
|
import dev.meloda.fast.model.api.domain.VkGroupCallDomain
|
||||||
import com.squareup.moshi.Json
|
import com.squareup.moshi.Json
|
||||||
import com.squareup.moshi.JsonClass
|
import com.squareup.moshi.JsonClass
|
||||||
import dev.meloda.fast.model.api.domain.VkGroupCallDomain
|
|
||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
data class VkGroupCallData(
|
data class VkGroupCallData(
|
||||||
@Json(name = "initiator_id") val initiatorId: Long,
|
@Json(name = "initiator_id") val initiatorId: Int,
|
||||||
@Json(name = "join_link") val joinLink: String,
|
@Json(name = "join_link") val joinLink: String,
|
||||||
@Json(name = "participants") val participants: Participants
|
@Json(name = "participants") val participants: Participants
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import kotlin.math.abs
|
|||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
data class VkGroupData(
|
data class VkGroupData(
|
||||||
@Json(name = "id") val id: Long,
|
@Json(name = "id") val id: Int,
|
||||||
@Json(name = "name") val name: String,
|
@Json(name = "name") val name: String,
|
||||||
@Json(name = "screen_name") val screenName: String,
|
@Json(name = "screen_name") val screenName: String,
|
||||||
@Json(name = "is_closed") val isClosed: Int?,
|
@Json(name = "is_closed") val isClosed: Int?,
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
package dev.meloda.fast.model.api.data
|
|
||||||
|
|
||||||
import com.squareup.moshi.Json
|
|
||||||
import com.squareup.moshi.JsonClass
|
|
||||||
import dev.meloda.fast.model.api.domain.VkGroupStickerDomain
|
|
||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
|
||||||
data class VkGroupStickerData(
|
|
||||||
val id: Long,
|
|
||||||
val owner_id: Long,
|
|
||||||
val pack_id: Long?,
|
|
||||||
val status: String?,
|
|
||||||
val is_deleted: Boolean?,
|
|
||||||
val images: List<Image>?
|
|
||||||
): VkAttachmentData {
|
|
||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
|
||||||
data class Image(
|
|
||||||
@Json(name = "width") val width: Int,
|
|
||||||
@Json(name = "height") val height: Int,
|
|
||||||
@Json(name = "url") val url: String
|
|
||||||
)
|
|
||||||
|
|
||||||
fun toDomain(): VkGroupStickerDomain = VkGroupStickerDomain(
|
|
||||||
id = id
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,33 +1,29 @@
|
|||||||
package dev.meloda.fast.model.api.data
|
package dev.meloda.fast.model.api.data
|
||||||
|
|
||||||
|
import dev.meloda.fast.model.api.domain.VkMessage
|
||||||
import com.squareup.moshi.Json
|
import com.squareup.moshi.Json
|
||||||
import com.squareup.moshi.JsonClass
|
import com.squareup.moshi.JsonClass
|
||||||
import dev.meloda.fast.model.api.domain.FormatDataType
|
|
||||||
import dev.meloda.fast.model.api.domain.VkMessage
|
|
||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
data class VkMessageData(
|
data class VkMessageData(
|
||||||
@Json(name = "id") val id: Long?,
|
@Json(name = "id") val id: Int?,
|
||||||
@Json(name = "peer_id") val peerId: Long?,
|
@Json(name = "peer_id") val peerId: Int?,
|
||||||
@Json(name = "date") val date: Int,
|
@Json(name = "date") val date: Int,
|
||||||
@Json(name = "from_id") val fromId: Long,
|
@Json(name = "from_id") val fromId: Int,
|
||||||
@Json(name = "out") val out: Int?,
|
@Json(name = "out") val out: Int?,
|
||||||
@Json(name = "text") val text: String,
|
@Json(name = "text") val text: String,
|
||||||
@Json(name = "conversation_message_id") val cmId: Long,
|
@Json(name = "conversation_message_id") val conversationMessageId: Int,
|
||||||
@Json(name = "fwd_messages") val fwdMessages: List<VkMessageData>? = emptyList(),
|
@Json(name = "fwd_messages") val fwdMessages: List<VkMessageData>? = emptyList(),
|
||||||
@Json(name = "important") val important: Boolean?,
|
@Json(name = "important") val important: Boolean = false,
|
||||||
@Json(name = "random_id") val randomId: Long?,
|
@Json(name = "random_id") val randomId: Int = 0,
|
||||||
@Json(name = "attachments") val attachments: List<VkAttachmentItemData> = emptyList(),
|
@Json(name = "attachments") val attachments: List<VkAttachmentItemData> = emptyList(),
|
||||||
@Json(name = "is_hidden") val isHidden: Boolean?,
|
@Json(name = "is_hidden") val isHidden: Boolean = false,
|
||||||
@Json(name = "payload") val payload: String?,
|
@Json(name = "payload") val payload: String?,
|
||||||
@Json(name = "geo") val geo: Geo?,
|
@Json(name = "geo") val geo: Geo?,
|
||||||
@Json(name = "action") val action: Action?,
|
@Json(name = "action") val action: Action?,
|
||||||
@Json(name = "ttl") val ttl: Int?,
|
@Json(name = "ttl") val ttl: Int?,
|
||||||
@Json(name = "reply_message") val replyMessage: VkMessageData?,
|
@Json(name = "reply_message") val replyMessage: VkMessageData?,
|
||||||
@Json(name = "update_time") val updateTime: Int?,
|
@Json(name = "update_time") val updateTime: Int?
|
||||||
@Json(name = "is_pinned") val isPinned: Boolean?,
|
|
||||||
@Json(name = "pinned_at") val pinnedAt: Int?,
|
|
||||||
@Json(name = "format_data") val formatData: FormatData?
|
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
@@ -54,58 +50,29 @@ data class VkMessageData(
|
|||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
data class Action(
|
data class Action(
|
||||||
@Json(name = "type") val type: String,
|
@Json(name = "type") val type: String,
|
||||||
@Json(name = "member_id") val memberId: Long?,
|
@Json(name = "member_id") val memberId: Int?,
|
||||||
@Json(name = "text") val text: String?,
|
@Json(name = "text") val text: String?,
|
||||||
@Json(name = "conversation_message_id") val conversationMessageId: Long?,
|
@Json(name = "conversation_message_id") val conversationMessageId: Int?,
|
||||||
@Json(name = "message") val message: String?
|
@Json(name = "message") val message: String?
|
||||||
)
|
)
|
||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
|
||||||
data class FormatData(
|
|
||||||
@Json(name = "version") val version: String,
|
|
||||||
@Json(name = "items") val items: List<Item>
|
|
||||||
) {
|
|
||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
|
||||||
data class Item(
|
|
||||||
@Json(name = "offset") val offset: Int,
|
|
||||||
@Json(name = "length") val length: Int,
|
|
||||||
@Json(name = "type") val type: String,
|
|
||||||
@Json(name = "url") val url: String?
|
|
||||||
)
|
|
||||||
|
|
||||||
fun asDomain(): VkMessage.FormatData = VkMessage.FormatData(
|
|
||||||
version = version,
|
|
||||||
items = items.mapNotNull { item ->
|
|
||||||
FormatDataType.parse(item.type)?.let { type ->
|
|
||||||
VkMessage.FormatData.Item(
|
|
||||||
offset = item.offset,
|
|
||||||
length = item.length,
|
|
||||||
type = type,
|
|
||||||
url = item.url
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun VkMessageData.asDomain(): VkMessage = VkMessage(
|
fun VkMessageData.asDomain(): VkMessage = VkMessage(
|
||||||
id = id ?: -1,
|
id = id ?: -1,
|
||||||
cmId = cmId,
|
conversationMessageId = conversationMessageId,
|
||||||
text = text.ifBlank { null },
|
text = text.ifBlank { null },
|
||||||
isOut = out == 1,
|
isOut = out == 1,
|
||||||
peerId = peerId ?: -1,
|
peerId = peerId ?: -1,
|
||||||
fromId = fromId,
|
fromId = fromId,
|
||||||
date = date,
|
date = date,
|
||||||
randomId = randomId ?: 0,
|
randomId = randomId,
|
||||||
action = VkMessage.Action.parse(action?.type),
|
action = VkMessage.Action.parse(action?.type),
|
||||||
actionMemberId = action?.memberId,
|
actionMemberId = action?.memberId,
|
||||||
actionText = action?.text,
|
actionText = action?.text,
|
||||||
actionConversationMessageId = action?.conversationMessageId,
|
actionConversationMessageId = action?.conversationMessageId,
|
||||||
actionMessage = action?.message,
|
actionMessage = action?.message,
|
||||||
geoType = geo?.type,
|
geoType = geo?.type,
|
||||||
isImportant = important ?: false,
|
important = important,
|
||||||
updateTime = updateTime,
|
updateTime = updateTime,
|
||||||
forwards = fwdMessages.orEmpty().map(VkMessageData::asDomain),
|
forwards = fwdMessages.orEmpty().map(VkMessageData::asDomain),
|
||||||
attachments = attachments.map(VkAttachmentItemData::toDomain),
|
attachments = attachments.map(VkAttachmentItemData::toDomain),
|
||||||
@@ -114,8 +81,4 @@ fun VkMessageData.asDomain(): VkMessage = VkMessage(
|
|||||||
group = null,
|
group = null,
|
||||||
actionUser = null,
|
actionUser = null,
|
||||||
actionGroup = null,
|
actionGroup = null,
|
||||||
pinnedAt = pinnedAt,
|
|
||||||
isPinned = isPinned == true,
|
|
||||||
formatData = formatData?.asDomain(),
|
|
||||||
isSpam = false
|
|
||||||
)
|
)
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user