mirror of https://github.com/zlatinb/muwire
fire an event after loading contacts
parent
c02d09c041
commit
f4ea9ad51b
|
@ -290,7 +290,7 @@ public class Core {
|
|||
log.info("initializing trust service")
|
||||
File goodTrust = new File(home, "trusted")
|
||||
File badTrust = new File(home, "distrusted")
|
||||
trustService = new TrustService(goodTrust, badTrust)
|
||||
trustService = new TrustService(eventBus, goodTrust, badTrust)
|
||||
eventBus.register(TrustEvent.class, trustService)
|
||||
|
||||
log.info("initializing content manager")
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.muwire.core.trust
|
||||
|
||||
import com.muwire.core.EventBus
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import java.util.concurrent.Executor
|
||||
import java.util.concurrent.Executors
|
||||
|
@ -18,6 +20,7 @@ import net.i2p.util.ConcurrentHashSet
|
|||
@Log
|
||||
class TrustService extends Service {
|
||||
|
||||
private final EventBus eventBus
|
||||
final File persistGood, persistBad
|
||||
|
||||
final Map<Destination, TrustEntry> good = new ConcurrentHashMap<>()
|
||||
|
@ -27,7 +30,8 @@ class TrustService extends Service {
|
|||
|
||||
TrustService() {}
|
||||
|
||||
TrustService(File persistGood, File persistBad) {
|
||||
TrustService(EventBus eventBus, File persistGood, File persistBad) {
|
||||
this.eventBus = eventBus
|
||||
this.persistBad = persistBad
|
||||
this.persistGood = persistGood
|
||||
}
|
||||
|
@ -67,6 +71,7 @@ class TrustService extends Service {
|
|||
})
|
||||
}
|
||||
loaded = true
|
||||
eventBus.publish(new TrustServiceLoadedEvent())
|
||||
}
|
||||
|
||||
private void persist() {
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
package com.muwire.core.trust
|
||||
|
||||
import com.muwire.core.Event
|
||||
|
||||
class TrustServiceLoadedEvent extends Event {
|
||||
}
|
|
@ -1,23 +1,30 @@
|
|||
package com.muwire.core.trust
|
||||
|
||||
import com.muwire.core.EventBus
|
||||
import org.junit.After
|
||||
import org.junit.AfterClass
|
||||
import org.junit.Before
|
||||
import org.junit.BeforeClass
|
||||
import org.junit.Test
|
||||
|
||||
import com.muwire.core.Destinations
|
||||
import com.muwire.core.Persona
|
||||
import com.muwire.core.Personas
|
||||
|
||||
import groovy.json.JsonSlurper
|
||||
import net.i2p.data.Base64
|
||||
import net.i2p.data.Destination
|
||||
|
||||
class TrustServiceTest {
|
||||
|
||||
private static EventBus eventBus
|
||||
TrustService service
|
||||
File persistGood, persistBad
|
||||
Personas personas = new Personas()
|
||||
|
||||
@BeforeClass
|
||||
static void beforeClass() {
|
||||
eventBus = new EventBus()
|
||||
}
|
||||
|
||||
@Before
|
||||
void before() {
|
||||
persistGood = new File("good.trust")
|
||||
|
@ -26,7 +33,7 @@ class TrustServiceTest {
|
|||
persistBad.delete()
|
||||
persistGood.deleteOnExit()
|
||||
persistBad.deleteOnExit()
|
||||
service = new TrustService(persistGood, persistBad)
|
||||
service = new TrustService(eventBus, persistGood, persistBad)
|
||||
service.start()
|
||||
}
|
||||
|
||||
|
@ -34,6 +41,11 @@ class TrustServiceTest {
|
|||
void after() {
|
||||
service.stop()
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
static void afterClass() {
|
||||
eventBus.shutdown()
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEmpty() {
|
||||
|
@ -79,7 +91,7 @@ class TrustServiceTest {
|
|||
service.stop()
|
||||
persistGood.append("{ \"persona\" : \"${personas.persona1.toBase64()}\", \"reason\":\"good\"}\n")
|
||||
persistBad.append("{ \"persona\" : \"${personas.persona2.toBase64()}\", \"reason\":\"bad\"}\n")
|
||||
service = new TrustService(persistGood, persistBad)
|
||||
service = new TrustService(eventBus, persistGood, persistBad)
|
||||
service.start()
|
||||
service.waitForLoad()
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ package com.muwire.gui
|
|||
import com.muwire.core.download.DownloadHopelessEvent
|
||||
import com.muwire.core.messenger.MessageFolderLoadingEvent
|
||||
import com.muwire.core.search.ResultsEvent
|
||||
import com.muwire.core.trust.TrustServiceLoadedEvent
|
||||
|
||||
import javax.swing.DefaultListModel
|
||||
import javax.swing.SwingWorker
|
||||
|
@ -307,6 +308,7 @@ class MainFrameModel {
|
|||
core.eventBus.register(UploadEvent.class, this)
|
||||
core.eventBus.register(UploadFinishedEvent.class, this)
|
||||
core.eventBus.register(TrustEvent.class, this)
|
||||
core.eventBus.register(TrustServiceLoadedEvent.class, this)
|
||||
core.eventBus.register(QueryEvent.class, this)
|
||||
core.eventBus.register(UpdateAvailableEvent.class, this)
|
||||
core.eventBus.register(FileDownloadedEvent.class, this)
|
||||
|
@ -679,15 +681,17 @@ class MainFrameModel {
|
|||
}
|
||||
}
|
||||
|
||||
void onTrustServiceLoadedEvent(TrustServiceLoadedEvent e) {
|
||||
runInsideUIAsync {
|
||||
refreshContacts()
|
||||
}
|
||||
}
|
||||
|
||||
void onTrustEvent(TrustEvent e) {
|
||||
runInsideUIAsync {
|
||||
|
||||
contacts.clear()
|
||||
contacts.addAll(core.trustService.good.values())
|
||||
contacts.addAll(core.trustService.bad.values())
|
||||
|
||||
updateTablePreservingSelection("contacts-table")
|
||||
|
||||
refreshContacts()
|
||||
|
||||
results.values().each { MVCGroup group ->
|
||||
if (group.alive) {
|
||||
group.view.onTrustChanged(e.persona)
|
||||
|
@ -695,6 +699,14 @@ class MainFrameModel {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshContacts() {
|
||||
contacts.clear()
|
||||
contacts.addAll(core.trustService.good.values())
|
||||
contacts.addAll(core.trustService.bad.values())
|
||||
|
||||
updateTablePreservingSelection("contacts-table")
|
||||
}
|
||||
|
||||
void onTrustSubscriptionUpdatedEvent(TrustSubscriptionUpdatedEvent e) {
|
||||
runInsideUIAsync {
|
||||
|
|
Loading…
Reference in New Issue