添加Chat处理逻辑

This commit is contained in:
2024-12-06 10:57:31 +08:00
parent cc7a65e016
commit 76e7bbb84a
6 changed files with 85 additions and 44 deletions

View File

@@ -10,6 +10,8 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import com.aiosman.ravenow.data.AccountService import com.aiosman.ravenow.data.AccountService
import com.aiosman.ravenow.data.AccountServiceImpl import com.aiosman.ravenow.data.AccountServiceImpl
import com.aiosman.ravenow.data.DictService
import com.aiosman.ravenow.data.DictServiceImpl
import com.aiosman.ravenow.entity.AccountProfileEntity import com.aiosman.ravenow.entity.AccountProfileEntity
import com.aiosman.ravenow.ui.favourite.FavouriteListViewModel import com.aiosman.ravenow.ui.favourite.FavouriteListViewModel
import com.aiosman.ravenow.ui.favourite.FavouriteNoticeViewModel import com.aiosman.ravenow.ui.favourite.FavouriteNoticeViewModel
@@ -40,6 +42,7 @@ object AppState {
var appTheme by mutableStateOf<AppThemeData>(LightThemeColors()) var appTheme by mutableStateOf<AppThemeData>(LightThemeColors())
var googleClientId: String? = null var googleClientId: String? = null
var enableGoogleLogin: Boolean = false var enableGoogleLogin: Boolean = false
var enableChat = false
suspend fun initWithAccount(scope: CoroutineScope, context: Context) { suspend fun initWithAccount(scope: CoroutineScope, context: Context) {
val accountService: AccountService = AccountServiceImpl() val accountService: AccountService = AccountServiceImpl()
// 获取用户认证信息 // 获取用户认证信息
@@ -62,6 +65,19 @@ object AppState {
// 注册 JPush // 注册 JPush
Messaging.registerDevice(scope, context) Messaging.registerDevice(scope, context)
initChat(context)
}
private suspend fun initChat(context: Context){
val dictService :DictService = DictServiceImpl()
val enableItem = dictService.getDictByKey(ConstVars.DICT_KEY_ENABLE_TRTC)
val isEnableTrtc = enableItem.value as? Boolean
if (isEnableTrtc != true) {
enableChat = false
return
}
val accountService: AccountService = AccountServiceImpl()
// 注册 Trtc // 注册 Trtc
val config = V2TIMSDKConfig() val config = V2TIMSDKConfig()
@@ -82,8 +98,10 @@ object AppState {
context.startService( context.startService(
Intent(context, TrtcService::class.java) Intent(context, TrtcService::class.java)
) )
enableChat = true
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() e.printStackTrace()
enableChat = false
} }
} }
@@ -93,7 +111,6 @@ object AppState {
override fun onError(code: Int, desc: String?) { override fun onError(code: Int, desc: String?) {
continuation.resumeWith(Result.failure(Exception("Login failed: $code, $desc"))) continuation.resumeWith(Result.failure(Exception("Login failed: $code, $desc")))
} }
override fun onSuccess() { override fun onSuccess() {
continuation.resumeWith(Result.success(true)) continuation.resumeWith(Result.success(true))
} }

View File

@@ -31,5 +31,11 @@ object ConstVars {
const val DICT_KEY_PRIVATE_POLICY_URL = "private_policy" const val DICT_KEY_PRIVATE_POLICY_URL = "private_policy"
// 重置邮箱间隔 // 重置邮箱间隔
const val DIC_KEY_RESET_EMAIL_INTERVAL = "send_reset_password_timeout" const val DIC_KEY_RESET_EMAIL_INTERVAL = "send_reset_password_timeout"
// 开启google登录
const val DICT_KEY_ENABLE_GOOGLE_LOGIN = "enable_google_login"
// google登录clientid
const val DICT_KEY_GOOGLE_LOGIN_CLIENT_ID = "google_login_client_id"
// trtc功能开启
const val DICT_KEY_ENABLE_TRTC = "enable_chat"
} }

View File

@@ -69,12 +69,12 @@ fun NotificationsScreen() {
val context = LocalContext.current val context = LocalContext.current
val state = rememberPullRefreshState(MessageListViewModel.isLoading, onRefresh = { val state = rememberPullRefreshState(MessageListViewModel.isLoading, onRefresh = {
MessageListViewModel.viewModelScope.launch { MessageListViewModel.viewModelScope.launch {
MessageListViewModel.initData(context, force = true) MessageListViewModel.initData(context, force = true, loadChat = AppState.enableChat)
} }
}) })
LaunchedEffect(Unit) { LaunchedEffect(Unit) {
systemUiController.setNavigationBarColor(Color.Transparent) systemUiController.setNavigationBarColor(Color.Transparent)
MessageListViewModel.initData(context) MessageListViewModel.initData(context, loadChat = AppState.enableChat)
} }
Column( Column(
modifier = Modifier.fillMaxSize() modifier = Modifier.fillMaxSize()
@@ -129,12 +129,13 @@ fun NotificationsScreen() {
} }
} }
HorizontalDivider(color = AppColors.divider, modifier = Modifier.padding(16.dp)) HorizontalDivider(color = AppColors.divider, modifier = Modifier.padding(16.dp))
// NotificationCounterItem(MessageListViewModel.unReadConversationCount.toInt())
Box( Box(
modifier = Modifier modifier = Modifier
.weight(1f) .weight(1f)
.fillMaxWidth() .fillMaxWidth(),
contentAlignment = Alignment.Center
) { ) {
if (AppState.enableChat){
ChatMessageList( ChatMessageList(
MessageListViewModel.chatList, MessageListViewModel.chatList,
onUserAvatarClick = { conv -> onUserAvatarClick = { conv ->
@@ -143,6 +144,15 @@ fun NotificationsScreen() {
) { conv -> ) { conv ->
MessageListViewModel.goToChat(conv, navController) MessageListViewModel.goToChat(conv, navController)
} }
}else{
// center text
Text(
text = "Chat service is under maintenance",
color = AppColors.text,
fontSize = 16.sp
)
}
} }
} }
PullRefreshIndicator( PullRefreshIndicator(

View File

@@ -83,9 +83,12 @@ object MessageListViewModel : ViewModel() {
var isLoading by mutableStateOf(false) var isLoading by mutableStateOf(false)
var unReadConversationCount by mutableStateOf(0L) var unReadConversationCount by mutableStateOf(0L)
var isFirstLoad = true var isFirstLoad = true
suspend fun initData(context: Context, force: Boolean = false) { suspend fun initData(context: Context, force: Boolean = false, loadChat: Boolean = false) {
if (loadChat) {
loadChatList(context) loadChatList(context)
loadUnreadCount() loadUnreadCount()
}
if (!isFirstLoad && !force) { if (!isFirstLoad && !force) {
return return
} }

View File

@@ -33,6 +33,7 @@ import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll import androidx.compose.foundation.verticalScroll
import androidx.compose.material.ExperimentalMaterialApi import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add import androidx.compose.material.icons.filled.Add
import androidx.compose.material.pullrefresh.PullRefreshIndicator import androidx.compose.material.pullrefresh.PullRefreshIndicator
@@ -427,7 +428,7 @@ fun ProfileV3(
contentScale = ContentScale.Crop contentScale = ContentScale.Crop
) )
Spacer(modifier = Modifier.width(16.dp)) Spacer(modifier = Modifier.width(16.dp))
androidx.compose.material3.Text( Text(
text = profile?.nickName ?: "", text = profile?.nickName ?: "",
fontSize = 16.sp, fontSize = 16.sp,
fontWeight = FontWeight.W600, fontWeight = FontWeight.W600,

View File

@@ -24,6 +24,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import com.aiosman.ravenow.AppState
import com.aiosman.ravenow.LocalAppTheme import com.aiosman.ravenow.LocalAppTheme
import com.aiosman.ravenow.R import com.aiosman.ravenow.R
import com.aiosman.ravenow.entity.AccountProfileEntity import com.aiosman.ravenow.entity.AccountProfileEntity
@@ -76,6 +77,7 @@ fun OtherProfileAction(
) )
} }
if (AppState.enableChat) {
Spacer(modifier = Modifier.width(8.dp)) Spacer(modifier = Modifier.width(8.dp))
Row( Row(
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
@@ -105,6 +107,8 @@ fun OtherProfileAction(
} }
} }
}
// 按钮 // 按钮
} }