-
Notifications
You must be signed in to change notification settings - Fork 748
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8941 from element-hq/feature/bma/elementCall
Element call incoming call
- Loading branch information
Showing
15 changed files
with
319 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Indicate when calls are unsupported in the timeline/notifications |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...in/java/org/matrix/android/sdk/api/session/room/model/message/ElementCallNotifyContent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2024 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.message | ||
|
||
import com.squareup.moshi.Json | ||
import com.squareup.moshi.JsonClass | ||
|
||
@JsonClass(generateAdapter = true) | ||
data class ElementCallNotifyContent( | ||
@Json(name = "application") val application: String? = null, | ||
@Json(name = "call_id") val callId: String? = null, | ||
@Json(name = "m.mentions") val mentions: Mentions? = null, | ||
@Json(name = "notify_type") val notifyType: String? = null, | ||
) | ||
|
||
@JsonClass(generateAdapter = true) | ||
data class Mentions( | ||
@Json(name = "room") val room: Boolean? = null, | ||
@Json(name = "user_ids") val userIds: List<String>? = null, | ||
) | ||
|
||
fun ElementCallNotifyContent.isUserMentioned(userId: String): Boolean { | ||
return mentions?.room == true || | ||
mentions?.userIds?.contains(userId) == true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
...n/java/im/vector/app/features/home/room/detail/timeline/factory/ElementCallItemFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Copyright 2024 New Vector Ltd. | ||
* | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
* Please see LICENSE in the repository root for full details. | ||
*/ | ||
package im.vector.app.features.home.room.detail.timeline.factory | ||
|
||
import im.vector.app.core.epoxy.VectorEpoxyModel | ||
import im.vector.app.core.resources.UserPreferencesProvider | ||
import im.vector.app.features.home.room.detail.timeline.MessageColorProvider | ||
import im.vector.app.features.home.room.detail.timeline.TimelineEventController | ||
import im.vector.app.features.home.room.detail.timeline.helper.AvatarSizeProvider | ||
import im.vector.app.features.home.room.detail.timeline.helper.MessageInformationDataFactory | ||
import im.vector.app.features.home.room.detail.timeline.helper.MessageItemAttributesFactory | ||
import im.vector.app.features.home.room.detail.timeline.item.ElementCallTileTimelineItem | ||
import im.vector.app.features.home.room.detail.timeline.item.ElementCallTileTimelineItem_ | ||
import im.vector.app.features.home.room.detail.timeline.item.MessageInformationData | ||
import im.vector.app.features.home.room.detail.timeline.item.ReactionsSummaryEvents | ||
import org.matrix.android.sdk.api.session.Session | ||
import org.matrix.android.sdk.api.session.events.model.EventType | ||
import org.matrix.android.sdk.api.session.events.model.toModel | ||
import org.matrix.android.sdk.api.session.room.model.RoomSummary | ||
import org.matrix.android.sdk.api.session.room.model.message.ElementCallNotifyContent | ||
import org.matrix.android.sdk.api.util.toMatrixItem | ||
import javax.inject.Inject | ||
|
||
class ElementCallItemFactory @Inject constructor( | ||
private val session: Session, | ||
private val userPreferencesProvider: UserPreferencesProvider, | ||
private val messageColorProvider: MessageColorProvider, | ||
private val messageInformationDataFactory: MessageInformationDataFactory, | ||
private val messageItemAttributesFactory: MessageItemAttributesFactory, | ||
private val avatarSizeProvider: AvatarSizeProvider, | ||
private val noticeItemFactory: NoticeItemFactory | ||
) { | ||
|
||
fun create(params: TimelineItemFactoryParams): VectorEpoxyModel<*>? { | ||
val event = params.event | ||
if (event.root.eventId == null) return null | ||
val showHiddenEvents = userPreferencesProvider.shouldShowHiddenEvents() | ||
val roomSummary = params.partialState.roomSummary ?: return null | ||
val informationData = messageInformationDataFactory.create(params) | ||
val callItem = when (event.root.getClearType()) { | ||
in EventType.ELEMENT_CALL_NOTIFY.values -> { | ||
val notifyContent: ElementCallNotifyContent = event.root.content.toModel() ?: return null | ||
createElementCallTileTimelineItem( | ||
roomSummary = roomSummary, | ||
callId = notifyContent.callId.orEmpty(), | ||
callStatus = ElementCallTileTimelineItem.CallStatus.INVITED, | ||
callKind = ElementCallTileTimelineItem.CallKind.VIDEO, | ||
callback = params.callback, | ||
highlight = params.isHighlighted, | ||
informationData = informationData, | ||
reactionsSummaryEvents = params.reactionsSummaryEvents | ||
) | ||
} | ||
else -> null | ||
} | ||
return if (callItem == null && showHiddenEvents) { | ||
// Fallback to notice item for showing hidden events | ||
noticeItemFactory.create(params) | ||
} else { | ||
callItem | ||
} | ||
} | ||
|
||
private fun createElementCallTileTimelineItem( | ||
roomSummary: RoomSummary, | ||
callId: String, | ||
callKind: ElementCallTileTimelineItem.CallKind, | ||
callStatus: ElementCallTileTimelineItem.CallStatus, | ||
informationData: MessageInformationData, | ||
highlight: Boolean, | ||
callback: TimelineEventController.Callback?, | ||
reactionsSummaryEvents: ReactionsSummaryEvents? | ||
): ElementCallTileTimelineItem? { | ||
val userOfInterest = roomSummary.toMatrixItem() | ||
val attributes = messageItemAttributesFactory.create(null, informationData, callback, reactionsSummaryEvents).let { | ||
ElementCallTileTimelineItem.Attributes( | ||
callId = callId, | ||
callKind = callKind, | ||
callStatus = callStatus, | ||
informationData = informationData, | ||
avatarRenderer = it.avatarRenderer, | ||
messageColorProvider = messageColorProvider, | ||
itemClickListener = it.itemClickListener, | ||
itemLongClickListener = it.itemLongClickListener, | ||
reactionPillCallback = it.reactionPillCallback, | ||
readReceiptsCallback = it.readReceiptsCallback, | ||
userOfInterest = userOfInterest, | ||
callback = callback, | ||
reactionsSummaryEvents = reactionsSummaryEvents | ||
) | ||
} | ||
return ElementCallTileTimelineItem_() | ||
.attributes(attributes) | ||
.highlighted(highlight) | ||
.leftGuideline(avatarSizeProvider.leftGuideline) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
...java/im/vector/app/features/home/room/detail/timeline/item/ElementCallTileTimelineItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright 2024 New Vector Ltd. | ||
* | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
* Please see LICENSE in the repository root for full details. | ||
*/ | ||
package im.vector.app.features.home.room.detail.timeline.item | ||
|
||
import android.content.res.Resources | ||
import android.view.View | ||
import android.widget.ImageView | ||
import android.widget.RelativeLayout | ||
import android.widget.TextView | ||
import androidx.annotation.DrawableRes | ||
import androidx.annotation.StringRes | ||
import androidx.core.view.updateLayoutParams | ||
import com.airbnb.epoxy.EpoxyAttribute | ||
import com.airbnb.epoxy.EpoxyModelClass | ||
import im.vector.app.R | ||
import im.vector.app.core.epoxy.ClickListener | ||
import im.vector.app.features.displayname.getBestName | ||
import im.vector.app.features.home.AvatarRenderer | ||
import im.vector.app.features.home.room.detail.timeline.MessageColorProvider | ||
import im.vector.app.features.home.room.detail.timeline.TimelineEventController | ||
import im.vector.lib.strings.CommonStrings | ||
import org.matrix.android.sdk.api.util.MatrixItem | ||
|
||
@EpoxyModelClass | ||
abstract class ElementCallTileTimelineItem : AbsBaseMessageItem<ElementCallTileTimelineItem.Holder>(R.layout.item_timeline_event_base_state) { | ||
|
||
override val baseAttributes: AbsBaseMessageItem.Attributes | ||
get() = attributes | ||
|
||
override fun isCacheable() = false | ||
|
||
@EpoxyAttribute | ||
lateinit var attributes: Attributes | ||
|
||
override fun getViewStubId() = STUB_ID | ||
|
||
override fun bind(holder: Holder) { | ||
super.bind(holder) | ||
holder.endGuideline.updateLayoutParams<RelativeLayout.LayoutParams> { | ||
this.marginEnd = leftGuideline | ||
} | ||
holder.creatorNameView.text = attributes.userOfInterest.getBestName() | ||
attributes.avatarRenderer.render(attributes.userOfInterest, holder.creatorAvatarView) | ||
renderSendState(holder.view, null, holder.failedToSendIndicator) | ||
} | ||
|
||
class Holder : AbsBaseMessageItem.Holder(STUB_ID) { | ||
val creatorAvatarView by bind<ImageView>(R.id.itemCallCreatorAvatar) | ||
val creatorNameView by bind<TextView>(R.id.itemCallCreatorNameTextView) | ||
val endGuideline by bind<View>(R.id.messageEndGuideline) | ||
val failedToSendIndicator by bind<ImageView>(R.id.messageFailToSendIndicator) | ||
|
||
val resources: Resources | ||
get() = view.context.resources | ||
} | ||
|
||
companion object { | ||
private val STUB_ID = R.id.messageElementCallStub | ||
} | ||
|
||
data class Attributes( | ||
val callId: String, | ||
val callKind: CallKind, | ||
val callStatus: CallStatus, | ||
val userOfInterest: MatrixItem, | ||
val callback: TimelineEventController.Callback? = null, | ||
override val informationData: MessageInformationData, | ||
override val avatarRenderer: AvatarRenderer, | ||
override val messageColorProvider: MessageColorProvider, | ||
override val itemLongClickListener: View.OnLongClickListener? = null, | ||
override val itemClickListener: ClickListener? = null, | ||
override val reactionPillCallback: TimelineEventController.ReactionPillCallback? = null, | ||
override val readReceiptsCallback: TimelineEventController.ReadReceiptsCallback? = null, | ||
override val reactionsSummaryEvents: ReactionsSummaryEvents? = null | ||
) : AbsBaseMessageItem.Attributes | ||
|
||
enum class CallKind(@DrawableRes val icon: Int, @StringRes val title: Int) { | ||
VIDEO(R.drawable.ic_call_video_small, CommonStrings.action_video_call), | ||
} | ||
|
||
enum class CallStatus { | ||
INVITED, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.