Use background coroutines for modification operations. Use FollowSet in callbacks, rather than just the set identifier.
This commit is contained in:
+6
-6
@@ -154,9 +154,9 @@ fun ListsScreen(
|
|||||||
account = accountViewModel.account,
|
account = accountViewModel.account,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
deleteItem = { identifier ->
|
deleteItem = { followSet ->
|
||||||
followSetsViewModel.deleteFollowSet(
|
followSetsViewModel.deleteFollowSet(
|
||||||
listIdentifier = identifier,
|
followSet = followSet,
|
||||||
account = accountViewModel.account,
|
account = accountViewModel.account,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -178,7 +178,7 @@ fun ListsScreen(
|
|||||||
onProfileRemove = {
|
onProfileRemove = {
|
||||||
followSetsViewModel.removeUserFromSet(
|
followSetsViewModel.removeUserFromSet(
|
||||||
it,
|
it,
|
||||||
leFollowSet.identifierTag,
|
leFollowSet,
|
||||||
accountViewModel.account,
|
accountViewModel.account,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -191,7 +191,7 @@ fun ListsScreen(
|
|||||||
onListDelete = {
|
onListDelete = {
|
||||||
isFollowSetSelected.value = false
|
isFollowSetSelected.value = false
|
||||||
followSetsViewModel.deleteFollowSet(
|
followSetsViewModel.deleteFollowSet(
|
||||||
leFollowSet.identifierTag,
|
leFollowSet,
|
||||||
accountViewModel.account,
|
accountViewModel.account,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -205,8 +205,8 @@ fun CustomListsScreen(
|
|||||||
refresh: () -> Unit,
|
refresh: () -> Unit,
|
||||||
addItem: (title: String, description: String?, listType: ListVisibility) -> Unit,
|
addItem: (title: String, description: String?, listType: ListVisibility) -> Unit,
|
||||||
openItem: (identifier: String) -> Unit,
|
openItem: (identifier: String) -> Unit,
|
||||||
renameItem: (targetSet: FollowSet, newName: String) -> Unit,
|
renameItem: (followSet: FollowSet, newName: String) -> Unit,
|
||||||
deleteItem: (setIdentifier: String) -> Unit,
|
deleteItem: (followSet: FollowSet) -> Unit,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
nav: INav,
|
nav: INav,
|
||||||
) {
|
) {
|
||||||
|
|||||||
+3
-3
@@ -48,7 +48,7 @@ fun FollowSetFeedView(
|
|||||||
onRefresh: () -> Unit = {},
|
onRefresh: () -> Unit = {},
|
||||||
onOpenItem: (String) -> Unit = {},
|
onOpenItem: (String) -> Unit = {},
|
||||||
onRenameItem: (targetSet: FollowSet, newName: String) -> Unit,
|
onRenameItem: (targetSet: FollowSet, newName: String) -> Unit,
|
||||||
onDeleteItem: (setIdentifier: String) -> Unit,
|
onDeleteItem: (followSet: FollowSet) -> Unit,
|
||||||
) {
|
) {
|
||||||
when (followSetState) {
|
when (followSetState) {
|
||||||
FollowSetState.Loading -> LoadingFeed()
|
FollowSetState.Loading -> LoadingFeed()
|
||||||
@@ -90,7 +90,7 @@ fun FollowListLoaded(
|
|||||||
onRefresh: () -> Unit = {},
|
onRefresh: () -> Unit = {},
|
||||||
onItemClick: (itemIdentifier: String) -> Unit = {},
|
onItemClick: (itemIdentifier: String) -> Unit = {},
|
||||||
onItemRename: (followSet: FollowSet, newName: String) -> Unit,
|
onItemRename: (followSet: FollowSet, newName: String) -> Unit,
|
||||||
onItemDelete: (itemIdentifier: String) -> Unit,
|
onItemDelete: (followSet: FollowSet) -> Unit,
|
||||||
) {
|
) {
|
||||||
Log.d("FollowSetComposable", "FollowListLoaded: Follow Set size: ${loadedFeedState.size}")
|
Log.d("FollowSetComposable", "FollowListLoaded: Follow Set size: ${loadedFeedState.size}")
|
||||||
|
|
||||||
@@ -113,7 +113,7 @@ fun FollowListLoaded(
|
|||||||
onItemRename(set, it)
|
onItemRename(set, it)
|
||||||
},
|
},
|
||||||
onFollowSetDelete = {
|
onFollowSetDelete = {
|
||||||
onItemDelete(set.identifierTag)
|
onItemDelete(set)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
Spacer(modifier = StdVertSpacer)
|
Spacer(modifier = StdVertSpacer)
|
||||||
|
|||||||
+17
-16
@@ -124,7 +124,7 @@ class NostrListFeedViewModel(
|
|||||||
if (account.settings.isWriteable()) {
|
if (account.settings.isWriteable()) {
|
||||||
println("You are in read-only mode. Please login to make modifications.")
|
println("You are in read-only mode. Please login to make modifications.")
|
||||||
} else {
|
} else {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
PeopleListEvent.createListWithDescription(
|
PeopleListEvent.createListWithDescription(
|
||||||
dTag = UUID.randomUUID().toString(),
|
dTag = UUID.randomUUID().toString(),
|
||||||
key = "title",
|
key = "title",
|
||||||
@@ -148,7 +148,7 @@ class NostrListFeedViewModel(
|
|||||||
if (!account.settings.isWriteable()) {
|
if (!account.settings.isWriteable()) {
|
||||||
println("You are in read-only mode. Please login to make modifications.")
|
println("You are in read-only mode. Please login to make modifications.")
|
||||||
} else {
|
} else {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
val setEvent = getFollowSetNote(followSet.identifierTag, account)?.event as PeopleListEvent
|
val setEvent = getFollowSetNote(followSet.identifierTag, account)?.event as PeopleListEvent
|
||||||
PeopleListEvent.modifyTag(
|
PeopleListEvent.modifyTag(
|
||||||
earlierVersion = setEvent,
|
earlierVersion = setEvent,
|
||||||
@@ -165,15 +165,15 @@ class NostrListFeedViewModel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun deleteFollowSet(
|
fun deleteFollowSet(
|
||||||
listIdentifier: String,
|
followSet: FollowSet,
|
||||||
account: Account,
|
account: Account,
|
||||||
) {
|
) {
|
||||||
if (!account.settings.isWriteable()) {
|
if (!account.settings.isWriteable()) {
|
||||||
println("You are in read-only mode. Please login to make modifications.")
|
println("You are in read-only mode. Please login to make modifications.")
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
val followSetEvent = getFollowSetNote(listIdentifier, account)?.event as PeopleListEvent
|
val followSetEvent = getFollowSetNote(followSet.identifierTag, account)?.event as PeopleListEvent
|
||||||
account.signer.sign(
|
account.signer.sign(
|
||||||
DeletionEvent.build(listOf(followSetEvent)),
|
DeletionEvent.build(listOf(followSetEvent)),
|
||||||
) {
|
) {
|
||||||
@@ -193,7 +193,7 @@ class NostrListFeedViewModel(
|
|||||||
println("You are in read-only mode. Please login to make modifications.")
|
println("You are in read-only mode. Please login to make modifications.")
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
val followSetEvent = getFollowSetNote(followSet.identifierTag, account)?.event as PeopleListEvent
|
val followSetEvent = getFollowSetNote(followSet.identifierTag, account)?.event as PeopleListEvent
|
||||||
PeopleListEvent.addUser(
|
PeopleListEvent.addUser(
|
||||||
earlierVersion = followSetEvent,
|
earlierVersion = followSetEvent,
|
||||||
@@ -210,18 +210,19 @@ class NostrListFeedViewModel(
|
|||||||
|
|
||||||
fun removeUserFromSet(
|
fun removeUserFromSet(
|
||||||
userProfileHex: String,
|
userProfileHex: String,
|
||||||
listIdentifier: String,
|
followSet: FollowSet,
|
||||||
account: Account,
|
account: Account,
|
||||||
) {
|
) {
|
||||||
if (!account.settings.isWriteable()) {
|
if (!account.settings.isWriteable()) {
|
||||||
println("You are in read-only mode. Please login to make modifications.")
|
println("You are in read-only mode. Please login to make modifications.")
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
val followSetEvent = getFollowSetNote(listIdentifier, account)?.event as PeopleListEvent
|
val followSetEvent = getFollowSetNote(followSet.identifierTag, account)?.event as PeopleListEvent
|
||||||
PeopleListEvent.removeUser(
|
PeopleListEvent.removeUser(
|
||||||
earlierVersion = followSetEvent,
|
earlierVersion = followSetEvent,
|
||||||
pubKeyHex = userProfileHex,
|
pubKeyHex = userProfileHex,
|
||||||
|
isPrivate = followSet.visibility == ListVisibility.Private,
|
||||||
signer = account.signer,
|
signer = account.signer,
|
||||||
) {
|
) {
|
||||||
Amethyst.instance.client.send(it)
|
Amethyst.instance.client.send(it)
|
||||||
@@ -242,13 +243,13 @@ class NostrListFeedViewModel(
|
|||||||
private val bundler = BundledUpdate(2000, Dispatchers.IO)
|
private val bundler = BundledUpdate(2000, Dispatchers.IO)
|
||||||
|
|
||||||
override fun invalidateData(ignoreIfDoing: Boolean) {
|
override fun invalidateData(ignoreIfDoing: Boolean) {
|
||||||
refresh()
|
// refresh()
|
||||||
// bundler.invalidate(ignoreIfDoing) {
|
bundler.invalidate(ignoreIfDoing) {
|
||||||
// // adds the time to perform the refresh into this delay
|
// adds the time to perform the refresh into this delay
|
||||||
// // holding off new updates in case of heavy refresh routines.
|
// holding off new updates in case of heavy refresh routines.
|
||||||
// sampleRefresh()
|
|
||||||
// // refreshSuspended()
|
refreshSuspended()
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var collectorJob: Job? = null
|
var collectorJob: Job? = null
|
||||||
|
|||||||
Reference in New Issue
Block a user