Skip to content

Commit

Permalink
Merge pull request #499 from stakwork/tt/feature/notification-level-d…
Browse files Browse the repository at this point in the history
…isabled

Changes to disable notification level feature
  • Loading branch information
tomastiminskas authored Oct 3, 2022
2 parents 3c9bd83 + c496616 commit dbca66a
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import chat.sphinx.wrapper_common.message.MessageId

@Suppress("NOTHING_TO_INLINE")
inline fun Chat.isMuted(): Boolean {
return notify?.isMuteChat() == true
// return notify?.isMuteChat() == true
return isMuted?.isTrue()
}

@Suppress("NOTHING_TO_INLINE")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ interface ChatRepository {
val networkRefreshChats: Flow<LoadResponse<Boolean, ResponseError>>

suspend fun getAllChatsByIds(chatIds: List<ChatId>): List<Chat>

/**
* Returns `true` if the user has muted the chat and there is a need
* to notify them that they won't receive messages anymore.
Expand All @@ -53,6 +54,7 @@ interface ChatRepository {
*
* Returns error if something went wrong (networking)
* */
suspend fun toggleChatMuted(chat: Chat): Response<Boolean, ResponseError>
suspend fun setNotificationLevel(chat: Chat, level: NotificationLevel): Response<Boolean, ResponseError>

suspend fun updateChatContentSeenAt(chatId: ChatId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3501,6 +3501,53 @@ abstract class SphinxRepository(
return response ?: Response.Error(ResponseError("Failed to pay for attachment"))
}

override suspend fun toggleChatMuted(chat: Chat): Response<Boolean, ResponseError> {
var response: Response<Boolean, ResponseError> = Response.Success(!chat.isMuted())

applicationScope.launch(mainImmediate) {
val queries = coreDB.getSphinxDatabaseQueries()
val currentMutedValue = chat.isMuted

chatLock.withLock {
withContext(io) {
queries.transaction {
updateChatMuted(
chat.id,
if (currentMutedValue.isTrue()) ChatMuted.False else ChatMuted.True,
queries
)
}
}
}

networkQueryChat.toggleMuteChat(chat.id, chat.isMuted).collect { loadResponse ->
when (loadResponse) {
is LoadResponse.Loading -> {
}
is Response.Error -> {
response = loadResponse

chatLock.withLock {
withContext(io) {
queries.transaction {
updateChatMuted(
chat.id,
currentMutedValue,
queries
)
}
}
}
}
is Response.Success -> {
}
}
}
}.join()

return response
}

override suspend fun setNotificationLevel(chat: Chat, level: NotificationLevel): Response<Boolean, ResponseError> {
var response: Response<Boolean, ResponseError> = Response.Success(level.isMuteChat())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ abstract class ChatViewModel<ARGS: NavArgs>(
_viewStateFlow.value = ChatHeaderViewState.Initialized(
chatHeaderName = chat?.name?.value ?: getChatInfo()?.first?.value ?: "",
showLock = chat != null,
isMuted = chat?.notify?.isMuteChat() == true,
isMuted = chat?.isMuted() == true,
// isMuted = chat?.notify?.isMuteChat() == true,
)
chat?.let { nnChat ->
if (nnChat.isPrivateTribe()) {
Expand Down Expand Up @@ -893,17 +894,22 @@ abstract class ChatViewModel<ARGS: NavArgs>(
fun toggleChatMuted() {
chatSharedFlow.replayCache.firstOrNull()?.let { chat ->

if (chat.isTribe()) {
navigateToNotificationLevel()
return@let
// if (chat.isTribe()) {
// navigateToNotificationLevel()
// return@let
// }

if (toggleChatMutedJob?.isActive == true) {
return
}

toggleChatMutedJob = viewModelScope.launch(mainImmediate) {

submitSideEffect(ChatSideEffect.ProduceHapticFeedback)

val newLevel = if (chat.notify?.isMuteChat() == true) NotificationLevel.SeeAll else NotificationLevel.MuteChat
val response = chatRepository.setNotificationLevel(chat, newLevel)
// val response = chatRepository.setNotificationLevel(chat, newLevel)
val response = chatRepository.toggleChatMuted(chat)

@Exhaustive
when (response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,15 @@ internal class ChatTribeFragment: ChatFragment<
)
)

menuOptions.add(
MenuBottomOption(
text = chat.sphinx.chat_common.R.string.bottom_menu_more_option_notification,
textColor = chat.sphinx.chat_common.R.color.primaryBlueFontColor,
onClick = {
viewModel.navigateToNotificationLevel()
}
)
)
// menuOptions.add(
// MenuBottomOption(
// text = chat.sphinx.chat_common.R.string.bottom_menu_more_option_notification,
// textColor = chat.sphinx.chat_common.R.color.primaryBlueFontColor,
// onClick = {
// viewModel.navigateToNotificationLevel()
// }
// )
// )

if (viewModel.moreOptionsMenuStateFlow.value is MoreMenuOptionsViewState.OwnTribe) {
menuOptions.add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ internal class OnBoardConnectingViewModel @Inject constructor(
is LoadResponse.Loading -> {}
is Response.Error -> {
submitSideEffect(OnBoardConnectingSideEffect.InvalidInvite)
navigator.popBackStack()
}
is Response.Success -> {
val inviteResponse = loadResponse.value.response
Expand Down

0 comments on commit dbca66a

Please sign in to comment.