mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-03-28 18:51:45 +01:00
Adds support for NIP-29 in public messages and new DMs. NIP-54 stays in NIP-54
This commit is contained in:
parent
54155a3c30
commit
e56377f8c3
@ -46,6 +46,7 @@ height="80">](https://github.com/vitorpamplona/amethyst/releases)
|
|||||||
- [ ] Delegated Event Signing (NIP-26, Will not implement)
|
- [ ] Delegated Event Signing (NIP-26, Will not implement)
|
||||||
- [x] Text Note References (NIP-27)
|
- [x] Text Note References (NIP-27)
|
||||||
- [x] Public Chats (NIP-28)
|
- [x] Public Chats (NIP-28)
|
||||||
|
- [x] Inline Metadata (NIP-29)
|
||||||
- [x] Custom Emoji (NIP-30)
|
- [x] Custom Emoji (NIP-30)
|
||||||
- [x] Event kind summaries (NIP-31)
|
- [x] Event kind summaries (NIP-31)
|
||||||
- [ ] Labeling (NIP-32)
|
- [ ] Labeling (NIP-32)
|
||||||
|
@ -1325,7 +1325,7 @@ class Account(
|
|||||||
directMentions: Set<HexKey>,
|
directMentions: Set<HexKey>,
|
||||||
relayList: List<Relay>? = null,
|
relayList: List<Relay>? = null,
|
||||||
geohash: String? = null,
|
geohash: String? = null,
|
||||||
nip94attachments: List<Event>? = null,
|
nip94attachments: List<FileHeaderEvent>? = null,
|
||||||
) {
|
) {
|
||||||
if (!isWriteable()) return
|
if (!isWriteable()) return
|
||||||
|
|
||||||
@ -1381,7 +1381,7 @@ class Account(
|
|||||||
zapRaiserAmount: Long? = null,
|
zapRaiserAmount: Long? = null,
|
||||||
relayList: List<Relay>? = null,
|
relayList: List<Relay>? = null,
|
||||||
geohash: String? = null,
|
geohash: String? = null,
|
||||||
nip94attachments: List<Event>? = null,
|
nip94attachments: List<FileHeaderEvent>? = null,
|
||||||
) {
|
) {
|
||||||
if (!isWriteable()) return
|
if (!isWriteable()) return
|
||||||
|
|
||||||
@ -1428,7 +1428,7 @@ class Account(
|
|||||||
wantsToMarkAsSensitive: Boolean,
|
wantsToMarkAsSensitive: Boolean,
|
||||||
zapRaiserAmount: Long? = null,
|
zapRaiserAmount: Long? = null,
|
||||||
geohash: String? = null,
|
geohash: String? = null,
|
||||||
nip94attachments: List<Event>? = null,
|
nip94attachments: List<FileHeaderEvent>? = null,
|
||||||
) {
|
) {
|
||||||
if (!isWriteable()) return
|
if (!isWriteable()) return
|
||||||
|
|
||||||
@ -1461,7 +1461,7 @@ class Account(
|
|||||||
wantsToMarkAsSensitive: Boolean,
|
wantsToMarkAsSensitive: Boolean,
|
||||||
zapRaiserAmount: Long? = null,
|
zapRaiserAmount: Long? = null,
|
||||||
geohash: String? = null,
|
geohash: String? = null,
|
||||||
nip94attachments: List<Event>? = null,
|
nip94attachments: List<FileHeaderEvent>? = null,
|
||||||
) {
|
) {
|
||||||
if (!isWriteable()) return
|
if (!isWriteable()) return
|
||||||
|
|
||||||
@ -1495,6 +1495,7 @@ class Account(
|
|||||||
wantsToMarkAsSensitive: Boolean,
|
wantsToMarkAsSensitive: Boolean,
|
||||||
zapRaiserAmount: Long? = null,
|
zapRaiserAmount: Long? = null,
|
||||||
geohash: String? = null,
|
geohash: String? = null,
|
||||||
|
nip94attachments: List<FileHeaderEvent>? = null,
|
||||||
) {
|
) {
|
||||||
sendPrivateMessage(
|
sendPrivateMessage(
|
||||||
message,
|
message,
|
||||||
@ -1505,6 +1506,7 @@ class Account(
|
|||||||
wantsToMarkAsSensitive,
|
wantsToMarkAsSensitive,
|
||||||
zapRaiserAmount,
|
zapRaiserAmount,
|
||||||
geohash,
|
geohash,
|
||||||
|
nip94attachments,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1517,6 +1519,7 @@ class Account(
|
|||||||
wantsToMarkAsSensitive: Boolean,
|
wantsToMarkAsSensitive: Boolean,
|
||||||
zapRaiserAmount: Long? = null,
|
zapRaiserAmount: Long? = null,
|
||||||
geohash: String? = null,
|
geohash: String? = null,
|
||||||
|
nip94attachments: List<FileHeaderEvent>? = null,
|
||||||
) {
|
) {
|
||||||
if (!isWriteable()) return
|
if (!isWriteable()) return
|
||||||
|
|
||||||
@ -1533,6 +1536,7 @@ class Account(
|
|||||||
markAsSensitive = wantsToMarkAsSensitive,
|
markAsSensitive = wantsToMarkAsSensitive,
|
||||||
zapRaiserAmount = zapRaiserAmount,
|
zapRaiserAmount = zapRaiserAmount,
|
||||||
geohash = geohash,
|
geohash = geohash,
|
||||||
|
nip94attachments = nip94attachments,
|
||||||
signer = signer,
|
signer = signer,
|
||||||
advertiseNip18 = false,
|
advertiseNip18 = false,
|
||||||
) {
|
) {
|
||||||
@ -1551,6 +1555,7 @@ class Account(
|
|||||||
wantsToMarkAsSensitive: Boolean,
|
wantsToMarkAsSensitive: Boolean,
|
||||||
zapRaiserAmount: Long? = null,
|
zapRaiserAmount: Long? = null,
|
||||||
geohash: String? = null,
|
geohash: String? = null,
|
||||||
|
nip94attachments: List<FileHeaderEvent>? = null,
|
||||||
) {
|
) {
|
||||||
if (!isWriteable()) return
|
if (!isWriteable()) return
|
||||||
|
|
||||||
@ -1567,6 +1572,7 @@ class Account(
|
|||||||
markAsSensitive = wantsToMarkAsSensitive,
|
markAsSensitive = wantsToMarkAsSensitive,
|
||||||
zapRaiserAmount = zapRaiserAmount,
|
zapRaiserAmount = zapRaiserAmount,
|
||||||
geohash = geohash,
|
geohash = geohash,
|
||||||
|
nip94attachments = nip94attachments,
|
||||||
signer = signer,
|
signer = signer,
|
||||||
) {
|
) {
|
||||||
broadcastPrivately(it)
|
broadcastPrivately(it)
|
||||||
|
@ -34,6 +34,9 @@ import com.vitorpamplona.amethyst.ui.components.imageExtensions
|
|||||||
import com.vitorpamplona.amethyst.ui.components.removeQueryParamsForExtensionComparison
|
import com.vitorpamplona.amethyst.ui.components.removeQueryParamsForExtensionComparison
|
||||||
import com.vitorpamplona.amethyst.ui.components.tagIndex
|
import com.vitorpamplona.amethyst.ui.components.tagIndex
|
||||||
import com.vitorpamplona.amethyst.ui.components.videoExtensions
|
import com.vitorpamplona.amethyst.ui.components.videoExtensions
|
||||||
|
import com.vitorpamplona.quartz.encoders.Nip29
|
||||||
|
import com.vitorpamplona.quartz.encoders.Nip54
|
||||||
|
import com.vitorpamplona.quartz.events.FileHeaderEvent
|
||||||
import com.vitorpamplona.quartz.events.ImmutableListOfLists
|
import com.vitorpamplona.quartz.events.ImmutableListOfLists
|
||||||
import kotlinx.collections.immutable.ImmutableList
|
import kotlinx.collections.immutable.ImmutableList
|
||||||
import kotlinx.collections.immutable.ImmutableMap
|
import kotlinx.collections.immutable.ImmutableMap
|
||||||
@ -94,27 +97,33 @@ val HTTPRegex =
|
|||||||
.toRegex(RegexOption.IGNORE_CASE)
|
.toRegex(RegexOption.IGNORE_CASE)
|
||||||
|
|
||||||
class RichTextParser() {
|
class RichTextParser() {
|
||||||
fun parseMediaUrl(fullUrl: String): ZoomableUrlContent? {
|
fun parseMediaUrl(
|
||||||
|
fullUrl: String,
|
||||||
|
tags: ImmutableListOfLists<String>,
|
||||||
|
): ZoomableUrlContent? {
|
||||||
val removedParamsFromUrl = removeQueryParamsForExtensionComparison(fullUrl)
|
val removedParamsFromUrl = removeQueryParamsForExtensionComparison(fullUrl)
|
||||||
return if (imageExtensions.any { removedParamsFromUrl.endsWith(it) }) {
|
return if (imageExtensions.any { removedParamsFromUrl.endsWith(it) }) {
|
||||||
val frags = Nip44UrlParser().parse(fullUrl)
|
val frags = Nip54().parse(fullUrl)
|
||||||
|
val tags = Nip29().parse(fullUrl, tags.lists)
|
||||||
|
|
||||||
ZoomableUrlImage(
|
ZoomableUrlImage(
|
||||||
url = fullUrl,
|
url = fullUrl,
|
||||||
description = frags["alt"],
|
description = frags[FileHeaderEvent.ALT] ?: tags[FileHeaderEvent.ALT],
|
||||||
hash = frags["x"],
|
hash = frags[FileHeaderEvent.HASH] ?: tags[FileHeaderEvent.HASH],
|
||||||
blurhash = frags["blurhash"],
|
blurhash = frags[FileHeaderEvent.BLUR_HASH] ?: tags[FileHeaderEvent.BLUR_HASH],
|
||||||
dim = frags["dim"],
|
dim = frags[FileHeaderEvent.DIMENSION] ?: tags[FileHeaderEvent.DIMENSION],
|
||||||
contentWarning = frags["content-warning"],
|
contentWarning = frags["content-warning"] ?: tags["content-warning"],
|
||||||
)
|
)
|
||||||
} else if (videoExtensions.any { removedParamsFromUrl.endsWith(it) }) {
|
} else if (videoExtensions.any { removedParamsFromUrl.endsWith(it) }) {
|
||||||
val frags = Nip44UrlParser().parse(fullUrl)
|
val frags = Nip54().parse(fullUrl)
|
||||||
|
val tags = Nip29().parse(fullUrl, tags.lists)
|
||||||
ZoomableUrlVideo(
|
ZoomableUrlVideo(
|
||||||
url = fullUrl,
|
url = fullUrl,
|
||||||
description = frags["alt"],
|
description = frags[FileHeaderEvent.ALT] ?: tags[FileHeaderEvent.ALT],
|
||||||
hash = frags["x"],
|
hash = frags[FileHeaderEvent.HASH] ?: tags[FileHeaderEvent.HASH],
|
||||||
blurhash = frags["blurhash"],
|
blurhash = frags[FileHeaderEvent.BLUR_HASH] ?: tags[FileHeaderEvent.BLUR_HASH],
|
||||||
dim = frags["dim"],
|
dim = frags[FileHeaderEvent.DIMENSION] ?: tags[FileHeaderEvent.DIMENSION],
|
||||||
contentWarning = frags["content-warning"],
|
contentWarning = frags["content-warning"] ?: tags["content-warning"],
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
@ -146,7 +155,7 @@ class RichTextParser() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val imagesForPager =
|
val imagesForPager =
|
||||||
urlSet.mapNotNull { fullUrl -> parseMediaUrl(fullUrl) }.associateBy { it.url }
|
urlSet.mapNotNull { fullUrl -> parseMediaUrl(fullUrl, tags) }.associateBy { it.url }
|
||||||
val imageList = imagesForPager.values.toList()
|
val imageList = imagesForPager.values.toList()
|
||||||
|
|
||||||
val emojiMap =
|
val emojiMap =
|
||||||
|
@ -71,7 +71,6 @@ import kotlinx.coroutines.flow.Flow
|
|||||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||||
import kotlinx.coroutines.flow.mapLatest
|
import kotlinx.coroutines.flow.mapLatest
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import java.net.URLEncoder
|
|
||||||
|
|
||||||
enum class UserSuggestionAnchor {
|
enum class UserSuggestionAnchor {
|
||||||
MAIN_MESSAGE,
|
MAIN_MESSAGE,
|
||||||
@ -89,6 +88,7 @@ open class NewPostViewModel() : ViewModel() {
|
|||||||
|
|
||||||
var pTags by mutableStateOf<List<User>?>(null)
|
var pTags by mutableStateOf<List<User>?>(null)
|
||||||
var eTags by mutableStateOf<List<Note>?>(null)
|
var eTags by mutableStateOf<List<Note>?>(null)
|
||||||
|
var imetaTags = mutableStateListOf<Array<String>>()
|
||||||
|
|
||||||
var nip94attachments by mutableStateOf<List<FileHeaderEvent>>(emptyList())
|
var nip94attachments by mutableStateOf<List<FileHeaderEvent>>(emptyList())
|
||||||
var nip95attachments by
|
var nip95attachments by
|
||||||
@ -266,44 +266,46 @@ open class NewPostViewModel() : ViewModel() {
|
|||||||
|
|
||||||
val urls = findURLs(tagger.message)
|
val urls = findURLs(tagger.message)
|
||||||
val usedAttachments = nip94attachments.filter { it.urls().intersect(urls.toSet()).isNotEmpty() }
|
val usedAttachments = nip94attachments.filter { it.urls().intersect(urls.toSet()).isNotEmpty() }
|
||||||
usedAttachments.forEach { account?.sendHeader(it, relayList, {}) }
|
// Doesn't send as nip94 yet because we don't know if it makes sense.
|
||||||
|
// usedAttachments.forEach { account?.sendHeader(it, relayList, {}) }
|
||||||
|
|
||||||
if (originalNote?.channelHex() != null) {
|
if (originalNote?.channelHex() != null) {
|
||||||
if (originalNote is AddressableEvent && originalNote?.address() != null) {
|
if (originalNote is AddressableEvent && originalNote?.address() != null) {
|
||||||
account?.sendLiveMessage(
|
account?.sendLiveMessage(
|
||||||
tagger.message,
|
message = tagger.message,
|
||||||
originalNote?.address()!!,
|
toChannel = originalNote?.address()!!,
|
||||||
tagger.eTags,
|
replyTo = tagger.eTags,
|
||||||
tagger.pTags,
|
mentions = tagger.pTags,
|
||||||
zapReceiver,
|
zapReceiver = zapReceiver,
|
||||||
wantsToMarkAsSensitive,
|
wantsToMarkAsSensitive = wantsToMarkAsSensitive,
|
||||||
localZapRaiserAmount,
|
zapRaiserAmount = localZapRaiserAmount,
|
||||||
geoHash,
|
geohash = geoHash,
|
||||||
nip94attachments = usedAttachments,
|
nip94attachments = usedAttachments,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
account?.sendChannelMessage(
|
account?.sendChannelMessage(
|
||||||
tagger.message,
|
message = tagger.message,
|
||||||
tagger.channelHex!!,
|
toChannel = tagger.channelHex!!,
|
||||||
tagger.eTags,
|
replyTo = tagger.eTags,
|
||||||
tagger.pTags,
|
mentions = tagger.pTags,
|
||||||
zapReceiver,
|
zapReceiver = zapReceiver,
|
||||||
wantsToMarkAsSensitive,
|
wantsToMarkAsSensitive = wantsToMarkAsSensitive,
|
||||||
localZapRaiserAmount,
|
zapRaiserAmount = localZapRaiserAmount,
|
||||||
geoHash,
|
geohash = geoHash,
|
||||||
nip94attachments = usedAttachments,
|
nip94attachments = usedAttachments,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else if (originalNote?.event is PrivateDmEvent) {
|
} else if (originalNote?.event is PrivateDmEvent) {
|
||||||
account?.sendPrivateMessage(
|
account?.sendPrivateMessage(
|
||||||
tagger.message,
|
message = tagger.message,
|
||||||
originalNote!!.author!!,
|
toUser = originalNote!!.author!!,
|
||||||
originalNote!!,
|
replyingTo = originalNote!!,
|
||||||
tagger.pTags,
|
mentions = tagger.pTags,
|
||||||
zapReceiver,
|
zapReceiver = zapReceiver,
|
||||||
wantsToMarkAsSensitive,
|
wantsToMarkAsSensitive = wantsToMarkAsSensitive,
|
||||||
localZapRaiserAmount,
|
zapRaiserAmount = localZapRaiserAmount,
|
||||||
geoHash,
|
geohash = geoHash,
|
||||||
|
nip94attachments = usedAttachments,
|
||||||
)
|
)
|
||||||
} else if (originalNote?.event is ChatMessageEvent) {
|
} else if (originalNote?.event is ChatMessageEvent) {
|
||||||
val receivers =
|
val receivers =
|
||||||
@ -324,6 +326,7 @@ open class NewPostViewModel() : ViewModel() {
|
|||||||
zapReceiver = zapReceiver,
|
zapReceiver = zapReceiver,
|
||||||
zapRaiserAmount = localZapRaiserAmount,
|
zapRaiserAmount = localZapRaiserAmount,
|
||||||
geohash = geoHash,
|
geohash = geoHash,
|
||||||
|
nip94attachments = usedAttachments,
|
||||||
)
|
)
|
||||||
} else if (!dmUsers.isNullOrEmpty()) {
|
} else if (!dmUsers.isNullOrEmpty()) {
|
||||||
if (nip24 || dmUsers.size > 1) {
|
if (nip24 || dmUsers.size > 1) {
|
||||||
@ -337,6 +340,7 @@ open class NewPostViewModel() : ViewModel() {
|
|||||||
zapReceiver = zapReceiver,
|
zapReceiver = zapReceiver,
|
||||||
zapRaiserAmount = localZapRaiserAmount,
|
zapRaiserAmount = localZapRaiserAmount,
|
||||||
geohash = geoHash,
|
geohash = geoHash,
|
||||||
|
nip94attachments = usedAttachments,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
account?.sendPrivateMessage(
|
account?.sendPrivateMessage(
|
||||||
@ -348,6 +352,7 @@ open class NewPostViewModel() : ViewModel() {
|
|||||||
zapReceiver = zapReceiver,
|
zapReceiver = zapReceiver,
|
||||||
zapRaiserAmount = localZapRaiserAmount,
|
zapRaiserAmount = localZapRaiserAmount,
|
||||||
geohash = geoHash,
|
geohash = geoHash,
|
||||||
|
nip94attachments = usedAttachments,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -461,21 +466,12 @@ open class NewPostViewModel() : ViewModel() {
|
|||||||
onProgress = {},
|
onProgress = {},
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!isPrivate) {
|
createNIP94Record(
|
||||||
createNIP94Record(
|
uploadingResult = result,
|
||||||
uploadingResult = result,
|
localContentType = contentType,
|
||||||
localContentType = contentType,
|
alt = alt,
|
||||||
alt = alt,
|
sensitiveContent = sensitiveContent,
|
||||||
sensitiveContent = sensitiveContent,
|
)
|
||||||
)
|
|
||||||
} else {
|
|
||||||
noNIP94(
|
|
||||||
uploadingResult = result,
|
|
||||||
localContentType = contentType,
|
|
||||||
alt = alt,
|
|
||||||
sensitiveContent = sensitiveContent,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
if (e is CancellationException) throw e
|
if (e is CancellationException) throw e
|
||||||
Log.e(
|
Log.e(
|
||||||
@ -508,6 +504,7 @@ open class NewPostViewModel() : ViewModel() {
|
|||||||
urlPreview = null
|
urlPreview = null
|
||||||
isUploadingImage = false
|
isUploadingImage = false
|
||||||
pTags = null
|
pTags = null
|
||||||
|
imetaTags.clear()
|
||||||
|
|
||||||
wantsDirectMessage = false
|
wantsDirectMessage = false
|
||||||
|
|
||||||
@ -703,21 +700,6 @@ open class NewPostViewModel() : ViewModel() {
|
|||||||
contentToAddUrl == null
|
contentToAddUrl == null
|
||||||
}
|
}
|
||||||
|
|
||||||
fun includePollHashtagInMessage(
|
|
||||||
include: Boolean,
|
|
||||||
hashtag: String,
|
|
||||||
) {
|
|
||||||
if (include) {
|
|
||||||
updateMessage(TextFieldValue(message.text + " $hashtag"))
|
|
||||||
} else {
|
|
||||||
updateMessage(
|
|
||||||
TextFieldValue(
|
|
||||||
message.text.replace(" $hashtag", "").replace(hashtag, ""),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun createNIP94Record(
|
suspend fun createNIP94Record(
|
||||||
uploadingResult: Nip96Uploader.PartialEvent,
|
uploadingResult: Nip96Uploader.PartialEvent,
|
||||||
localContentType: String?,
|
localContentType: String?,
|
||||||
@ -751,25 +733,13 @@ open class NewPostViewModel() : ViewModel() {
|
|||||||
mimeType = remoteMimeType ?: localContentType,
|
mimeType = remoteMimeType ?: localContentType,
|
||||||
dimPrecomputed = dim,
|
dimPrecomputed = dim,
|
||||||
onReady = { header: FileHeader ->
|
onReady = { header: FileHeader ->
|
||||||
account?.createHeader(imageUrl, magnet, header, alt, sensitiveContent, originalHash) {
|
account?.createHeader(imageUrl, magnet, header, alt, sensitiveContent, originalHash) { event ->
|
||||||
event,
|
|
||||||
->
|
|
||||||
isUploadingImage = false
|
isUploadingImage = false
|
||||||
nip94attachments = nip94attachments + event
|
nip94attachments = nip94attachments + event
|
||||||
val contentWarning = if (sensitiveContent) "" else null
|
|
||||||
message =
|
message =
|
||||||
TextFieldValue(
|
TextFieldValue(
|
||||||
message.text +
|
message.text + "\n" + imageUrl,
|
||||||
"\n" +
|
|
||||||
addInlineMetadataAsNIP54(
|
|
||||||
imageUrl,
|
|
||||||
header.dim,
|
|
||||||
header.mimeType,
|
|
||||||
alt,
|
|
||||||
header.blurHash,
|
|
||||||
header.hash,
|
|
||||||
contentWarning,
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
urlPreview = findUrlInMessage()
|
urlPreview = findUrlInMessage()
|
||||||
}
|
}
|
||||||
@ -781,84 +751,6 @@ open class NewPostViewModel() : ViewModel() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun noNIP94(
|
|
||||||
uploadingResult: Nip96Uploader.PartialEvent,
|
|
||||||
localContentType: String?,
|
|
||||||
alt: String?,
|
|
||||||
sensitiveContent: Boolean,
|
|
||||||
) {
|
|
||||||
// Images don't seem to be ready immediately after upload
|
|
||||||
val imageUrl = uploadingResult.tags?.firstOrNull { it.size > 1 && it[0] == "url" }?.get(1)
|
|
||||||
val remoteMimeType =
|
|
||||||
uploadingResult.tags?.firstOrNull { it.size > 1 && it[0] == "m" }?.get(1)?.ifBlank { null }
|
|
||||||
val dim =
|
|
||||||
uploadingResult.tags?.firstOrNull { it.size > 1 && it[0] == "dim" }?.get(1)?.ifBlank { null }
|
|
||||||
|
|
||||||
if (imageUrl.isNullOrBlank()) {
|
|
||||||
Log.e("ImageDownload", "Couldn't download image from server")
|
|
||||||
cancel()
|
|
||||||
isUploadingImage = false
|
|
||||||
viewModelScope.launch { imageUploadingError.emit("Server failed to return a url") }
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
FileHeader.prepare(
|
|
||||||
fileUrl = imageUrl,
|
|
||||||
mimeType = remoteMimeType ?: localContentType,
|
|
||||||
dimPrecomputed = dim,
|
|
||||||
onReady = { header: FileHeader ->
|
|
||||||
isUploadingImage = false
|
|
||||||
val contentWarning = if (sensitiveContent) "" else null
|
|
||||||
message =
|
|
||||||
TextFieldValue(
|
|
||||||
message.text +
|
|
||||||
"\n" +
|
|
||||||
addInlineMetadataAsNIP54(
|
|
||||||
imageUrl,
|
|
||||||
header.dim,
|
|
||||||
header.mimeType,
|
|
||||||
alt,
|
|
||||||
header.blurHash,
|
|
||||||
header.hash,
|
|
||||||
contentWarning,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
urlPreview = findUrlInMessage()
|
|
||||||
},
|
|
||||||
onError = {
|
|
||||||
isUploadingImage = false
|
|
||||||
viewModelScope.launch { imageUploadingError.emit("Failed to upload the image / video") }
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun addInlineMetadataAsNIP54(
|
|
||||||
imageUrl: String,
|
|
||||||
dim: String?,
|
|
||||||
m: String?,
|
|
||||||
alt: String?,
|
|
||||||
blurHash: String?,
|
|
||||||
x: String?,
|
|
||||||
sensitiveContent: String?,
|
|
||||||
): String {
|
|
||||||
val extension =
|
|
||||||
listOfNotNull(
|
|
||||||
m?.ifBlank { null }?.let { "m=${URLEncoder.encode(it, "utf-8")}" },
|
|
||||||
dim?.ifBlank { null }?.let { "dim=${URLEncoder.encode(it, "utf-8")}" },
|
|
||||||
alt?.ifBlank { null }?.let { "alt=${URLEncoder.encode(it, "utf-8")}" },
|
|
||||||
blurHash?.ifBlank { null }?.let { "blurhash=${URLEncoder.encode(it, "utf-8")}" },
|
|
||||||
x?.ifBlank { null }?.let { "x=${URLEncoder.encode(it, "utf-8")}" },
|
|
||||||
sensitiveContent?.let { "content-warning=${URLEncoder.encode(it, "utf-8")}" },
|
|
||||||
)
|
|
||||||
.joinToString("&")
|
|
||||||
|
|
||||||
return if (imageUrl.contains("#")) {
|
|
||||||
"$imageUrl&$extension"
|
|
||||||
} else {
|
|
||||||
"$imageUrl#$extension"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun createNIP95Record(
|
fun createNIP95Record(
|
||||||
bytes: ByteArray,
|
bytes: ByteArray,
|
||||||
mimeType: String?,
|
mimeType: String?,
|
||||||
|
@ -103,6 +103,7 @@ import com.vitorpamplona.amethyst.ui.theme.markdownStyle
|
|||||||
import com.vitorpamplona.amethyst.ui.theme.replyModifier
|
import com.vitorpamplona.amethyst.ui.theme.replyModifier
|
||||||
import com.vitorpamplona.amethyst.ui.uriToRoute
|
import com.vitorpamplona.amethyst.ui.uriToRoute
|
||||||
import com.vitorpamplona.quartz.encoders.Nip19
|
import com.vitorpamplona.quartz.encoders.Nip19
|
||||||
|
import com.vitorpamplona.quartz.events.EmptyTagList
|
||||||
import com.vitorpamplona.quartz.events.ImmutableListOfLists
|
import com.vitorpamplona.quartz.events.ImmutableListOfLists
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@ -184,7 +185,7 @@ private fun RenderRegular(
|
|||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
nav: (String) -> Unit,
|
nav: (String) -> Unit,
|
||||||
) {
|
) {
|
||||||
val state by remember(content) { mutableStateOf(CachedRichTextParser.parseText(content, tags)) }
|
val state by remember(content, tags) { mutableStateOf(CachedRichTextParser.parseText(content, tags)) }
|
||||||
|
|
||||||
val currentTextStyle = LocalTextStyle.current
|
val currentTextStyle = LocalTextStyle.current
|
||||||
val currentTextColor = LocalContentColor.current
|
val currentTextColor = LocalContentColor.current
|
||||||
@ -416,8 +417,8 @@ private fun RenderContentAsMarkdown(
|
|||||||
onMediaCompose = { title, destination ->
|
onMediaCompose = { title, destination ->
|
||||||
ZoomableContentView(
|
ZoomableContentView(
|
||||||
content =
|
content =
|
||||||
remember(destination) {
|
remember(destination, tags) {
|
||||||
RichTextParser().parseMediaUrl(destination) ?: ZoomableUrlImage(url = destination)
|
RichTextParser().parseMediaUrl(destination, tags ?: EmptyTagList) ?: ZoomableUrlImage(url = destination)
|
||||||
},
|
},
|
||||||
roundedCorner = true,
|
roundedCorner = true,
|
||||||
accountViewModel = accountViewModel,
|
accountViewModel = accountViewModel,
|
||||||
|
@ -78,6 +78,7 @@ import com.vitorpamplona.amethyst.ui.theme.ChatPaddingInnerQuoteModifier
|
|||||||
import com.vitorpamplona.amethyst.ui.theme.ChatPaddingModifier
|
import com.vitorpamplona.amethyst.ui.theme.ChatPaddingModifier
|
||||||
import com.vitorpamplona.amethyst.ui.theme.DoubleHorzSpacer
|
import com.vitorpamplona.amethyst.ui.theme.DoubleHorzSpacer
|
||||||
import com.vitorpamplona.amethyst.ui.theme.Font12SP
|
import com.vitorpamplona.amethyst.ui.theme.Font12SP
|
||||||
|
import com.vitorpamplona.amethyst.ui.theme.HalfTopPadding
|
||||||
import com.vitorpamplona.amethyst.ui.theme.ReactionRowHeightChat
|
import com.vitorpamplona.amethyst.ui.theme.ReactionRowHeightChat
|
||||||
import com.vitorpamplona.amethyst.ui.theme.Size10dp
|
import com.vitorpamplona.amethyst.ui.theme.Size10dp
|
||||||
import com.vitorpamplona.amethyst.ui.theme.Size15Modifier
|
import com.vitorpamplona.amethyst.ui.theme.Size15Modifier
|
||||||
@ -619,19 +620,18 @@ private fun RenderRegularTextNote(
|
|||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
nav: (String) -> Unit,
|
nav: (String) -> Unit,
|
||||||
) {
|
) {
|
||||||
val tags = remember(note.event) { note.event?.tags()?.toImmutableListOfLists() ?: EmptyTagList }
|
|
||||||
val modifier = remember { Modifier.padding(top = 5.dp) }
|
|
||||||
|
|
||||||
LoadDecryptedContentOrNull(note = note, accountViewModel = accountViewModel) { eventContent ->
|
LoadDecryptedContentOrNull(note = note, accountViewModel = accountViewModel) { eventContent ->
|
||||||
if (eventContent != null) {
|
if (eventContent != null) {
|
||||||
SensitivityWarning(
|
SensitivityWarning(
|
||||||
note = note,
|
note = note,
|
||||||
accountViewModel = accountViewModel,
|
accountViewModel = accountViewModel,
|
||||||
) {
|
) {
|
||||||
|
val tags = remember(note.event) { note.event?.tags()?.toImmutableListOfLists() ?: EmptyTagList }
|
||||||
|
|
||||||
TranslatableRichTextViewer(
|
TranslatableRichTextViewer(
|
||||||
content = eventContent!!,
|
content = eventContent,
|
||||||
canPreview = canPreview,
|
canPreview = canPreview,
|
||||||
modifier = modifier,
|
modifier = HalfTopPadding,
|
||||||
tags = tags,
|
tags = tags,
|
||||||
backgroundColor = backgroundBubbleColor,
|
backgroundColor = backgroundBubbleColor,
|
||||||
accountViewModel = accountViewModel,
|
accountViewModel = accountViewModel,
|
||||||
@ -642,8 +642,8 @@ private fun RenderRegularTextNote(
|
|||||||
TranslatableRichTextViewer(
|
TranslatableRichTextViewer(
|
||||||
content = stringResource(id = R.string.could_not_decrypt_the_message),
|
content = stringResource(id = R.string.could_not_decrypt_the_message),
|
||||||
canPreview = true,
|
canPreview = true,
|
||||||
modifier = modifier,
|
modifier = HalfTopPadding,
|
||||||
tags = tags,
|
tags = EmptyTagList,
|
||||||
backgroundColor = backgroundBubbleColor,
|
backgroundColor = backgroundBubbleColor,
|
||||||
accountViewModel = accountViewModel,
|
accountViewModel = accountViewModel,
|
||||||
nav = nav,
|
nav = nav,
|
||||||
|
@ -156,6 +156,7 @@ import com.vitorpamplona.amethyst.ui.theme.placeholderText
|
|||||||
import com.vitorpamplona.quartz.events.EmptyTagList
|
import com.vitorpamplona.quartz.events.EmptyTagList
|
||||||
import com.vitorpamplona.quartz.events.LiveActivitiesEvent.Companion.STATUS_LIVE
|
import com.vitorpamplona.quartz.events.LiveActivitiesEvent.Companion.STATUS_LIVE
|
||||||
import com.vitorpamplona.quartz.events.Participant
|
import com.vitorpamplona.quartz.events.Participant
|
||||||
|
import com.vitorpamplona.quartz.events.findURLs
|
||||||
import com.vitorpamplona.quartz.events.toImmutableListOfLists
|
import com.vitorpamplona.quartz.events.toImmutableListOfLists
|
||||||
import kotlinx.collections.immutable.ImmutableList
|
import kotlinx.collections.immutable.ImmutableList
|
||||||
import kotlinx.collections.immutable.persistentListOf
|
import kotlinx.collections.immutable.persistentListOf
|
||||||
@ -300,6 +301,10 @@ fun ChannelScreen(
|
|||||||
dao = accountViewModel,
|
dao = accountViewModel,
|
||||||
)
|
)
|
||||||
tagger.run()
|
tagger.run()
|
||||||
|
|
||||||
|
val urls = findURLs(tagger.message)
|
||||||
|
val usedAttachments = newPostModel.nip94attachments.filter { it.urls().intersect(urls.toSet()).isNotEmpty() }
|
||||||
|
|
||||||
if (channel is PublicChatChannel) {
|
if (channel is PublicChatChannel) {
|
||||||
accountViewModel.account.sendChannelMessage(
|
accountViewModel.account.sendChannelMessage(
|
||||||
message = tagger.message,
|
message = tagger.message,
|
||||||
@ -307,6 +312,7 @@ fun ChannelScreen(
|
|||||||
replyTo = tagger.eTags,
|
replyTo = tagger.eTags,
|
||||||
mentions = tagger.pTags,
|
mentions = tagger.pTags,
|
||||||
wantsToMarkAsSensitive = false,
|
wantsToMarkAsSensitive = false,
|
||||||
|
nip94attachments = usedAttachments,
|
||||||
)
|
)
|
||||||
} else if (channel is LiveActivitiesChannel) {
|
} else if (channel is LiveActivitiesChannel) {
|
||||||
accountViewModel.account.sendLiveMessage(
|
accountViewModel.account.sendLiveMessage(
|
||||||
@ -315,6 +321,7 @@ fun ChannelScreen(
|
|||||||
replyTo = tagger.eTags,
|
replyTo = tagger.eTags,
|
||||||
mentions = tagger.pTags,
|
mentions = tagger.pTags,
|
||||||
wantsToMarkAsSensitive = false,
|
wantsToMarkAsSensitive = false,
|
||||||
|
nip94attachments = usedAttachments,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
newPostModel.message = TextFieldValue("")
|
newPostModel.message = TextFieldValue("")
|
||||||
|
@ -115,6 +115,7 @@ import com.vitorpamplona.amethyst.ui.theme.StdPadding
|
|||||||
import com.vitorpamplona.amethyst.ui.theme.placeholderText
|
import com.vitorpamplona.amethyst.ui.theme.placeholderText
|
||||||
import com.vitorpamplona.quartz.events.ChatMessageEvent
|
import com.vitorpamplona.quartz.events.ChatMessageEvent
|
||||||
import com.vitorpamplona.quartz.events.ChatroomKey
|
import com.vitorpamplona.quartz.events.ChatroomKey
|
||||||
|
import com.vitorpamplona.quartz.events.findURLs
|
||||||
import kotlinx.collections.immutable.persistentSetOf
|
import kotlinx.collections.immutable.persistentSetOf
|
||||||
import kotlinx.collections.immutable.toPersistentList
|
import kotlinx.collections.immutable.toPersistentList
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@ -324,6 +325,9 @@ fun ChatroomScreen(
|
|||||||
// LAST ROW
|
// LAST ROW
|
||||||
PrivateMessageEditFieldRow(newPostModel, isPrivate = true, accountViewModel) {
|
PrivateMessageEditFieldRow(newPostModel, isPrivate = true, accountViewModel) {
|
||||||
scope.launch(Dispatchers.IO) {
|
scope.launch(Dispatchers.IO) {
|
||||||
|
val urls = findURLs(newPostModel.message.text)
|
||||||
|
val usedAttachments = newPostModel.nip94attachments.filter { it.urls().intersect(urls.toSet()).isNotEmpty() }
|
||||||
|
|
||||||
if (newPostModel.nip24 || room.users.size > 1 || replyTo.value?.event is ChatMessageEvent) {
|
if (newPostModel.nip24 || room.users.size > 1 || replyTo.value?.event is ChatMessageEvent) {
|
||||||
accountViewModel.account.sendNIP24PrivateMessage(
|
accountViewModel.account.sendNIP24PrivateMessage(
|
||||||
message = newPostModel.message.text,
|
message = newPostModel.message.text,
|
||||||
@ -331,6 +335,7 @@ fun ChatroomScreen(
|
|||||||
replyingTo = replyTo.value,
|
replyingTo = replyTo.value,
|
||||||
mentions = null,
|
mentions = null,
|
||||||
wantsToMarkAsSensitive = false,
|
wantsToMarkAsSensitive = false,
|
||||||
|
nip94attachments = usedAttachments,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
accountViewModel.account.sendPrivateMessage(
|
accountViewModel.account.sendPrivateMessage(
|
||||||
@ -339,6 +344,7 @@ fun ChatroomScreen(
|
|||||||
replyingTo = replyTo.value,
|
replyingTo = replyTo.value,
|
||||||
mentions = null,
|
mentions = null,
|
||||||
wantsToMarkAsSensitive = false,
|
wantsToMarkAsSensitive = false,
|
||||||
|
nip94attachments = usedAttachments,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,76 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2023 Vitor Pamplona
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to use,
|
||||||
|
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||||
|
* Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
* subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||||
|
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.vitorpamplona.quartz.encoders
|
||||||
|
|
||||||
|
import com.vitorpamplona.quartz.events.FileHeaderEvent
|
||||||
|
|
||||||
|
class Nip29 {
|
||||||
|
companion object {
|
||||||
|
private const val IMETA = "imeta"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun convertFromFileHeader(header: FileHeaderEvent): Array<String>? {
|
||||||
|
val myUrl = header.url() ?: return null
|
||||||
|
return createTag(
|
||||||
|
myUrl,
|
||||||
|
header.tags,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun createTag(
|
||||||
|
imageUrl: String,
|
||||||
|
tags: Array<Array<String>>,
|
||||||
|
): Array<String> {
|
||||||
|
return arrayOf(
|
||||||
|
IMETA,
|
||||||
|
"url $imageUrl",
|
||||||
|
) +
|
||||||
|
tags.mapNotNull {
|
||||||
|
if (it.isNotEmpty() && it[0] != "url") {
|
||||||
|
if (it.size > 1) {
|
||||||
|
"${it[0]} ${it[1]}"
|
||||||
|
} else {
|
||||||
|
"${it[0]}}"
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun parse(
|
||||||
|
imageUrl: String,
|
||||||
|
tags: Array<Array<String>>,
|
||||||
|
): Map<String, String> {
|
||||||
|
return tags.firstOrNull {
|
||||||
|
it.size > 1 && it[0] == IMETA && it[1] == "url $imageUrl"
|
||||||
|
}?.let { tagList ->
|
||||||
|
tagList.associate { tag ->
|
||||||
|
val parts = tag.split(" ", limit = 2)
|
||||||
|
when (parts.size) {
|
||||||
|
2 -> parts[0] to parts[1]
|
||||||
|
1 -> parts[0] to ""
|
||||||
|
else -> "" to ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} ?: emptyMap()
|
||||||
|
}
|
||||||
|
}
|
@ -18,13 +18,47 @@
|
|||||||
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
package com.vitorpamplona.amethyst.service
|
package com.vitorpamplona.quartz.encoders
|
||||||
|
|
||||||
|
import com.vitorpamplona.quartz.events.FileHeaderEvent
|
||||||
import java.net.URI
|
import java.net.URI
|
||||||
import java.net.URLDecoder
|
import java.net.URLDecoder
|
||||||
|
import java.net.URLEncoder
|
||||||
import kotlin.coroutines.cancellation.CancellationException
|
import kotlin.coroutines.cancellation.CancellationException
|
||||||
|
|
||||||
class Nip44UrlParser {
|
class Nip54 {
|
||||||
|
fun convertFromFileHeader(header: FileHeaderEvent): String? {
|
||||||
|
val myUrl = header.url() ?: return null
|
||||||
|
return createUrl(
|
||||||
|
myUrl,
|
||||||
|
header.tags,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun createUrl(
|
||||||
|
imageUrl: String,
|
||||||
|
tags: Array<Array<String>>,
|
||||||
|
): String {
|
||||||
|
val extension =
|
||||||
|
tags.mapNotNull {
|
||||||
|
if (it.isNotEmpty() && it[0] != "url") {
|
||||||
|
if (it.size > 1) {
|
||||||
|
"${it[0]}=${URLEncoder.encode(it[1], "utf-8")}"
|
||||||
|
} else {
|
||||||
|
"${it[0]}}="
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}.joinToString("&")
|
||||||
|
|
||||||
|
return if (imageUrl.contains("#")) {
|
||||||
|
"$imageUrl&$extension"
|
||||||
|
} else {
|
||||||
|
"$imageUrl#$extension"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun parse(url: String): Map<String, String> {
|
fun parse(url: String): Map<String, String> {
|
||||||
return try {
|
return try {
|
||||||
fragments(URI(url))
|
fragments(URI(url))
|
@ -22,6 +22,7 @@ package com.vitorpamplona.quartz.events
|
|||||||
|
|
||||||
import androidx.compose.runtime.Immutable
|
import androidx.compose.runtime.Immutable
|
||||||
import com.vitorpamplona.quartz.encoders.HexKey
|
import com.vitorpamplona.quartz.encoders.HexKey
|
||||||
|
import com.vitorpamplona.quartz.encoders.Nip29
|
||||||
import com.vitorpamplona.quartz.signers.NostrSigner
|
import com.vitorpamplona.quartz.signers.NostrSigner
|
||||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||||
|
|
||||||
@ -58,7 +59,7 @@ class ChannelMessageEvent(
|
|||||||
markAsSensitive: Boolean,
|
markAsSensitive: Boolean,
|
||||||
zapRaiserAmount: Long?,
|
zapRaiserAmount: Long?,
|
||||||
geohash: String? = null,
|
geohash: String? = null,
|
||||||
nip94attachments: List<Event>? = null,
|
nip94attachments: List<FileHeaderEvent>? = null,
|
||||||
onReady: (ChannelMessageEvent) -> Unit,
|
onReady: (ChannelMessageEvent) -> Unit,
|
||||||
) {
|
) {
|
||||||
val tags =
|
val tags =
|
||||||
@ -77,7 +78,9 @@ class ChannelMessageEvent(
|
|||||||
geohash?.let { tags.addAll(geohashMipMap(it)) }
|
geohash?.let { tags.addAll(geohashMipMap(it)) }
|
||||||
nip94attachments?.let {
|
nip94attachments?.let {
|
||||||
it.forEach {
|
it.forEach {
|
||||||
// tags.add(arrayOf("nip94", it.toJson()))
|
Nip29().convertFromFileHeader(it)?.let {
|
||||||
|
tags.add(it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tags.add(
|
tags.add(
|
||||||
|
@ -23,6 +23,7 @@ package com.vitorpamplona.quartz.events
|
|||||||
import androidx.compose.runtime.Immutable
|
import androidx.compose.runtime.Immutable
|
||||||
import androidx.compose.runtime.Stable
|
import androidx.compose.runtime.Stable
|
||||||
import com.vitorpamplona.quartz.encoders.HexKey
|
import com.vitorpamplona.quartz.encoders.HexKey
|
||||||
|
import com.vitorpamplona.quartz.encoders.Nip29
|
||||||
import com.vitorpamplona.quartz.signers.NostrSigner
|
import com.vitorpamplona.quartz.signers.NostrSigner
|
||||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||||
import kotlinx.collections.immutable.ImmutableSet
|
import kotlinx.collections.immutable.ImmutableSet
|
||||||
@ -80,6 +81,7 @@ class ChatMessageEvent(
|
|||||||
geohash: String? = null,
|
geohash: String? = null,
|
||||||
signer: NostrSigner,
|
signer: NostrSigner,
|
||||||
createdAt: Long = TimeUtils.now(),
|
createdAt: Long = TimeUtils.now(),
|
||||||
|
nip94attachments: List<FileHeaderEvent>? = null,
|
||||||
onReady: (ChatMessageEvent) -> Unit,
|
onReady: (ChatMessageEvent) -> Unit,
|
||||||
) {
|
) {
|
||||||
val tags = mutableListOf<Array<String>>()
|
val tags = mutableListOf<Array<String>>()
|
||||||
@ -95,6 +97,13 @@ class ChatMessageEvent(
|
|||||||
zapRaiserAmount?.let { tags.add(arrayOf("zapraiser", "$it")) }
|
zapRaiserAmount?.let { tags.add(arrayOf("zapraiser", "$it")) }
|
||||||
geohash?.let { tags.addAll(geohashMipMap(it)) }
|
geohash?.let { tags.addAll(geohashMipMap(it)) }
|
||||||
subject?.let { tags.add(arrayOf("subject", it)) }
|
subject?.let { tags.add(arrayOf("subject", it)) }
|
||||||
|
nip94attachments?.let {
|
||||||
|
it.forEach {
|
||||||
|
Nip29().convertFromFileHeader(it)?.let {
|
||||||
|
tags.add(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
// tags.add(arrayOf("alt", alt))
|
// tags.add(arrayOf("alt", alt))
|
||||||
|
|
||||||
signer.sign(createdAt, KIND, tags.toTypedArray(), msg, onReady)
|
signer.sign(createdAt, KIND, tags.toTypedArray(), msg, onReady)
|
||||||
|
@ -62,17 +62,17 @@ class FileHeaderEvent(
|
|||||||
const val KIND = 1063
|
const val KIND = 1063
|
||||||
const val ALT_DESCRIPTION = "Verifiable file url"
|
const val ALT_DESCRIPTION = "Verifiable file url"
|
||||||
|
|
||||||
private const val URL = "url"
|
const val URL = "url"
|
||||||
private const val ENCRYPTION_KEY = "aes-256-gcm"
|
const val ENCRYPTION_KEY = "aes-256-gcm"
|
||||||
private const val MIME_TYPE = "m"
|
const val MIME_TYPE = "m"
|
||||||
private const val FILE_SIZE = "size"
|
const val FILE_SIZE = "size"
|
||||||
private const val DIMENSION = "dim"
|
const val DIMENSION = "dim"
|
||||||
private const val HASH = "x"
|
const val HASH = "x"
|
||||||
private const val MAGNET_URI = "magnet"
|
const val MAGNET_URI = "magnet"
|
||||||
private const val TORRENT_INFOHASH = "i"
|
const val TORRENT_INFOHASH = "i"
|
||||||
private const val BLUR_HASH = "blurhash"
|
const val BLUR_HASH = "blurhash"
|
||||||
private const val ORIGINAL_HASH = "ox"
|
const val ORIGINAL_HASH = "ox"
|
||||||
private const val ALT = "alt"
|
const val ALT = "alt"
|
||||||
|
|
||||||
fun create(
|
fun create(
|
||||||
url: String,
|
url: String,
|
||||||
|
@ -23,6 +23,7 @@ package com.vitorpamplona.quartz.events
|
|||||||
import androidx.compose.runtime.Immutable
|
import androidx.compose.runtime.Immutable
|
||||||
import com.vitorpamplona.quartz.encoders.ATag
|
import com.vitorpamplona.quartz.encoders.ATag
|
||||||
import com.vitorpamplona.quartz.encoders.HexKey
|
import com.vitorpamplona.quartz.encoders.HexKey
|
||||||
|
import com.vitorpamplona.quartz.encoders.Nip29
|
||||||
import com.vitorpamplona.quartz.signers.NostrSigner
|
import com.vitorpamplona.quartz.signers.NostrSigner
|
||||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||||
|
|
||||||
@ -70,7 +71,7 @@ class LiveActivitiesChatMessageEvent(
|
|||||||
markAsSensitive: Boolean,
|
markAsSensitive: Boolean,
|
||||||
zapRaiserAmount: Long?,
|
zapRaiserAmount: Long?,
|
||||||
geohash: String? = null,
|
geohash: String? = null,
|
||||||
nip94attachments: List<Event>? = null,
|
nip94attachments: List<FileHeaderEvent>? = null,
|
||||||
onReady: (LiveActivitiesChatMessageEvent) -> Unit,
|
onReady: (LiveActivitiesChatMessageEvent) -> Unit,
|
||||||
) {
|
) {
|
||||||
val content = message
|
val content = message
|
||||||
@ -90,7 +91,9 @@ class LiveActivitiesChatMessageEvent(
|
|||||||
geohash?.let { tags.addAll(geohashMipMap(it)) }
|
geohash?.let { tags.addAll(geohashMipMap(it)) }
|
||||||
nip94attachments?.let {
|
nip94attachments?.let {
|
||||||
it.forEach {
|
it.forEach {
|
||||||
// tags.add(arrayOf("nip94", it.toJson()))
|
Nip29().convertFromFileHeader(it)?.let {
|
||||||
|
tags.add(it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tags.add(arrayOf("alt", ALT))
|
tags.add(arrayOf("alt", ALT))
|
||||||
|
@ -77,6 +77,7 @@ class NIP24Factory {
|
|||||||
markAsSensitive: Boolean = false,
|
markAsSensitive: Boolean = false,
|
||||||
zapRaiserAmount: Long? = null,
|
zapRaiserAmount: Long? = null,
|
||||||
geohash: String? = null,
|
geohash: String? = null,
|
||||||
|
nip94attachments: List<FileHeaderEvent>? = null,
|
||||||
onReady: (Result) -> Unit,
|
onReady: (Result) -> Unit,
|
||||||
) {
|
) {
|
||||||
val senderPublicKey = signer.pubKey
|
val senderPublicKey = signer.pubKey
|
||||||
@ -92,6 +93,7 @@ class NIP24Factory {
|
|||||||
markAsSensitive = markAsSensitive,
|
markAsSensitive = markAsSensitive,
|
||||||
zapRaiserAmount = zapRaiserAmount,
|
zapRaiserAmount = zapRaiserAmount,
|
||||||
geohash = geohash,
|
geohash = geohash,
|
||||||
|
nip94attachments = nip94attachments,
|
||||||
) { senderMessage ->
|
) { senderMessage ->
|
||||||
createWraps(senderMessage, to.plus(senderPublicKey).toSet(), signer) { wraps ->
|
createWraps(senderMessage, to.plus(senderPublicKey).toSet(), signer) { wraps ->
|
||||||
onReady(
|
onReady(
|
||||||
|
@ -23,6 +23,7 @@ package com.vitorpamplona.quartz.events
|
|||||||
import androidx.compose.runtime.Immutable
|
import androidx.compose.runtime.Immutable
|
||||||
import com.vitorpamplona.quartz.encoders.ATag
|
import com.vitorpamplona.quartz.encoders.ATag
|
||||||
import com.vitorpamplona.quartz.encoders.HexKey
|
import com.vitorpamplona.quartz.encoders.HexKey
|
||||||
|
import com.vitorpamplona.quartz.encoders.Nip29
|
||||||
import com.vitorpamplona.quartz.signers.NostrSigner
|
import com.vitorpamplona.quartz.signers.NostrSigner
|
||||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||||
|
|
||||||
@ -78,7 +79,7 @@ class PollNoteEvent(
|
|||||||
markAsSensitive: Boolean,
|
markAsSensitive: Boolean,
|
||||||
zapRaiserAmount: Long?,
|
zapRaiserAmount: Long?,
|
||||||
geohash: String? = null,
|
geohash: String? = null,
|
||||||
nip94attachments: List<Event>? = null,
|
nip94attachments: List<FileHeaderEvent>? = null,
|
||||||
onReady: (PollNoteEvent) -> Unit,
|
onReady: (PollNoteEvent) -> Unit,
|
||||||
) {
|
) {
|
||||||
val tags = mutableListOf<Array<String>>()
|
val tags = mutableListOf<Array<String>>()
|
||||||
@ -104,7 +105,9 @@ class PollNoteEvent(
|
|||||||
geohash?.let { tags.addAll(geohashMipMap(it)) }
|
geohash?.let { tags.addAll(geohashMipMap(it)) }
|
||||||
nip94attachments?.let {
|
nip94attachments?.let {
|
||||||
it.forEach {
|
it.forEach {
|
||||||
// tags.add(arrayOf("nip94", it.toJson()))
|
Nip29().convertFromFileHeader(it)?.let {
|
||||||
|
tags.add(it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tags.add(arrayOf("alt", ALT))
|
tags.add(arrayOf("alt", ALT))
|
||||||
|
@ -24,6 +24,7 @@ import androidx.compose.runtime.Immutable
|
|||||||
import com.vitorpamplona.quartz.encoders.Hex
|
import com.vitorpamplona.quartz.encoders.Hex
|
||||||
import com.vitorpamplona.quartz.encoders.HexKey
|
import com.vitorpamplona.quartz.encoders.HexKey
|
||||||
import com.vitorpamplona.quartz.encoders.HexValidator
|
import com.vitorpamplona.quartz.encoders.HexValidator
|
||||||
|
import com.vitorpamplona.quartz.encoders.Nip54
|
||||||
import com.vitorpamplona.quartz.signers.NostrSigner
|
import com.vitorpamplona.quartz.signers.NostrSigner
|
||||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||||
import kotlinx.collections.immutable.persistentSetOf
|
import kotlinx.collections.immutable.persistentSetOf
|
||||||
@ -122,14 +123,24 @@ class PrivateDmEvent(
|
|||||||
markAsSensitive: Boolean,
|
markAsSensitive: Boolean,
|
||||||
zapRaiserAmount: Long?,
|
zapRaiserAmount: Long?,
|
||||||
geohash: String? = null,
|
geohash: String? = null,
|
||||||
|
nip94attachments: List<FileHeaderEvent>? = null,
|
||||||
onReady: (PrivateDmEvent) -> Unit,
|
onReady: (PrivateDmEvent) -> Unit,
|
||||||
) {
|
) {
|
||||||
val message =
|
var message = msg
|
||||||
|
nip94attachments?.forEach {
|
||||||
|
val myUrl = it.url()
|
||||||
|
if (myUrl != null) {
|
||||||
|
message = message.replace(myUrl, Nip54().createUrl(myUrl, it.tags))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
message =
|
||||||
if (advertiseNip18) {
|
if (advertiseNip18) {
|
||||||
NIP_18_ADVERTISEMENT
|
NIP_18_ADVERTISEMENT + message
|
||||||
} else {
|
} else {
|
||||||
""
|
message
|
||||||
} + msg
|
}
|
||||||
|
|
||||||
val tags = mutableListOf<Array<String>>()
|
val tags = mutableListOf<Array<String>>()
|
||||||
publishedRecipientPubKey?.let { tags.add(arrayOf("p", publishedRecipientPubKey)) }
|
publishedRecipientPubKey?.let { tags.add(arrayOf("p", publishedRecipientPubKey)) }
|
||||||
replyTos?.forEach { tags.add(arrayOf("e", it)) }
|
replyTos?.forEach { tags.add(arrayOf("e", it)) }
|
||||||
@ -142,6 +153,15 @@ class PrivateDmEvent(
|
|||||||
}
|
}
|
||||||
zapRaiserAmount?.let { tags.add(arrayOf("zapraiser", "$it")) }
|
zapRaiserAmount?.let { tags.add(arrayOf("zapraiser", "$it")) }
|
||||||
geohash?.let { tags.addAll(geohashMipMap(it)) }
|
geohash?.let { tags.addAll(geohashMipMap(it)) }
|
||||||
|
/* Privacy issue: DO NOT ADD THESE TO THE TAGS.
|
||||||
|
nip94attachments?.let {
|
||||||
|
it.forEach {
|
||||||
|
Nip29().convertFromFileHeader(it)?.let {
|
||||||
|
tags.add(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
tags.add(arrayOf("alt", ALT))
|
tags.add(arrayOf("alt", ALT))
|
||||||
|
|
||||||
signer.nip04Encrypt(message, recipientPubKey) { content ->
|
signer.nip04Encrypt(message, recipientPubKey) { content ->
|
||||||
|
@ -25,6 +25,7 @@ import com.linkedin.urls.detection.UrlDetector
|
|||||||
import com.linkedin.urls.detection.UrlDetectorOptions
|
import com.linkedin.urls.detection.UrlDetectorOptions
|
||||||
import com.vitorpamplona.quartz.encoders.ATag
|
import com.vitorpamplona.quartz.encoders.ATag
|
||||||
import com.vitorpamplona.quartz.encoders.HexKey
|
import com.vitorpamplona.quartz.encoders.HexKey
|
||||||
|
import com.vitorpamplona.quartz.encoders.Nip29
|
||||||
import com.vitorpamplona.quartz.signers.NostrSigner
|
import com.vitorpamplona.quartz.signers.NostrSigner
|
||||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||||
|
|
||||||
@ -55,7 +56,7 @@ class TextNoteEvent(
|
|||||||
root: String?,
|
root: String?,
|
||||||
directMentions: Set<HexKey>,
|
directMentions: Set<HexKey>,
|
||||||
geohash: String? = null,
|
geohash: String? = null,
|
||||||
nip94attachments: List<Event>? = null,
|
nip94attachments: List<FileHeaderEvent>? = null,
|
||||||
signer: NostrSigner,
|
signer: NostrSigner,
|
||||||
createdAt: Long = TimeUtils.now(),
|
createdAt: Long = TimeUtils.now(),
|
||||||
onReady: (TextNoteEvent) -> Unit,
|
onReady: (TextNoteEvent) -> Unit,
|
||||||
@ -106,7 +107,9 @@ class TextNoteEvent(
|
|||||||
geohash?.let { tags.addAll(geohashMipMap(it)) }
|
geohash?.let { tags.addAll(geohashMipMap(it)) }
|
||||||
nip94attachments?.let {
|
nip94attachments?.let {
|
||||||
it.forEach {
|
it.forEach {
|
||||||
// tags.add(arrayOf("nip94", it.toJson()))
|
Nip29().convertFromFileHeader(it)?.let {
|
||||||
|
tags.add(it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user