Skip to content

Commit

Permalink
edits after first review on Github
Browse files Browse the repository at this point in the history
  • Loading branch information
cintek committed Dec 16, 2022
1 parent adc9136 commit 015bd8b
Show file tree
Hide file tree
Showing 40 changed files with 347 additions and 406 deletions.
2 changes: 1 addition & 1 deletion changelog.d/7762.feature
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Added lab feature to pin/unpin messages
Added lab feature to pin/unpin messages
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# The setting is particularly useful for tweaking memory settings.

# Build Time Optimizations
org.gradle.jvmargs=-Xmx4g -Xms512M -XX:MaxPermSize=2048m -XX:MaxMetaspaceSize=1g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -XX:+UseParallelGC
org.gradle.jvmargs=-Xmx4g -Xms512M -XX:MaxMetaspaceSize=1g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -XX:+UseParallelGC
org.gradle.configureondemand=true
org.gradle.parallel=true
org.gradle.vfs.watch=true
Expand Down
16 changes: 9 additions & 7 deletions library/ui-strings/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@
<string name="notice_room_server_acl_set_allowed">• Servers matching %s are allowed.</string>
<string name="notice_room_server_acl_set_ip_literals_allowed">• Servers matching IP literals are allowed.</string>
<string name="notice_room_server_acl_set_ip_literals_not_allowed">• Servers matching IP literals are banned.</string>
<string name="notice_user_pinned_event">%1$s pinned a message.</string>
<string name="notice_user_unpinned_event">%1$s unpinned a message.</string>
<string name="notice_user_pinned_event_by_you">You pinned a message.</string>
<string name="notice_user_unpinned_event_by_you">You unpinned a message.</string>

<string name="notice_room_server_acl_updated_title">%s changed the server ACLs for this room.</string>
<string name="notice_room_server_acl_updated_title_by_you">You changed the server ACLs for this room.</string>
Expand Down Expand Up @@ -373,7 +377,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_open_pinned_events">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>
Expand Down Expand Up @@ -803,11 +807,9 @@
<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>
<string name="pinning_event">Pin</string>
<string name="unpinning_event">Unpin</string>
<string name="pinned_events_timeline_title">Pinned Messages</string>

<!-- Search -->
<string name="search_hint">Search</string>
Expand Down Expand Up @@ -3039,7 +3041,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_pinned_events">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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,10 @@ fun Event.supportsNotification() =
fun Event.isContentReportable() =
this.getClearType() in EventType.MESSAGE + EventType.STATE_ROOM_BEACON_INFO.values

