+
+
+
+
+
diff --git a/server/src/saros/server/console/InviteCommand.java b/server/src/saros/server/console/InviteCommand.java
index 4716c4e1ca..4bd54286a8 100644
--- a/server/src/saros/server/console/InviteCommand.java
+++ b/server/src/saros/server/console/InviteCommand.java
@@ -5,9 +5,14 @@
import java.io.PrintStream;
import java.util.List;
import java.util.Map;
+import java.util.function.BiPredicate;
import org.apache.log4j.Logger;
+import saros.exceptions.OperationCanceledException;
import saros.net.util.XMPPUtils;
import saros.net.xmpp.JID;
+import saros.net.xmpp.contact.XMPPContact;
+import saros.net.xmpp.contact.XMPPContactsService;
+import saros.repackaged.picocontainer.annotations.Inject;
import saros.session.ISarosSessionManager;
public class InviteCommand extends ConsoleCommand {
@@ -19,6 +24,8 @@ public InviteCommand(ISarosSessionManager sessionManager, ServerConsole console)
console.registerCommand(this);
}
+ @Inject private XMPPContactsService contactsService;
+
@Override
public String identifier() {
return "invite";
@@ -44,9 +51,58 @@ public void execute(List args, PrintStream out) {
log.warn("Invalid JID skipped: " + jid);
}
- sessionManager.invite(jids.get(true), "Invitation by server command");
for (JID jid : jids.get(true)) {
- sessionManager.startSharingReferencePoints(jid);
+
+ // --------------add contact if not already--------------
+ boolean contactFound = false;
+ for (XMPPContact contact :
+ contactsService.getAllContacts()) { // loop and check if contact was already added
+ if (contact.getBareJid().equals(jid)) {
+ contactFound = true;
+ break;
+ }
+ }
+
+ if (!contactFound) { // add contact
+ log.warn(
+ "Adding "
+ + jid
+ + " as new contact. You will have to reinvite him after he accepted being added to the contacts");
+ out.println(
+ "Adding "
+ + jid
+ + " as new contact. You will have to reinvite him after he accepted being added to the contacts"); // the previous warning wont be displayed in the console
+
+ final BiPredicate questionDialogHandler = // error handler
+ (title, message) -> {
+ log.error(
+ title
+ + message.replace(
+ "Do you want to add the contact anyway?",
+ "It will be continued anyway"));
+ // It will always throw an Not subscribed error for any reason so it cant
+ // test if the contact exists.
+ // Reviewers please tell if its an bug or me being unexperienced
+ return true;
+ };
+
+ try {
+ contactsService.addContact(jid, null, questionDialogHandler);
+ log.info(
+ "The contact was added successfully. Please invite him again after he accepted");
+ out.println(
+ "The contact was added successfully. Please invite him again after he accepted");
+ return; // exit because the user cant accept the invite in time
+ } catch (OperationCanceledException e) {
+ log.error(e);
+ }
+ }
+ // --------------end add contact if not already--------------
+
+ sessionManager.invite(
+ jid,
+ "Invitation by server command"); // invite will fail because user has not accepted yet
+ sessionManager.startSharingReferencePoints(jid); // share
}
} catch (Exception e) {
log.error("Error inviting users", e);