登出时取消消息推送注册
This commit is contained in:
@@ -49,7 +49,7 @@ object AppState {
|
||||
UserId = resp.id
|
||||
|
||||
// 注册 JPush
|
||||
Messaging.RegistDevice(scope, context)
|
||||
Messaging.registerDevice(scope, context)
|
||||
// 注册 Trtc
|
||||
val config = V2TIMSDKConfig()
|
||||
|
||||
@@ -140,6 +140,5 @@ object AppState {
|
||||
TrtcService::class.java
|
||||
)
|
||||
context.stopService(trtcService)
|
||||
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,9 @@ import android.content.Context
|
||||
object ConstVars {
|
||||
// api 地址
|
||||
// const val BASE_SERVER = "http://192.168.31.130:8088"
|
||||
const val BASE_SERVER = "http://192.168.142.140:8088"
|
||||
// const val BASE_SERVER = "https://8.137.22.101:8088"
|
||||
const val BASE_SERVER = "https://rider-pro.aiosman.com/beta_api"
|
||||
// const val BASE_SERVER = "https://rider-pro.aiosman.com/beta_api"
|
||||
|
||||
const val MOMENT_LIKE_CHANNEL_ID = "moment_like"
|
||||
const val MOMENT_LIKE_CHANNEL_NAME = "Moment Like"
|
||||
|
||||
@@ -11,12 +11,17 @@ import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
object Messaging {
|
||||
fun RegistDevice(scope: CoroutineScope, context: Context) {
|
||||
fun registerDevice(scope: CoroutineScope, context: Context) {
|
||||
|
||||
registerJpush(scope, context)
|
||||
// registerFCM(scope)
|
||||
}
|
||||
|
||||
suspend fun unregisterDevice(context: Context) {
|
||||
unregisterJpush(context)
|
||||
}
|
||||
|
||||
|
||||
fun registerJpush(scope: CoroutineScope, context: Context) {
|
||||
val accountService: AccountService = AccountServiceImpl()
|
||||
val regId = JPushInterface.getRegistrationID(context)
|
||||
@@ -25,6 +30,12 @@ object Messaging {
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun unregisterJpush(context: Context) {
|
||||
val accountService: AccountService = AccountServiceImpl()
|
||||
val regId = JPushInterface.getRegistrationID(context)
|
||||
accountService.unregisterMessageChannel(client = "jpush", identifier = regId)
|
||||
}
|
||||
|
||||
fun registerFCM(scope: CoroutineScope) {
|
||||
val accountService: AccountService = AccountServiceImpl()
|
||||
FirebaseMessaging.getInstance().token.addOnCompleteListener(OnCompleteListener { task ->
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.aiosman.riderpro.data.api.RegisterMessageChannelRequestBody
|
||||
import com.aiosman.riderpro.data.api.RegisterRequestBody
|
||||
import com.aiosman.riderpro.data.api.ResetPasswordRequestBody
|
||||
import com.aiosman.riderpro.data.api.TrtcSignResponseBody
|
||||
import com.aiosman.riderpro.data.api.UnRegisterMessageChannelRequestBody
|
||||
import com.aiosman.riderpro.data.api.UpdateNoticeRequestBody
|
||||
import com.aiosman.riderpro.data.api.UpdateUserLangRequestBody
|
||||
import com.aiosman.riderpro.entity.AccountFavouriteEntity
|
||||
@@ -360,6 +361,11 @@ interface AccountService {
|
||||
*/
|
||||
suspend fun registerMessageChannel(client: String, identifier: String)
|
||||
|
||||
/**
|
||||
* 取消注册消息通道
|
||||
*/
|
||||
suspend fun unregisterMessageChannel(client: String, identifier: String)
|
||||
|
||||
/**
|
||||
* 重置密码
|
||||
*/
|
||||
@@ -501,6 +507,10 @@ class AccountServiceImpl : AccountService {
|
||||
ApiClient.api.registerMessageChannel(RegisterMessageChannelRequestBody(client, identifier))
|
||||
}
|
||||
|
||||
override suspend fun unregisterMessageChannel(client: String, identifier: String) {
|
||||
ApiClient.api.unRegisterMessageChannel(UnRegisterMessageChannelRequestBody(client, identifier))
|
||||
}
|
||||
|
||||
override suspend fun resetPassword(email: String) {
|
||||
val resp = ApiClient.api.resetPassword(
|
||||
ResetPasswordRequestBody(
|
||||
|
||||
@@ -28,9 +28,8 @@ data class RegisterRequestBody(
|
||||
@SerializedName("username")
|
||||
val username: String,
|
||||
@SerializedName("password")
|
||||
val password: String,
|
||||
|
||||
)
|
||||
val password: String
|
||||
)
|
||||
|
||||
data class LoginUserRequestBody(
|
||||
@SerializedName("username")
|
||||
@@ -96,6 +95,12 @@ data class RegisterMessageChannelRequestBody(
|
||||
val identifier: String,
|
||||
)
|
||||
|
||||
data class UnRegisterMessageChannelRequestBody(
|
||||
@SerializedName("client")
|
||||
val client: String,
|
||||
@SerializedName("identifier")
|
||||
val identifier: String,
|
||||
)
|
||||
data class ResetPasswordRequestBody(
|
||||
@SerializedName("username")
|
||||
val username: String,
|
||||
@@ -151,10 +156,12 @@ data class CheckLoginCaptchaRequestBody(
|
||||
@SerializedName("username")
|
||||
val username: String,
|
||||
)
|
||||
|
||||
data class GenerateLoginCaptchaRequestBody(
|
||||
@SerializedName("username")
|
||||
val username: String,
|
||||
)
|
||||
|
||||
data class DotPosition(
|
||||
@SerializedName("index")
|
||||
val index: Int,
|
||||
@@ -163,6 +170,7 @@ data class DotPosition(
|
||||
@SerializedName("y")
|
||||
val y: Int,
|
||||
)
|
||||
|
||||
data class CaptchaInfo(
|
||||
@SerializedName("id")
|
||||
val id: Int,
|
||||
@@ -318,6 +326,10 @@ interface RiderProAPI {
|
||||
@Body body: RegisterMessageChannelRequestBody
|
||||
): Response<Unit>
|
||||
|
||||
@POST("account/my/messaging/unregister")
|
||||
suspend fun unRegisterMessageChannel(
|
||||
@Body body: UnRegisterMessageChannelRequestBody
|
||||
): Response<Unit>
|
||||
|
||||
@GET("profile/{id}")
|
||||
suspend fun getAccountProfileById(
|
||||
|
||||
@@ -12,8 +12,12 @@ import androidx.paging.Pager
|
||||
import androidx.paging.PagingConfig
|
||||
import androidx.paging.PagingData
|
||||
import androidx.paging.cachedIn
|
||||
import cn.jpush.android.api.JPushInterface
|
||||
import com.aiosman.riderpro.AppState
|
||||
import com.aiosman.riderpro.AppStore
|
||||
import com.aiosman.riderpro.JpushService
|
||||
import com.aiosman.riderpro.Messaging
|
||||
import com.aiosman.riderpro.data.AccountProfile
|
||||
import com.aiosman.riderpro.data.AccountService
|
||||
import com.aiosman.riderpro.data.AccountServiceImpl
|
||||
import com.aiosman.riderpro.data.MomentService
|
||||
@@ -73,15 +77,20 @@ object MyProfileViewModel : ViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun logout(context: Context) {
|
||||
fun logout(context: Context) {
|
||||
viewModelScope.launch {
|
||||
Messaging.unregisterDevice(context)
|
||||
AppStore.apply {
|
||||
token = null
|
||||
rememberMe = false
|
||||
saveData()
|
||||
}
|
||||
// 删除推送渠道
|
||||
AppState.ReloadAppState(context)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun updateUserProfileBanner(bannerImageUrl: Uri?,file:File, context: Context) {
|
||||
viewModelScope.launch {
|
||||
val newBanner = bannerImageUrl?.let {
|
||||
|
||||
@@ -19,10 +19,7 @@ fun ProfileWrap(
|
||||
MyProfileViewModel.updateUserProfileBanner(uri, file, context)
|
||||
},
|
||||
onLogout = {
|
||||
MyProfileViewModel.viewModelScope.launch {
|
||||
MyProfileViewModel.logout(context)
|
||||
}
|
||||
|
||||
},
|
||||
profile = MyProfileViewModel.profile,
|
||||
sharedFlow = MyProfileViewModel.sharedFlow
|
||||
|
||||
Reference in New Issue
Block a user