Skip to content
Snippets Groups Projects
Commit 3117ea59 authored by helene ortiz's avatar helene ortiz
Browse files

file attachments in chat (to be continued...)

parent 5f80617c
No related branches found
No related tags found
No related merge requests found
......@@ -52,6 +52,7 @@ public class ChatFileManager {
private final static String MESSAGE_PREFIX = "message:";
private final static String SENDER_PREFIX = "sender:";
private final static String TIMESTAMP_PREFIX = "timestamp:";
private final static String FILE_PREFIX = "file:";
private final static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
......@@ -94,7 +95,15 @@ public class ChatFileManager {
String timestampString = tokenizer.nextToken();
timestampString = timestampString.replace(TIMESTAMP_PREFIX, "");
LocalDateTime timestamp = LocalDateTime.parse(timestampString, formatter);
ChatEvent event = new ChatEvent(sender, message, timestamp);
ChatEvent event;
if (tokenizer.hasMoreTokens()) {
String file = tokenizer.nextToken();
file = file.replace(FILE_PREFIX, "");
event = new AttachedFileChatEvent(sender, message, file, file.substring(file.lastIndexOf(".")+1));
} else {
event = new ChatEvent(sender, message, timestamp);
}
messages.add(event);
}
} catch (NoSuchElementException e) {
......@@ -138,7 +147,7 @@ public class ChatFileManager {
String chatLine = MESSAGE_PREFIX + message + CHAT_DELIMITER + SENDER_PREFIX + event.getSender() + CHAT_DELIMITER + TIMESTAMP_PREFIX + formatter.format(event.getTimestamp());
if (event.hasAttachment()) {
chatLine = chatLine + CHAT_DELIMITER + ((AttachedFileChatEvent)event).getShortFileName();
chatLine = chatLine + CHAT_DELIMITER + FILE_PREFIX + ((AttachedFileChatEvent)event).getShortFileName();
}
// Update chat's file
......@@ -153,7 +162,7 @@ public class ChatFileManager {
private String getFilePath(long proposNo) {
return getDirectoryPath() + "chat"+ proposNo + ".xml";
}
private String getAttachedFilePath(long proposNo) {
return getDirectoryPath() + proposNo + ConfigManager.FILE_SEPARATOR;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment