streamlines function calls on AccountViewModel

This commit is contained in:
Vitor Pamplona
2025-08-21 17:10:10 -04:00
parent 965db8b91b
commit d810aaa2d0
@@ -667,9 +667,7 @@ class AccountViewModel(
note: Note, note: Note,
type: ReportType, type: ReportType,
content: String = "", content: String = "",
) { ) = runIOCatching { account.report(note, type, content) }
runIOCatching { account.report(note, type, content) }
}
fun report( fun report(
user: User, user: User,
@@ -681,17 +679,11 @@ class AccountViewModel(
} }
} }
fun boost(note: Note) { fun boost(note: Note) = runIOCatching { account.boost(note) }
runIOCatching { account.boost(note) }
}
fun removeEmojiPack(emojiPack: Note) { fun removeEmojiPack(emojiPack: Note) = runIOCatching { account.removeEmojiPack(emojiPack) }
runIOCatching { account.removeEmojiPack(emojiPack) }
}
fun addEmojiPack(emojiPack: Note) { fun addEmojiPack(emojiPack: Note) = runIOCatching { account.addEmojiPack(emojiPack) }
runIOCatching { account.addEmojiPack(emojiPack) }
}
fun addMediaToGallery( fun addMediaToGallery(
hex: String, hex: String,
@@ -701,13 +693,9 @@ class AccountViewModel(
dim: DimensionTag?, dim: DimensionTag?,
hash: String?, hash: String?,
mimeType: String?, mimeType: String?,
) { ) = runIOCatching { account.addToGallery(hex, url, relay, blurhash, dim, hash, mimeType) }
runIOCatching { account.addToGallery(hex, url, relay, blurhash, dim, hash, mimeType) }
}
fun removeFromMediaGallery(note: Note) { fun removeFromMediaGallery(note: Note) = runIOCatching { account.removeFromGallery(note) }
runIOCatching { account.removeFromGallery(note) }
}
fun hashtagFollows(user: User): Note = LocalCache.getOrCreateAddressableNote(HashtagListEvent.createAddress(user.pubkeyHex)) fun hashtagFollows(user: User): Note = LocalCache.getOrCreateAddressableNote(HashtagListEvent.createAddress(user.pubkeyHex))
@@ -736,13 +724,9 @@ class AccountViewModel(
} }
} }
fun delete(notes: List<Note>) { fun delete(notes: List<Note>) = runIOCatching { account.delete(notes) }
runIOCatching { account.delete(notes) }
}
fun delete(note: Note) { fun delete(note: Note) = runIOCatching { account.delete(note) }
runIOCatching { account.delete(note) }
}
fun cachedDecrypt(note: Note): String? = account.cachedDecryptContent(note) fun cachedDecrypt(note: Note): String? = account.cachedDecryptContent(note)
@@ -790,61 +774,33 @@ class AccountViewModel(
} }
} }
fun follow(community: AddressableNote) { fun follow(community: AddressableNote) = runIOCatching { account.follow(community) }
runIOCatching { account.follow(community) }
}
fun follow(channel: PublicChatChannel) { fun follow(channel: PublicChatChannel) = runIOCatching { account.follow(channel) }
runIOCatching { account.follow(channel) }
}
fun follow(channel: EphemeralChatChannel) { fun follow(channel: EphemeralChatChannel) = runIOCatching { account.follow(channel) }
runIOCatching { account.follow(channel) }
}
fun unfollow(community: AddressableNote) { fun unfollow(community: AddressableNote) = runIOCatching { account.unfollow(community) }
runIOCatching { account.unfollow(community) }
}
fun unfollow(channel: PublicChatChannel) { fun unfollow(channel: PublicChatChannel) = runIOCatching { account.unfollow(channel) }
runIOCatching { account.unfollow(channel) }
}
fun unfollow(channel: EphemeralChatChannel) { fun unfollow(channel: EphemeralChatChannel) = runIOCatching { account.unfollow(channel) }
runIOCatching { account.unfollow(channel) }
}
fun follow(user: User) { fun follow(user: User) = runIOCatching { account.follow(user) }
runIOCatching { account.follow(user) }
}
fun unfollow(user: User) { fun unfollow(user: User) = runIOCatching { account.unfollow(user) }
runIOCatching { account.unfollow(user) }
}
fun followGeohash(tag: String) { fun followGeohash(tag: String) = runIOCatching { account.followGeohash(tag) }
runIOCatching { account.followGeohash(tag) }
}
fun unfollowGeohash(tag: String) { fun unfollowGeohash(tag: String) = runIOCatching { account.unfollowGeohash(tag) }
runIOCatching { account.unfollowGeohash(tag) }
}
fun followHashtag(tag: String) { fun followHashtag(tag: String) = runIOCatching { account.followHashtag(tag) }
runIOCatching { account.followHashtag(tag) }
}
fun unfollowHashtag(tag: String) { fun unfollowHashtag(tag: String) = runIOCatching { account.unfollowHashtag(tag) }
runIOCatching { account.unfollowHashtag(tag) }
}
fun showWord(word: String) { fun showWord(word: String) = runIOCatching { account.showWord(word) }
runIOCatching { account.showWord(word) }
}
fun hideWord(word: String) { fun hideWord(word: String) = runIOCatching { account.hideWord(word) }
runIOCatching { account.hideWord(word) }
}
fun isLoggedUser(pubkeyHex: HexKey?): Boolean = account.signer.pubKey == pubkeyHex fun isLoggedUser(pubkeyHex: HexKey?): Boolean = account.signer.pubKey == pubkeyHex
@@ -927,17 +883,14 @@ class AccountViewModel(
fun updateStatus( fun updateStatus(
address: Address, address: Address,
newStatus: String, newStatus: String,
) { ) = runIOCatching {
runIOCatching { account.updateStatus(LocalCache.getOrCreateAddressableNote(address), newStatus)
account.updateStatus(LocalCache.getOrCreateAddressableNote(address), newStatus)
}
} }
fun deleteStatus(address: Address) { fun deleteStatus(address: Address) =
runIOCatching { runIOCatching {
account.deleteStatus(LocalCache.getOrCreateAddressableNote(address)) account.deleteStatus(LocalCache.getOrCreateAddressableNote(address))
} }
}
fun urlPreview( fun urlPreview(
url: String, url: String,
@@ -1578,7 +1531,7 @@ class AccountViewModel(
root: InteractiveStoryBaseEvent, root: InteractiveStoryBaseEvent,
readingScene: InteractiveStoryBaseEvent, readingScene: InteractiveStoryBaseEvent,
) { ) {
viewModelScope.launch(Dispatchers.IO) { runIOCatching {
val sceneNoteRelayHint = LocalCache.getOrCreateAddressableNote(readingScene.address()).relayHintUrl() val sceneNoteRelayHint = LocalCache.getOrCreateAddressableNote(readingScene.address()).relayHintUrl()
val readingState = getInteractiveStoryReadingState(root.addressTag()) val readingState = getInteractiveStoryReadingState(root.addressTag())