|
@@ -22,21 +22,15 @@
|
22
|
22
|
|
23
|
23
|
package com.dmdirc.ui.messages;
|
24
|
24
|
|
25
|
|
-import com.dmdirc.config.ConfigBinding;
|
26
|
|
-import com.dmdirc.events.BaseChannelTextEvent;
|
27
|
|
-import com.dmdirc.events.BaseQueryTextEvent;
|
28
|
25
|
import com.dmdirc.events.ChannelHighlightEvent;
|
|
26
|
+import com.dmdirc.events.ChannelMessageEvent;
|
29
|
27
|
import com.dmdirc.events.DisplayProperty;
|
30
|
|
-import com.dmdirc.events.DisplayableEvent;
|
31
|
28
|
import com.dmdirc.events.QueryHighlightEvent;
|
|
29
|
+import com.dmdirc.events.QueryMessageEvent;
|
32
|
30
|
import com.dmdirc.events.ServerConnectedEvent;
|
33
|
31
|
import com.dmdirc.events.ServerNickChangeEvent;
|
34
|
32
|
import com.dmdirc.interfaces.User;
|
35
|
33
|
import com.dmdirc.interfaces.WindowModel;
|
36
|
|
-import com.dmdirc.interfaces.config.AggregateConfigProvider;
|
37
|
|
-import com.dmdirc.util.colours.Colour;
|
38
|
|
-
|
39
|
|
-import com.google.common.base.Strings;
|
40
|
34
|
|
41
|
35
|
import java.util.ArrayList;
|
42
|
36
|
import java.util.Collection;
|
|
@@ -55,46 +49,34 @@ public class HighlightManager {
|
55
|
49
|
|
56
|
50
|
private final Collection<Pattern> patterns = new ArrayList<>();
|
57
|
51
|
private final WindowModel serverWindow;
|
58
|
|
- private final AggregateConfigProvider configProvider;
|
59
|
|
- private final ColourManager colourManager;
|
60
|
52
|
|
61
|
53
|
private Optional<Pattern> nicknamePattern = Optional.empty();
|
62
|
54
|
|
63
|
|
- private Optional<Colour> backgroundColour = Optional.empty();
|
64
|
|
- private Optional<Colour> foregroundColour = Optional.empty();
|
65
|
|
-
|
66
|
|
- public HighlightManager(
|
67
|
|
- final WindowModel serverWindow,
|
68
|
|
- final AggregateConfigProvider configProvider,
|
69
|
|
- final ColourManager colourManager) {
|
|
55
|
+ public HighlightManager(final WindowModel serverWindow) {
|
70
|
56
|
this.serverWindow = serverWindow;
|
71
|
|
- this.configProvider = configProvider;
|
72
|
|
- this.colourManager = colourManager;
|
73
|
|
- }
|
74
|
|
-
|
75
|
|
- public void init() {
|
76
|
|
- configProvider.getBinder().bind(this, HighlightManager.class);
|
77
|
57
|
}
|
78
|
58
|
|
79
|
|
- public void stop() {
|
80
|
|
- configProvider.getBinder().unbind(this);
|
81
|
|
- }
|
82
|
|
-
|
83
|
|
- @Handler
|
84
|
|
- void handleChannelMessage(final BaseChannelTextEvent event) {
|
|
59
|
+ @Handler(rejectSubtypes = true)
|
|
60
|
+ void handleChannelMessage(final ChannelMessageEvent event) {
|
85
|
61
|
if (event.getChannel().getConnection().get().getWindowModel().equals(serverWindow)
|
86
|
62
|
&& patterns.stream().anyMatch(p -> p.matcher(event.getMessage()).matches())) {
|
87
|
|
- setColours(event);
|
88
|
|
- event.getChannel().getEventBus().publishAsync(new ChannelHighlightEvent(event));
|
|
63
|
+ event.setDisplayProperty(DisplayProperty.DO_NOT_DISPLAY, true);
|
|
64
|
+ event.getChannel().getEventBus().publishAsync(
|
|
65
|
+ new ChannelHighlightEvent(
|
|
66
|
+ event.getTimestamp(), event.getChannel(), event.getClient(),
|
|
67
|
+ event.getMessage()));
|
89
|
68
|
}
|
90
|
69
|
}
|
91
|
70
|
|
92
|
|
- @Handler
|
93
|
|
- void handleQueryMessage(final BaseQueryTextEvent event) {
|
|
71
|
+ @Handler(rejectSubtypes = true)
|
|
72
|
+ void handleQueryMessage(final QueryMessageEvent event) {
|
94
|
73
|
if (event.getUser().getConnection().getWindowModel().equals(serverWindow)
|
95
|
74
|
&& patterns.stream().anyMatch(p -> p.matcher(event.getMessage()).matches())) {
|
96
|
|
- setColours(event);
|
97
|
|
- event.getQuery().getEventBus().publishAsync(new QueryHighlightEvent(event));
|
|
75
|
+ event.setDisplayProperty(DisplayProperty.DO_NOT_DISPLAY, true);
|
|
76
|
+ event.getQuery().getEventBus().publishAsync(
|
|
77
|
+ new QueryHighlightEvent(
|
|
78
|
+ event.getTimestamp(), event.getQuery(), event.getUser(),
|
|
79
|
+ event.getMessage()));
|
98
|
80
|
}
|
99
|
81
|
}
|
100
|
82
|
|
|
@@ -121,31 +103,6 @@ public class HighlightManager {
|
121
|
103
|
}
|
122
|
104
|
}
|
123
|
105
|
|
124
|
|
- @ConfigBinding(domain = "ui", key = "highlightLineForegroundColour", required = false)
|
125
|
|
- void handleForegroundColour(final String value) {
|
126
|
|
- if (Strings.isNullOrEmpty(value)) {
|
127
|
|
- foregroundColour = Optional.empty();
|
128
|
|
- } else {
|
129
|
|
- foregroundColour = Optional.ofNullable(colourManager.getColourFromString(value, null));
|
130
|
|
- }
|
131
|
|
- }
|
132
|
|
-
|
133
|
|
- @ConfigBinding(domain = "ui", key = "highlightLineBackgroundColour", required = false)
|
134
|
|
- void handleBackgroundColour(final String value) {
|
135
|
|
- if (Strings.isNullOrEmpty(value)) {
|
136
|
|
- backgroundColour = Optional.empty();
|
137
|
|
- } else {
|
138
|
|
- backgroundColour = Optional.ofNullable(colourManager.getColourFromString(value, null));
|
139
|
|
- }
|
140
|
|
- }
|
141
|
|
-
|
142
|
|
- private void setColours(final DisplayableEvent event) {
|
143
|
|
- backgroundColour.ifPresent(
|
144
|
|
- c -> event.setDisplayProperty(DisplayProperty.BACKGROUND_COLOUR, c));
|
145
|
|
- foregroundColour.ifPresent(
|
146
|
|
- c -> event.setDisplayProperty(DisplayProperty.FOREGROUND_COLOUR, c));
|
147
|
|
- }
|
148
|
|
-
|
149
|
106
|
private void setNickname(final String newNick) {
|
150
|
107
|
nicknamePattern.ifPresent(patterns::remove);
|
151
|
108
|
nicknamePattern = Optional.of(compile(newNick));
|