-
Notifications
You must be signed in to change notification settings - Fork 676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added lab feature to pin/unpin messages #7762
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for your Pull Request!
I have made a bunch of first remarks.
@@ -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>? { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should return a List
instead of a MutableList
. There are other similar remarks in your PR, I will just comment the others with List
.
return getClearContent()?.toModel<PinnedEventsStateContent>()?.eventIds | ||
} | ||
|
||
fun Event.getPreviousIdsOfPinnedEvents(): MutableList<String>? { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
List
*/ | ||
@JsonClass(generateAdapter = true) | ||
data class PinnedEventsStateContent( | ||
@Json(name = "pinned") val eventIds: MutableList<String> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
List
/** | ||
* Pin a message of the room. | ||
*/ | ||
suspend fun pinMessage(eventIds: MutableList<String>) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is taking a list of eventIds, so the doc is not accurate.
the SDK could expose a higher level API like
suspend fun pinEvent(eventId: String)
suspend fun unpinEvent(eventId: String)
and compute the new event data regarding the current one.
it may expose this API
suspend fun setPinnedEvents(eventIds: List<String>)
as a bonus for advanced usages like removing all the pinned events, and pinning multiple events in one request.
For the current usages added by this PR, I would just expose pinEvent
and unpinEvent
methods here.
/** | ||
* Get state event containing the IDs of pinned events of the room | ||
*/ | ||
fun getPinnedEventsState(): Event? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not add this method in this Service, since this is a shortcut for getStateEvent
.
@@ -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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
List
@@ -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)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this tmp log.
@@ -872,6 +889,7 @@ class NoticeEventFormatter @Inject constructor( | |||
} | |||
|
|||
fun formatRedactedEvent(event: Event): String { | |||
Timber.v("°°°°°°°formatRedactedEvent°°°°°°") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this tmp log.
is DisplayFragment.ErrorFragment -> { | ||
finish() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit over engineered. I would simply write
private fun initFragment() {
if (isFirstCreation()) {
val args = getPinnedMessagesTimelineArgs()
if(args == null) {
finish()
} else {
initPinnedMessagesTimelineFragment(args)
}
}
}
And cleanup all unused code.
val avatarUrl: String?, | ||
val roomEncryptionTrustLevel: RoomEncryptionTrustLevel?, | ||
val rootPinnedMessageEventId: String? | ||
) : Parcelable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per my previous remark, I would only keep the roomId
here.
@bmarty thanks for your review! I edited the things you marked and also did some additional refactoring (renamed files and variables to have more consistency). |
In case that someone wants to know where the icons which are used in this PR come from : They are from Microsoft's Fluent Icons. |
Waiting for this to be merged, it's a very useful feature. Right now I have to explore the room data and copy out the pin IDs, then check them one by one. It isnt very convenient at all |
I'd also vote for removing the |
@bmarty any updates? |
nice feature here! Does it need more changes before merging it @bmarty ? |
Type of change
Content
This PR adds a new feature so users can (un)pin messages and open a timeline where only the pinned messages are visible. The feature can be found and activated in the "Labs" settings.
Details of this feature:
Little background:
Currently, if pinned messages are missing the client will load chunks of older messages like it does in the "normal" timeline until all pinned messages are available. This is not very efficient but it works for now.
Motivation and context
Solves #5933 and #357
Screenshots / GIFs
Here you can see the context menu which includes a button to pin a message. When a message is pinned already a button to do the opposite will be shown.
When there are pinned messages available a button to open a timeline with these messages appears at the top right corner.
Tests
Tested devices
Checklist
Signed-off-by: Christoph Klassen christoph.klassen@intevation.de