Browse Source

Fixups for away colours plugin.

pull/221/head
Greg Holmes 9 years ago
parent
commit
10844842fc

+ 1
- 3
awaycolours/plugin.config View File

@@ -23,6 +23,4 @@ version:
23 23
   friendly=0.1
24 24
 
25 25
 defaults:
26
-  colour=15
27
-  text=true
28
-  nicklist=true
26
+  colour=15

+ 4
- 30
awaycolours/src/com/dmdirc/addons/awaycolours/AwayColoursManager.java View File

@@ -22,13 +22,13 @@
22 22
 
23 23
 package com.dmdirc.addons.awaycolours;
24 24
 
25
-import com.dmdirc.ChannelClientProperty;
26 25
 import com.dmdirc.ClientModule.GlobalConfig;
27 26
 import com.dmdirc.DMDircMBassador;
28 27
 import com.dmdirc.config.ConfigBinder;
29 28
 import com.dmdirc.config.ConfigBinding;
30 29
 import com.dmdirc.events.ChannelUserAwayEvent;
31 30
 import com.dmdirc.events.ChannelUserBackEvent;
31
+import com.dmdirc.events.DisplayProperty;
32 32
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
33 33
 import com.dmdirc.plugins.PluginDomain;
34 34
 import com.dmdirc.ui.messages.ColourManager;
