Search in sources :

Example 1 with ChatMessage

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);
}
Also used : ChatMessage(org.apache.openmeetings.db.entity.basic.ChatMessage) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) Strategy(org.simpleframework.xml.strategy.Strategy) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) Registry(org.simpleframework.xml.convert.Registry) Persister(org.simpleframework.xml.core.Persister) Serializer(org.simpleframework.xml.Serializer)

Example 2 with ChatMessage

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());
    }
}
Also used : UserConverter(org.apache.openmeetings.backup.converter.UserConverter) RoomConverter(org.apache.openmeetings.backup.converter.RoomConverter) ChatMessage(org.apache.openmeetings.db.entity.basic.ChatMessage) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) Strategy(org.simpleframework.xml.strategy.Strategy) Registry(org.simpleframework.xml.convert.Registry) Persister(org.simpleframework.xml.core.Persister) Serializer(org.simpleframework.xml.Serializer)

Example 3 with ChatMessage

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("&nbsp;", " ") + " ";
        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);
}
Also used : JSONObject(com.github.openjson.JSONObject) ChatMessage(org.apache.openmeetings.db.entity.basic.ChatMessage) JSONArray(com.github.openjson.JSONArray) FastDateFormat(org.apache.commons.lang3.time.FastDateFormat)

Example 4 with ChatMessage

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()));
    }
}
Also used : PriorityHeaderItem(org.apache.wicket.markup.head.PriorityHeaderItem) ChatMessage(org.apache.openmeetings.db.entity.basic.ChatMessage) JavaScriptResourceReference(org.apache.wicket.request.resource.JavaScriptResourceReference) ArrayList(java.util.ArrayList) Room(org.apache.openmeetings.db.entity.room.Room)

Aggregations

ChatMessage (org.apache.openmeetings.db.entity.basic.ChatMessage)4 Serializer (org.simpleframework.xml.Serializer)2 Registry (org.simpleframework.xml.convert.Registry)2 RegistryStrategy (org.simpleframework.xml.convert.RegistryStrategy)2 Persister (org.simpleframework.xml.core.Persister)2 Strategy (org.simpleframework.xml.strategy.Strategy)2 JSONArray (com.github.openjson.JSONArray)1 JSONObject (com.github.openjson.JSONObject)1 ArrayList (java.util.ArrayList)1 FastDateFormat (org.apache.commons.lang3.time.FastDateFormat)1 RoomConverter (org.apache.openmeetings.backup.converter.RoomConverter)1 UserConverter (org.apache.openmeetings.backup.converter.UserConverter)1 Room (org.apache.openmeetings.db.entity.room.Room)1 PriorityHeaderItem (org.apache.wicket.markup.head.PriorityHeaderItem)1 JavaScriptResourceReference (org.apache.wicket.request.resource.JavaScriptResourceReference)1