Search in sources :

Example 16 with Buddy

use of org.olat.instantMessaging.model.Buddy in project OpenOLAT by OpenOLAT.

the class InstantMessageServiceTest method testGetBuddiesListenTo.

@Test
public void testGetBuddiesListenTo() {
    DummyListener dummyListener = new DummyListener();
    Identity chatter1 = JunitTestHelper.createAndPersistIdentityAsUser("Chat-1-" + UUID.randomUUID().toString());
    Identity chatter2 = JunitTestHelper.createAndPersistIdentityAsUser("Chat-2-" + UUID.randomUUID().toString());
    OLATResourceable chatResource = OresHelper.createOLATResourceableInstance(UUID.randomUUID().toString(), chatter1.getKey());
    imService.listenChat(chatter1, chatResource, null, false, false, dummyListener);
    imService.listenChat(chatter2, chatResource, "Chatter-2", true, true, dummyListener);
    dbInstance.commitAndCloseSession();
    // check if the buddies listen to the chat
    List<Buddy> buddies = imService.getBuddiesListenTo(chatResource);
    Assert.assertNotNull(buddies);
    Assert.assertEquals(2, buddies.size());
    // check the properties of buddy 1
    Buddy buddy1 = buddies.get(0).getIdentityKey().equals(chatter1.getKey()) ? buddies.get(0) : buddies.get(1);
    Assert.assertTrue(buddy1.getUsername().equals(chatter1.getName()));
    Assert.assertFalse(buddy1.isAnonym());
    Assert.assertFalse(buddy1.isVip());
    // check the properties of buddy 2
    Buddy buddy2 = buddies.get(0).getIdentityKey().equals(chatter2.getKey()) ? buddies.get(0) : buddies.get(1);
    Assert.assertTrue(buddy2.getUsername().equals(chatter2.getName()));
    Assert.assertTrue(buddy2.isAnonym());
    Assert.assertTrue(buddy2.isVip());
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) Identity(org.olat.core.id.Identity) Buddy(org.olat.instantMessaging.model.Buddy) Test(org.junit.Test)

Example 17 with Buddy

use of org.olat.instantMessaging.model.Buddy in project OpenOLAT by OpenOLAT.

the class InstantMessagingMainController method loadNotifications.

private void loadNotifications() {
    List<InstantMessageNotification> notifications = imService.getNotifications(getIdentity());
    for (InstantMessageNotification notification : notifications) {
        if (!showNewMessageHolder.contains(notification.getFromIdentityKey())) {
            showNewMessageHolder.add(notification.getFromIdentityKey());
            Buddy buddy = imService.getBuddyById(notification.getFromIdentityKey());
            createShowNewMessageLink(buddy);
        }
    }
}
Also used : InstantMessageNotification(org.olat.instantMessaging.InstantMessageNotification) Buddy(org.olat.instantMessaging.model.Buddy)

Example 18 with Buddy

use of org.olat.instantMessaging.model.Buddy in project OpenOLAT by OpenOLAT.

the class InstantMessagingMainController method processInstantMessageEvent.

private void processInstantMessageEvent(InstantMessagingEvent imEvent) {
    if (imEvent.getCommand().equals("message")) {
        // user receives messages from an other user
        Long fromId = imEvent.getFromId();
        if (!chatMgrCtrl.hasRunningChat(imEvent.getChatResource())) {
            // add follow up message to info holder
            if (!showNewMessageHolder.contains(fromId)) {
                Buddy buddy = imService.getBuddyById(fromId);
                if (Presence.available.name().equals(imStatus) && !inAssessment) {
                    doOpenPrivateChat(new SyntheticUserRequest(getIdentity(), getLocale()), buddy);
                } else {
                    showNewMessageHolder.add(fromId);
                    createShowNewMessageLink(buddy);
                }
            }
        }
    }
}
Also used : SyntheticUserRequest(org.olat.core.gui.util.SyntheticUserRequest) Buddy(org.olat.instantMessaging.model.Buddy)

