Skip to content
Snippets Groups Projects
Commit c5bb75b7 authored by srosse's avatar srosse
Browse files

OO-1052: use a concurrent list to maintain the messages history of a chat

parent fad93e5d
No related branches found
No related tags found
No related merge requests found
......@@ -98,11 +98,13 @@ public class MapperDispatcher extends LogDelegator implements Dispatcher {
UserSession usess = CoreSpringFactory.getImpl(UserSessionManager.class).getUserSession(hreq);
Mapper m = CoreSpringFactory.getImpl(MapperService.class).getMapperById(usess, smappath);
if (m == null) {
logWarn(
"Call to mapped resource, but mapper does not exist for path::"
+ pathInfo, null);
DispatcherModule.sendNotFound(pathInfo, hres);
return;
//an anonymous mapper?
m = CoreSpringFactory.getImpl(MapperService.class).getMapperById(null, smappath);
if(m == null) {
logWarn("Call to mapped resource, but mapper does not exist for path::" + smappath, null);
DispatcherModule.sendNotFound(pathInfo, hres);
return;
}
}
String mod = slashPos > 0 ? subInfo.substring(slashPos) : "";
if (mod.indexOf("..") != -1) {
......
......@@ -48,6 +48,7 @@ import org.olat.core.id.Identity;
import org.olat.core.logging.AssertException;
import org.olat.core.logging.OLog;
import org.olat.core.logging.Tracing;
import org.olat.core.util.UserSession;
import org.olat.core.util.Util;
/**
......@@ -229,12 +230,13 @@ public abstract class BasicController extends DefaultController {
if (mappers == null) {
mappers = new ArrayList<Mapper>(2);
}
String mapperBaseURL;
String mapperBaseURL;
UserSession usess = ureq == null ? null : ureq.getUserSession();
if (cacheableMapperID == null) {
// use non cacheable as fallback
mapperBaseURL = CoreSpringFactory.getImpl(MapperService.class).register(ureq.getUserSession(), m);
mapperBaseURL = CoreSpringFactory.getImpl(MapperService.class).register(usess, m);
} else {
mapperBaseURL = CoreSpringFactory.getImpl(MapperService.class).register(ureq.getUserSession(), cacheableMapperID, m, expirationTime);
mapperBaseURL = CoreSpringFactory.getImpl(MapperService.class).register(usess, cacheableMapperID, m, expirationTime);
}
// registration was successful, add to our mapper list
mappers.add(m);
......
......@@ -28,9 +28,11 @@ package org.olat.instantMessaging.ui;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.LinkedBlockingDeque;
import javax.servlet.http.HttpServletRequest;
......@@ -79,7 +81,7 @@ public class ChatController extends BasicController implements GenericEventListe
private final VelocityContainer chatMsgFieldContent;
private Map<Long,String> avatarKeyCache = new HashMap<Long,String>();
private List<ChatMessage> messageHistory = new ArrayList<ChatMessage>();
private Deque<ChatMessage> messageHistory = new LinkedBlockingDeque<>();
private Link refresh, todayLink, lastWeek, lastMonth;
private JSAndCSSComponent jsc;
......@@ -343,25 +345,21 @@ public class ChatController extends BasicController implements GenericEventListe
creationDate = formatter.formatDateAndTime(message.getCreationDate());
}
boolean first = true;
String from = message.getFromNickName();
synchronized (messageHistory) {
boolean first = true;
if(!messageHistory.isEmpty()) {
ChatMessage last = messageHistory.get(messageHistory.size() - 1);
if(from.equals(last.getFrom())) {
first = false;
}
}
ChatMessage last = messageHistory.peekLast();
if(last != null && from.equals(last.getFrom())) {
first = false;
}
boolean anonym = message.isAnonym();
Long fromKey = message.getFromKey();
ChatMessage msg = new ChatMessage(creationDate, from, fromKey, m, first, anonym);
if(!anonym ) {
msg.setAvatarKey(getAvatarKey(message.getFromKey()));
}
messageHistory.add(msg);
boolean anonym = message.isAnonym();
Long fromKey = message.getFromKey();
ChatMessage msg = new ChatMessage(creationDate, from, fromKey, m, first, anonym);
if(!anonym ) {
msg.setAvatarKey(getAvatarKey(message.getFromKey()));
}
messageHistory.addLast(msg);
chatMsgFieldContent.contextPut("chatMessages", messageHistory);
chatMsgFieldContent.contextPut("focus", new Boolean(focus));
}
......
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