Benoit Marty
2 years ago
committed by
Benoit Marty
16 changed files with 228 additions and 22 deletions
@ -0,0 +1,27 @@
@@ -0,0 +1,27 @@
|
||||
/* |
||||
* Copyright (c) 2023 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 io.element.android.libraries.matrix.api.notification |
||||
|
||||
import io.element.android.libraries.matrix.api.timeline.MatrixTimelineItem |
||||
|
||||
data class NotificationData( |
||||
val item: MatrixTimelineItem, |
||||
val title: String, |
||||
val subtitle: String?, |
||||
val isNoisy: Boolean, |
||||
val avatarUrl: String?, |
||||
) |
@ -0,0 +1,21 @@
@@ -0,0 +1,21 @@
|
||||
/* |
||||
* Copyright (c) 2023 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 io.element.android.libraries.matrix.api.notification |
||||
|
||||
interface NotificationService { |
||||
fun getNotification(userId: String, roomId: String, eventId: String): NotificationData? |
||||
} |
@ -0,0 +1,51 @@
@@ -0,0 +1,51 @@
|
||||
/* |
||||
* Copyright (c) 2023 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 io.element.android.libraries.matrix.impl.notification |
||||
|
||||
import io.element.android.libraries.matrix.api.notification.NotificationData |
||||
import io.element.android.libraries.matrix.impl.timeline.MatrixTimelineItemMapper |
||||
import io.element.android.libraries.matrix.impl.timeline.item.event.EventMessageMapper |
||||
import io.element.android.libraries.matrix.impl.timeline.item.event.EventTimelineItemMapper |
||||
import io.element.android.libraries.matrix.impl.timeline.item.event.TimelineEventContentMapper |
||||
import io.element.android.libraries.matrix.impl.timeline.item.virtual.VirtualTimelineItemMapper |
||||
import org.matrix.rustcomponents.sdk.NotificationItem |
||||
import org.matrix.rustcomponents.sdk.use |
||||
import javax.inject.Inject |
||||
|
||||
class NotificationMapper @Inject constructor() { |
||||
// TODO Inject and remove duplicate? |
||||
private val timelineItemFactory = MatrixTimelineItemMapper( |
||||
virtualTimelineItemMapper = VirtualTimelineItemMapper(), |
||||
eventTimelineItemMapper = EventTimelineItemMapper( |
||||
contentMapper = TimelineEventContentMapper( |
||||
eventMessageMapper = EventMessageMapper() |
||||
) |
||||
) |
||||
) |
||||
|
||||
fun map(notificationItem: NotificationItem): NotificationData { |
||||
return notificationItem.use { |
||||
NotificationData( |
||||
item = timelineItemFactory.map(it.item), |
||||
title = it.title, |
||||
subtitle = it.subtitle, |
||||
isNoisy = it.isNoisy, |
||||
avatarUrl = it.avatarUrl, |
||||
) |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,39 @@
@@ -0,0 +1,39 @@
|
||||
/* |
||||
* Copyright (c) 2023 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 io.element.android.libraries.matrix.impl.notification |
||||
|
||||
import io.element.android.libraries.matrix.api.notification.NotificationData |
||||
import io.element.android.libraries.matrix.api.notification.NotificationService |
||||
import java.io.File |
||||
|
||||
class RustNotificationService( |
||||
private val baseDirectory: File, |
||||
) : NotificationService { |
||||
private val notificationMapper: NotificationMapper = NotificationMapper() |
||||
|
||||
override fun getNotification(userId: String, roomId: String, eventId: String): NotificationData? { |
||||
return org.matrix.rustcomponents.sdk.NotificationService( |
||||
basePath = File(baseDirectory, "sessions").absolutePath, |
||||
userId = userId |
||||
).use { |
||||
// TODO Not implemented yet, see https://github.com/matrix-org/matrix-rust-sdk/issues/1628 |
||||
it.getNotificationItem(roomId, eventId)?.let { notificationItem -> |
||||
notificationMapper.map(notificationItem) |
||||
} |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue