|
@@ -30,7 +30,6 @@ import com.dmdirc.events.ServerConnectErrorEvent;
|
30
|
30
|
import com.dmdirc.events.ServerConnectedEvent;
|
31
|
31
|
import com.dmdirc.events.ServerConnectingEvent;
|
32
|
32
|
import com.dmdirc.events.ServerDisconnectedEvent;
|
33
|
|
-import com.dmdirc.events.ServerInviteExpiredEvent;
|
34
|
33
|
import com.dmdirc.interfaces.Connection;
|
35
|
34
|
import com.dmdirc.interfaces.GroupChatManager;
|
36
|
35
|
import com.dmdirc.interfaces.InviteManager;
|
|
@@ -40,7 +39,6 @@ import com.dmdirc.interfaces.config.ConfigProvider;
|
40
|
39
|
import com.dmdirc.interfaces.config.ConfigProviderMigrator;
|
41
|
40
|
import com.dmdirc.interfaces.config.IdentityFactory;
|
42
|
41
|
import com.dmdirc.logger.ErrorLevel;
|
43
|
|
-import com.dmdirc.parser.common.ChannelJoinRequest;
|
44
|
42
|
import com.dmdirc.parser.common.DefaultStringConverter;
|
45
|
43
|
import com.dmdirc.parser.common.IgnoreList;
|
46
|
44
|
import com.dmdirc.parser.common.ParserError;
|
|
@@ -97,7 +95,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
97
|
95
|
* The Server class represents the client's view of a server. It maintains a list of all channels,
|
98
|
96
|
* queries, etc, and handles parser callbacks pertaining to the server.
|
99
|
97
|
*/
|
100
|
|
-public class Server extends FrameContainer implements Connection, InviteManager {
|
|
98
|
+public class Server extends FrameContainer implements Connection {
|
101
|
99
|
|
102
|
100
|
private static final Logger LOG = LoggerFactory.getLogger(Server.class);
|
103
|
101
|
/** The name of the general domain. */
|
|
@@ -106,7 +104,7 @@ public class Server extends FrameContainer implements Connection, InviteManager
|
106
|
104
|
/** Manager of group chats. */
|
107
|
105
|
private final GroupChatManagerImpl groupChatManager;
|
108
|
106
|
/** Manager of invites. */
|
109
|
|
- private final InviteManager inviteManager = this;
|
|
107
|
+ private final InviteManager inviteManager;
|
110
|
108
|
/** Open query windows on the server. */
|
111
|
109
|
private final Map<String, Query> queries = new ConcurrentSkipListMap<>();
|
112
|
110
|
/** The user manager to retrieve users from. */
|
|
@@ -148,8 +146,6 @@ public class Server extends FrameContainer implements Connection, InviteManager
|
148
|
146
|
private Optional<String> awayMessage;
|
149
|
147
|
/** Our event handler. */
|
150
|
148
|
private final ServerEventHandler eventHandler;
|
151
|
|
- /** A list of outstanding invites. */
|
152
|
|
- private final List<Invite> invites = new ArrayList<>();
|
153
|
149
|
/** Our ignore list. */
|
154
|
150
|
private final IgnoreList ignoreList = new IgnoreList();
|
155
|
151
|
/** Our string convertor. */
|
|
@@ -221,6 +217,7 @@ public class Server extends FrameContainer implements Connection, InviteManager
|
221
|
217
|
this.messageEncoderFactory = messageEncoderFactory;
|
222
|
218
|
this.userManager = userManager;
|
223
|
219
|
this.groupChatManager = groupChatManagerFactory.create(this, executorService);
|
|
220
|
+ this.inviteManager = new InviteManagerImpl(this);
|
224
|
221
|
|
225
|
222
|
awayMessage = Optional.empty();
|
226
|
223
|
eventHandler = new ServerEventHandler(this, groupChatManager, eventBus);
|
|
@@ -349,7 +346,7 @@ public class Server extends FrameContainer implements Connection, InviteManager
|
349
|
346
|
doCallbacks();
|
350
|
347
|
|
351
|
348
|
updateAwayState(Optional.empty());
|
352
|
|
- removeInvites();
|
|
349
|
+ inviteManager.removeInvites();
|
353
|
350
|
|
354
|
351
|
newParser.connect();
|
355
|
352
|
if (newParser instanceof ThreadedParser) {
|
|
@@ -412,7 +409,7 @@ public class Server extends FrameContainer implements Connection, InviteManager
|
412
|
409
|
if (parser.isPresent()) {
|
413
|
410
|
myState.transition(ServerState.DISCONNECTING);
|
414
|
411
|
|
415
|
|
- removeInvites();
|
|
412
|
+ inviteManager.removeInvites();
|
416
|
413
|
updateIcon();
|
417
|
414
|
|
418
|
415
|
parser.get().disconnect(reason);
|
|
@@ -756,7 +753,7 @@ public class Server extends FrameContainer implements Connection, InviteManager
|
756
|
753
|
|
757
|
754
|
groupChatManager.closeAll();
|
758
|
755
|
closeQueries();
|
759
|
|
- removeInvites();
|
|
756
|
+ inviteManager.removeInvites();
|
760
|
757
|
|
761
|
758
|
super.close();
|
762
|
759
|
}
|
|
@@ -882,7 +879,7 @@ public class Server extends FrameContainer implements Connection, InviteManager
|
882
|
879
|
closeQueries();
|
883
|
880
|
}
|
884
|
881
|
|
885
|
|
- removeInvites();
|
|
882
|
+ inviteManager.removeInvites();
|
886
|
883
|
updateAwayState(Optional.empty());
|
887
|
884
|
|
888
|
885
|
if (getConfigManager().getOptionBool(DOMAIN_GENERAL,
|
|
@@ -1015,59 +1012,6 @@ public class Server extends FrameContainer implements Connection, InviteManager
|
1015
|
1012
|
return identityFactory.createNetworkConfig(getNetwork());
|
1016
|
1013
|
}
|
1017
|
1014
|
|
1018
|
|
- @Override
|
1019
|
|
- public void addInvite(final Invite invite) {
|
1020
|
|
- synchronized (invites) {
|
1021
|
|
- new ArrayList<>(invites).stream()
|
1022
|
|
- .filter(oldInvite -> oldInvite.getChannel().equals(invite.getChannel()))
|
1023
|
|
- .forEach(this::removeInvite);
|
1024
|
|
-
|
1025
|
|
- invites.add(invite);
|
1026
|
|
- }
|
1027
|
|
- }
|
1028
|
|
-
|
1029
|
|
- @Override
|
1030
|
|
- public void acceptInvites(final Invite... invites) {
|
1031
|
|
- final ChannelJoinRequest[] requests = new ChannelJoinRequest[invites.length];
|
1032
|
|
-
|
1033
|
|
- for (int i = 0; i < invites.length; i++) {
|
1034
|
|
- requests[i] = new ChannelJoinRequest(invites[i].getChannel());
|
1035
|
|
- }
|
1036
|
|
-
|
1037
|
|
- getGroupChatManager().join(requests);
|
1038
|
|
- }
|
1039
|
|
-
|
1040
|
|
- @Override
|
1041
|
|
- public void acceptInvites() {
|
1042
|
|
- synchronized (invites) {
|
1043
|
|
- acceptInvites(invites.toArray(new Invite[invites.size()]));
|
1044
|
|
- }
|
1045
|
|
- }
|
1046
|
|
-
|
1047
|
|
- @Override
|
1048
|
|
- public void removeInvites(final String channel) {
|
1049
|
|
- new ArrayList<>(invites).stream().filter(invite -> invite.getChannel().equals(channel))
|
1050
|
|
- .forEach(this::removeInvite);
|
1051
|
|
- }
|
1052
|
|
-
|
1053
|
|
- @Override
|
1054
|
|
- public void removeInvites() {
|
1055
|
|
- new ArrayList<>(invites).forEach(this::removeInvite);
|
1056
|
|
- }
|
1057
|
|
-
|
1058
|
|
- @Override
|
1059
|
|
- public void removeInvite(final Invite invite) {
|
1060
|
|
- synchronized (invites) {
|
1061
|
|
- invites.remove(invite);
|
1062
|
|
- getEventBus().publishAsync(new ServerInviteExpiredEvent(this, invite));
|
1063
|
|
- }
|
1064
|
|
- }
|
1065
|
|
-
|
1066
|
|
- @Override
|
1067
|
|
- public List<Invite> getInvites() {
|
1068
|
|
- return Collections.unmodifiableList(invites);
|
1069
|
|
- }
|
1070
|
|
-
|
1071
|
1015
|
@Override
|
1072
|
1016
|
public void updateAwayState(final Optional<String> message) {
|
1073
|
1017
|
checkNotNull(message);
|