@@ -47,8 +47,6 @@ public class AwayColoursManager {
47 47
     private final ConfigBinder binder;
48 48
     private final ColourManager colourManager;
49 49
     private Colour colour = Colour.BLACK;
50
-    private boolean nicklist = true;
51
-    private boolean text = true;
52 50
 
53 51
     @Inject
54 52
     public AwayColoursManager(final DMDircMBassador eventBus,
@@ -75,39 +73,15 @@ public class AwayColoursManager {
75 73
         this.colour = colourManager.getColourFromString(colour, Colour.GRAY);
76 74
     }
77 75
 
78
-    @ConfigBinding(key = "nicklist")
79
-    public void handleNicklistChange(final boolean nicklist) {
80
-        this.nicklist = nicklist;
81
-    }
82
-
83
-    @ConfigBinding(key = "text")
84
-    public void handleTextChange(final boolean text) {
85
-        this.text = text;
86
-    }
87
-
88 76
     @Handler
89 77
     public void handleAwayEvent(final ChannelUserAwayEvent event) {
90
-        if (nicklist) {
91
-            event.getUser().getMap().put(ChannelClientProperty.NICKLIST_FOREGROUND, colour);
92
-        }
93
-        if (text) {
94
-            event.getUser().getMap().put(ChannelClientProperty.TEXT_FOREGROUND, colour);
95
-        }
96
-        if (nicklist || text) {
78
+            event.getUser().setDisplayProperty(DisplayProperty.FOREGROUND_COLOUR, colour);
97 79
             event.getChannel().refreshClients();
98
-        }
99 80
     }
100 81
 
101 82
     @Handler
102 83
     public void handleBackEvent(final ChannelUserBackEvent event) {
103
-        if (nicklist) {
104
-            event.getUser().getMap().remove(ChannelClientProperty.NICKLIST_FOREGROUND);
105
-        }
106
-        if (text) {
107
-            event.getUser().getMap().remove(ChannelClientProperty.TEXT_FOREGROUND);
108
-        }
109
-        if (nicklist || text) {
110
-            event.getChannel().refreshClients();
111
-        }
84
+        event.getUser().removeDisplayProperty(DisplayProperty.FOREGROUND_COLOUR);
85
+        event.getChannel().refreshClients();
112 86
     }
113 87
 }

+ 7
- 56
awaycolours/test/com/dmdirc/addons/awaycolours/AwayColoursManagerTest.java View File

@@ -23,18 +23,16 @@
23 23
 package com.dmdirc.addons.awaycolours;
24 24
 
25 25
 import com.dmdirc.Channel;
26
-import com.dmdirc.ChannelClientProperty;
27 26
 import com.dmdirc.DMDircMBassador;
28 27
 import com.dmdirc.config.ConfigBinder;
29 28
 import com.dmdirc.events.ChannelUserAwayEvent;
30 29
 import com.dmdirc.events.ChannelUserBackEvent;
30
+import com.dmdirc.events.DisplayProperty;
31
+import com.dmdirc.interfaces.GroupChatUser;
31 32
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
32
-import com.dmdirc.parser.interfaces.ChannelClientInfo;
33 33
 import com.dmdirc.ui.messages.ColourManager;
34 34
 import com.dmdirc.util.colours.Colour;
35 35
 
36
-import java.util.Map;
37
-
38 36
 import org.junit.Before;
39 37
 import org.junit.Test;
40 38
 import org.junit.runner.RunWith;
@@ -42,7 +40,6 @@ import org.mockito.Mock;
42 40
 import org.mockito.runners.MockitoJUnitRunner;
43 41
 
44 42
 import static org.mockito.Matchers.anyString;
45
-import static org.mockito.Mockito.never;
46 43
 import static org.mockito.Mockito.verify;
47 44
 import static org.mockito.Mockito.when;
48 45
 
@@ -54,9 +51,8 @@ public class AwayColoursManagerTest {
54 51
     @Mock private ConfigBinder binder;
55 52
     @Mock private ChannelUserAwayEvent awayEvent;
56 53
     @Mock private ChannelUserBackEvent backEvent;
57
-    @Mock private ChannelClientInfo user;
54
+    @Mock private GroupChatUser user;
58 55
     @Mock private Channel channel;
59
-    @Mock private Map<Object, Object> map;
60 56
     @Mock private ColourManager colourManager;
61 57
     private AwayColoursManager instance;
62 58
     private String red;
@@ -74,7 +70,6 @@ public class AwayColoursManagerTest {
74 70
         when(awayEvent.getChannel()).thenReturn(channel);
75 71
         when(backEvent.getUser()).thenReturn(user);
76 72
         when(backEvent.getChannel()).thenReturn(channel);
77
-        when(user.getMap()).thenReturn(map);
78 73
         when(config.getBinder()).thenReturn(binder);
79 74
         when(binder.withDefaultDomain(anyString())).thenReturn(binder);
80 75
         when(colourManager.getColourFromString(red, Colour.GRAY)).thenReturn(redColour);
@@ -97,67 +92,23 @@ public class AwayColoursManagerTest {
97 92
     @Test
98 93
     public void testHandleColourChange() throws Exception {
99 94
         instance.handleColourChange(red);
100
-        instance.handleNicklistChange(true);
101
-        instance.handleTextChange(true);
102
-        instance.handleAwayEvent(awayEvent);
103
-        verify(map).put(ChannelClientProperty.NICKLIST_FOREGROUND, redColour);
104
-        verify(map).put(ChannelClientProperty.TEXT_FOREGROUND, redColour);
105
-        instance.handleColourChange(black);
106
-        instance.handleNicklistChange(true);
107
-        instance.handleTextChange(true);
108
-        instance.handleAwayEvent(awayEvent);
109
-        verify(map).put(ChannelClientProperty.NICKLIST_FOREGROUND, blackColour);
110
-        verify(map).put(ChannelClientProperty.TEXT_FOREGROUND, blackColour);
111
-    }
112
-
113
-    @Test
114
-    public void testHandleNicklistChange() throws Exception {
115
-        instance.handleColourChange(red);
116
-        instance.handleNicklistChange(true);
117
-        instance.handleTextChange(true);
118
-        instance.handleAwayEvent(awayEvent);
119
-        verify(map).put(ChannelClientProperty.NICKLIST_FOREGROUND, redColour);
120
-        verify(map).put(ChannelClientProperty.TEXT_FOREGROUND, redColour);
121
-        instance.handleColourChange(black);
122
-        instance.handleNicklistChange(false);
123
-        instance.handleTextChange(true);
124
-        instance.handleAwayEvent(awayEvent);
125
-        verify(map, never()).put(ChannelClientProperty.NICKLIST_FOREGROUND, blackColour);
126
-        verify(map).put(ChannelClientProperty.TEXT_FOREGROUND, blackColour);
127
-    }
128
-
129
-    @Test
130
-    public void testHandleTextChange() throws Exception {
131
-        instance.handleColourChange(red);
132
-        instance.handleNicklistChange(true);
133
-        instance.handleTextChange(true);
134 95
         instance.handleAwayEvent(awayEvent);
135
-        verify(map).put(ChannelClientProperty.NICKLIST_FOREGROUND, redColour);
136
-        verify(map).put(ChannelClientProperty.TEXT_FOREGROUND, redColour);
96
+        verify(user).setDisplayProperty(DisplayProperty.FOREGROUND_COLOUR, redColour);
137 97
         instance.handleColourChange(black);
138
-        instance.handleNicklistChange(true);
139
-        instance.handleTextChange(false);
140 98
         instance.handleAwayEvent(awayEvent);
141
-        verify(map).put(ChannelClientProperty.NICKLIST_FOREGROUND, blackColour);
142
-        verify(map, never()).put(ChannelClientProperty.TEXT_FOREGROUND, blackColour);
99
+        verify(user).setDisplayProperty(DisplayProperty.FOREGROUND_COLOUR, blackColour);
143 100
     }
144 101
 
145 102
     @Test
146 103
     public void testHandleAwayEvent() throws Exception {
147
-        instance.handleNicklistChange(true);
148
-        instance.handleTextChange(true);
149 104
         instance.handleBackEvent(backEvent);
150
-        verify(map).remove(ChannelClientProperty.NICKLIST_FOREGROUND);
151
-        verify(map).remove(ChannelClientProperty.TEXT_FOREGROUND);
105
+        verify(user).removeDisplayProperty(DisplayProperty.FOREGROUND_COLOUR);
152 106
     }
153 107
 
154 108
     @Test
155 109
     public void testHandleBackEvent() throws Exception {
156 110
         instance.handleColourChange(red);
157
-        instance.handleNicklistChange(true);
158
-        instance.handleTextChange(true);
159 111
         instance.handleAwayEvent(awayEvent);
160
-        verify(map).put(ChannelClientProperty.NICKLIST_FOREGROUND, redColour);
161
-        verify(map).put(ChannelClientProperty.TEXT_FOREGROUND, redColour);
112
+        verify(user).setDisplayProperty(DisplayProperty.FOREGROUND_COLOUR, redColour);
162 113
     }
163 114
 }

Loading…
Cancel
Save