Example 19 with Buddy

use of org.olat.instantMessaging.model.Buddy in project OpenOLAT by OpenOLAT.

the class IMBuddyListController method event.

@Override
protected void event(UserRequest ureq, Component source, Event event) {
    // buddies list
    if (source == toggleOffline) {
        if (viewMode == ViewMode.onlineUsers) {
            toggleOffline.setCustomDisplayText(translate("im.hide.offline.buddies"));
            toggleOffline.setIconLeftCSS("o_icon o_icon-fw o_icon_status_available");
            toggleOffline.setElementCssClass("o_im_hideofflineswitch");
            loadRoster(ViewMode.offlineUsers);
        } else {
            toggleOffline.setCustomDisplayText(translate("im.show.offline.buddies"));
            toggleOffline.setIconLeftCSS("o_icon o_icon-fw o_icon_status_unavailable");
            toggleOffline.setElementCssClass("o_im_showofflineswitch");
            loadRoster(ViewMode.onlineUsers);
        }
    } else if (source == toggleGroup) {
        if (viewGroups) {
            toggleGroup.setCustomDisplayText(translate("im.show.groups"));
            toggleGroup.setElementCssClass("o_im_hidegroupswitch");
            buddiesListContent.contextPut("viewGroups", Boolean.FALSE);
            viewGroups = false;
        } else {
            toggleGroup.setCustomDisplayText(translate("im.hide.groups"));
            toggleGroup.setElementCssClass("o_im_showgroupswitch");
            buddiesListContent.contextPut("viewGroups", Boolean.TRUE);
            viewGroups = true;
        }
    } else if (source instanceof Link) {
        Link link = (Link) source;
        if ("cmd.buddy".equals(link.getCommand())) {
            Buddy buddy = (Buddy) link.getUserObject();
            fireEvent(ureq, new OpenInstantMessageEvent(ureq, buddy));
        }
    }
}
Also used : OpenInstantMessageEvent(org.olat.instantMessaging.OpenInstantMessageEvent) Link(org.olat.core.gui.components.link.Link) Buddy(org.olat.instantMessaging.model.Buddy)

Example 20 with Buddy

use of org.olat.instantMessaging.model.Buddy in project OpenOLAT by OpenOLAT.

the class MembersTableController method doOpenChat.

private void doOpenChat(MemberView member, UserRequest ureq) {
    Buddy buddy = imService.getBuddyById(member.getIdentityKey());
    OpenInstantMessageEvent e = new OpenInstantMessageEvent(ureq, buddy);
    ureq.getUserSession().getSingleUserEventCenter().fireEventToListenersOf(e, InstantMessagingService.TOWER_EVENT_ORES);
}
Also used : OpenInstantMessageEvent(org.olat.instantMessaging.OpenInstantMessageEvent) Buddy(org.olat.instantMessaging.model.Buddy)

Aggregations

Buddy (org.olat.instantMessaging.model.Buddy)36 OpenInstantMessageEvent (org.olat.instantMessaging.OpenInstantMessageEvent)16 BuddyGroup (org.olat.instantMessaging.model.BuddyGroup)6 ArrayList (java.util.ArrayList)4 Link (org.olat.core.gui.components.link.Link)4 HashSet (java.util.HashSet)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 Test (org.junit.Test)2 UserSessionView (org.olat.admin.sysinfo.model.UserSessionView)2 IdentityShort (org.olat.basesecurity.IdentityShort)2 TableEvent (org.olat.core.gui.components.table.TableEvent)2 SyntheticUserRequest (org.olat.core.gui.util.SyntheticUserRequest)2 Identity (org.olat.core.id.Identity)2 OLATResourceable (org.olat.core.id.OLATResourceable)2 UserSession (org.olat.core.util.UserSession)2 InstantMessageNotification (org.olat.instantMessaging.InstantMessageNotification)2 RosterEntryView (org.olat.instantMessaging.model.RosterEntryView)2