Package rocks.xmpp.extensions.muc.model.user

Examples of rocks.xmpp.extensions.muc.model.user.MucUser


                                notifySubjectChangeListeners(new SubjectChangeEvent(ChatRoom.this, message.getSubject(), message.getFrom().getResource(), delayedDelivery != null, date));
                            } else {
                                notifyMessageListeners(new MessageEvent(ChatRoom.this, message, true));
                            }
                        } else {
                            MucUser mucUser = message.getExtension(MucUser.class);
                            if (mucUser != null) {
                                Decline decline = mucUser.getDecline();
                                if (decline != null) {
                                    notifyInvitationDeclineListeners(new InvitationDeclineEvent(ChatRoom.this, roomJid, decline.getFrom(), decline.getReason()));
                                }
                            }
                        }
                    }
                }
            }
        };

        presenceListener = new PresenceListener() {
            @Override
            public void handle(PresenceEvent e) {
                Presence presence = e.getPresence();
                // If the presence came from the room.
                if (presence.getFrom() != null && presence.getFrom().asBareJid().equals(roomJid)) {
                    if (e.isIncoming()) {
                        MucUser mucUser = presence.getExtension(MucUser.class);
                        if (mucUser != null) {
                            String nick = presence.getFrom().getResource();

                            if (nick != null) {
                                boolean isSelfPresence = isSelfPresence(presence);
                                if (presence.isAvailable()) {
                                    Occupant occupant = new Occupant(presence, isSelfPresence);
                                    Occupant previousOccupant = occupantMap.put(nick, occupant);
                                    // A new occupant entered the room.
                                    if (previousOccupant == null) {
                                        // Only notify about "joins", if it's not our own join and we are already in the room.
                                        if (!isSelfPresence && entered) {
                                            notifyOccupantListeners(new OccupantEvent(ChatRoom.this, occupant, OccupantEvent.Type.ENTERED, null, null, null));
                                        }
                                    } else {
                                        notifyOccupantListeners(new OccupantEvent(ChatRoom.this, occupant, OccupantEvent.Type.STATUS_CHANGED, null, null, null));
                                    }
                                } else if (presence.getType() == Presence.Type.UNAVAILABLE) {
                                    // Occupant has exited the room.
                                    Occupant occupant = occupantMap.remove(nick);
                                    if (occupant != null) {
                                        if (mucUser.getItem() != null) {
                                            Actor actor = mucUser.getItem().getActor();
                                            String reason = mucUser.getItem().getReason();
                                            if (!mucUser.getStatusCodes().isEmpty()) {
                                                if (mucUser.getStatusCodes().contains(Status.kicked())) {
                                                    notifyOccupantListeners(new OccupantEvent(ChatRoom.this, occupant, OccupantEvent.Type.KICKED, actor, reason, null));
                                                } else if (mucUser.getStatusCodes().contains(Status.banned())) {
                                                    notifyOccupantListeners(new OccupantEvent(ChatRoom.this, occupant, OccupantEvent.Type.BANNED, actor, reason, null));
                                                } else if (mucUser.getStatusCodes().contains(Status.membershipRevoked())) {
                                                    notifyOccupantListeners(new OccupantEvent(ChatRoom.this, occupant, OccupantEvent.Type.MEMBERSHIP_REVOKED, actor, reason, null));
                                                } else if (mucUser.getStatusCodes().contains(Status.nicknameChanged())) {
                                                    notifyOccupantListeners(new OccupantEvent(ChatRoom.this, occupant, OccupantEvent.Type.NICKNAME_CHANGED, actor, reason, null));
                                                } else if (mucUser.getStatusCodes().contains(Status.systemShutdown())) {
                                                    notifyOccupantListeners(new OccupantEvent(ChatRoom.this, occupant, OccupantEvent.Type.SYSTEM_SHUTDOWN, actor, reason, null));
                                                }
                                            } else if (mucUser.getDestroy() != null) {
                                                notifyOccupantListeners(new OccupantEvent(ChatRoom.this, occupant, OccupantEvent.Type.ROOM_DESTROYED, actor, mucUser.getDestroy().getReason(), mucUser.getDestroy().getJid()));
                                            } else {
                                                notifyOccupantListeners(new OccupantEvent(ChatRoom.this, occupant, OccupantEvent.Type.EXITED, null, null, null));
                                            }
                                        } else {
                                            notifyOccupantListeners(new OccupantEvent(ChatRoom.this, occupant, OccupantEvent.Type.EXITED, null, null, null));
View Full Code Here


        }
    }

    private boolean isSelfPresence(Presence presence) {
        boolean isSelfPresence = false;
        MucUser mucUser = presence.getExtension(MucUser.class);
        if (mucUser != null) {
            // If the presence is self-presence (110) or if the service assigned another nickname (210) to the user (but didn't include 110).
            isSelfPresence = mucUser.getStatusCodes().contains(Status.self()) || mucUser.getStatusCodes().contains(Status.serviceHasAssignedOrModifiedNick());
        }
        return isSelfPresence || nick != null && presence.getFrom() != null && nick.equals(presence.getFrom().getResource());
    }
View Full Code Here

                "  <x xmlns='http://jabber.org/protocol/muc#user'>\n" +
                "    <item affiliation='owner' role='moderator'/>\n" +
                "  </x>\n" +
                "</presence>\n";
        Presence presence = unmarshal(xml, Presence.class);
        MucUser mucUser = presence.getExtension(MucUser.class);
        Assert.assertNotNull(mucUser);
        Assert.assertNotNull(mucUser.getItem());
        Assert.assertEquals(mucUser.getItem().getAffiliation(), Affiliation.OWNER);
        Assert.assertEquals(mucUser.getItem().getRole(), Role.MODERATOR);
    }
View Full Code Here

    @Test
    public void testAffiliationAndRole1() throws XMLStreamException, JAXBException {
        String xml = "<x xmlns='http://jabber.org/protocol/muc#user'>" +
                "<item affiliation='member' role='moderator'/>" +
                "</x>";
        MucUser mucUser = unmarshal(xml, MucUser.class);
        Assert.assertEquals(mucUser.getItem().getAffiliation(), Affiliation.MEMBER);
        Assert.assertEquals(mucUser.getItem().getRole(), Role.MODERATOR);
    }
View Full Code Here

    @Test
    public void testAffiliationAndRole2() throws XMLStreamException, JAXBException {
        String xml = "<x xmlns='http://jabber.org/protocol/muc#user'>" +
                "<item affiliation='admin' role='none'/>" +
                "</x>";
        MucUser mucUser = unmarshal(xml, MucUser.class);
        Assert.assertEquals(mucUser.getItem().getAffiliation(), Affiliation.ADMIN);
        Assert.assertEquals(mucUser.getItem().getRole(), Role.NONE);
    }
View Full Code Here

    @Test
    public void testAffiliationAndRole3() throws XMLStreamException, JAXBException {
        String xml = "<x xmlns='http://jabber.org/protocol/muc#user'>" +
                "<item affiliation='none' role='participant'/>" +
                "</x>";
        MucUser mucUser = unmarshal(xml, MucUser.class);
        Assert.assertEquals(mucUser.getItem().getAffiliation(), Affiliation.NONE);
        Assert.assertEquals(mucUser.getItem().getRole(), Role.PARTICIPANT);
    }
View Full Code Here

    @Test
    public void testAffiliationAndRole4() throws XMLStreamException, JAXBException {
        String xml = "<x xmlns='http://jabber.org/protocol/muc#user'>" +
                "<item affiliation='outcast' role='visitor'/>" +
                "</x>";
        MucUser mucUser = unmarshal(xml, MucUser.class);
        Assert.assertEquals(mucUser.getItem().getAffiliation(), Affiliation.OUTCAST);
        Assert.assertEquals(mucUser.getItem().getRole(), Role.VISITOR);
    }
View Full Code Here

                "    <status code='110'/>\n" +
                "    <status code='210'/>\n" +
                "  </x>\n" +
                "</presence>\n";
        Presence presence = unmarshal(xml, Presence.class);
        MucUser mucUser = presence.getExtension(MucUser.class);
        Assert.assertNotNull(mucUser);
        Assert.assertNotNull(mucUser.getItem());
        Assert.assertEquals(mucUser.getStatusCodes().size(), 2);
        Assert.assertEquals(mucUser.getStatusCodes().get(0).getCode(), 110);
        Assert.assertEquals(mucUser.getStatusCodes().get(1).getCode(), 210);
    }
View Full Code Here

    private final Presence presence;

    Occupant(Presence presence, boolean isSelf) {
        this.presence = presence;
        this.nick = presence.getFrom().getResource();
        MucUser mucUser = presence.getExtension(MucUser.class);
        if (mucUser != null && mucUser.getItem() != null) {
            this.affiliation = mucUser.getItem().getAffiliation();
            this.role = mucUser.getItem().getRole();
            this.jid = mucUser.getItem().getJid();
            this.isSelf = isSelf;
        } else {
            this.affiliation = null;
            this.role = null;
            this.jid = null;
View Full Code Here

                "          nick='oldhag'\n" +
                "          role='participant'/>\n" +
                "  </x>\n" +
                "</presence>\n";
        Presence presence = unmarshal(xml, Presence.class);
        MucUser mucUser = presence.getExtension(MucUser.class);
        Assert.assertNotNull(mucUser);
        Assert.assertNotNull(mucUser.getItem());
        Assert.assertEquals(mucUser.getItem().getJid(), Jid.valueOf("hag66@shakespeare.lit/pda"));
        Assert.assertEquals(mucUser.getItem().getNick(), "oldhag");
    }
View Full Code Here

TOP

Related Classes of rocks.xmpp.extensions.muc.model.user.MucUser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.