|
|
@@ -2,6 +2,7 @@ package com.iscs.bozzys.ui.pages.vm
|
|
|
|
|
|
import androidx.compose.ui.graphics.Color
|
|
|
import androidx.lifecycle.viewModelScope
|
|
|
+import com.alibaba.sdk.android.push.noonesdk.PushServiceFactory
|
|
|
import com.iscs.bozzys.R
|
|
|
import com.iscs.bozzys.api.ApiRequest
|
|
|
import com.iscs.bozzys.api.ApiRequest.getResponse
|
|
|
@@ -16,6 +17,7 @@ import com.iscs.bozzys.event.RefreshEventBus
|
|
|
import com.iscs.bozzys.ui.common.VMBase
|
|
|
import com.iscs.bozzys.ui.theme.Text
|
|
|
import com.iscs.bozzys.utils.Storage
|
|
|
+import com.iscs.bozzys.utils.Storage.saveRoleList
|
|
|
import com.iscs.bozzys.utils.Storage.saveUserAvatar
|
|
|
import com.iscs.bozzys.utils.isAdmin
|
|
|
import kotlinx.coroutines.async
|
|
|
@@ -122,6 +124,8 @@ class VMHome : VMBase() {
|
|
|
fun getHomeTaskData(showLoading: Boolean = false, done: () -> Unit = {}) {
|
|
|
viewModelScope.launch {
|
|
|
loading.emit(StateLoading(show = showLoading))
|
|
|
+ // 执行消息推送注册
|
|
|
+ registerPush()
|
|
|
// 查询权限信息
|
|
|
val permissionRsp = ApiRequest.getUserPermission().getOrElse { it.getResponse() }
|
|
|
if (!permissionRsp.code.isCodeOk()) {
|
|
|
@@ -189,6 +193,7 @@ class VMHome : VMBase() {
|
|
|
return@launch
|
|
|
}
|
|
|
permissionRsp.data?.user?.avatar.saveUserAvatar()
|
|
|
+ permissionRsp.data?.roleList?.saveRoleList()
|
|
|
_state.value = _state.value.copy(
|
|
|
homeTasks = ArrayList(tasksRsp.data?.list ?: emptyList()),
|
|
|
messageList = ArrayList(msgRsp.data?.list ?: emptyList()),
|
|
|
@@ -290,6 +295,15 @@ class VMHome : VMBase() {
|
|
|
*/
|
|
|
fun logout(done: () -> Unit) {
|
|
|
viewModelScope.launch {
|
|
|
+ val deviceId = PushServiceFactory.getCloudPushService().deviceId
|
|
|
+ // 执行注销消息推送操作
|
|
|
+ if (!deviceId.isNullOrEmpty()) {
|
|
|
+ val rsp = ApiRequest.updateMessagePushStatus(deviceId, true).getOrElse { it.getResponse() }
|
|
|
+ if (!rsp.code.isCodeOk()) {
|
|
|
+ toast.emit(rsp.msg)
|
|
|
+ return@launch
|
|
|
+ }
|
|
|
+ }
|
|
|
ApiRequest.logout().onSuccess {
|
|
|
// 清除本地数据
|
|
|
Storage.saveLogin(false)
|
|
|
@@ -321,6 +335,19 @@ class VMHome : VMBase() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 消息推送注册
|
|
|
+ */
|
|
|
+ private fun registerPush() {
|
|
|
+ viewModelScope.launch {
|
|
|
+ val pushService = PushServiceFactory.getCloudPushService()
|
|
|
+ val deviceId = pushService.deviceId
|
|
|
+ if (deviceId.isNullOrEmpty()) return@launch
|
|
|
+ // 不处理结果
|
|
|
+ ApiRequest.updateMessagePushStatus(deviceId, false)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|