2019-01-18 10:12:08 +00:00
|
|
|
/*
|
2019-01-25 13:04:59 +00:00
|
|
|
* Copyright 2019 New Vector Ltd
|
2019-01-18 10:12:08 +00:00
|
|
|
*
|
2019-01-25 13:04:59 +00:00
|
|
|
* 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
|
2019-01-18 10:12:08 +00:00
|
|
|
*
|
2019-01-25 13:04:59 +00:00
|
|
|
* 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.
|
2019-01-18 10:12:08 +00:00
|
|
|
*/
|
|
|
|
|
2019-07-02 15:27:08 +00:00
|
|
|
package im.vector.riotx.features.home.room.detail.timeline.factory
|
2019-01-15 14:47:03 +00:00
|
|
|
|
|
|
|
import im.vector.matrix.android.api.session.events.model.EventType
|
2019-01-18 15:26:17 +00:00
|
|
|
import im.vector.matrix.android.api.session.room.timeline.TimelineEvent
|
2019-07-02 15:27:08 +00:00
|
|
|
import im.vector.riotx.core.epoxy.EmptyItem_
|
|
|
|
import im.vector.riotx.core.epoxy.VectorEpoxyModel
|
|
|
|
import im.vector.riotx.features.home.room.detail.timeline.TimelineEventController
|
2019-05-20 08:30:33 +00:00
|
|
|
import timber.log.Timber
|
2019-06-18 18:00:20 +00:00
|
|
|
import javax.inject.Inject
|
2019-01-15 14:47:03 +00:00
|
|
|
|
2019-06-18 18:00:20 +00:00
|
|
|
class TimelineItemFactory @Inject constructor(private val messageItemFactory: MessageItemFactory,
|
|
|
|
private val encryptionItemFactory: EncryptionItemFactory,
|
|
|
|
private val encryptedItemFactory: EncryptedItemFactory,
|
|
|
|
private val noticeItemFactory: NoticeItemFactory,
|
2019-06-27 14:48:07 +00:00
|
|
|
private val defaultItemFactory: DefaultItemFactory,
|
2019-08-12 15:59:07 +00:00
|
|
|
private val roomCreateItemFactory: RoomCreateItemFactory) {
|
2019-01-15 14:47:03 +00:00
|
|
|
|
|
|
|
fun create(event: TimelineEvent,
|
|
|
|
nextEvent: TimelineEvent?,
|
2019-06-20 14:27:43 +00:00
|
|
|
eventIdToHighlight: String?,
|
2019-04-18 17:09:15 +00:00
|
|
|
callback: TimelineEventController.Callback?): VectorEpoxyModel<*> {
|
2019-06-20 14:27:43 +00:00
|
|
|
val highlight = event.root.eventId == eventIdToHighlight
|
2019-01-15 14:47:03 +00:00
|
|
|
|
2019-02-20 15:14:12 +00:00
|
|
|
val computedModel = try {
|
2019-05-26 17:21:45 +00:00
|
|
|
when (event.root.getClearType()) {
|
2019-06-20 14:27:43 +00:00
|
|
|
EventType.MESSAGE -> messageItemFactory.create(event, nextEvent, highlight, callback)
|
2019-06-04 15:36:49 +00:00
|
|
|
// State and call
|
2019-07-25 17:34:39 +00:00
|
|
|
EventType.STATE_ROOM_TOMBSTONE,
|
2019-05-21 11:20:11 +00:00
|
|
|
EventType.STATE_ROOM_NAME,
|
|
|
|
EventType.STATE_ROOM_TOPIC,
|
|
|
|
EventType.STATE_ROOM_MEMBER,
|
|
|
|
EventType.STATE_HISTORY_VISIBILITY,
|
2019-04-18 17:09:15 +00:00
|
|
|
EventType.CALL_INVITE,
|
|
|
|
EventType.CALL_HANGUP,
|
2019-08-12 15:59:07 +00:00
|
|
|
EventType.CALL_ANSWER,
|
|
|
|
EventType.REACTION,
|
|
|
|
EventType.REDACTION -> noticeItemFactory.create(event, highlight, callback)
|
2019-07-25 17:34:39 +00:00
|
|
|
// State room create
|
|
|
|
EventType.STATE_ROOM_CREATE -> roomCreateItemFactory.create(event, callback)
|
2019-06-07 16:53:24 +00:00
|
|
|
// Crypto
|
2019-06-20 14:27:43 +00:00
|
|
|
EventType.ENCRYPTION -> encryptionItemFactory.create(event, highlight, callback)
|
2019-06-21 10:04:48 +00:00
|
|
|
EventType.ENCRYPTED -> {
|
|
|
|
if (event.root.isRedacted()) {
|
|
|
|
// Redacted event, let the MessageItemFactory handle it
|
|
|
|
messageItemFactory.create(event, nextEvent, highlight, callback)
|
|
|
|
} else {
|
|
|
|
encryptedItemFactory.create(event, nextEvent, highlight, callback)
|
|
|
|
}
|
|
|
|
}
|
2019-05-16 08:23:57 +00:00
|
|
|
|
2019-06-04 15:36:49 +00:00
|
|
|
// Unhandled event types (yet)
|
2019-04-18 17:09:15 +00:00
|
|
|
EventType.STATE_ROOM_THIRD_PARTY_INVITE,
|
2019-08-28 15:31:31 +00:00
|
|
|
EventType.STICKER -> defaultItemFactory.create(event, highlight, callback)
|
2019-06-04 15:36:49 +00:00
|
|
|
else -> {
|
2019-08-12 15:59:07 +00:00
|
|
|
Timber.v("Type ${event.root.getClearType()} not handled")
|
|
|
|
null
|
2019-06-04 15:36:49 +00:00
|
|
|
}
|
2019-02-11 12:47:47 +00:00
|
|
|
}
|
|
|
|
} catch (e: Exception) {
|
2019-06-07 16:53:24 +00:00
|
|
|
Timber.e(e, "failed to create message item")
|
2019-08-28 15:31:31 +00:00
|
|
|
defaultItemFactory.create(event, highlight, callback, e)
|
2019-01-15 14:47:03 +00:00
|
|
|
}
|
2019-04-18 17:09:15 +00:00
|
|
|
return (computedModel ?: EmptyItem_())
|
2019-01-15 14:47:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|