fix merge

This commit is contained in:
greenart7c3
2023-08-14 10:51:14 -03:00
parent 012fdc8cc6
commit d2eea9f0ae

View File

@@ -158,122 +158,130 @@ open class NewPostViewModel() : ViewModel() {
} }
fun sendPost(relayList: List<Relay>? = null, signEvent: Boolean = true): Event? { fun sendPost(relayList: List<Relay>? = null, signEvent: Boolean = true): Event? {
val tagger = NewMessageTagger(message.text, mentions, replyTos, originalNote?.channelHex()) try {
tagger.run() val tagger = NewMessageTagger(message.text, mentions, replyTos, originalNote?.channelHex())
tagger.run()
val toUsersTagger = NewMessageTagger(toUsers.text, null, null, null) val toUsersTagger = NewMessageTagger(toUsers.text, null, null, null)
toUsersTagger.run() toUsersTagger.run()
val dmUsers = toUsersTagger.mentions val dmUsers = toUsersTagger.mentions
val zapReceiver = if (wantsForwardZapTo) { val zapReceiver = if (wantsForwardZapTo) {
if (forwardZapTo != null) { if (forwardZapTo != null) {
forwardZapTo?.info?.lud16 ?: forwardZapTo?.info?.lud06 forwardZapTo?.info?.lud16 ?: forwardZapTo?.info?.lud06
} else {
forwardZapToEditting.text
}
} else { } else {
forwardZapToEditting.text null
} }
} else {
null
}
val geoLocation = locUtil?.locationStateFlow?.value val geoLocation = locUtil?.locationStateFlow?.value
val geoHash = if (wantsToAddGeoHash && geoLocation != null) { val geoHash = if (wantsToAddGeoHash && geoLocation != null) {
geoLocation.toGeoHash(GeohashPrecision.KM_5_X_5.digits).toString() geoLocation.toGeoHash(GeohashPrecision.KM_5_X_5.digits).toString()
} else {
null
}
val localZapRaiserAmount = if (wantsZapraiser) zapRaiserAmount else null
if (originalNote?.channelHex() != null) {
if (originalNote is AddressableEvent && originalNote?.address() != null) {
account?.sendLiveMessage(tagger.message, originalNote?.address()!!, tagger.replyTos, tagger.mentions, zapReceiver, wantsToMarkAsSensitive, localZapRaiserAmount, geoHash)
} else { } else {
account?.sendChannelMessage(tagger.message, tagger.channelHex!!, tagger.replyTos, tagger.mentions, zapReceiver, wantsToMarkAsSensitive, localZapRaiserAmount, geoHash) null
} }
} else if (originalNote?.event is PrivateDmEvent) {
account?.sendPrivateMessage(tagger.message, originalNote!!.author!!, originalNote!!, tagger.mentions, zapReceiver, wantsToMarkAsSensitive, localZapRaiserAmount, geoHash)
} else if (originalNote?.event is ChatMessageEvent) {
val receivers = (originalNote?.event as ChatMessageEvent).recipientsPubKey().plus(originalNote?.author?.pubkeyHex).filterNotNull().toSet().toList()
account?.sendNIP24PrivateMessage( val localZapRaiserAmount = if (wantsZapraiser) zapRaiserAmount else null
message = tagger.message,
toUsers = receivers, if (originalNote?.channelHex() != null) {
subject = subject.text.ifBlank { null }, if (originalNote is AddressableEvent && originalNote?.address() != null) {
replyingTo = originalNote!!, return account?.sendLiveMessage(tagger.message, originalNote?.address()!!, tagger.replyTos, tagger.mentions, zapReceiver, wantsToMarkAsSensitive, localZapRaiserAmount, geoHash, signEvent)
mentions = tagger.mentions, } else {
wantsToMarkAsSensitive = wantsToMarkAsSensitive, return account?.sendChannelMessage(tagger.message, tagger.channelHex!!, tagger.replyTos, tagger.mentions, zapReceiver, wantsToMarkAsSensitive, localZapRaiserAmount, geoHash, signEvent)
zapReceiver = zapReceiver, }
zapRaiserAmount = localZapRaiserAmount, } else if (originalNote?.event is PrivateDmEvent) {
geohash = geoHash account?.sendPrivateMessage(tagger.message, originalNote!!.author!!, originalNote!!, tagger.mentions, zapReceiver, wantsToMarkAsSensitive, localZapRaiserAmount, geoHash)
) return null
} else if (!dmUsers.isNullOrEmpty()) { } else if (originalNote?.event is ChatMessageEvent) {
if (nip24 || dmUsers.size > 1) { val receivers = (originalNote?.event as ChatMessageEvent).recipientsPubKey().plus(originalNote?.author?.pubkeyHex).filterNotNull().toSet().toList()
account?.sendNIP24PrivateMessage( account?.sendNIP24PrivateMessage(
message = tagger.message, message = tagger.message,
toUsers = dmUsers.map { it.pubkeyHex }, toUsers = receivers,
subject = subject.text.ifBlank { null }, subject = subject.text.ifBlank { null },
replyingTo = tagger.replyTos?.firstOrNull(), replyingTo = originalNote!!,
mentions = tagger.mentions, mentions = tagger.mentions,
wantsToMarkAsSensitive = wantsToMarkAsSensitive, wantsToMarkAsSensitive = wantsToMarkAsSensitive,
zapReceiver = zapReceiver, zapReceiver = zapReceiver,
zapRaiserAmount = localZapRaiserAmount, zapRaiserAmount = localZapRaiserAmount,
geohash = geoHash geohash = geoHash
) )
return null
} else if (!dmUsers.isNullOrEmpty()) {
if (nip24 || dmUsers.size > 1) {
account?.sendNIP24PrivateMessage(
message = tagger.message,
toUsers = dmUsers.map { it.pubkeyHex },
subject = subject.text.ifBlank { null },
replyingTo = tagger.replyTos?.firstOrNull(),
mentions = tagger.mentions,
wantsToMarkAsSensitive = wantsToMarkAsSensitive,
zapReceiver = zapReceiver,
zapRaiserAmount = localZapRaiserAmount,
geohash = geoHash
)
return null
} else {
account?.sendPrivateMessage(
message = tagger.message,
toUser = dmUsers.first().pubkeyHex,
replyingTo = originalNote,
mentions = tagger.mentions,
wantsToMarkAsSensitive = wantsToMarkAsSensitive,
zapReceiver = zapReceiver,
zapRaiserAmount = localZapRaiserAmount,
geohash = geoHash
)
return null
}
} else { } else {
account?.sendPrivateMessage( if (wantsPoll) {
message = tagger.message, return account?.sendPoll(
toUser = dmUsers.first().pubkeyHex, tagger.message,
replyingTo = originalNote, tagger.replyTos,
mentions = tagger.mentions, tagger.mentions,
wantsToMarkAsSensitive = wantsToMarkAsSensitive, pollOptions,
zapReceiver = zapReceiver, valueMaximum,
zapRaiserAmount = localZapRaiserAmount, valueMinimum,
geohash = geoHash consensusThreshold,
) closedAt,
} zapReceiver,
} else { wantsToMarkAsSensitive,
if (wantsPoll) { localZapRaiserAmount,
account?.sendPoll( relayList,
tagger.message, geoHash,
tagger.replyTos, signEvent
tagger.mentions, )
pollOptions, } else {
valueMaximum, // adds markers
valueMinimum, val rootId =
consensusThreshold, (originalNote?.event as? TextNoteEvent)?.root() // if it has a marker as root
closedAt, ?: originalNote?.replyTo?.firstOrNull { it.event != null && it.replyTo?.isEmpty() == true }?.idHex // if it has loaded events with zero replies in the reply list
zapReceiver, ?: originalNote?.replyTo?.firstOrNull()?.idHex // old rules, first item is root.
wantsToMarkAsSensitive, val replyId = originalNote?.idHex
localZapRaiserAmount,
relayList,
geoHash
)
} else {
// adds markers
val rootId =
(originalNote?.event as? TextNoteEvent)?.root() // if it has a marker as root
?: originalNote?.replyTo?.firstOrNull { it.event != null && it.replyTo?.isEmpty() == true }?.idHex // if it has loaded events with zero replies in the reply list
?: originalNote?.replyTo?.firstOrNull()?.idHex // old rules, first item is root.
val replyId = originalNote?.idHex
account?.sendPost( return account?.sendPost(
message = tagger.message, message = tagger.message,
replyTo = tagger.replyTos, replyTo = tagger.replyTos,
mentions = tagger.mentions, mentions = tagger.mentions,
tags = null, tags = null,
zapReceiver = zapReceiver, zapReceiver = zapReceiver,
wantsToMarkAsSensitive = wantsToMarkAsSensitive, wantsToMarkAsSensitive = wantsToMarkAsSensitive,
zapRaiserAmount = localZapRaiserAmount, zapRaiserAmount = localZapRaiserAmount,
replyingTo = replyId, replyingTo = replyId,
root = rootId, root = rootId,
directMentions = tagger.directMentions, directMentions = tagger.directMentions,
relayList = relayList, relayList = relayList,
geohash = geoHash geohash = geoHash,
) signEvent = signEvent
)
}
} }
} finally {
cancel()
} }
cancel()
} }
fun upload(galleryUri: Uri, description: String, sensitiveContent: Boolean, server: ServersAvailable, context: Context, relayList: List<Relay>? = null) { fun upload(galleryUri: Uri, description: String, sensitiveContent: Boolean, server: ServersAvailable, context: Context, relayList: List<Relay>? = null) {