2024-11-26 08:38:12 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2024 Meshtastic LLC
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2024-09-24 19:39:20 -03:00
|
|
|
package com.geeksville.mesh.model
|
|
|
|
|
|
|
|
|
|
import com.geeksville.mesh.MeshProtos.Routing
|
|
|
|
|
import com.geeksville.mesh.MessageStatus
|
|
|
|
|
import com.geeksville.mesh.R
|
2024-12-05 19:50:15 -03:00
|
|
|
import com.geeksville.mesh.database.entity.NodeEntity
|
2024-12-03 05:57:35 -06:00
|
|
|
import com.geeksville.mesh.database.entity.Reaction
|
2024-09-24 19:39:20 -03:00
|
|
|
|
|
|
|
|
val Routing.Error.stringRes: Int
|
|
|
|
|
get() = when (this) {
|
|
|
|
|
Routing.Error.NONE -> R.string.routing_error_none
|
|
|
|
|
Routing.Error.NO_ROUTE -> R.string.routing_error_no_route
|
|
|
|
|
Routing.Error.GOT_NAK -> R.string.routing_error_got_nak
|
|
|
|
|
Routing.Error.TIMEOUT -> R.string.routing_error_timeout
|
|
|
|
|
Routing.Error.NO_INTERFACE -> R.string.routing_error_no_interface
|
|
|
|
|
Routing.Error.MAX_RETRANSMIT -> R.string.routing_error_max_retransmit
|
|
|
|
|
Routing.Error.NO_CHANNEL -> R.string.routing_error_no_channel
|
|
|
|
|
Routing.Error.TOO_LARGE -> R.string.routing_error_too_large
|
|
|
|
|
Routing.Error.NO_RESPONSE -> R.string.routing_error_no_response
|
|
|
|
|
Routing.Error.DUTY_CYCLE_LIMIT -> R.string.routing_error_duty_cycle_limit
|
|
|
|
|
Routing.Error.BAD_REQUEST -> R.string.routing_error_bad_request
|
|
|
|
|
Routing.Error.NOT_AUTHORIZED -> R.string.routing_error_not_authorized
|
|
|
|
|
Routing.Error.PKI_FAILED -> R.string.routing_error_pki_failed
|
|
|
|
|
Routing.Error.PKI_UNKNOWN_PUBKEY -> R.string.routing_error_pki_unknown_pubkey
|
2024-10-06 08:36:22 -03:00
|
|
|
Routing.Error.ADMIN_BAD_SESSION_KEY -> R.string.routing_error_admin_bad_session_key
|
|
|
|
|
Routing.Error.ADMIN_PUBLIC_KEY_UNAUTHORIZED -> R.string.routing_error_admin_public_key_unauthorized
|
2024-09-24 19:39:20 -03:00
|
|
|
else -> R.string.unrecognized
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data class Message(
|
|
|
|
|
val uuid: Long,
|
|
|
|
|
val receivedTime: Long,
|
2024-12-05 19:50:15 -03:00
|
|
|
val node: NodeEntity,
|
2024-09-24 19:39:20 -03:00
|
|
|
val text: String,
|
2024-10-26 05:44:59 -03:00
|
|
|
val time: String,
|
2024-09-24 19:39:20 -03:00
|
|
|
val read: Boolean,
|
|
|
|
|
val status: MessageStatus?,
|
|
|
|
|
val routingError: Int,
|
2024-12-03 05:57:35 -06:00
|
|
|
val packetId: Int,
|
|
|
|
|
val emojis: List<Reaction>,
|
2024-09-24 19:39:20 -03:00
|
|
|
) {
|
|
|
|
|
private fun getStatusStringRes(value: Int): Int {
|
|
|
|
|
val error = Routing.Error.forNumber(value) ?: Routing.Error.UNRECOGNIZED
|
|
|
|
|
return error.stringRes
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun getStatusStringRes(): Pair<Int, Int> {
|
|
|
|
|
val title = if (routingError > 0) R.string.error else R.string.message_delivery_status
|
|
|
|
|
val text = when (status) {
|
|
|
|
|
MessageStatus.RECEIVED -> R.string.delivery_confirmed
|
|
|
|
|
MessageStatus.QUEUED -> R.string.message_status_queued
|
|
|
|
|
MessageStatus.ENROUTE -> R.string.message_status_enroute
|
|
|
|
|
else -> getStatusStringRes(routingError)
|
|
|
|
|
}
|
|
|
|
|
return title to text
|
|
|
|
|
}
|
|
|
|
|
}
|