Browse Source

add messagesender runnable

Patrick Glavin 6 years ago
parent
commit
8fc0c383e0

+ 2
- 0
Client/src/main/java/IDGetter.java View File

@@ -0,0 +1,2 @@
1
+public class IDGetter {
2
+}

+ 31
- 1
Client/src/main/java/MessageSender.java View File

@@ -1,5 +1,35 @@
1
+import java.util.List;
2
+
1 3
 public class MessageSender implements Runnable{
2
-    public void run() {
4
+    List<String> list;
5
+    User user;
6
+    YouAreEll webber;
3 7
 
8
+    public MessageSender(List<String> list, User user, YouAreEll webber) {
9
+        this.list = list;
10
+        this.user = user;
11
+        this.webber = webber;
12
+    }
13
+
14
+    public void run() {
15
+        Message message;
16
+        String sentence = "";
17
+        for (int i = 2; i < list.size(); i++) {
18
+            sentence += list.get(i) + " ";
19
+        }
20
+        sentence = sentence.substring(0, sentence.length()-1);
21
+        if (list.get(1).equalsIgnoreCase("group")){
22
+            message = new Message(user.getGithub(), "", sentence);
23
+        } else {
24
+            message = new Message(user.getGithub(), list.get(1), sentence);
25
+        }
26
+        
27
+        String results = webber.send_message(message);
28
+        try {
29
+            Thread.sleep(10000);
30
+        } catch (InterruptedException e){
31
+            e.printStackTrace();
32
+        }
33
+        SimpleShell.prettyPrintMessage(results);
4 34
     }
5 35
 }

+ 2
- 14
Client/src/main/java/SimpleShell.java View File

@@ -126,21 +126,9 @@ public class SimpleShell {
126 126
                 }
127 127
 
128 128
                 if (list.contains("send")) {
129
-                    Message message;
130
-                    String sentence = "";
131
-                    for (int i = 2; i < list.size(); i++) {
132
-                        sentence += list.get(i) + " ";
133
-                    }
134
-                    sentence = sentence.substring(0, sentence.length()-1);
135
-                    if (list.get(1).equalsIgnoreCase("group")){
136
-                        message = new Message(user.getGithub(), "", sentence);
137
-                    } else {
138
-                        message = new Message(user.getGithub(), list.get(1), sentence);
139
-                    }
140
-                    String results;
141
-                    Thread thread = new Thread(results = webber.send_message(message));
129
+                    MessageSender sender = new MessageSender(list, user, webber);
130
+                    Thread thread = new Thread(sender);
142 131
                     thread.run();
143
-                    SimpleShell.prettyPrintMessage(results);
144 132
                     continue;
145 133
                 }
146 134