|
@@ -30,17 +30,27 @@ import com.dmdirc.interfaces.WindowModel;
|
30
|
30
|
import com.dmdirc.util.colours.Colour;
|
31
|
31
|
|
32
|
32
|
import java.util.Optional;
|
33
|
|
-
|
|
33
|
+import java.util.concurrent.TimeUnit;
|
|
34
|
+
|
|
35
|
+import io.reactivex.Emitter;
|
|
36
|
+import io.reactivex.Observable;
|
|
37
|
+import io.reactivex.ObservableEmitter;
|
|
38
|
+import io.reactivex.Observer;
|
|
39
|
+import io.reactivex.functions.Consumer;
|
|
40
|
+import io.reactivex.subjects.PublishSubject;
|
|
41
|
+import io.reactivex.subjects.ReplaySubject;
|
|
42
|
+import io.reactivex.subjects.Subject;
|
34
|
43
|
import net.engio.mbassy.listener.Handler;
|
|
44
|
+import org.reactivestreams.Publisher;
|
35
|
45
|
|
36
|
46
|
/**
|
37
|
47
|
* Tracks unread messages and other notifications.
|
38
|
48
|
*/
|
39
|
49
|
public class UnreadStatusManagerImpl implements UnreadStatusManager {
|
40
|
50
|
|
41
|
|
- private final EventBus eventBus;
|
42
|
51
|
private final WindowModel container;
|
43
|
52
|
private final ColourManager colourManager;
|
|
53
|
+ private final Subject<UnreadStatusChangedEvent> eventSubject;
|
44
|
54
|
|
45
|
55
|
private int unreadLines;
|
46
|
56
|
private Optional<Colour> notificationColour = Optional.empty();
|
|
@@ -51,8 +61,12 @@ public class UnreadStatusManagerImpl implements UnreadStatusManager {
|
51
|
61
|
|
52
|
62
|
public UnreadStatusManagerImpl(final WindowModel container) {
|
53
|
63
|
this.container = container;
|
54
|
|
- this.eventBus = container.getEventBus();
|
55
|
64
|
this.colourManager = new ColourManagerImpl(container.getConfigManager());
|
|
65
|
+ this.eventSubject = PublishSubject.create();
|
|
66
|
+
|
|
67
|
+ eventSubject
|
|
68
|
+ .throttleLast(200, TimeUnit.MILLISECONDS)
|
|
69
|
+ .subscribe(unreadStatusChangedEvent -> container.getEventBus().publish(unreadStatusChangedEvent));
|
56
|
70
|
}
|
57
|
71
|
|
58
|
72
|
@Handler
|
|
@@ -177,7 +191,7 @@ public class UnreadStatusManagerImpl implements UnreadStatusManager {
|
177
|
191
|
}
|
178
|
192
|
|
179
|
193
|
private void publishChangedEvent() {
|
180
|
|
- eventBus.publishAsync(new UnreadStatusChangedEvent(container, this, notificationColour,
|
|
194
|
+ eventSubject.onNext(new UnreadStatusChangedEvent(container, this, notificationColour,
|
181
|
195
|
unreadLines));
|
182
|
196
|
}
|
183
|
197
|
|