void RosterManager::handlePresence( const Presence& presence ) { if( presence.subtype() == Presence::Error ) return; bool self = false; Roster::iterator it = m_roster.find( presence.from().bare() ); if( it != m_roster.end() || ( self = ( presence.from().bareJID() == m_self->jidJID() ) ) ) { RosterItem* ri = self ? m_self : (*it).second; const std::string& resource = presence.from().resource(); if( presence.presence() == Presence::Unavailable ) ri->removeResource( resource ); else { ri->setPresence( resource, presence.presence() ); ri->setStatus( resource, presence.status() ); ri->setPriority( resource, presence.priority() ); ri->setExtensions( resource, presence.extensions() ); } if( m_rosterListener && !self ) m_rosterListener->handleRosterPresence( *ri, resource, presence.presence(), presence.status() ); else if( m_rosterListener && self ) m_rosterListener->handleSelfPresence( *ri, resource, presence.presence(), presence.status() ); } else { if( m_rosterListener ) m_rosterListener->handleNonrosterPresence( presence ); } }
virtual void handleMUCParticipantPresence( MUCRoom * /*room*/, const MUCRoomParticipant participant, const Presence& presence ) { if( presence.presence() == Presence::Available ) printf( "!!!!!!!!!!!!!!!! %s is in the room, too\n", participant.nick->resource().c_str() ); else if( presence.presence() == Presence::Unavailable ) printf( "!!!!!!!!!!!!!!!! %s left the room\n", participant.nick->resource().c_str() ); else printf( "Presence is %d of %s\n", presence.presence(), participant.nick->resource().c_str() ); }
void ResourceManager::setResource(const Presence &stanza) { std::string resource = stanza.from().resource(); if (resource.empty()) return; Tag *stanzaTag = stanza.tag(); Tag *c = stanzaTag->findChildWithAttrib("xmlns", "http://jabber.org/protocol/caps"); int caps = -1; // presence has caps if (c != NULL) { caps = Transport::instance()->getCapabilities(c->findAttribute("ver")); } setResource(resource, stanza.priority(), caps, (int) stanza.presence(), stanza.status()); delete stanzaTag; }
void jConference::handlePresence (const Presence &presence) { if(presence.subtype()==Presence::Error) return; const MUCRoom::MUCUser* mu = presence.findExtension<MUCRoom::MUCUser>(ExtMUCUser); if(!mu) return; QString conference = utils::fromStd(presence.from().bare()); Room *room = m_rooms.value(conference); if(!room) return; QString nick = utils::fromStd(presence.from().resource()); QHash<QString,MucContact> &contacts = room->contacts_list; int flags = mu->flags(); bool send_role=false; if( flags & UserNickChanged && mu->newNick() ) { // changed nick to new_nick QString new_nick = utils::fromStd(*mu->newNick()); if(!contacts.contains(nick)) return; MucContact contact = contacts[nick]; jBuddy::ResourceInfo *info = &contact.m_info; info->m_name = new_nick; contacts.remove(nick); contacts.insert(new_nick, contact); emit addSystemMessageToConference("Jabber",conference,m_account_name,tr("%1 is now known as %2").arg(nick).arg(new_nick),QDateTime(),false); emit renameConferenceItem("Jabber", conference, m_account_name, nick, new_nick); return; } bool if_join=false; if(presence.presence()==Presence::Unavailable && contacts.contains(nick)) { QString reason = ""; if(mu->reason()) reason = utils::fromStd(*mu->reason()); if (utils::fromStd(room->entity->nick()) == nick) { QString msgtxt; if(flags & UserKicked){ msgtxt += tr("You have been kicked from")+" "+conference+".\n"; if (!reason.isEmpty()){ msgtxt += tr("with reason:")+" "+reason+".\n"; } else { msgtxt += tr("without reason")+".\n"; } QMessageBox::warning(0, tr("You have been kicked"), msgtxt, QMessageBox::Ok); // //TODO: autorejoin? // msgtxt += tr("Do you want to rejoin?"); // int ret = QMessageBox::warning(0, tr("You have been kicked"), msgtxt, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); // if(ret==QMessageBox::Yes) { // JID jid(utils::toStd(conference)); // m_room_list[conference]->leave(""); // m_room_list[conference]->join(m_presence->presence(), m_presence->status()); //// createConferenceRoom(utils::fromStd(jid.server()), utils::fromStd(jid.username()), nick, "" ); // return; // } } else if(flags & UserBanned){ msgtxt += tr("You have been banned from")+" "+conference+".\n"; if (!reason.isEmpty()){ msgtxt += tr("with reason:")+" "+reason+".\n"; } else { msgtxt += tr("without reason")+".\n"; } QMessageBox::warning(0, tr("You have been banned"), msgtxt, QMessageBox::Ok); } } //offline contacts.remove(nick); emit removeConferenceItem("Jabber", conference, m_account_name, nick); QString text; if(flags & UserKicked) text = tr("%1 has been kicked").arg(nick); else if(flags & UserBanned) text = tr("%1 has been banned").arg(nick); else text = tr("%1 has left the room").arg(nick); if (!reason.isEmpty()) text += " ("+reason+")"; emit addSystemMessageToConference("Jabber",conference,m_account_name,text,QDateTime(),false); return; } else if(presence.presence()==Presence::Unavailable) return; else { QString status; int mass; switch(presence.presence()) { case Presence::Chat: status="ffc"; mass=1; break; case Presence::Away: status="away"; mass=2; break; case Presence::DND: status="dnd"; mass=3; break; case Presence::XA: status="na"; mass=4; break; case Presence::Error: return; case Presence::Available: default: status="online"; mass=0; break; } if(!contacts.contains(nick) || contacts[nick].m_info.m_name.isNull() || contacts[nick].m_info.m_name.isEmpty()) { //online if(!contacts.contains(nick)) { MucContact contact; jBuddy::ResourceInfo info; info.m_name = nick; info.m_chat_state = ChatStateActive; contact.m_info = info; contact.m_affiliation = AffiliationNone; contact.m_role = RoleInvalid ; contacts.insert(nick,contact); emit addConferenceItem("Jabber", conference, m_account_name, nick); } MucContact *contact = &contacts[nick]; jBuddy::ResourceInfo *info = &contact->m_info; info->m_name = nick; info->m_presence = presence.presence(); if(presence.presence() == Presence::Invalid) info->m_presence = Presence::Available; info->m_priority = 0; if_join=true; emit setConferenceItemRole("Jabber", conference, m_account_name, nick, status, mass); send_role=true; // JID jid(room->name()+"@"+room->service()+"/"+participant.nick->resource()); // jClientIdentification::instance().setClient(&(contacts[nick]),jid,m_client_base,this); } else contacts[nick].m_info.m_presence = presence.presence(); if(contacts[nick].m_real_jid.isEmpty() && mu->jid()) contacts[nick].m_real_jid = utils::fromStd(*mu->jid()); //changed status emit setConferenceItemStatus("Jabber", conference, m_account_name, nick, status, mass); } if(contacts.contains(nick)) { MucContact *contact = &contacts[nick]; QString message; if(!if_join && mu->role()==contact->m_role && mu->affiliation()==contact->m_affiliation) return; if(if_join && contact->m_real_jid.isEmpty()) { if(mu->role()!=contact->m_role&&mu->affiliation()!=contact->m_affiliation) message = tr("%3 has joined the room as %1 and %2"); else if(mu->role()!=contact->m_role||mu->affiliation()!=contact->m_affiliation) message = tr("%2 has joined the room as %1"); else message = tr("%2 has joined the room"); } else if(if_join) { if(mu->role()!=contact->m_role&&mu->affiliation()!=contact->m_affiliation) message = tr("%4 (%3) has joined the room as %1 and %2"); else if(mu->role()!=contact->m_role||mu->affiliation()!=contact->m_affiliation) message = tr("%3 (%2) has joined the room as %1"); else message = tr("%2 (%1) has joined the room"); } else if(contact->m_real_jid.isEmpty()) { if(mu->role()!=contact->m_role&&mu->affiliation()!=contact->m_affiliation) message = tr("%3 now is %1 and %2"); else if(mu->role()!=contact->m_role||mu->affiliation()!=contact->m_affiliation) message = tr("%2 now is %1"); } else { if(mu->role()!=contact->m_role&&mu->affiliation()!=contact->m_affiliation) message = tr("%4 (%3) now is %1 and %2"); else if(mu->role()!=contact->m_role||mu->affiliation()!=contact->m_affiliation) message = tr("%3 (%2) now is %1"); } if(mu->role()!=contact->m_role) { int mass; QString role; switch(mu->role()) { case RoleModerator: role=tr("moderator"); mass=1; break; case RoleParticipant: role=tr("participant"); mass=2; break; default: case RoleVisitor: role=tr("visitor"); mass=3; break; } contact->m_role = mu->role(); contact->m_role_string = role; message = message.arg(role); contact->m_info.m_priority = mass; emit setConferenceItemRole("Jabber", conference, m_account_name, nick, role, mass); } if(mu->affiliation()!=contact->m_affiliation) { QString affiliation; switch(mu->affiliation()) { case AffiliationOutcast: affiliation=tr("banned"); break; case AffiliationMember: affiliation=tr("member"); break; case AffiliationOwner: affiliation=tr("owner"); break; case AffiliationAdmin: affiliation=tr("administrator"); break; default: affiliation=tr("guest"); break; } contact->m_affiliation = mu->affiliation(); contact->m_affiliation_string = mu->affiliation()==AffiliationNone?"":affiliation; message = message.arg(affiliation); } if(!contact->m_real_jid.isEmpty()) message = message.arg(contact->m_real_jid); message = message.arg(nick); emit addSystemMessageToConference("Jabber",conference,m_account_name,message,QDateTime(),false); } jBuddy::ResourceInfo *info = &contacts[nick].m_info; info->m_status_message = utils::fromStd(presence.status()); info->m_status_message.replace("\n","<br/>"); if(info->m_client_name.isEmpty()||info->m_client_name.isNull()) { const Capabilities *caps = presence.capabilities(); if(caps) { info->m_caps_ver = utils::fromStd(caps->ver()); info->m_caps_node = utils::fromStd(caps->node()); } else { info->m_caps_ver = ""; info->m_caps_node = ""; } jClientIdentification::instance().setClient(info,presence.from(),m_client_base,this); emit conferenceClientVersion("Jabber",conference,m_account_name,nick, info->m_client_name); } const VCardUpdate *vcard_update = presence.findExtension<VCardUpdate>(ExtVCardUpdate); if(vcard_update) { QString hash = utils::fromStd(vcard_update->hash()); if(!hash.isEmpty()) { if(QFile(m_jabber_account->getPathToAvatars()+"/"+hash).exists()) { setAvatar(conference,nick,m_jabber_account->getPathToAvatars()+"/"+hash); } else { m_real_parent->fetchVCard(conference+"/"+nick,true); } } } const XStatusExtension *xstatus = presence.findExtension<XStatusExtension>(SExtXStatus); if(xstatus) { if(xstatus->status_id()<0) info->m_x_status=""; else info->m_x_status = QString("icq_xstatus%1").arg(xstatus->status_id()); emit setConferenceItemIcon("Jabber",conference,m_account_name,nick, info->m_x_status, 5); } }