mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
Show all conversations but disable non-encrypted ones if in secure mode
This commit is contained in:
parent
01361bfcaa
commit
d002d308c4
6 changed files with 65 additions and 22 deletions
|
|
@ -40,7 +40,10 @@ import org.linphone.utils.LinphoneUtils
|
|||
import org.linphone.utils.ShortcutUtils
|
||||
import org.linphone.utils.TimestampUtils
|
||||
|
||||
class ConversationModel @WorkerThread constructor(val chatRoom: ChatRoom) {
|
||||
class ConversationModel @WorkerThread constructor(
|
||||
val chatRoom: ChatRoom,
|
||||
val isDisabledBecauseNotSecured: Boolean = false
|
||||
) {
|
||||
companion object {
|
||||
private const val TAG = "[Conversation Model]"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ import org.linphone.core.tools.Log
|
|||
import org.linphone.ui.main.chat.model.EventLogModel
|
||||
import org.linphone.ui.main.chat.model.MessageModel
|
||||
import org.linphone.ui.main.contacts.model.ContactAvatarModel
|
||||
import org.linphone.ui.main.model.isInSecureMode
|
||||
import org.linphone.utils.AppUtils
|
||||
import org.linphone.utils.Event
|
||||
import org.linphone.utils.ImageUtils
|
||||
|
|
@ -71,6 +72,8 @@ class ConversationViewModel @UiThread constructor() : ViewModel() {
|
|||
|
||||
val isReadOnly = MutableLiveData<Boolean>()
|
||||
|
||||
val isDisabledBecauseNotSecured = MutableLiveData<Boolean>()
|
||||
|
||||
val composingLabel = MutableLiveData<String>()
|
||||
|
||||
val searchBarVisible = MutableLiveData<Boolean>()
|
||||
|
|
@ -314,6 +317,7 @@ class ConversationViewModel @UiThread constructor() : ViewModel() {
|
|||
init {
|
||||
searchBarVisible.value = false
|
||||
isUserScrollingUp.value = false
|
||||
isDisabledBecauseNotSecured.value = false
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
|
|
@ -561,6 +565,16 @@ class ConversationViewModel @UiThread constructor() : ViewModel() {
|
|||
Log.w("$TAG Conversation with subject [${chatRoom.subject}] is read only!")
|
||||
}
|
||||
|
||||
if (!chatRoom.hasCapability(ChatRoom.Capabilities.Encrypted.toInt())) {
|
||||
val account = LinphoneUtils.getDefaultAccount()
|
||||
if (account?.isInSecureMode() == true) {
|
||||
Log.w(
|
||||
"$TAG Conversation with subject [${chatRoom.subject}] has been disabled because it isn't encrypted and default account is in secure mode"
|
||||
)
|
||||
isDisabledBecauseNotSecured.postValue(true)
|
||||
}
|
||||
}
|
||||
|
||||
subject.postValue(chatRoom.subject)
|
||||
|
||||
val friends = arrayListOf<Friend>()
|
||||
|
|
|
|||
|
|
@ -142,18 +142,11 @@ class ConversationsListViewModel @UiThread constructor() : AbstractTopBarViewMod
|
|||
val account = LinphoneUtils.getDefaultAccount()
|
||||
val chatRooms = account?.chatRooms ?: coreContext.core.chatRooms
|
||||
for (chatRoom in chatRooms) {
|
||||
// TODO: remove when SDK will do it automatically
|
||||
if (account?.isInSecureMode() == true) {
|
||||
if (!chatRoom.hasCapability(Capabilities.Encrypted.toInt()) && chatRoom.unreadMessagesCount == 0) { // TODO: remove message count check later
|
||||
Log.d(
|
||||
"$TAG Skipping conversation [${LinphoneUtils.getChatRoomId(chatRoom)}] as it is not E2E encrypted and default account requires it"
|
||||
)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
val disabledBecauseNotSecured = account?.isInSecureMode() == true && !chatRoom.hasCapability(
|
||||
Capabilities.Encrypted.toInt()
|
||||
)
|
||||
if (filter.isEmpty()) {
|
||||
val model = ConversationModel(chatRoom)
|
||||
val model = ConversationModel(chatRoom, disabledBecauseNotSecured)
|
||||
list.add(model)
|
||||
count += 1
|
||||
} else {
|
||||
|
|
@ -175,7 +168,7 @@ class ConversationsListViewModel @UiThread constructor() : AbstractTopBarViewMod
|
|||
chatRoom.peerAddress.asStringUriOnly().contains(filter, ignoreCase = true) ||
|
||||
chatRoom.subject.orEmpty().contains(filter, ignoreCase = true)
|
||||
) {
|
||||
val model = ConversationModel(chatRoom)
|
||||
val model = ConversationModel(chatRoom, disabledBecauseNotSecured)
|
||||
list.add(model)
|
||||
count += 1
|
||||
}
|
||||
|
|
|
|||
|
|
@ -251,15 +251,34 @@
|
|||
android:textSize="12sp"
|
||||
android:textColor="?attr/color_main2_400"
|
||||
android:visibility="@{viewModel.composingLabel.length() == 0 ? View.GONE : View.VISIBLE}"
|
||||
app:layout_constraintBottom_toTopOf="@id/send_area"
|
||||
app:layout_constraintBottom_toTopOf="@id/warning_disabled_not_secured"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
style="@style/default_text_style"
|
||||
android:id="@+id/warning_disabled_not_secured"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:text="@string/conversation_warning_disabled_because_not_secured"
|
||||
android:textColor="?attr/color_warning_600"
|
||||
android:textSize="16sp"
|
||||
android:maxLines="2"
|
||||
android:ellipsize="end"
|
||||
android:drawableStart="@drawable/warning_circle"
|
||||
android:drawableTint="?attr/color_warning_600"
|
||||
android:drawablePadding="10dp"
|
||||
android:visibility="@{viewModel.isDisabledBecauseNotSecured ? View.VISIBLE : View.GONE, default=gone}"
|
||||
app:layout_constraintBottom_toTopOf="@id/send_area"/>
|
||||
|
||||
<include
|
||||
android:id="@+id/send_area"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="@{viewModel.isReadOnly ? View.GONE : View.VISIBLE}"
|
||||
android:visibility="@{viewModel.isReadOnly || viewModel.isDisabledBecauseNotSecured ? View.GONE : View.VISIBLE}"
|
||||
layout="@layout/chat_conversation_send_area"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
bind:openFilePickerClickListener="@{openFilePickerClickListener}"
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:barrierDirection="start"
|
||||
app:constraint_referenced_ids="notifications_count, date_time, ephemeral, muted, last_sent_message_status" />
|
||||
app:constraint_referenced_ids="warning_disabled_not_secured, notifications_count, date_time, ephemeral, muted, last_sent_message_status" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
style="@style/default_text_style"
|
||||
|
|
@ -95,7 +95,6 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
android:text="@{model.isGroup ? model.subject : model.avatarModel.name, default=`John Doe`}"
|
||||
|
|
@ -113,7 +112,6 @@
|
|||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:gravity="center_vertical|start"
|
||||
android:maxLines="2"
|
||||
android:ellipsize="end"
|
||||
|
|
@ -126,12 +124,27 @@
|
|||
app:layout_constraintTop_toBottomOf="@id/name"
|
||||
app:layout_constraintBottom_toTopOf="@id/separator" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/warning_disabled_not_secured"
|
||||
android:layout_width="@dimen/icon_size"
|
||||
android:layout_height="@dimen/icon_size"
|
||||
android:layout_marginStart="5dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:src="@drawable/warning_circle"
|
||||
android:visibility="@{model.isDisabledBecauseNotSecured ? View.VISIBLE : View.GONE}"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/right_border"
|
||||
app:layout_constraintEnd_toStartOf="@id/notifications_count"
|
||||
app:tint="?attr/color_warning_600" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
style="@style/default_text_style"
|
||||
android:id="@+id/notifications_count"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_width="@dimen/icon_size"
|
||||
android:layout_height="@dimen/icon_size"
|
||||
android:layout_marginStart="5dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:gravity="center"
|
||||
android:background="@drawable/shape_red_round"
|
||||
android:text="@{String.valueOf(model.unreadMessageCount), default=`1`}"
|
||||
|
|
@ -142,7 +155,7 @@
|
|||
app:layout_constraintHorizontal_bias="1"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/name"
|
||||
app:layout_constraintStart_toEndOf="@id/warning_disabled_not_secured"
|
||||
app:layout_constraintEnd_toStartOf="@id/unread_count_right_border"/>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
|
|
|
|||
|
|
@ -439,6 +439,7 @@
|
|||
<string name="conversation_info_admin_menu_unset_participant_admin">Remove admin rights</string>
|
||||
<string name="conversation_info_menu_go_to_contact">See contact profile</string>
|
||||
<string name="conversation_info_menu_add_to_contacts">Add to contacts</string>
|
||||
<string name="conversation_warning_disabled_because_not_secured">This conversation was disabled because it is not encrypted!</string>
|
||||
|
||||
<string name="conversation_event_conference_created">You have joined the group</string>
|
||||
<string name="conversation_event_conference_destroyed">You have left the group</string>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue