mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-25 10:55:55 +03:00
Added lab feature to pin/unpin messages
This commit is contained in:
parent
dba8aaea16
commit
45f6bfc0f0
40 changed files with 590 additions and 22 deletions
|
@ -373,6 +373,7 @@
|
|||
<string name="action_sign_out_confirmation_simple">Are you sure you want to sign out?</string>
|
||||
<string name="action_voice_call">Voice Call</string>
|
||||
<string name="action_video_call">Video Call</string>
|
||||
<string name="action_open_pinned_messages">Open Pinned Messages</string>
|
||||
<string name="action_view_threads">View Threads</string>
|
||||
<string name="action_mark_all_as_read">Mark all as read</string>
|
||||
<string name="action_quick_reply">Quick reply</string>
|
||||
|
@ -801,6 +802,12 @@
|
|||
<string name="threads_labs_enable_notice_title">Threads Beta</string>
|
||||
<string name="threads_labs_enable_notice_message">Your homeserver does not currently support threads, so this feature may be unreliable. Some threaded messages may not be reliably available. %sDo you want to enable threads anyway?</string>
|
||||
|
||||
<!-- Pinning -->
|
||||
<string name="pinning_message">Pin</string>
|
||||
<string name="unpinning_message">Unpin</string>
|
||||
<string name="pinned_messages_timeline_title">Pinned Messages</string>
|
||||
<string name="user_pinned_message">%1$s pinned a message.</string>
|
||||
<string name="user_unpinned_message">%1$s unpinned a message.</string>
|
||||
|
||||
<!-- Search -->
|
||||
<string name="search_hint">Search</string>
|
||||
|
@ -3032,6 +3039,7 @@
|
|||
|
||||
<string name="labs_auto_report_uisi">Auto Report Decryption Errors.</string>
|
||||
<string name="labs_auto_report_uisi_desc">Your system will automatically send logs when an unable to decrypt error occurs</string>
|
||||
<string name="labs_enable_pinned_messages">Enable Pinned Messages</string>
|
||||
<string name="labs_enable_thread_messages">Enable Thread Messages</string>
|
||||
<string name="labs_enable_thread_messages_desc">Note: app will be restarted</string>
|
||||
<string name="settings_show_latest_profile">Show latest user info</string>
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.matrix.android.sdk.api.session.room.model.message.MessageContent
|
|||
import org.matrix.android.sdk.api.session.room.model.message.MessagePollContent
|
||||
import org.matrix.android.sdk.api.session.room.model.message.MessageType
|
||||
import org.matrix.android.sdk.api.session.room.model.message.asMessageAudioEvent
|
||||
import org.matrix.android.sdk.api.session.room.model.pinnedmessages.PinnedEventsStateContent
|
||||
import org.matrix.android.sdk.api.session.room.model.relation.RelationDefaultContent
|
||||
import org.matrix.android.sdk.api.session.room.model.relation.isReply
|
||||
import org.matrix.android.sdk.api.session.room.model.relation.shouldRenderInThread
|
||||
|
@ -447,3 +448,11 @@ fun Event.supportsNotification() =
|
|||
|
||||
fun Event.isContentReportable() =
|
||||
this.getClearType() in EventType.MESSAGE + EventType.STATE_ROOM_BEACON_INFO.values
|
||||
|
||||
fun Event.getIdsOfPinnedEvents(): MutableList<String>? {
|
||||
return getClearContent()?.toModel<PinnedEventsStateContent>()?.eventIds
|
||||
}
|
||||
|
||||
fun Event.getPreviousIdsOfPinnedEvents(): MutableList<String>? {
|
||||
return resolvedPrevContent()?.toModel<PinnedEventsStateContent>()?.eventIds
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ object EventType {
|
|||
const val STATE_ROOM_NAME = "m.room.name"
|
||||
const val STATE_ROOM_TOPIC = "m.room.topic"
|
||||
const val STATE_ROOM_AVATAR = "m.room.avatar"
|
||||
const val STATE_ROOM_PINNED_EVENT = "m.room.pinned_events"
|
||||
const val STATE_ROOM_MEMBER = "m.room.member"
|
||||
const val STATE_ROOM_THIRD_PARTY_INVITE = "m.room.third_party_invite"
|
||||
const val STATE_ROOM_CREATE = "m.room.create"
|
||||
|
@ -67,7 +68,6 @@ object EventType {
|
|||
const val STATE_ROOM_CANONICAL_ALIAS = "m.room.canonical_alias"
|
||||
const val STATE_ROOM_HISTORY_VISIBILITY = "m.room.history_visibility"
|
||||
const val STATE_ROOM_RELATED_GROUPS = "m.room.related_groups"
|
||||
const val STATE_ROOM_PINNED_EVENT = "m.room.pinned_events"
|
||||
const val STATE_ROOM_ENCRYPTION = "m.room.encryption"
|
||||
const val STATE_ROOM_SERVER_ACL = "m.room.server_acl"
|
||||
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright 2021 The Matrix.org Foundation C.I.C.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.api.session.room.model.pinnedmessages
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
||||
/**
|
||||
* Class representing a pinned event content.
|
||||
*/
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class PinnedEventsStateContent(
|
||||
@Json(name = "pinned") val eventIds: MutableList<String>
|
||||
)
|
|
@ -66,6 +66,11 @@ interface StateService {
|
|||
*/
|
||||
suspend fun deleteAvatar()
|
||||
|
||||
/**
|
||||
* Pin a message of the room.
|
||||
*/
|
||||
suspend fun pinMessage(eventIds: MutableList<String>)
|
||||
|
||||
/**
|
||||
* Send a state event to the room.
|
||||
* @param eventType The type of event to send.
|
||||
|
@ -103,6 +108,16 @@ interface StateService {
|
|||
*/
|
||||
fun getStateEventsLive(eventTypes: Set<String>, stateKey: QueryStateEventValue): LiveData<List<Event>>
|
||||
|
||||
/**
|
||||
* Get state event containing the IDs of pinned events of the room
|
||||
*/
|
||||
fun getPinnedEventsState(): Event?
|
||||
|
||||
/**
|
||||
* Tells if an event is a pinned message
|
||||
*/
|
||||
fun isPinned(eventId: String): Boolean?
|
||||
|
||||
suspend fun setJoinRulePublic()
|
||||
suspend fun setJoinRuleInviteOnly()
|
||||
suspend fun setJoinRuleRestricted(allowList: List<String>)
|
||||
|
|
|
@ -43,7 +43,7 @@ interface Timeline {
|
|||
/**
|
||||
* This must be called before any other method after creating the timeline. It ensures the underlying database is open
|
||||
*/
|
||||
fun start(rootThreadEventId: String? = null)
|
||||
fun start(rootThreadEventId: String? = null, rootPinnedMessageEventId: String? = null)
|
||||
|
||||
/**
|
||||
* This must be called when you don't need the timeline. It ensures the underlying database get closed.
|
||||
|
|
|
@ -32,6 +32,10 @@ data class TimelineSettings(
|
|||
* The root thread eventId if this is a thread timeline, or null if this is NOT a thread timeline.
|
||||
*/
|
||||
val rootThreadEventId: String? = null,
|
||||
/**
|
||||
* The root pinned message eventId if this is a pinned messages timeline, or null if this is NOT a pinned messages timeline.
|
||||
*/
|
||||
val rootPinnedMessageEventId: String? = null,
|
||||
/**
|
||||
* If true Sender Info shown in room will get the latest data information (avatar + displayName).
|
||||
*/
|
||||
|
@ -42,4 +46,9 @@ data class TimelineSettings(
|
|||
* Returns true if this is a thread timeline or false otherwise.
|
||||
*/
|
||||
fun isThreadTimeline() = rootThreadEventId != null
|
||||
|
||||
/**
|
||||
* Returns true if this is a pinned messages timeline or false otherwise.
|
||||
*/
|
||||
fun isPinnedMessagesTimeline() = rootPinnedMessageEventId != null
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ import org.matrix.android.sdk.internal.session.room.membership.RoomMembersRespon
|
|||
import org.matrix.android.sdk.internal.session.room.membership.admin.UserIdAndReason
|
||||
import org.matrix.android.sdk.internal.session.room.membership.joining.InviteBody
|
||||
import org.matrix.android.sdk.internal.session.room.membership.threepid.ThreePidInviteBody
|
||||
import org.matrix.android.sdk.internal.session.room.pinnedmessages.PinnedEventsStateResponse
|
||||
import org.matrix.android.sdk.internal.session.room.read.ReadBody
|
||||
import org.matrix.android.sdk.internal.session.room.relation.RelationsResponse
|
||||
import org.matrix.android.sdk.internal.session.room.reporting.ReportContentBody
|
||||
|
@ -233,11 +234,22 @@ internal interface RoomAPI {
|
|||
): SendResponse
|
||||
|
||||
/**
|
||||
* Get state events of a room
|
||||
* Get all state events of a room
|
||||
* Ref: https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-rooms-roomid-state
|
||||
*/
|
||||
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/state")
|
||||
suspend fun getRoomState(@Path("roomId") roomId: String): List<Event>
|
||||
suspend fun getAllRoomStates(@Path("roomId") roomId: String): List<Event>
|
||||
|
||||
/**
|
||||
* Get specific state event of a room
|
||||
* Ref: https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-rooms-roomid-state-eventtype-statekey
|
||||
*/
|
||||
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/state/{eventType}/{state_key}")
|
||||
suspend fun getRoomState(
|
||||
@Path("roomId") roomId: String,
|
||||
@Path("eventType") eventType: String,
|
||||
@Path("state_key") stateKey: String
|
||||
): PinnedEventsStateResponse
|
||||
|
||||
/**
|
||||
* Paginate relations for event based in normal topological order.
|
||||
|
|
|
@ -36,7 +36,7 @@ internal class DefaultResolveRoomStateTask @Inject constructor(
|
|||
|
||||
override suspend fun execute(params: ResolveRoomStateTask.Params): List<Event> {
|
||||
return executeRequest(globalErrorReceiver) {
|
||||
roomAPI.getRoomState(params.roomId)
|
||||
roomAPI.getAllRoomStates(params.roomId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright 2022 The Matrix.org Foundation C.I.C.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.internal.session.room.pinnedmessages
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
internal data class PinnedEventsStateResponse(
|
||||
/**
|
||||
* A unique identifier for the event.
|
||||
*/
|
||||
@Json(name = "pinned") val pinned: List<String>
|
||||
)
|
|
@ -22,8 +22,10 @@ import dagger.assisted.Assisted
|
|||
import dagger.assisted.AssistedFactory
|
||||
import dagger.assisted.AssistedInject
|
||||
import org.matrix.android.sdk.api.query.QueryStateEventValue
|
||||
import org.matrix.android.sdk.api.query.QueryStringValue
|
||||
import org.matrix.android.sdk.api.session.events.model.Event
|
||||
import org.matrix.android.sdk.api.session.events.model.EventType
|
||||
import org.matrix.android.sdk.api.session.events.model.getIdsOfPinnedEvents
|
||||
import org.matrix.android.sdk.api.session.events.model.toContent
|
||||
import org.matrix.android.sdk.api.session.room.model.GuestAccess
|
||||
import org.matrix.android.sdk.api.session.room.model.RoomCanonicalAliasContent
|
||||
|
@ -31,6 +33,7 @@ import org.matrix.android.sdk.api.session.room.model.RoomHistoryVisibility
|
|||
import org.matrix.android.sdk.api.session.room.model.RoomJoinRules
|
||||
import org.matrix.android.sdk.api.session.room.model.RoomJoinRulesAllowEntry
|
||||
import org.matrix.android.sdk.api.session.room.model.RoomJoinRulesContent
|
||||
import org.matrix.android.sdk.api.session.room.model.pinnedmessages.PinnedEventsStateContent
|
||||
import org.matrix.android.sdk.api.session.room.state.StateService
|
||||
import org.matrix.android.sdk.api.util.JsonDict
|
||||
import org.matrix.android.sdk.api.util.MimeTypes
|
||||
|
@ -170,6 +173,23 @@ internal class DefaultStateService @AssistedInject constructor(
|
|||
)
|
||||
}
|
||||
|
||||
override suspend fun pinMessage(eventIds: MutableList<String>) {
|
||||
sendStateEvent(
|
||||
eventType = EventType.STATE_ROOM_PINNED_EVENT,
|
||||
body = PinnedEventsStateContent(eventIds).toContent(),
|
||||
stateKey = ""
|
||||
)
|
||||
}
|
||||
|
||||
override fun getPinnedEventsState(): Event? {
|
||||
return getStateEvent(EventType.STATE_ROOM_PINNED_EVENT, QueryStringValue.Equals(""))
|
||||
}
|
||||
|
||||
override fun isPinned(eventId: String): Boolean? {
|
||||
val idsOfPinnedEvents: MutableList<String> = getPinnedEventsState()?.getIdsOfPinnedEvents() ?: return null
|
||||
return idsOfPinnedEvents.contains(eventId)
|
||||
}
|
||||
|
||||
override suspend fun setJoinRulePublic() {
|
||||
updateJoinRule(RoomJoinRules.PUBLIC, null)
|
||||
}
|
||||
|
|
|
@ -34,6 +34,9 @@ import kotlinx.coroutines.withContext
|
|||
import okhttp3.internal.closeQuietly
|
||||
import org.matrix.android.sdk.api.MatrixCoroutineDispatchers
|
||||
import org.matrix.android.sdk.api.extensions.tryOrNull
|
||||
import org.matrix.android.sdk.api.query.QueryStringValue
|
||||
import org.matrix.android.sdk.api.session.events.model.EventType
|
||||
import org.matrix.android.sdk.api.session.events.model.getIdsOfPinnedEvents
|
||||
import org.matrix.android.sdk.api.session.room.model.Membership
|
||||
import org.matrix.android.sdk.api.session.room.timeline.Timeline
|
||||
import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
|
||||
|
@ -63,7 +66,8 @@ internal class DefaultTimeline(
|
|||
private val settings: TimelineSettings,
|
||||
private val coroutineDispatchers: MatrixCoroutineDispatchers,
|
||||
private val clock: Clock,
|
||||
stateEventDataSource: StateEventDataSource,
|
||||
private val stateEventDataSource: StateEventDataSource,
|
||||
private val timelineEventDataSource: TimelineEventDataSource,
|
||||
paginationTask: PaginationTask,
|
||||
getEventTask: GetContextOfEventTask,
|
||||
fetchTokenAndPaginateTask: FetchTokenAndPaginateTask,
|
||||
|
@ -95,6 +99,9 @@ internal class DefaultTimeline(
|
|||
private var isFromThreadTimeline = false
|
||||
private var rootThreadEventId: String? = null
|
||||
|
||||
private var isFromPinnedMessagesTimeline = false
|
||||
private var rootPinnedMessageEventId: String? = null
|
||||
|
||||
private val strategyDependencies = LoadTimelineStrategy.Dependencies(
|
||||
timelineSettings = settings,
|
||||
realm = backgroundRealm,
|
||||
|
@ -125,7 +132,11 @@ internal class DefaultTimeline(
|
|||
override fun addListener(listener: Timeline.Listener): Boolean {
|
||||
listeners.add(listener)
|
||||
timelineScope.launch {
|
||||
val snapshot = strategy.buildSnapshot()
|
||||
val snapshot = if (isFromPinnedMessagesTimeline) {
|
||||
getPinnedEvents()
|
||||
} else {
|
||||
strategy.buildSnapshot()
|
||||
}
|
||||
withContext(coroutineDispatchers.main) {
|
||||
tryOrNull { listener.onTimelineUpdated(snapshot) }
|
||||
}
|
||||
|
@ -141,7 +152,7 @@ internal class DefaultTimeline(
|
|||
listeners.clear()
|
||||
}
|
||||
|
||||
override fun start(rootThreadEventId: String?) {
|
||||
override fun start(rootThreadEventId: String?, rootPinnedMessageEventId: String?) {
|
||||
timelineScope.launch {
|
||||
loadRoomMembersIfNeeded()
|
||||
}
|
||||
|
@ -150,6 +161,8 @@ internal class DefaultTimeline(
|
|||
if (isStarted.compareAndSet(false, true)) {
|
||||
isFromThreadTimeline = rootThreadEventId != null
|
||||
this@DefaultTimeline.rootThreadEventId = rootThreadEventId
|
||||
isFromPinnedMessagesTimeline = rootPinnedMessageEventId != null
|
||||
this@DefaultTimeline.rootPinnedMessageEventId = rootPinnedMessageEventId
|
||||
// /
|
||||
val realm = Realm.getInstance(realmConfiguration)
|
||||
ensureReadReceiptAreLoaded(realm)
|
||||
|
@ -254,7 +267,12 @@ internal class DefaultTimeline(
|
|||
}
|
||||
}
|
||||
Timber.v("$baseLogMessage: result $loadMoreResult")
|
||||
val hasMoreToLoad = loadMoreResult != LoadMoreResult.REACHED_END
|
||||
val hasMoreToLoad = if (isFromPinnedMessagesTimeline) {
|
||||
!areAllPinnedMessagesLoaded()
|
||||
} else {
|
||||
loadMoreResult != LoadMoreResult.REACHED_END
|
||||
}
|
||||
|
||||
updateState(direction) {
|
||||
it.copy(loading = false, hasMoreToLoad = hasMoreToLoad)
|
||||
}
|
||||
|
@ -334,7 +352,11 @@ internal class DefaultTimeline(
|
|||
}
|
||||
|
||||
private suspend fun postSnapshot() {
|
||||
val snapshot = strategy.buildSnapshot()
|
||||
val snapshot = if (isFromPinnedMessagesTimeline) {
|
||||
getPinnedEvents()
|
||||
} else {
|
||||
strategy.buildSnapshot()
|
||||
}
|
||||
Timber.v("Post snapshot of ${snapshot.size} events")
|
||||
withContext(coroutineDispatchers.main) {
|
||||
listeners.forEach {
|
||||
|
@ -349,6 +371,28 @@ internal class DefaultTimeline(
|
|||
}
|
||||
}
|
||||
|
||||
private fun getIdsOfPinnedEvents(): MutableList<String> {
|
||||
return stateEventDataSource
|
||||
.getStateEvent(roomId, EventType.STATE_ROOM_PINNED_EVENT, QueryStringValue.Equals(""))
|
||||
?.getIdsOfPinnedEvents() ?: mutableListOf("")
|
||||
}
|
||||
|
||||
private fun getPinnedEvents(): List<TimelineEvent> {
|
||||
val idsOfPinnedEvents = getIdsOfPinnedEvents()
|
||||
val pinnedEvents = ArrayList<TimelineEvent>()
|
||||
for (id in idsOfPinnedEvents) {
|
||||
val timelineEvent = timelineEventDataSource.getTimelineEvent(roomId, id)
|
||||
if (timelineEvent != null) {
|
||||
pinnedEvents.add(timelineEvent)
|
||||
}
|
||||
}
|
||||
return pinnedEvents.reversed()
|
||||
}
|
||||
|
||||
private fun areAllPinnedMessagesLoaded(): Boolean {
|
||||
return getIdsOfPinnedEvents().size == getPinnedEvents().size
|
||||
}
|
||||
|
||||
private fun onNewTimelineEvents(eventIds: List<String>) {
|
||||
timelineScope.launch(coroutineDispatchers.main) {
|
||||
listeners.forEach {
|
||||
|
|
|
@ -82,6 +82,7 @@ internal class DefaultTimelineService @AssistedInject constructor(
|
|||
lightweightSettingsStorage = lightweightSettingsStorage,
|
||||
clock = clock,
|
||||
stateEventDataSource = stateEventDataSource,
|
||||
timelineEventDataSource = timelineEventDataSource,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
<!-- Level 1: Labs -->
|
||||
<bool name="settings_labs_deferred_dm_visible">true</bool>
|
||||
<bool name="settings_labs_deferred_dm_default">true</bool>
|
||||
<bool name="settings_labs_pinned_messages_default">false</bool>
|
||||
<bool name="settings_labs_thread_messages_default">false</bool>
|
||||
<bool name="settings_labs_new_app_layout_default">true</bool>
|
||||
<bool name="settings_labs_new_session_manager_default">false</bool>
|
||||
|
|
|
@ -149,6 +149,7 @@
|
|||
<activity android:name=".features.roomdirectory.roompreview.RoomPreviewActivity" />
|
||||
<activity android:name=".features.home.room.filtered.FilteredRoomsActivity" />
|
||||
<activity android:name=".features.home.room.threads.ThreadsActivity" />
|
||||
<activity android:name=".features.home.room.pinnedmessages.PinnedMessagesActivity" />
|
||||
|
||||
<activity
|
||||
android:name=".features.home.room.detail.RoomDetailActivity"
|
||||
|
|
|
@ -30,6 +30,8 @@ import org.matrix.android.sdk.api.session.widgets.model.Widget
|
|||
import org.matrix.android.sdk.api.util.MatrixItem
|
||||
|
||||
sealed class RoomDetailAction : VectorViewModelAction {
|
||||
data class PinMessage(val eventId: String) : RoomDetailAction()
|
||||
data class UnpinMessage(val eventId: String) : RoomDetailAction()
|
||||
data class SendSticker(val stickerContent: MessageStickerContent) : RoomDetailAction()
|
||||
data class SendMedia(val attachments: List<ContentAttachmentData>, val compressBeforeSending: Boolean) : RoomDetailAction()
|
||||
data class TimelineEventTurnsVisible(val event: TimelineEvent) : RoomDetailAction()
|
||||
|
|
|
@ -71,6 +71,7 @@ data class RoomDetailViewState(
|
|||
val isAllowedToManageWidgets: Boolean = false,
|
||||
val isAllowedToStartWebRTCCall: Boolean = true,
|
||||
val isAllowedToSetupEncryption: Boolean = true,
|
||||
val rootPinnedMessageEventId: String?,
|
||||
val hasFailedSending: Boolean = false,
|
||||
val jitsiState: JitsiState = JitsiState(),
|
||||
val switchToParentSpace: Boolean = false,
|
||||
|
@ -92,6 +93,7 @@ data class RoomDetailViewState(
|
|||
rootThreadEventId = args.threadTimelineArgs?.rootThreadEventId,
|
||||
showKeyboardWhenPresented = args.threadTimelineArgs?.showKeyboard.orFalse(),
|
||||
sharedData = args.sharedData,
|
||||
rootPinnedMessageEventId = args.pinnedMessagesTimelineArgs?.rootPinnedMessageEventId,
|
||||
)
|
||||
|
||||
fun isCallOptionAvailable(): Boolean {
|
||||
|
@ -113,5 +115,7 @@ data class RoomDetailViewState(
|
|||
|
||||
fun isThreadTimeline() = rootThreadEventId != null
|
||||
|
||||
fun isPinnedMessagesTimeline() = rootPinnedMessageEventId != null
|
||||
|
||||
fun isLocalRoom() = RoomLocalEcho.isLocalEchoId(roomId)
|
||||
}
|
||||
|
|
|
@ -159,6 +159,7 @@ import im.vector.app.features.home.room.detail.timeline.url.PreviewUrlRetriever
|
|||
import im.vector.app.features.home.room.detail.upgrade.MigrateRoomBottomSheet
|
||||
import im.vector.app.features.home.room.detail.views.RoomDetailLazyLoadedViews
|
||||
import im.vector.app.features.home.room.detail.widget.RoomWidgetsBottomSheet
|
||||
import im.vector.app.features.home.room.pinnedmessages.arguments.PinnedMessagesTimelineArgs
|
||||
import im.vector.app.features.home.room.threads.ThreadsManager
|
||||
import im.vector.app.features.home.room.threads.arguments.ThreadTimelineArgs
|
||||
import im.vector.app.features.html.EventHtmlRenderer
|
||||
|
@ -378,6 +379,11 @@ class TimelineFragment :
|
|||
)
|
||||
}
|
||||
|
||||
if (isPinnedMessagesTimeline()) {
|
||||
views.composerContainer.isVisible = false
|
||||
views.voiceMessageRecorderContainer.isVisible = false
|
||||
}
|
||||
|
||||
timelineViewModel.observeViewEvents {
|
||||
when (it) {
|
||||
is RoomDetailViewEvents.Failure -> displayErrorMessage(it)
|
||||
|
@ -877,6 +883,10 @@ class TimelineFragment :
|
|||
callActionsHandler.onVideoCallClicked()
|
||||
true
|
||||
}
|
||||
R.id.open_pinned_messages -> {
|
||||
navigateToPinnedMessages()
|
||||
true
|
||||
}
|
||||
R.id.menu_timeline_thread_list -> {
|
||||
navigateToThreadList()
|
||||
true
|
||||
|
@ -1106,7 +1116,7 @@ class TimelineFragment :
|
|||
}
|
||||
|
||||
private fun updateJumpToReadMarkerViewVisibility() {
|
||||
if (isThreadTimeLine()) return
|
||||
if (isThreadTimeLine() || isPinnedMessagesTimeline()) return
|
||||
viewLifecycleOwner.lifecycleScope.launchWhenResumed {
|
||||
val state = timelineViewModel.awaitState()
|
||||
val showJumpToUnreadBanner = when (state.unreadState) {
|
||||
|
@ -1235,6 +1245,17 @@ class TimelineFragment :
|
|||
}
|
||||
views.includeThreadToolbar.roomToolbarThreadTitleTextView.text = resources.getText(R.string.thread_timeline_title)
|
||||
}
|
||||
isPinnedMessagesTimeline() -> {
|
||||
views.includeRoomToolbar.roomToolbarContentView.isVisible = false
|
||||
views.includeThreadToolbar.roomToolbarThreadConstraintLayout.isVisible = true
|
||||
timelineArgs.pinnedMessagesTimelineArgs?.let {
|
||||
val matrixItem = MatrixItem.RoomItem(it.roomId, it.displayName, it.avatarUrl)
|
||||
avatarRenderer.render(matrixItem, views.includeThreadToolbar.roomToolbarThreadImageView)
|
||||
views.includeThreadToolbar.roomToolbarThreadShieldImageView.render(it.roomEncryptionTrustLevel)
|
||||
views.includeThreadToolbar.roomToolbarThreadSubtitleTextView.text = it.displayName
|
||||
}
|
||||
views.includeThreadToolbar.roomToolbarThreadTitleTextView.text = resources.getText(R.string.pinned_messages_timeline_title)
|
||||
}
|
||||
else -> {
|
||||
views.includeRoomToolbar.roomToolbarContentView.isVisible = true
|
||||
views.includeThreadToolbar.roomToolbarThreadConstraintLayout.isVisible = false
|
||||
|
@ -1543,7 +1564,7 @@ class TimelineFragment :
|
|||
this.view?.hideKeyboard()
|
||||
|
||||
MessageActionsBottomSheet
|
||||
.newInstance(roomId, informationData, isThreadTimeLine())
|
||||
.newInstance(roomId, informationData, isThreadTimeLine(), isPinnedMessagesTimeline())
|
||||
.show(requireActivity().supportFragmentManager, "MESSAGE_CONTEXTUAL_ACTIONS")
|
||||
|
||||
return true
|
||||
|
@ -1795,6 +1816,15 @@ class TimelineFragment :
|
|||
requireActivity().toast(R.string.error_voice_message_cannot_reply_or_edit)
|
||||
}
|
||||
}
|
||||
is EventSharedAction.PinMessage -> {
|
||||
timelineViewModel.handle(RoomDetailAction.PinMessage(action.eventId))
|
||||
}
|
||||
is EventSharedAction.UnpinMessage -> {
|
||||
timelineViewModel.handle(RoomDetailAction.UnpinMessage(action.eventId))
|
||||
}
|
||||
is EventSharedAction.ViewPinnedMessageInRoom -> {
|
||||
handleViewInRoomAction(action.eventId)
|
||||
}
|
||||
is EventSharedAction.ReplyInThread -> {
|
||||
if (withState(messageComposerViewModel) { it.isVoiceMessageIdle }) {
|
||||
onReplyInThreadClicked(action)
|
||||
|
@ -1974,6 +2004,32 @@ class TimelineFragment :
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Navigate to pinned messages for the current room using the PinnedMessagesActivity.
|
||||
*/
|
||||
private fun navigateToPinnedMessages() = withState(timelineViewModel) { state ->
|
||||
val pinnedEventId = timelineViewModel.getIdOfLastPinnedEvent()
|
||||
context?.let {
|
||||
val pinnedMessagesTimelineArgs = PinnedMessagesTimelineArgs(
|
||||
roomId = timelineArgs.roomId,
|
||||
displayName = state.asyncRoomSummary()?.displayName,
|
||||
roomEncryptionTrustLevel = state.asyncRoomSummary()?.roomEncryptionTrustLevel,
|
||||
avatarUrl = state.asyncRoomSummary()?.avatarUrl,
|
||||
rootPinnedMessageEventId = pinnedEventId
|
||||
)
|
||||
navigator.openPinnedMessages(it, pinnedMessagesTimelineArgs)
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleViewInRoomAction(eventId: String) {
|
||||
val newRoom = timelineArgs.copy(threadTimelineArgs = null, pinnedMessagesTimelineArgs = null, eventId = eventId)
|
||||
context?.let { con ->
|
||||
val intent = RoomDetailActivity.newIntent(con, newRoom, false)
|
||||
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
con.startActivity(intent)
|
||||
}
|
||||
}
|
||||
|
||||
// VectorInviteView.Callback
|
||||
override fun onAcceptInvite() {
|
||||
timelineViewModel.handle(RoomDetailAction.AcceptInvite)
|
||||
|
@ -2027,6 +2083,11 @@ class TimelineFragment :
|
|||
*/
|
||||
private fun isThreadTimeLine(): Boolean = withState(timelineViewModel) { it.isThreadTimeline() }
|
||||
|
||||
/**
|
||||
* Returns true if the current room is a Pinned Messages room, false otherwise.
|
||||
*/
|
||||
private fun isPinnedMessagesTimeline(): Boolean = withState(timelineViewModel) { it.isPinnedMessagesTimeline() }
|
||||
|
||||
/**
|
||||
* Returns true if the current room is a local room, false otherwise.
|
||||
*/
|
||||
|
|
|
@ -89,6 +89,7 @@ import org.matrix.android.sdk.api.raw.RawService
|
|||
import org.matrix.android.sdk.api.session.Session
|
||||
import org.matrix.android.sdk.api.session.crypto.MXCryptoError
|
||||
import org.matrix.android.sdk.api.session.events.model.EventType
|
||||
import org.matrix.android.sdk.api.session.events.model.getIdsOfPinnedEvents
|
||||
import org.matrix.android.sdk.api.session.events.model.LocalEcho
|
||||
import org.matrix.android.sdk.api.session.events.model.RelationType
|
||||
import org.matrix.android.sdk.api.session.events.model.content.WithHeldCode
|
||||
|
@ -203,10 +204,12 @@ class TimelineViewModel @AssistedInject constructor(
|
|||
}
|
||||
|
||||
private fun initSafe(room: Room, timeline: Timeline) {
|
||||
timeline.start(initialState.rootThreadEventId)
|
||||
timeline.start(initialState.rootThreadEventId, initialState.rootPinnedMessageEventId)
|
||||
timeline.addListener(this)
|
||||
observeMembershipChanges()
|
||||
observeSummaryState()
|
||||
if (!initialState.isPinnedMessagesTimeline()) {
|
||||
observeSummaryState()
|
||||
}
|
||||
getUnreadState()
|
||||
observeSyncState()
|
||||
observeDataStore()
|
||||
|
@ -448,6 +451,8 @@ class TimelineViewModel @AssistedInject constructor(
|
|||
|
||||
override fun handle(action: RoomDetailAction) {
|
||||
when (action) {
|
||||
is RoomDetailAction.PinMessage -> handlePinMessage(action)
|
||||
is RoomDetailAction.UnpinMessage -> handleUnpinMessage(action)
|
||||
is RoomDetailAction.ComposerFocusChange -> handleComposerFocusChange(action)
|
||||
is RoomDetailAction.SendMedia -> handleSendMedia(action)
|
||||
is RoomDetailAction.SendSticker -> handleSendSticker(action)
|
||||
|
@ -757,6 +762,14 @@ class TimelineViewModel @AssistedInject constructor(
|
|||
return room?.membershipService()?.getRoomMember(userId)
|
||||
}
|
||||
|
||||
fun getIdOfLastPinnedEvent(): String? {
|
||||
return room
|
||||
?.stateService()
|
||||
?.getPinnedEventsState()
|
||||
?.getIdsOfPinnedEvents()
|
||||
?.last()
|
||||
}
|
||||
|
||||
private fun handleComposerFocusChange(action: RoomDetailAction.ComposerFocusChange) {
|
||||
if (room == null) return
|
||||
// Ensure outbound session keys
|
||||
|
@ -827,6 +840,7 @@ class TimelineViewModel @AssistedInject constructor(
|
|||
else -> false
|
||||
}
|
||||
}
|
||||
initialState.isPinnedMessagesTimeline() -> false
|
||||
else -> {
|
||||
when (itemId) {
|
||||
R.id.timeline_setting -> true
|
||||
|
@ -837,6 +851,7 @@ class TimelineViewModel @AssistedInject constructor(
|
|||
// Show Join conference button only if there is an active conf id not joined. Otherwise fallback to default video disabled. ^
|
||||
R.id.join_conference -> !state.isCallOptionAvailable() && state.jitsiState.confId != null && !state.jitsiState.hasJoined
|
||||
R.id.search -> state.isSearchAvailable()
|
||||
R.id.open_pinned_messages -> vectorPreferences.arePinnedMessagesEnabled() && areTherePinnedMessages()
|
||||
R.id.menu_timeline_thread_list -> vectorPreferences.areThreadMessagesEnabled()
|
||||
R.id.dev_tools -> vectorPreferences.developerMode()
|
||||
else -> false
|
||||
|
@ -1023,6 +1038,47 @@ class TimelineViewModel @AssistedInject constructor(
|
|||
_viewEvents.post(RoomDetailViewEvents.NavigateToEvent(targetEventId))
|
||||
}
|
||||
|
||||
private fun handlePinMessage(action: RoomDetailAction.PinMessage) {
|
||||
if (room == null) return
|
||||
val idsOfPinnedMessages = getIdsOfPinnedEvents()
|
||||
if (idsOfPinnedMessages == null) return
|
||||
idsOfPinnedMessages.add(action.eventId)
|
||||
sendPinnedStateEvent(idsOfPinnedMessages, action)
|
||||
}
|
||||
|
||||
private fun handleUnpinMessage(action: RoomDetailAction.UnpinMessage) {
|
||||
if (room == null) return
|
||||
val idsOfPinnedMessages = getIdsOfPinnedEvents()
|
||||
if (idsOfPinnedMessages == null) return
|
||||
idsOfPinnedMessages.remove(action.eventId)
|
||||
sendPinnedStateEvent(idsOfPinnedMessages, action)
|
||||
}
|
||||
|
||||
private fun getIdsOfPinnedEvents(): MutableList<String>? {
|
||||
return room
|
||||
?.stateService()
|
||||
?.getPinnedEventsState()
|
||||
?.getIdsOfPinnedEvents()
|
||||
}
|
||||
|
||||
private fun areTherePinnedMessages(): Boolean {
|
||||
val idsOfPinnedMessages = getIdsOfPinnedEvents() ?: return false
|
||||
return idsOfPinnedMessages.isNotEmpty()
|
||||
}
|
||||
|
||||
private fun sendPinnedStateEvent(eventIds: MutableList<String>, action: RoomDetailAction) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
try {
|
||||
room
|
||||
?.stateService()
|
||||
?.pinMessage(eventIds)
|
||||
_viewEvents.post(RoomDetailViewEvents.ActionSuccess(action))
|
||||
} catch (failure: Throwable) {
|
||||
_viewEvents.post(RoomDetailViewEvents.ActionFailure(action, failure))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleResendEvent(action: RoomDetailAction.ResendMessage) {
|
||||
if (room == null) return
|
||||
val targetEventId = action.eventId
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
package im.vector.app.features.home.room.detail.arguments
|
||||
|
||||
import android.os.Parcelable
|
||||
import im.vector.app.features.home.room.pinnedmessages.arguments.PinnedMessagesTimelineArgs
|
||||
import im.vector.app.features.home.room.threads.arguments.ThreadTimelineArgs
|
||||
import im.vector.app.features.share.SharedData
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
@ -28,6 +29,7 @@ data class TimelineArgs(
|
|||
val sharedData: SharedData? = null,
|
||||
val openShareSpaceForId: String? = null,
|
||||
val threadTimelineArgs: ThreadTimelineArgs? = null,
|
||||
val pinnedMessagesTimelineArgs: PinnedMessagesTimelineArgs? = null,
|
||||
val switchToParentSpace: Boolean = false,
|
||||
val isInviteAlreadyAccepted: Boolean = false
|
||||
) : Parcelable
|
||||
|
|
|
@ -53,6 +53,15 @@ sealed class EventSharedAction(
|
|||
data class ReplyInThread(val eventId: String, val startsThread: Boolean) :
|
||||
EventSharedAction(R.string.reply_in_thread, R.drawable.ic_reply_in_thread)
|
||||
|
||||
data class PinMessage(val eventId: String) :
|
||||
EventSharedAction(R.string.pinning_message, R.drawable.ic_pin_message)
|
||||
|
||||
data class UnpinMessage(val eventId: String) :
|
||||
EventSharedAction(R.string.unpinning_message, R.drawable.ic_unpin_message)
|
||||
|
||||
data class ViewPinnedMessageInRoom(val eventId: String) :
|
||||
EventSharedAction(R.string.view_in_room, R.drawable.ic_threads_view_in_room_24)
|
||||
|
||||
object ViewInRoom :
|
||||
EventSharedAction(R.string.view_in_room, R.drawable.ic_threads_view_in_room_24)
|
||||
|
||||
|
|
|
@ -35,7 +35,8 @@ data class ToggleState(
|
|||
data class ActionPermissions(
|
||||
val canSendMessage: Boolean = false,
|
||||
val canReact: Boolean = false,
|
||||
val canRedact: Boolean = false
|
||||
val canRedact: Boolean = false,
|
||||
val canPinMessage: Boolean = false
|
||||
)
|
||||
|
||||
data class MessageActionState(
|
||||
|
@ -50,14 +51,16 @@ data class MessageActionState(
|
|||
val actions: List<EventSharedAction> = emptyList(),
|
||||
val expendedReportContentMenu: Boolean = false,
|
||||
val actionPermissions: ActionPermissions = ActionPermissions(),
|
||||
val isFromThreadTimeline: Boolean = false
|
||||
val isFromThreadTimeline: Boolean = false,
|
||||
val isFromPinnedMessagesTimeline: Boolean = false
|
||||
) : MavericksState {
|
||||
|
||||
constructor(args: TimelineEventFragmentArgs) : this(
|
||||
roomId = args.roomId,
|
||||
eventId = args.eventId,
|
||||
informationData = args.informationData,
|
||||
isFromThreadTimeline = args.isFromThreadTimeline
|
||||
isFromThreadTimeline = args.isFromThreadTimeline,
|
||||
isFromPinnedMessagesTimeline = args.isFromPinnedMessagesTimeline
|
||||
)
|
||||
|
||||
fun senderName(): String = informationData.memberName?.toString() ?: ""
|
||||
|
|
|
@ -93,14 +93,15 @@ class MessageActionsBottomSheet :
|
|||
}
|
||||
|
||||
companion object {
|
||||
fun newInstance(roomId: String, informationData: MessageInformationData, isFromThreadTimeline: Boolean): MessageActionsBottomSheet {
|
||||
fun newInstance(roomId: String, informationData: MessageInformationData, isFromThreadTimeline: Boolean, isFromPinnedMessagesTimeline: Boolean): MessageActionsBottomSheet {
|
||||
return MessageActionsBottomSheet().apply {
|
||||
setArguments(
|
||||
TimelineEventFragmentArgs(
|
||||
informationData.eventId,
|
||||
roomId,
|
||||
informationData,
|
||||
isFromThreadTimeline
|
||||
isFromThreadTimeline,
|
||||
isFromPinnedMessagesTimeline
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
|
@ -131,7 +131,8 @@ class MessageActionsViewModel @AssistedInject constructor(
|
|||
val canReact = powerLevelsHelper.isUserAllowedToSend(session.myUserId, false, EventType.REACTION)
|
||||
val canRedact = powerLevelsHelper.isUserAbleToRedact(session.myUserId)
|
||||
val canSendMessage = powerLevelsHelper.isUserAllowedToSend(session.myUserId, false, EventType.MESSAGE)
|
||||
val permissions = ActionPermissions(canSendMessage = canSendMessage, canRedact = canRedact, canReact = canReact)
|
||||
val canPinMessage = powerLevelsHelper.isUserAllowedToSend(session.myUserId, false, EventType.STATE_ROOM_PINNED_EVENT)
|
||||
val permissions = ActionPermissions(canSendMessage = canSendMessage, canRedact = canRedact, canReact = canReact, canPinMessage = canPinMessage)
|
||||
setState {
|
||||
copy(actionPermissions = permissions)
|
||||
}
|
||||
|
@ -333,6 +334,13 @@ class MessageActionsViewModel @AssistedInject constructor(
|
|||
) {
|
||||
val eventId = timelineEvent.eventId
|
||||
if (!timelineEvent.root.isRedacted()) {
|
||||
if (initialState.isFromPinnedMessagesTimeline) {
|
||||
if (actionPermissions.canPinMessage && vectorPreferences.arePinnedMessagesEnabled()) {
|
||||
add(EventSharedAction.UnpinMessage(eventId))
|
||||
add(EventSharedAction.ViewPinnedMessageInRoom(eventId))
|
||||
}
|
||||
return
|
||||
}
|
||||
if (canReply(timelineEvent, messageContent, actionPermissions)) {
|
||||
add(EventSharedAction.Reply(eventId))
|
||||
}
|
||||
|
@ -362,6 +370,16 @@ class MessageActionsViewModel @AssistedInject constructor(
|
|||
add(EventSharedAction.AddReaction(eventId))
|
||||
}
|
||||
|
||||
if (actionPermissions.canPinMessage && vectorPreferences.arePinnedMessagesEnabled()) {
|
||||
val id: String = timelineEvent.root.eventId ?: return
|
||||
val isPinned: Boolean = room?.stateService()?.isPinned(id) ?: return
|
||||
if (isPinned) {
|
||||
add(EventSharedAction.UnpinMessage(eventId))
|
||||
} else {
|
||||
add(EventSharedAction.PinMessage(eventId))
|
||||
}
|
||||
}
|
||||
|
||||
if (canViewReactions(timelineEvent)) {
|
||||
add(EventSharedAction.ViewReactions(informationData))
|
||||
}
|
||||
|
|
|
@ -25,5 +25,6 @@ data class TimelineEventFragmentArgs(
|
|||
val eventId: String,
|
||||
val roomId: String,
|
||||
val informationData: MessageInformationData,
|
||||
val isFromThreadTimeline: Boolean = false
|
||||
val isFromThreadTimeline: Boolean = false,
|
||||
val isFromPinnedMessagesTimeline: Boolean = false
|
||||
) : Parcelable
|
||||
|
|
|
@ -71,6 +71,7 @@ class TimelineItemFactory @Inject constructor(
|
|||
EventType.STATE_ROOM_TOPIC,
|
||||
EventType.STATE_ROOM_AVATAR,
|
||||
EventType.STATE_ROOM_MEMBER,
|
||||
EventType.STATE_ROOM_PINNED_EVENT,
|
||||
EventType.STATE_ROOM_THIRD_PARTY_INVITE,
|
||||
EventType.STATE_ROOM_CANONICAL_ALIAS,
|
||||
EventType.STATE_ROOM_JOIN_RULES,
|
||||
|
|
|
@ -28,6 +28,8 @@ import org.matrix.android.sdk.api.extensions.orFalse
|
|||
import org.matrix.android.sdk.api.session.events.model.Event
|
||||
import org.matrix.android.sdk.api.session.events.model.EventType
|
||||
import org.matrix.android.sdk.api.session.events.model.content.EncryptionEventContent
|
||||
import org.matrix.android.sdk.api.session.events.model.getIdsOfPinnedEvents
|
||||
import org.matrix.android.sdk.api.session.events.model.getPreviousIdsOfPinnedEvents
|
||||
import org.matrix.android.sdk.api.session.events.model.isThread
|
||||
import org.matrix.android.sdk.api.session.events.model.toModel
|
||||
import org.matrix.android.sdk.api.session.room.model.GuestAccess
|
||||
|
@ -86,6 +88,7 @@ class NoticeEventFormatter @Inject constructor(
|
|||
EventType.STATE_ROOM_WIDGET_LEGACY -> formatWidgetEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName)
|
||||
EventType.STATE_ROOM_TOMBSTONE -> formatRoomTombstoneEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName, isDm)
|
||||
EventType.STATE_ROOM_POWER_LEVELS -> formatRoomPowerLevels(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName)
|
||||
EventType.STATE_ROOM_PINNED_EVENT -> formatPinnedEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName)
|
||||
EventType.CALL_INVITE,
|
||||
EventType.CALL_CANDIDATES,
|
||||
EventType.CALL_HANGUP,
|
||||
|
@ -118,6 +121,19 @@ class NoticeEventFormatter @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun formatPinnedEvent(event: Event, disambiguatedDisplayName: String): CharSequence? {
|
||||
val idsOfPinnedEvents: MutableList<String> = event.getIdsOfPinnedEvents() ?: return null
|
||||
val previousIdsOfPinnedEvents: MutableList<String>? = event.getPreviousIdsOfPinnedEvents()
|
||||
// A message was pinned
|
||||
val pinnedMessageString = if (event.resolvedPrevContent() == null || previousIdsOfPinnedEvents != null && previousIdsOfPinnedEvents.size < idsOfPinnedEvents.size) {
|
||||
sp.getString(R.string.user_pinned_message, disambiguatedDisplayName)
|
||||
// A message was unpinned
|
||||
} else {
|
||||
sp.getString(R.string.user_unpinned_message, disambiguatedDisplayName)
|
||||
}
|
||||
return pinnedMessageString
|
||||
}
|
||||
|
||||
private fun formatRoomPowerLevels(event: Event, disambiguatedDisplayName: String): CharSequence? {
|
||||
val powerLevelsContent: PowerLevelsContent = event.content.toModel() ?: return null
|
||||
val previousPowerLevelsContent: PowerLevelsContent = event.resolvedPrevContent().toModel() ?: return null
|
||||
|
@ -178,6 +194,7 @@ class NoticeEventFormatter @Inject constructor(
|
|||
}
|
||||
|
||||
fun format(event: Event, senderName: String?, isDm: Boolean): CharSequence? {
|
||||
Timber.v("°°°°°°°°°°°°°°°°°°°format(event: Event, senderName: String?, isDm: Boolean)")
|
||||
return when (val type = event.getClearType()) {
|
||||
EventType.STATE_ROOM_JOIN_RULES -> formatJoinRulesEvent(event, senderName, isDm)
|
||||
EventType.STATE_ROOM_NAME -> formatRoomNameEvent(event, senderName)
|
||||
|
@ -872,6 +889,7 @@ class NoticeEventFormatter @Inject constructor(
|
|||
}
|
||||
|
||||
fun formatRedactedEvent(event: Event): String {
|
||||
Timber.v("°°°°°°°formatRedactedEvent°°°°°°")
|
||||
return (event
|
||||
.unsignedData
|
||||
?.redactedEvent
|
||||
|
|
|
@ -38,6 +38,7 @@ object TimelineDisplayableEvents {
|
|||
EventType.STATE_ROOM_HISTORY_VISIBILITY,
|
||||
EventType.STATE_ROOM_SERVER_ACL,
|
||||
EventType.STATE_ROOM_POWER_LEVELS,
|
||||
EventType.STATE_ROOM_PINNED_EVENT,
|
||||
EventType.CALL_INVITE,
|
||||
EventType.CALL_HANGUP,
|
||||
EventType.CALL_ANSWER,
|
||||
|
|
|
@ -113,7 +113,7 @@ class MergedTimelines(
|
|||
secondaryTimeline.removeAllListeners()
|
||||
}
|
||||
|
||||
override fun start(rootThreadEventId: String?) {
|
||||
override fun start(rootThreadEventId: String?, rootPinnedMessageEventId: String?) {
|
||||
mainTimeline.start()
|
||||
secondaryTimeline.start()
|
||||
}
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
* Copyright (c) 2022 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.app.features.home.room.pinnedmessages
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import im.vector.app.core.extensions.replaceFragment
|
||||
import im.vector.app.core.platform.VectorBaseActivity
|
||||
import im.vector.app.databinding.ActivityPinnedMessagesBinding
|
||||
import im.vector.app.features.home.AvatarRenderer
|
||||
import im.vector.app.features.home.room.detail.TimelineFragment
|
||||
import im.vector.app.features.home.room.detail.arguments.TimelineArgs
|
||||
import im.vector.app.features.home.room.pinnedmessages.arguments.PinnedMessagesTimelineArgs
|
||||
import im.vector.lib.core.utils.compat.getParcelableCompat
|
||||
import javax.inject.Inject
|
||||
|
||||
@AndroidEntryPoint
|
||||
class PinnedMessagesActivity : VectorBaseActivity<ActivityPinnedMessagesBinding>() {
|
||||
|
||||
@Inject lateinit var avatarRenderer: AvatarRenderer
|
||||
|
||||
override fun getBinding() = ActivityPinnedMessagesBinding.inflate(layoutInflater)
|
||||
|
||||
override fun getCoordinatorLayout() = views.coordinatorLayout
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
initFragment()
|
||||
}
|
||||
|
||||
private fun initFragment() {
|
||||
if (isFirstCreation()) {
|
||||
when (val fragment = fragmentToNavigate()) {
|
||||
is DisplayFragment.PinnedMessagesTimeLine -> {
|
||||
initPinnedMessagesTimelineFragment(fragment.pinnedMessagesTimelineArgs)
|
||||
}
|
||||
is DisplayFragment.ErrorFragment -> {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun initPinnedMessagesTimelineFragment(pinnedMessagesTimelineArgs: PinnedMessagesTimelineArgs) =
|
||||
replaceFragment(
|
||||
views.pinnedMessagesActivityFragmentContainer,
|
||||
TimelineFragment::class.java,
|
||||
TimelineArgs(
|
||||
roomId = pinnedMessagesTimelineArgs.roomId,
|
||||
pinnedMessagesTimelineArgs = pinnedMessagesTimelineArgs
|
||||
)
|
||||
)
|
||||
|
||||
/**
|
||||
* Determine in witch fragment we should navigate.
|
||||
*/
|
||||
private fun fragmentToNavigate(): DisplayFragment {
|
||||
getPinnedMessagesTimelineArgs()?.let {
|
||||
return DisplayFragment.PinnedMessagesTimeLine(it)
|
||||
}
|
||||
return DisplayFragment.ErrorFragment
|
||||
}
|
||||
|
||||
private fun getPinnedMessagesTimelineArgs(): PinnedMessagesTimelineArgs? = intent?.extras?.getParcelableCompat(PINNED_MESSAGES_TIMELINE_ARGS)
|
||||
|
||||
companion object {
|
||||
const val PINNED_MESSAGES_TIMELINE_ARGS = "PINNED_MESSAGES_TIMELINE_ARGS"
|
||||
|
||||
fun newIntent(
|
||||
context: Context,
|
||||
pinnedMessagesTimelineArgs: PinnedMessagesTimelineArgs?,
|
||||
): Intent {
|
||||
return Intent(context, PinnedMessagesActivity::class.java).apply {
|
||||
putExtra(PINNED_MESSAGES_TIMELINE_ARGS, pinnedMessagesTimelineArgs)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sealed class DisplayFragment {
|
||||
data class PinnedMessagesTimeLine(val pinnedMessagesTimelineArgs: PinnedMessagesTimelineArgs) : DisplayFragment()
|
||||
object ErrorFragment : DisplayFragment()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright (c) 2022 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.app.features.home.room.pinnedmessages.arguments
|
||||
|
||||
import android.os.Parcelable
|
||||
import kotlinx.parcelize.Parcelize
|
||||
import org.matrix.android.sdk.api.session.crypto.model.RoomEncryptionTrustLevel
|
||||
|
||||
@Parcelize
|
||||
data class PinnedMessagesTimelineArgs(
|
||||
val roomId: String,
|
||||
val displayName: String?,
|
||||
val avatarUrl: String?,
|
||||
val roomEncryptionTrustLevel: RoomEncryptionTrustLevel?,
|
||||
val rootPinnedMessageEventId: String?
|
||||
) : Parcelable
|
|
@ -58,6 +58,8 @@ import im.vector.app.features.home.room.detail.arguments.TimelineArgs
|
|||
import im.vector.app.features.home.room.detail.search.SearchActivity
|
||||
import im.vector.app.features.home.room.detail.search.SearchArgs
|
||||
import im.vector.app.features.home.room.filtered.FilteredRoomsActivity
|
||||
import im.vector.app.features.home.room.pinnedmessages.arguments.PinnedMessagesTimelineArgs
|
||||
import im.vector.app.features.home.room.pinnedmessages.PinnedMessagesActivity
|
||||
import im.vector.app.features.home.room.threads.ThreadsActivity
|
||||
import im.vector.app.features.home.room.threads.arguments.ThreadListArgs
|
||||
import im.vector.app.features.home.room.threads.arguments.ThreadTimelineArgs
|
||||
|
@ -599,6 +601,15 @@ class DefaultNavigator @Inject constructor(
|
|||
)
|
||||
}
|
||||
|
||||
override fun openPinnedMessages(context: Context, pinnedMessagesTimelineArgs: PinnedMessagesTimelineArgs) {
|
||||
context.startActivity(
|
||||
PinnedMessagesActivity.newIntent(
|
||||
context = context,
|
||||
pinnedMessagesTimelineArgs = pinnedMessagesTimelineArgs
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
override fun openScreenSharingPermissionDialog(
|
||||
screenCaptureIntent: Intent,
|
||||
activityResultLauncher: ActivityResultLauncher<Intent>
|
||||
|
|
|
@ -27,6 +27,7 @@ import androidx.fragment.app.FragmentActivity
|
|||
import im.vector.app.features.analytics.plan.ViewRoom
|
||||
import im.vector.app.features.crypto.recover.SetupMode
|
||||
import im.vector.app.features.displayname.getBestName
|
||||
import im.vector.app.features.home.room.pinnedmessages.arguments.PinnedMessagesTimelineArgs
|
||||
import im.vector.app.features.home.room.threads.arguments.ThreadTimelineArgs
|
||||
import im.vector.app.features.location.LocationData
|
||||
import im.vector.app.features.location.LocationSharingMode
|
||||
|
@ -198,6 +199,8 @@ interface Navigator {
|
|||
|
||||
fun openThreadList(context: Context, threadTimelineArgs: ThreadTimelineArgs)
|
||||
|
||||
fun openPinnedMessages(context: Context, pinnedMessagesTimelineArgs: PinnedMessagesTimelineArgs)
|
||||
|
||||
fun openScreenSharingPermissionDialog(
|
||||
screenCaptureIntent: Intent,
|
||||
activityResultLauncher: ActivityResultLauncher<Intent>
|
||||
|
|
|
@ -234,6 +234,8 @@ class VectorPreferences @Inject constructor(
|
|||
|
||||
private const val SETTINGS_LABS_ENABLE_ELEMENT_CALL_PERMISSION_SHORTCUTS = "SETTINGS_LABS_ENABLE_ELEMENT_CALL_PERMISSION_SHORTCUTS"
|
||||
|
||||
private const val SETTINGS_LABS_ENABLE_PINNED_MESSAGES = "SETTINGS_LABS_ENABLE_PINNED_MESSAGES"
|
||||
|
||||
// This key will be used to identify clients with the old thread support enabled io.element.thread
|
||||
const val SETTINGS_LABS_ENABLE_THREAD_MESSAGES_OLD_CLIENTS = "SETTINGS_LABS_ENABLE_THREAD_MESSAGES"
|
||||
|
||||
|
@ -1112,6 +1114,10 @@ class VectorPreferences @Inject constructor(
|
|||
return defaultPrefs.getBoolean(SETTINGS_LABS_ENABLE_ELEMENT_CALL_PERMISSION_SHORTCUTS, false)
|
||||
}
|
||||
|
||||
fun arePinnedMessagesEnabled(): Boolean {
|
||||
return defaultPrefs.getBoolean(SETTINGS_LABS_ENABLE_PINNED_MESSAGES, getDefault(R.bool.settings_labs_pinned_messages_default))
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether or not thread messages are enabled.
|
||||
*/
|
||||
|
|
9
vector/src/main/res/drawable/ic_open_pinned_messages.xml
Normal file
9
vector/src/main/res/drawable/ic_open_pinned_messages.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="m21.068,7.758 l-4.826,-4.826a2.75,2.75 0,0 0,-4.404 0.715l-2.435,4.87a0.75,0.75 0,0 1,-0.426 0.374L4.81,10.33a1.25,1.25 0,0 0,-0.476 2.065L7.439,15.5 3,19.94V21h1.06l4.44,-4.44 3.104,3.105a1.25,1.25 0,0 0,2.066 -0.476l1.44,-4.166a0.75,0.75 0,0 1,0.373 -0.426l4.87,-2.435a2.75,2.75 0,0 0,0.715 -4.404Z"
|
||||
android:fillColor="#70a81d"/>
|
||||
</vector>
|
9
vector/src/main/res/drawable/ic_pin_message.xml
Normal file
9
vector/src/main/res/drawable/ic_pin_message.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="m16.242,2.932 l4.826,4.826a2.75,2.75 0,0 1,-0.715 4.404l-4.87,2.435a0.75,0.75 0,0 0,-0.374 0.426l-1.44,4.166a1.25,1.25 0,0 1,-2.065 0.476L8.5,16.561 4.06,21L3,21v-1.06l4.44,-4.44 -3.105,-3.104a1.25,1.25 0,0 1,0.476 -2.066l4.166,-1.44a0.75,0.75 0,0 0,0.426 -0.373l2.435,-4.87a2.75,2.75 0,0 1,4.405 -0.715ZM20.008,8.818 L15.182,3.992a1.25,1.25 0,0 0,-2.002 0.325l-2.435,4.871a2.25,2.25 0,0 1,-1.278 1.12l-3.789,1.31 6.705,6.704 1.308,-3.789a2.25,2.25 0,0 1,1.12 -1.277l4.872,-2.436a1.25,1.25 0,0 0,0.325 -2.002Z"
|
||||
android:fillColor="#aeb5bc"/>
|
||||
</vector>
|
9
vector/src/main/res/drawable/ic_unpin_message.xml
Normal file
9
vector/src/main/res/drawable/ic_unpin_message.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="M3.28,2.22a0.75,0.75 0,0 0,-1.06 1.06l5.905,5.905L4.81,10.33a1.25,1.25 0,0 0,-0.476 2.065L7.439,15.5 3,19.94L3,21h1.06l4.44,-4.44 3.105,3.105a1.25,1.25 0,0 0,2.065 -0.476l1.145,-3.313 5.905,5.904a0.75,0.75 0,0 0,1.06 -1.06L3.28,2.22ZM13.635,14.696 L12.383,18.322 5.678,11.617 9.304,10.365 13.635,14.696ZM19.683,10.82 L15.896,12.714 17.014,13.832 20.354,12.162a2.75,2.75 0,0 0,0.714 -4.404l-4.825,-4.826a2.75,2.75 0,0 0,-4.405 0.715l-1.67,3.34 1.118,1.117 1.894,-3.787a1.25,1.25 0,0 1,2.002 -0.325l4.826,4.826a1.25,1.25 0,0 1,-0.325 2.002Z"
|
||||
android:fillColor="#aeb5bc"/>
|
||||
</vector>
|
24
vector/src/main/res/layout/activity_pinned_messages.xml
Normal file
24
vector/src/main/res/layout/activity_pinned_messages.xml
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/coordinatorLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<androidx.fragment.app.FragmentContainerView
|
||||
android:id="@+id/pinnedMessagesActivityFragmentContainer"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
|
@ -40,6 +40,16 @@
|
|||
app:showAsAction="always"
|
||||
tools:visible="true" />
|
||||
|
||||
<!-- We always want to show this item as an icon -->
|
||||
<item
|
||||
android:id="@+id/open_pinned_messages"
|
||||
android:icon="@drawable/ic_open_pinned_messages"
|
||||
android:title="@string/action_open_pinned_messages"
|
||||
android:visible="true"
|
||||
app:iconTint="?colorPrimary"
|
||||
app:showAsAction="always"
|
||||
tools:visible="true" />
|
||||
|
||||
<!-- We always want to show this item as an icon -->
|
||||
<item
|
||||
android:id="@+id/menu_timeline_thread_list"
|
||||
|
|
|
@ -59,6 +59,11 @@
|
|||
android:title="@string/labs_enable_latex_maths" />
|
||||
<!--</im.vector.app.core.preference.VectorPreferenceCategory>-->
|
||||
|
||||
<im.vector.app.core.preference.VectorSwitchPreference
|
||||
android:defaultValue="@bool/settings_labs_pinned_messages_default"
|
||||
android:key="SETTINGS_LABS_ENABLE_PINNED_MESSAGES"
|
||||
android:title="@string/labs_enable_pinned_messages" />
|
||||
|
||||
<im.vector.app.core.preference.VectorSwitchPreference
|
||||
android:defaultValue="@bool/settings_labs_thread_messages_default"
|
||||
android:key="SETTINGS_LABS_ENABLE_THREAD_MESSAGES_FINAL"
|
||||
|
|
Loading…
Reference in a new issue