fun Event.getIdsOfPinnedEvents(): MutableList<String>? {
fun Event.getIdsOfPinnedEvents(): List<String>? {
return getClearContent()?.toModel<PinnedEventsStateContent>()?.eventIds
}

fun Event.getPreviousIdsOfPinnedEvents(): MutableList<String>? {
fun Event.getPreviousIdsOfPinnedEvents(): List<String>? {
return resolvedPrevContent()?.toModel<PinnedEventsStateContent>()?.eventIds
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ import com.squareup.moshi.JsonClass
*/
@JsonClass(generateAdapter = true)
data class PinnedEventsStateContent(
@Json(name = "pinned") val eventIds: MutableList<String>
@Json(name = "pinned") val eventIds: List<String>
)
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,14 @@ interface StateService {
suspend fun deleteAvatar()

/**
* Pin a message of the room.
* Pin an event of the room.
*/
suspend fun pinMessage(eventIds: MutableList<String>)
suspend fun pinEvent(eventId: String)

/**
* Unpin an event of the room.
*/
suspend fun unpinEvent(eventId: String)

/**
* Send a state event to the room.
Expand Down Expand Up @@ -108,16 +113,6 @@ 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>)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, rootPinnedMessageEventId: String? = null)
fun start(rootThreadEventId: String? = null, isFromPinnedEventsTimeline: Boolean = false)

/**
* This must be called when you don't need the timeline. It ensures the underlying database get closed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ data class TimelineSettings(
*/
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.
* True if the timeline is a pinned messages timeline.
*/
val rootPinnedMessageEventId: String? = null,
val isFromPinnedEventsTimeline: Boolean = false,
/**
* If true Sender Info shown in room will get the latest data information (avatar + displayName).
*/
Expand All @@ -50,5 +50,5 @@ data class TimelineSettings(
/**
* Returns true if this is a pinned messages timeline or false otherwise.
*/
fun isPinnedMessagesTimeline() = rootPinnedMessageEventId != null
fun isPinnedEventsTimeline() = isFromPinnedEventsTimeline
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ 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
Expand Down Expand Up @@ -249,7 +248,7 @@ internal interface RoomAPI {
@Path("roomId") roomId: String,
@Path("eventType") eventType: String,
@Path("state_key") stateKey: String
): PinnedEventsStateResponse
): Content

/**
* Paginate relations for event based in normal topological order.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -173,23 +173,32 @@ internal class DefaultStateService @AssistedInject constructor(
)
}

override suspend fun pinMessage(eventIds: MutableList<String>) {
override suspend fun pinEvent(eventId: String) {
val pinnedEvents = getStateEvent(EventType.STATE_ROOM_PINNED_EVENT, QueryStringValue.Equals(""))
?.getIdsOfPinnedEvents()
?.toMutableList()
pinnedEvents?.add(eventId)
val newListOfPinnedEvents = pinnedEvents?.toList() ?: return
setPinnedEvents(newListOfPinnedEvents)
}

override suspend fun unpinEvent(eventId: String) {
val pinnedEvents = getStateEvent(EventType.STATE_ROOM_PINNED_EVENT, QueryStringValue.Equals(""))
?.getIdsOfPinnedEvents()
?.toMutableList()
pinnedEvents?.remove(eventId)
val newListOfPinnedEvents = pinnedEvents?.toList() ?: return
setPinnedEvents(newListOfPinnedEvents)
}

private suspend fun setPinnedEvents(eventIds: List<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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ internal class DefaultTimeline(
private var isFromThreadTimeline = false
private var rootThreadEventId: String? = null

private var isFromPinnedMessagesTimeline = false
private var rootPinnedMessageEventId: String? = null
private var isFromPinnedEventsTimeline = false

private val strategyDependencies = LoadTimelineStrategy.Dependencies(
timelineSettings = settings,
Expand Down Expand Up @@ -132,7 +131,7 @@ internal class DefaultTimeline(
override fun addListener(listener: Timeline.Listener): Boolean {
listeners.add(listener)
timelineScope.launch {
val snapshot = if (isFromPinnedMessagesTimeline) {
val snapshot = if (isFromPinnedEventsTimeline) {
getPinnedEvents()
} else {
strategy.buildSnapshot()
Expand All @@ -152,7 +151,7 @@ internal class DefaultTimeline(
listeners.clear()
}

override fun start(rootThreadEventId: String?, rootPinnedMessageEventId: String?) {
override fun start(rootThreadEventId: String?, isFromPinnedEventsTimeline: Boolean) {
timelineScope.launch {
loadRoomMembersIfNeeded()
}
Expand All @@ -161,8 +160,7 @@ internal class DefaultTimeline(
if (isStarted.compareAndSet(false, true)) {
isFromThreadTimeline = rootThreadEventId != null
this@DefaultTimeline.rootThreadEventId = rootThreadEventId
isFromPinnedMessagesTimeline = rootPinnedMessageEventId != null
this@DefaultTimeline.rootPinnedMessageEventId = rootPinnedMessageEventId
this@DefaultTimeline.isFromPinnedEventsTimeline = isFromPinnedEventsTimeline
// /
val realm = Realm.getInstance(realmConfiguration)
ensureReadReceiptAreLoaded(realm)
Expand Down Expand Up @@ -267,8 +265,8 @@ internal class DefaultTimeline(
}
}
Timber.v("$baseLogMessage: result $loadMoreResult")
val hasMoreToLoad = if (isFromPinnedMessagesTimeline) {
!areAllPinnedMessagesLoaded()
val hasMoreToLoad = if (isFromPinnedEventsTimeline) {
!areAllPinnedEventsLoaded()
} else {
loadMoreResult != LoadMoreResult.REACHED_END
}
Expand Down Expand Up @@ -352,7 +350,7 @@ internal class DefaultTimeline(
}

private suspend fun postSnapshot() {
val snapshot = if (isFromPinnedMessagesTimeline) {
val snapshot = if (isFromPinnedEventsTimeline) {
getPinnedEvents()
} else {
strategy.buildSnapshot()
Expand All @@ -371,25 +369,22 @@ internal class DefaultTimeline(
}
}

private fun getIdsOfPinnedEvents(): MutableList<String> {
private fun getIdsOfPinnedEvents(): List<String> {
return stateEventDataSource
.getStateEvent(roomId, EventType.STATE_ROOM_PINNED_EVENT, QueryStringValue.Equals(""))
?.getIdsOfPinnedEvents() ?: mutableListOf("")
?.getIdsOfPinnedEvents()
.orEmpty()
}

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()
return getIdsOfPinnedEvents()
.mapNotNull { id ->
timelineEventDataSource.getTimelineEvent(roomId, id)
}
.reversed()
}

private fun areAllPinnedMessagesLoaded(): Boolean {
private fun areAllPinnedEventsLoaded(): Boolean {
return getIdsOfPinnedEvents().size == getPinnedEvents().size
}

Expand Down
2 changes: 1 addition & 1 deletion vector-config/src/main/res/values/config-settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +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_pinned_events_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>
Expand Down
2 changes: 1 addition & 1 deletion vector/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +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.pinnedmessages.PinnedEventsActivity" />

<activity
android:name=".features.home.room.detail.RoomDetailActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +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 PinEvent(val eventId: String) : RoomDetailAction()
data class UnpinEvent(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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ 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,
Expand All @@ -81,6 +80,7 @@ data class RoomDetailViewState(
val isSharingLiveLocation: Boolean = false,
val showKeyboardWhenPresented: Boolean = false,
val sharedData: SharedData? = null,
val isFromPinnedEventsTimeline: Boolean = false,
) : MavericksState {

constructor(args: TimelineArgs) : this(
Expand All @@ -93,7 +93,7 @@ data class RoomDetailViewState(
rootThreadEventId = args.threadTimelineArgs?.rootThreadEventId,
showKeyboardWhenPresented = args.threadTimelineArgs?.showKeyboard.orFalse(),
sharedData = args.sharedData,
rootPinnedMessageEventId = args.pinnedMessagesTimelineArgs?.rootPinnedMessageEventId,
isFromPinnedEventsTimeline = args.pinnedEventsTimelineArgs != null,
)

fun isCallOptionAvailable(): Boolean {
Expand All @@ -115,7 +115,7 @@ data class RoomDetailViewState(

fun isThreadTimeline() = rootThreadEventId != null

fun isPinnedMessagesTimeline() = rootPinnedMessageEventId != null
fun isPinnedEventsTimeline() = isFromPinnedEventsTimeline

fun isLocalRoom() = RoomLocalEcho.isLocalEchoId(roomId)
}
Loading

0 comments on commit 015bd8b

Please sign in to comment.