use of org.apache.openmeetings.db.entity.basic.ChatMessage in project openmeetings by apache.
the class BackupExport method exportChat.
/*
* ##################### Chat
*/
private void exportChat(ZipOutputStream zos, ProgressHolder progressHolder) throws Exception {
List<ChatMessage> list = chatDao.get(0, Integer.MAX_VALUE);
Registry registry = new Registry();
registry.bind(User.class, UserConverter.class);
registry.bind(Room.class, RoomConverter.class);
Strategy strategy = new RegistryStrategy(registry);
Serializer serializer = new Persister(strategy);
bindDate(registry, list, ChatMessage::getSent);
writeList(serializer, zos, "chat_messages.xml", "chat_messages", list);
progressHolder.setProgress(85);
}
use of org.apache.openmeetings.db.entity.basic.ChatMessage in project openmeetings by apache.
the class BackupImport method importChat.
/*
* ##################### Import Chat messages
*/
private void importChat(File f) throws Exception {
log.info("Room groups import complete, starting chat messages import");
Registry registry = new Registry();
Strategy strategy = new RegistryStrategy(registry);
Serializer serializer = new Persister(strategy);
registry.bind(User.class, new UserConverter(userDao, userMap));
registry.bind(Room.class, new RoomConverter(roomDao, roomMap));
registry.bind(Date.class, DateConverter.class);
List<ChatMessage> list = readList(serializer, f, "chat_messages.xml", "chat_messages", ChatMessage.class);
for (ChatMessage m : list) {
m.setId(null);
if (m.getFromUser() == null || m.getFromUser().getId() == null) {
continue;
}
chatDao.update(m, m.getSent());
}
}
use of org.apache.openmeetings.db.entity.basic.ChatMessage in project openmeetings by apache.
the class WebSocketHelper method getMessage.
public static JSONObject getMessage(User curUser, List<ChatMessage> list, BiConsumer<JSONObject, User> uFmt) {
JSONArray arr = new JSONArray();
final FastDateFormat fullFmt = FormatHelper.getDateTimeFormat(curUser);
final FastDateFormat dateFmt = FormatHelper.getDateFormat(curUser);
final FastDateFormat timeFmt = FormatHelper.getTimeFormat(curUser);
for (ChatMessage m : list) {
String smsg = m.getMessage();
smsg = smsg == null ? smsg : " " + smsg.replaceAll(" ", " ") + " ";
JSONObject from = new JSONObject().put("id", m.getFromUser().getId()).put("displayName", m.getFromName()).put("name", getDisplayName(m.getFromUser()));
if (uFmt != null) {
uFmt.accept(from, m.getFromUser());
}
arr.put(setScope(new JSONObject(), m, curUser.getId()).put("id", m.getId()).put("message", smsg).put("from", from).put("actions", curUser.getId() == m.getFromUser().getId() ? "short" : "full").put("sent", fullFmt.format(m.getSent())).put("date", dateFmt.format(m.getSent())).put("time", timeFmt.format(m.getSent())));
}
return new JSONObject().put("type", "chat").put("msg", arr);
}
use of org.apache.openmeetings.db.entity.basic.ChatMessage in project openmeetings by apache.
the class Chat method renderHead.
@Override
public void renderHead(IHeaderResponse response) {
super.renderHead(response);
response.render(new PriorityHeaderItem(JavaScriptHeaderItem.forReference(new JavaScriptResourceReference(Chat.class, "chat.js"))));
response.render(new PriorityHeaderItem(getNamedFunction("chatActivity", chatActivity, explicit(PARAM_TYPE), explicit(PARAM_ROOM_ID), explicit(PARAM_MSG_ID))));
if (showDashboardChat) {
StringBuilder sb = new StringBuilder(getReinit());
List<ChatMessage> list = new ArrayList<>(chatDao.getGlobal(0, 30));
for (Long roomId : cm.listRoomIds(getUserId())) {
Room r = roomDao.get(roomId);
sb.append(addRoom(r));
}
list.addAll(chatDao.getUserRecent(getUserId(), Date.from(Instant.now().minus(Duration.ofHours(1L))), 0, 30));
if (!list.isEmpty()) {
sb.append("Chat.addMessage(").append(getMessage(list).toString()).append(");");
}
response.render(OnDomReadyHeaderItem.forScript(sb.toString()));
}
}
Aggregations