mirror of
https://github.com/nextcloud/talk-android
synced 2025-03-08 23:19:55 +00:00
Migrate remaining chat models to kotlin data classes
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
parent
d683cb109a
commit
5484511d96
@ -176,8 +176,7 @@ data class ChatMessage(
|
|||||||
"file".toByteArray()
|
"file".toByteArray()
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
|
// FIX-ME: this selectedIndividualHashMap stuff needs to be analyzed and most likely be refactored!
|
||||||
// TODO: this selectedIndividualHashMap stuff needs to be analyzed and most likely be refactored!
|
|
||||||
// it just feels wrong to fill this here inside getImageUrl()
|
// it just feels wrong to fill this here inside getImageUrl()
|
||||||
selectedIndividualHashMap = individualHashMap
|
selectedIndividualHashMap = individualHashMap
|
||||||
if (!isVoiceMessage) {
|
if (!isVoiceMessage) {
|
||||||
@ -189,8 +188,8 @@ data class ChatMessage(
|
|||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
Log.e(
|
Log.e(
|
||||||
TAG, "activeUser or activeUser.getBaseUrl() were null when trying to " +
|
TAG,
|
||||||
"getImageUrl()"
|
"activeUser or activeUser.getBaseUrl() were null when trying to getImageUrl()"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -203,22 +202,21 @@ data class ChatMessage(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getCalculateMessageType(): MessageType {
|
fun getCalculateMessageType(): MessageType {
|
||||||
if (!TextUtils.isEmpty(systemMessage)) {
|
return if (!TextUtils.isEmpty(systemMessage)) {
|
||||||
return MessageType.SYSTEM_MESSAGE
|
MessageType.SYSTEM_MESSAGE
|
||||||
}
|
} else if (isVoiceMessage) {
|
||||||
if (isVoiceMessage) {
|
MessageType.VOICE_MESSAGE
|
||||||
return MessageType.VOICE_MESSAGE
|
} else if (hasFileAttachment()) {
|
||||||
}
|
MessageType.SINGLE_NC_ATTACHMENT_MESSAGE
|
||||||
if (hasFileAttachment()) {
|
} else if (hasGeoLocation()) {
|
||||||
return MessageType.SINGLE_NC_ATTACHMENT_MESSAGE
|
|
||||||
}
|
|
||||||
return if (hasGeoLocation()) {
|
|
||||||
MessageType.SINGLE_NC_GEOLOCATION_MESSAGE
|
MessageType.SINGLE_NC_GEOLOCATION_MESSAGE
|
||||||
} else MessageType.REGULAR_TEXT_MESSAGE
|
} else {
|
||||||
|
MessageType.REGULAR_TEXT_MESSAGE
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getId(): String {
|
override fun getId(): String {
|
||||||
return Integer.toString(jsonMessageId)
|
return jsonMessageId.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getText(): String {
|
override fun getText(): String {
|
||||||
@ -227,29 +225,41 @@ data class ChatMessage(
|
|||||||
|
|
||||||
/*} else if (getCalculateMessageType().equals(MessageType.SINGLE_LINK_MESSAGE)) {
|
/*} else if (getCalculateMessageType().equals(MessageType.SINGLE_LINK_MESSAGE)) {
|
||||||
if (actorId.equals(activeUser.getUserId())) {
|
if (actorId.equals(activeUser.getUserId())) {
|
||||||
return (NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_sent_a_link_you));
|
return (
|
||||||
|
NextcloudTalkApplication
|
||||||
|
.Companion.getSharedApplication()
|
||||||
|
.getString(R.string.nc_sent_a_link_you)
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
return (String.format(NextcloudTalkApplication.Companion.getSharedApplication().getResources().getString(R.string.nc_sent_a_link),
|
return (String.format(NextcloudTalkApplication.
|
||||||
!TextUtils.isEmpty(actorDisplayName) ? actorDisplayName : NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_guest)));
|
Companion.
|
||||||
|
getSharedApplication().
|
||||||
|
getResources().
|
||||||
|
getString(R.string.nc_sent_a_link),
|
||||||
|
!TextUtils.isEmpty(actorDisplayName) ? actorDisplayName : NextcloudTalkApplication.
|
||||||
|
Companion.
|
||||||
|
getSharedApplication().
|
||||||
|
getString(R.string.nc_guest))
|
||||||
|
);
|
||||||
}*/
|
}*/
|
||||||
val lastMessageDisplayText: String
|
val lastMessageDisplayText: String
|
||||||
get() {
|
get() {
|
||||||
if (getCalculateMessageType() == MessageType.REGULAR_TEXT_MESSAGE ||
|
if (getCalculateMessageType() == MessageType.REGULAR_TEXT_MESSAGE ||
|
||||||
getCalculateMessageType() == MessageType.SYSTEM_MESSAGE ||
|
getCalculateMessageType() == MessageType.SYSTEM_MESSAGE ||
|
||||||
getCalculateMessageType() == MessageType.SINGLE_LINK_MESSAGE) {
|
getCalculateMessageType() == MessageType.SINGLE_LINK_MESSAGE
|
||||||
|
) {
|
||||||
return text
|
return text
|
||||||
} else {
|
} else {
|
||||||
if (MessageType.SINGLE_LINK_GIPHY_MESSAGE == getCalculateMessageType() ||
|
if (MessageType.SINGLE_LINK_GIPHY_MESSAGE == getCalculateMessageType() ||
|
||||||
MessageType.SINGLE_LINK_TENOR_MESSAGE == getCalculateMessageType() ||
|
MessageType.SINGLE_LINK_TENOR_MESSAGE == getCalculateMessageType() ||
|
||||||
MessageType.SINGLE_LINK_GIF_MESSAGE == getCalculateMessageType()) {
|
MessageType.SINGLE_LINK_GIF_MESSAGE == getCalculateMessageType()
|
||||||
|
) {
|
||||||
return if (actorId == activeUser!!.userId) {
|
return if (actorId == activeUser!!.userId) {
|
||||||
sharedApplication!!.getString(R.string.nc_sent_a_gif_you)
|
sharedApplication!!.getString(R.string.nc_sent_a_gif_you)
|
||||||
} else {
|
} else {
|
||||||
String.format(
|
String.format(
|
||||||
sharedApplication!!.resources.getString(R.string.nc_sent_a_gif),
|
sharedApplication!!.resources.getString(R.string.nc_sent_a_gif),
|
||||||
if (!TextUtils.isEmpty(actorDisplayName)) actorDisplayName else sharedApplication!!.getString(
|
getNullsafeActorDisplayName()
|
||||||
R.string.nc_guest
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else if (MessageType.SINGLE_NC_ATTACHMENT_MESSAGE == getCalculateMessageType()) {
|
} else if (MessageType.SINGLE_NC_ATTACHMENT_MESSAGE == getCalculateMessageType()) {
|
||||||
@ -258,9 +268,7 @@ data class ChatMessage(
|
|||||||
} else {
|
} else {
|
||||||
String.format(
|
String.format(
|
||||||
sharedApplication!!.resources.getString(R.string.nc_sent_an_attachment),
|
sharedApplication!!.resources.getString(R.string.nc_sent_an_attachment),
|
||||||
if (!TextUtils.isEmpty(actorDisplayName)) actorDisplayName else sharedApplication!!.getString(
|
getNullsafeActorDisplayName()
|
||||||
R.string.nc_guest
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else if (MessageType.SINGLE_NC_GEOLOCATION_MESSAGE == getCalculateMessageType()) {
|
} else if (MessageType.SINGLE_NC_GEOLOCATION_MESSAGE == getCalculateMessageType()) {
|
||||||
@ -269,9 +277,7 @@ data class ChatMessage(
|
|||||||
} else {
|
} else {
|
||||||
String.format(
|
String.format(
|
||||||
sharedApplication!!.resources.getString(R.string.nc_sent_location),
|
sharedApplication!!.resources.getString(R.string.nc_sent_location),
|
||||||
if (!TextUtils.isEmpty(actorDisplayName)) actorDisplayName else sharedApplication!!.getString(
|
getNullsafeActorDisplayName()
|
||||||
R.string.nc_guest
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else if (MessageType.VOICE_MESSAGE == getCalculateMessageType()) {
|
} else if (MessageType.VOICE_MESSAGE == getCalculateMessageType()) {
|
||||||
@ -280,17 +286,29 @@ data class ChatMessage(
|
|||||||
} else {
|
} else {
|
||||||
String.format(
|
String.format(
|
||||||
sharedApplication!!.resources.getString(R.string.nc_sent_voice),
|
sharedApplication!!.resources.getString(R.string.nc_sent_voice),
|
||||||
if (!TextUtils.isEmpty(actorDisplayName)) actorDisplayName else sharedApplication!!.getString(
|
getNullsafeActorDisplayName()
|
||||||
R.string.nc_guest
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
/*} else if (getCalculateMessageType().equals(MessageType.SINGLE_LINK_MESSAGE)) {
|
/*} else if (getCalculateMessageType().equals(MessageType.SINGLE_LINK_MESSAGE)) {
|
||||||
if (actorId.equals(activeUser.getUserId())) {
|
if (actorId.equals(activeUser.getUserId())) {
|
||||||
return (NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_sent_a_link_you));
|
return (
|
||||||
|
NextcloudTalkApplication
|
||||||
|
.Companion
|
||||||
|
.getSharedApplication()
|
||||||
|
.getString(R.string.nc_sent_a_link_you)
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
return (String.format(NextcloudTalkApplication.Companion.getSharedApplication().getResources().getString(R.string.nc_sent_a_link),
|
return (String.format(
|
||||||
!TextUtils.isEmpty(actorDisplayName) ? actorDisplayName : NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_guest)));
|
NextcloudTalkApplication
|
||||||
|
.Companion
|
||||||
|
.getSharedApplication()
|
||||||
|
.getResources()
|
||||||
|
.getString(R.string.nc_sent_a_link),
|
||||||
|
!TextUtils.isEmpty(actorDisplayName) ? actorDisplayName : NextcloudTalkApplication.
|
||||||
|
Companion.
|
||||||
|
getSharedApplication().
|
||||||
|
getString(R.string.nc_guest))
|
||||||
|
);
|
||||||
}*/
|
}*/
|
||||||
} else if (MessageType.SINGLE_LINK_AUDIO_MESSAGE == getCalculateMessageType()) {
|
} else if (MessageType.SINGLE_LINK_AUDIO_MESSAGE == getCalculateMessageType()) {
|
||||||
return if (actorId == activeUser!!.userId) {
|
return if (actorId == activeUser!!.userId) {
|
||||||
@ -298,9 +316,7 @@ data class ChatMessage(
|
|||||||
} else {
|
} else {
|
||||||
String.format(
|
String.format(
|
||||||
sharedApplication!!.resources.getString(R.string.nc_sent_an_audio),
|
sharedApplication!!.resources.getString(R.string.nc_sent_an_audio),
|
||||||
if (!TextUtils.isEmpty(actorDisplayName)) actorDisplayName else sharedApplication!!.getString(
|
getNullsafeActorDisplayName()
|
||||||
R.string.nc_guest
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else if (MessageType.SINGLE_LINK_VIDEO_MESSAGE == getCalculateMessageType()) {
|
} else if (MessageType.SINGLE_LINK_VIDEO_MESSAGE == getCalculateMessageType()) {
|
||||||
@ -309,9 +325,7 @@ data class ChatMessage(
|
|||||||
} else {
|
} else {
|
||||||
String.format(
|
String.format(
|
||||||
sharedApplication!!.resources.getString(R.string.nc_sent_a_video),
|
sharedApplication!!.resources.getString(R.string.nc_sent_a_video),
|
||||||
if (!TextUtils.isEmpty(actorDisplayName)) actorDisplayName else sharedApplication!!.getString(
|
getNullsafeActorDisplayName()
|
||||||
R.string.nc_guest
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else if (MessageType.SINGLE_LINK_IMAGE_MESSAGE == getCalculateMessageType()) {
|
} else if (MessageType.SINGLE_LINK_IMAGE_MESSAGE == getCalculateMessageType()) {
|
||||||
@ -320,9 +334,7 @@ data class ChatMessage(
|
|||||||
} else {
|
} else {
|
||||||
String.format(
|
String.format(
|
||||||
sharedApplication!!.resources.getString(R.string.nc_sent_an_image),
|
sharedApplication!!.resources.getString(R.string.nc_sent_an_image),
|
||||||
if (!TextUtils.isEmpty(actorDisplayName)) actorDisplayName else sharedApplication!!.getString(
|
getNullsafeActorDisplayName()
|
||||||
R.string.nc_guest
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -330,6 +342,12 @@ data class ChatMessage(
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getNullsafeActorDisplayName() = if (!TextUtils.isEmpty(actorDisplayName)) {
|
||||||
|
actorDisplayName
|
||||||
|
} else {
|
||||||
|
sharedApplication!!.getString(R.string.nc_guest)
|
||||||
|
}
|
||||||
|
|
||||||
override fun getUser(): IUser {
|
override fun getUser(): IUser {
|
||||||
return object : IUser {
|
return object : IUser {
|
||||||
override fun getId(): String {
|
override fun getId(): String {
|
||||||
@ -369,7 +387,7 @@ data class ChatMessage(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getCreatedAt(): Date {
|
override fun getCreatedAt(): Date {
|
||||||
return Date(timestamp * 1000L)
|
return Date(timestamp * MILLIES)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getSystemMessage(): String {
|
override fun getSystemMessage(): String {
|
||||||
@ -450,5 +468,6 @@ data class ChatMessage(
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val TAG = "ChatMessage"
|
private const val TAG = "ChatMessage"
|
||||||
|
private const val MILLIES: Long = 1000L
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -131,10 +131,14 @@ data class Conversation(
|
|||||||
get() = ConversationType.ROOM_PUBLIC_CALL == type
|
get() = ConversationType.ROOM_PUBLIC_CALL == type
|
||||||
|
|
||||||
val isGuest: Boolean
|
val isGuest: Boolean
|
||||||
get() = ParticipantType.GUEST == participantType || ParticipantType.GUEST_MODERATOR == participantType || ParticipantType.USER_FOLLOWING_LINK == participantType
|
get() = ParticipantType.GUEST == participantType ||
|
||||||
|
ParticipantType.GUEST_MODERATOR == participantType ||
|
||||||
|
ParticipantType.USER_FOLLOWING_LINK == participantType
|
||||||
|
|
||||||
val isParticipantOwnerOrModerator: Boolean
|
val isParticipantOwnerOrModerator: Boolean
|
||||||
get() = ParticipantType.OWNER == participantType || ParticipantType.GUEST_MODERATOR == participantType || ParticipantType.MODERATOR == participantType
|
get() = ParticipantType.OWNER == participantType ||
|
||||||
|
ParticipantType.GUEST_MODERATOR == participantType ||
|
||||||
|
ParticipantType.MODERATOR == participantType
|
||||||
|
|
||||||
private fun isLockedOneToOne(conversationUser: UserEntity): Boolean {
|
private fun isLockedOneToOne(conversationUser: UserEntity): Boolean {
|
||||||
return type == ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL &&
|
return type == ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL &&
|
||||||
@ -150,7 +154,8 @@ data class Conversation(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun isLobbyViewApplicable(conversationUser: UserEntity): Boolean {
|
fun isLobbyViewApplicable(conversationUser: UserEntity): Boolean {
|
||||||
return !canModerate(conversationUser) && (type == ConversationType.ROOM_GROUP_CALL || type == ConversationType.ROOM_PUBLIC_CALL)
|
return !canModerate(conversationUser) &&
|
||||||
|
(type == ConversationType.ROOM_GROUP_CALL || type == ConversationType.ROOM_PUBLIC_CALL)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isNameEditable(conversationUser: UserEntity): Boolean {
|
fun isNameEditable(conversationUser: UserEntity): Boolean {
|
||||||
|
@ -171,6 +171,7 @@ class EnumSystemMessageTypeConverter : StringBasedTypeConverter<ChatMessage.Syst
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("Detekt.ComplexMethod")
|
||||||
override fun convertToString(`object`: ChatMessage.SystemMessageType?): String {
|
override fun convertToString(`object`: ChatMessage.SystemMessageType?): String {
|
||||||
|
|
||||||
if (`object` == null) {
|
if (`object` == null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user