Skip to content
Snippets Groups Projects
Verified Commit db52fba7 authored by Mikolai Gütschow's avatar Mikolai Gütschow
Browse files

move GroupAddedEvent handling to separate function

parent 1776178c
No related branches found
No related tags found
1 merge request!258Update forum list item on new message
Pipeline #12657 passed
...@@ -85,17 +85,8 @@ class ForumViewModel @Inject constructor( ...@@ -85,17 +85,8 @@ class ForumViewModel @Inject constructor(
override fun eventOccurred(e: Event) { override fun eventOccurred(e: Event) {
when { when {
e is GroupAddedEvent && e.group.clientId == ForumManager.CLIENT_ID -> { e is GroupAddedEvent && e.group.clientId == ForumManager.CLIENT_ID ->
runOnDbThreadWithTransaction(true) { txn -> onGroupAdded(e.group.id)
val item = ForumItem(
forum = forumManager.getForum(txn, e.group.id),
groupCount = forumManager.getGroupCount(txn, e.group.id),
)
txn.attach {
addItem(item)
}
}
}
e is GroupRemovedEvent && e.group.clientId == ForumManager.CLIENT_ID -> { e is GroupRemovedEvent && e.group.clientId == ForumManager.CLIENT_ID -> {
removeItem(e.group.id) removeItem(e.group.id)
...@@ -108,6 +99,16 @@ class ForumViewModel @Inject constructor( ...@@ -108,6 +99,16 @@ class ForumViewModel @Inject constructor(
} }
} }
private fun onGroupAdded(id: GroupId) = runOnDbThreadWithTransaction(true) { txn ->
val item = ForumItem(
forum = forumManager.getForum(txn, id),
groupCount = forumManager.getGroupCount(txn, id),
)
txn.attach {
addItem(item)
}
}
fun createForum(name: String) = runOnDbThread { fun createForum(name: String) = runOnDbThread {
forumManager.addForum(name) forumManager.addForum(name)
} }
...@@ -135,7 +136,7 @@ class ForumViewModel @Inject constructor( ...@@ -135,7 +136,7 @@ class ForumViewModel @Inject constructor(
_filterBy.value = filter _filterBy.value = filter
} }
fun addOwnPost(header: ForumPostHeader) { private fun addOwnPost(header: ForumPostHeader) {
selectedGroupItem.value?.id?.let { id -> updateItem(id) { it.updateOnPostReceived(header) } } selectedGroupItem.value?.id?.let { id -> updateItem(id) { it.updateOnPostReceived(header) } }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment