Added option to save labels
and other improvements and fixes used for exports and imports
This commit is contained in:
@ -23,6 +23,7 @@ import ch.dissem.bitmessage.entity.Plaintext.Status.PUBKEY_REQUESTED
|
||||
import ch.dissem.bitmessage.entity.payload.*
|
||||
import ch.dissem.bitmessage.entity.valueobject.InventoryVector
|
||||
import ch.dissem.bitmessage.exception.DecryptionFailedException
|
||||
import ch.dissem.bitmessage.ports.AlreadyStoredException
|
||||
import ch.dissem.bitmessage.ports.Labeler
|
||||
import ch.dissem.bitmessage.ports.NetworkHandler
|
||||
import ch.dissem.bitmessage.utils.Strings.hex
|
||||
@ -65,7 +66,7 @@ open class DefaultMessageListener(
|
||||
|
||||
protected fun receive(objectMessage: ObjectMessage, getPubkey: GetPubkey) {
|
||||
val identity = ctx.addressRepository.findIdentity(getPubkey.ripeTag)
|
||||
if (identity != null && identity.privateKey != null && !identity.isChan) {
|
||||
if (identity?.privateKey != null && !identity.isChan) {
|
||||
LOG.info("Got pubkey request for identity " + identity)
|
||||
// FIXME: only send pubkey if it wasn't sent in the last TTL.pubkey() days
|
||||
ctx.sendPubkey(identity, objectMessage.stream)
|
||||
@ -90,7 +91,6 @@ open class DefaultMessageListener(
|
||||
}
|
||||
} catch (_: DecryptionFailedException) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun updatePubkey(address: BitmessageAddress, pubkey: Pubkey) {
|
||||
@ -157,14 +157,18 @@ open class DefaultMessageListener(
|
||||
|
||||
msg.inventoryVector = iv
|
||||
labeler.setLabels(msg)
|
||||
ctx.messageRepository.save(msg)
|
||||
listener.receive(msg)
|
||||
try {
|
||||
ctx.messageRepository.save(msg)
|
||||
listener.receive(msg)
|
||||
|
||||
if (msg.type == Plaintext.Type.MSG && msg.to!!.has(Pubkey.Feature.DOES_ACK)) {
|
||||
msg.ackMessage?.let {
|
||||
ctx.inventory.storeObject(it)
|
||||
ctx.networkHandler.offer(it.inventoryVector)
|
||||
} ?: LOG.debug("ack message expected")
|
||||
if (msg.type == Plaintext.Type.MSG && msg.to!!.has(Pubkey.Feature.DOES_ACK)) {
|
||||
msg.ackMessage?.let {
|
||||
ctx.inventory.storeObject(it)
|
||||
ctx.networkHandler.offer(it.inventoryVector)
|
||||
} ?: LOG.debug("ack message expected")
|
||||
}
|
||||
} catch (e: AlreadyStoredException) {
|
||||
LOG.trace("Message was already received before.", e)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,8 @@ data class Label(
|
||||
/**
|
||||
* RGBA representation for the color.
|
||||
*/
|
||||
var color: Int = 0
|
||||
var color: Int = 0,
|
||||
var ord: Int = 1000
|
||||
) : Serializable {
|
||||
|
||||
var id: Any? = null
|
||||
|
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2017 Christian Basler
|
||||
*
|
||||
* 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 ch.dissem.bitmessage.ports
|
||||
|
||||
/**
|
||||
* Should be thrown if a received and decrypted message can't be stored because it has already been received and stored.
|
||||
* (So it's not announced again to the client.)
|
||||
*/
|
||||
class AlreadyStoredException(message: String? = null, cause: Throwable? = null) : Exception(message, cause)
|
@ -28,6 +28,8 @@ interface MessageRepository {
|
||||
|
||||
fun getLabels(vararg types: Label.Type): List<Label>
|
||||
|
||||
fun save(label: Label)
|
||||
|
||||
fun countUnread(label: Label?): Int
|
||||
|
||||
fun getAllMessages(): List<Plaintext>
|
||||
|
Reference in New Issue
Block a user