diff --git a/core/src/main/groovy/com/muwire/core/Core.groovy b/core/src/main/groovy/com/muwire/core/Core.groovy index bb5998c6..182e2783 100644 --- a/core/src/main/groovy/com/muwire/core/Core.groovy +++ b/core/src/main/groovy/com/muwire/core/Core.groovy @@ -171,7 +171,7 @@ class Core { eventBus.register(SearchEvent.class, fileManager) log.info "initializing results sender" - ResultsSender resultsSender = new ResultsSender() + ResultsSender resultsSender = new ResultsSender(eventBus, me) log.info "initializing search manager" SearchManager searchManager = new SearchManager(eventBus, resultsSender) @@ -193,6 +193,7 @@ class Core { def binding = new Binding() def shell = new GroovyShell(binding) binding.setProperty('eventBus', eventBus) + binding.setProperty('me', me) // TOOD: other bindings? def script = shell.parse(f) script.run() diff --git a/core/src/main/groovy/com/muwire/core/files/UIResultEvent.groovy b/core/src/main/groovy/com/muwire/core/files/UIResultEvent.groovy new file mode 100644 index 00000000..93dd8e89 --- /dev/null +++ b/core/src/main/groovy/com/muwire/core/files/UIResultEvent.groovy @@ -0,0 +1,8 @@ +package com.muwire.core.files + +import com.muwire.core.Event +import com.muwire.core.search.ResultsEvent + +class UIResultEvent extends Event { + ResultsEvent resultsEvent +} \ No newline at end of file diff --git a/core/src/main/groovy/com/muwire/core/search/ResultsSender.groovy b/core/src/main/groovy/com/muwire/core/search/ResultsSender.groovy index 158aa4da..b4b4d742 100644 --- a/core/src/main/groovy/com/muwire/core/search/ResultsSender.groovy +++ b/core/src/main/groovy/com/muwire/core/search/ResultsSender.groovy @@ -1,6 +1,9 @@ package com.muwire.core.search import com.muwire.core.SharedFile +import com.muwire.core.files.UIResultEvent +import com.muwire.core.Persona +import com.muwire.core.EventBus import groovy.util.logging.Log import net.i2p.data.Destination @@ -8,7 +11,20 @@ import net.i2p.data.Destination @Log class ResultsSender { + private final Persona me + private final EventBus eventBus + + ResultsSender(EventBus eventBus, Persona me) { + this.eventBus = eventBus + this.me = me + } + void sendResults(UUID uuid, SharedFile[] results, Destination target) { - log.info("Sending $results.length results for uuid $uuid to ${target.toBase32()}") + log.info("Sending $results.length results for uuid $uuid to ${target.toBase32()}") + if (target.equals(me.destination)) { + def resultEvent = new ResultsEvent( uuid : uuid, results : results ) + def uiResultEvent = new UIResultEvent(resultsEvent : resultEvent) + eventBus.publish(uiResultEvent) + } } }