Search in sources :

Example 6 with InstantMessage

use of org.olat.instantMessaging.InstantMessage in project openolat by klemens.

the class ChatController method processInstantMessageEvent.

private void processInstantMessageEvent(InstantMessagingEvent event) {
    if ("message".equals(event.getCommand())) {
        Long from = event.getFromId();
        if (!getIdentity().getKey().equals(from)) {
            Long messageId = event.getMessageId();
            InstantMessage message = imService.getMessageById(getIdentity(), messageId, true);
            appendToMessageHistory(message, false);
        }
    } else if ("participant".equals(event.getCommand())) {
        if (event.getFromId() != null) {
            updateRosterList(event.getFromId(), event.getName(), event.isAnonym(), event.isVip());
        }
    }
}
Also used : InstantMessage(org.olat.instantMessaging.InstantMessage)

Example 7 with InstantMessage

use of org.olat.instantMessaging.InstantMessage in project openolat by klemens.

the class ChatLogHelper method archive.

public void archive(OLATResourceable ores, File exportDirectory) {
    ObjectOutputStream out = null;
    try {
        File file = new File(exportDirectory, "chat.xml");
        Writer writer = new FileWriter(file);
        out = logXStream.createObjectOutputStream(writer);
        int counter = 0;
        List<InstantMessage> messages;
        do {
            messages = imDao.getMessages(ores, null, counter, BATCH_SIZE);
            for (InstantMessage message : messages) {
                out.writeObject(message);
            }
            counter += messages.size();
        } while (messages.size() == BATCH_SIZE);
    } catch (IOException e) {
        log.error("", e);
    } finally {
        IOUtils.closeQuietly(out);
    }
}
Also used : FileWriter(java.io.FileWriter) InstantMessage(org.olat.instantMessaging.InstantMessage) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 8 with InstantMessage

use of org.olat.instantMessaging.InstantMessage in project OpenOLAT by OpenOLAT.

the class ChatLogHelper method archive.

public void archive(OLATResourceable ores, File exportDirectory) {
    ObjectOutputStream out = null;
    try {
        File file = new File(exportDirectory, "chat.xml");
        Writer writer = new FileWriter(file);
        out = logXStream.createObjectOutputStream(writer);
        int counter = 0;
        List<InstantMessage> messages;
        do {
            messages = imDao.getMessages(ores, null, counter, BATCH_SIZE);
            for (InstantMessage message : messages) {
                out.writeObject(message);
            }
            counter += messages.size();
        } while (messages.size() == BATCH_SIZE);
    } catch (IOException e) {
        log.error("", e);
    } finally {
        IOUtils.closeQuietly(out);
    }
}
Also used : FileWriter(java.io.FileWriter) InstantMessage(org.olat.instantMessaging.InstantMessage) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 9 with InstantMessage

use of org.olat.instantMessaging.InstantMessage in project OpenOLAT by OpenOLAT.

the class ChatLogHelper method logMediaResource.

public MediaResource logMediaResource(OLATResourceable ores, Locale locale) {
    Translator translator = Util.createPackageTranslator(ChatController.class, locale);
    String tableExportTitle = translator.translate("logChat.export.title");
    String label = tableExportTitle + Formatter.formatDatetimeFilesystemSave(new Date(System.currentTimeMillis())) + ".xlsx";
    return new OpenXMLWorkbookResource(label) {

        @Override
        protected void generate(OutputStream out) {
            try (OpenXMLWorkbook workbook = new OpenXMLWorkbook(out, 1)) {
                // headers
                OpenXMLWorksheet exportSheet = workbook.nextWorksheet();
                Row headerRow = exportSheet.newRow();
                headerRow.addCell(0, "User", workbook.getStyles().getHeaderStyle());
                headerRow.addCell(1, "Date", workbook.getStyles().getHeaderStyle());
                headerRow.addCell(2, "Content", workbook.getStyles().getHeaderStyle());
                // content
                List<InstantMessage> messages = imDao.getMessages(ores, null, 0, -1);
                for (InstantMessage message : messages) {
                    Row dataRow = exportSheet.newRow();
                    dataRow.addCell(0, message.getFromNickName(), null);
                    dataRow.addCell(1, message.getCreationDate(), workbook.getStyles().getDateStyle());
                    dataRow.addCell(2, message.getBody(), null);
                }
            } catch (IOException e) {
                log.error("", e);
            }
        }
    };
}
Also used : Translator(org.olat.core.gui.translator.Translator) OpenXMLWorkbookResource(org.olat.core.util.openxml.OpenXMLWorkbookResource) ObjectOutputStream(java.io.ObjectOutputStream) OutputStream(java.io.OutputStream) InstantMessage(org.olat.instantMessaging.InstantMessage) OpenXMLWorkbook(org.olat.core.util.openxml.OpenXMLWorkbook) Row(org.olat.core.util.openxml.OpenXMLWorksheet.Row) IOException(java.io.IOException) OpenXMLWorksheet(org.olat.core.util.openxml.OpenXMLWorksheet) Date(java.util.Date)

Example 10 with InstantMessage

use of org.olat.instantMessaging.InstantMessage in project OpenOLAT by OpenOLAT.

the class InstantMessagingServiceImpl method sendMessage.

@Override
public InstantMessage sendMessage(Identity from, String fromNickName, boolean anonym, String body, OLATResourceable chatResource) {
    InstantMessage message = imDao.createMessage(from, fromNickName, anonym, body, chatResource);
    // commit before sending event
    dbInstance.commit();
    InstantMessagingEvent event = new InstantMessagingEvent("message", chatResource);
    event.setFromId(from.getKey());
    event.setName(fromNickName);
    event.setAnonym(anonym);
    event.setMessageId(message.getKey());
    coordinator.getCoordinator().getEventBus().fireEventToListenersOf(event, chatResource);
    return message;
}
Also used : InstantMessage(org.olat.instantMessaging.InstantMessage) InstantMessagingEvent(org.olat.instantMessaging.InstantMessagingEvent)

Aggregations

InstantMessage (org.olat.instantMessaging.InstantMessage)14 IOException (java.io.IOException)4 ObjectOutputStream (java.io.ObjectOutputStream)4 InstantMessagingEvent (org.olat.instantMessaging.InstantMessagingEvent)4 File (java.io.File)2 FileWriter (java.io.FileWriter)2 OutputStream (java.io.OutputStream)2 Writer (java.io.Writer)2 Date (java.util.Date)2 Translator (org.olat.core.gui.translator.Translator)2 OLATResourceable (org.olat.core.id.OLATResourceable)2 OpenXMLWorkbook (org.olat.core.util.openxml.OpenXMLWorkbook)2 OpenXMLWorkbookResource (org.olat.core.util.openxml.OpenXMLWorkbookResource)2 OpenXMLWorksheet (org.olat.core.util.openxml.OpenXMLWorksheet)2 Row (org.olat.core.util.openxml.OpenXMLWorksheet.Row)2 CloseInstantMessagingEvent (org.olat.instantMessaging.CloseInstantMessagingEvent)2