Add shortcut suggestions for rooms, remove then when leaving (#5180)
* Report shortcut usage for outgoing messages This patch adds support for creating and pushing dynamic long-lived shortcuts for outgoing messages. This together with an existing reference to the roomId used by the shortcuts as an identifer allows conversations to be prioritized. See https://developer.android.com/training/sharing/direct-share-targets#report-usage-outgoing * Simplify how to get the other user in a DM room * Add initial avatar icons to shortcuts * Remove room shortcuts when they're no longer joined * Try using API 33 for the new tests. They worked locally with API 30, so it's weird the CI asks for a higher API version. * Add observers for the pin code and session logout states. With this we can prevent new shortcuts from being created and remove existing ones when needed. * Wrap all calls to `ShortcutManagerCompat` with `runCatchingExceptions` to avoid crashes * Make `DefaultNotificationConversationService` a singleton. --------- Co-authored-by: networkException <git@nwex.de> Co-authored-by: ElementBot <android@element.io>
This commit is contained in:
parent
35928e3630
commit
9bc2c4a776
27 changed files with 681 additions and 27 deletions
|
|
@ -17,5 +17,6 @@ dependencies {
|
|||
implementation(libs.coroutines.core)
|
||||
implementation(libs.coil.compose)
|
||||
implementation(projects.libraries.matrix.api)
|
||||
implementation(projects.libraries.matrixui)
|
||||
implementation(projects.libraries.pushproviders.api)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,14 +10,20 @@ package io.element.android.libraries.push.api.notifications
|
|||
import android.graphics.Bitmap
|
||||
import androidx.core.graphics.drawable.IconCompat
|
||||
import coil3.ImageLoader
|
||||
import io.element.android.libraries.matrix.ui.media.AVATAR_THUMBNAIL_SIZE_IN_PIXEL
|
||||
|
||||
interface NotificationBitmapLoader {
|
||||
/**
|
||||
* Get icon of a room.
|
||||
* @param path mxc url
|
||||
* @param imageLoader Coil image loader
|
||||
* @param targetSize The size we want the bitmap to be resized to
|
||||
*/
|
||||
suspend fun getRoomBitmap(path: String?, imageLoader: ImageLoader): Bitmap?
|
||||
suspend fun getRoomBitmap(
|
||||
path: String?,
|
||||
imageLoader: ImageLoader,
|
||||
targetSize: Long = AVATAR_THUMBNAIL_SIZE_IN_PIXEL,
|
||||
): Bitmap?
|
||||
|
||||
/**
|
||||
* Get icon of a user.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright 2025 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.libraries.push.api.notifications.conversations
|
||||
|
||||
import io.element.android.libraries.matrix.api.core.RoomId
|
||||
import io.element.android.libraries.matrix.api.core.SessionId
|
||||
|
||||
/**
|
||||
* Service to handle conversation-related notifications.
|
||||
*/
|
||||
interface NotificationConversationService {
|
||||
/**
|
||||
* Called when a new message is received in a room.
|
||||
* It should create a new conversation shortcut for this room.
|
||||
*/
|
||||
suspend fun onSendMessage(
|
||||
sessionId: SessionId,
|
||||
roomId: RoomId,
|
||||
roomName: String,
|
||||
roomIsDirect: Boolean,
|
||||
roomAvatarUrl: String?,
|
||||
)
|
||||
|
||||
/**
|
||||
* Called when a room is left.
|
||||
* It should remove the conversation shortcut for this room.
|
||||
*/
|
||||
suspend fun onLeftRoom(sessionId: SessionId, roomId: RoomId)
|
||||
|
||||
/**
|
||||
* Called when the list of available rooms changes.
|
||||
* It should update the conversation shortcuts accordingly, removing shortcuts for no longer joined rooms.
|
||||
*/
|
||||
suspend fun onAvailableRoomsChanged(sessionId: SessionId, roomIds: Set<RoomId>)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue