本文整理汇总了Java中org.xmpp.packet.Presence.setStatus方法的典型用法代码示例。如果您正苦于以下问题:Java Presence.setStatus方法的具体用法?Java Presence.setStatus怎么用?Java Presence.setStatus使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.xmpp.packet.Presence
的用法示例。
在下文中一共展示了Presence.setStatus方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setPresence
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* Sets the current status.
*
* @param newpresence New presence to set to.
*/
public void setPresence(PresenceType newpresence) {
if (newpresence == null) {
newpresence = PresenceType.unknown;
}
if (newpresence.equals(PresenceType.unavailable)) {
verboseStatus = "";
}
if (!presence.equals(newpresence) && newpresence != PresenceType.unknown) {
Presence p = new Presence();
p.setTo(getManager().getSession().getJID());
p.setFrom(jid);
getManager().getSession().getTransport().setUpPresencePacket(p, newpresence);
if (!verboseStatus.equals("")) {
p.setStatus(verboseStatus);
}
if (avatarSet && avatar != null) {
Element vcard = p.addChildElement("x", NameSpace.VCARD_TEMP_X_UPDATE);
vcard.addElement("photo").addCDATA(avatar.getXmppHash());
vcard.addElement("hash").addCDATA(avatar.getXmppHash());
}
getManager().sendPacket(p);
}
presence = newpresence;
lastActivityTimestamp = new Date().getTime();
}
示例2: setVerboseStatus
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* Sets the current verbose status.
*
* @param newstatus New verbose status.
*/
public void setVerboseStatus(String newstatus) {
if (newstatus == null) {
newstatus = "";
}
if (!verboseStatus.equals(newstatus)) {
Presence p = new Presence();
p.setTo(getManager().getSession().getJID());
p.setFrom(jid);
getManager().getSession().getTransport().setUpPresencePacket(p, presence);
if (!newstatus.equals("")) {
p.setStatus(newstatus);
}
if (avatarSet && avatar != null) {
Element vcard = p.addChildElement("x", NameSpace.VCARD_TEMP_X_UPDATE);
vcard.addElement("photo").addCDATA(avatar.getXmppHash());
vcard.addElement("hash").addCDATA(avatar.getXmppHash());
}
getManager().sendPacket(p);
}
verboseStatus = newstatus;
lastActivityTimestamp = new Date().getTime();
lastActivityEvent = verboseStatus;
}
示例3: sendPresence
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* Sends the current presence to the session user.
*
* @param to JID to send presence updates to.
*/
public void sendPresence(JID to) {
// TODO: Should figure out best way to handle unknown here.
Presence p = new Presence();
p.setTo(to);
p.setFrom(jid);
getManager().getSession().getTransport().setUpPresencePacket(p, presence);
if (verboseStatus != null && verboseStatus.length() > 0) {
p.setStatus(verboseStatus);
}
if (avatarSet && avatar != null) {
Element vcard = p.addChildElement("x", NameSpace.VCARD_TEMP_X_UPDATE);
vcard.addElement("photo").addCDATA(avatar.getXmppHash());
vcard.addElement("hash").addCDATA(avatar.getXmppHash());
}
getManager().sendPacket(p);
}
示例4: setAvatar
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* Sets the current avatar for this contact.
*
* @param avatar Avatar instance to associate with this contact.
*/
public void setAvatar(Avatar avatar) {
boolean triggerUpdate = false;
if ( (avatar != null && this.avatar == null) ||
(avatar == null && this.avatar != null) ||
(avatar != null && !this.avatar.getXmppHash().equals(avatar.getXmppHash()))) {
triggerUpdate = true;
}
this.avatar = avatar;
this.avatarSet = true;
if (triggerUpdate) {
Presence p = new Presence();
p.setTo(getManager().getSession().getJID());
p.setFrom(jid);
getManager().getSession().getTransport().setUpPresencePacket(p, presence);
if (!verboseStatus.equals("")) {
p.setStatus(verboseStatus);
}
Element vcard = p.addChildElement("x", NameSpace.VCARD_TEMP_X_UPDATE);
if (avatar != null) {
vcard.addElement("photo").addCDATA(avatar.getXmppHash());
vcard.addElement("hash").addCDATA(avatar.getXmppHash());
}
getManager().sendPacket(p);
}
}
示例5: testFilterAvailablePresence
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
@Test
public void testFilterAvailablePresence() throws Exception {
// setup available presence
Presence presence = new Presence();
presence.setStatus("fox is now online!");
System.out.println(presence.toXML());
// filter on the word "fox" and "dog"
filter.setPatterns("fox,dog");
filter.setMask("**");
boolean matched = filter.filter(presence);
// matches should not be found
assertTrue(matched);
// content has changed
assertEquals("** is now online!", presence.getStatus());
}
示例6: testFilterAvailablePresence
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
public void testFilterAvailablePresence() throws Exception {
// setup available presence
Presence presence = new Presence();
presence.setStatus("fox is now online!");
System.out.println(presence.toXML());
// filter on the word "fox" and "dog"
filter.setPatterns("fox,dog");
filter.setMask("**");
boolean matched = filter.filter(presence);
// matches should not be found
assertTrue(matched);
// content has changed
assertEquals("** is now online!", presence.getStatus());
}
示例7: registerBot
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* Register a bot with the specified mmxUserName.
*
* @param appId
* @param botUserName
*/
@Override
public void registerBot(String appId, String botUserName, AutoResponseProcessor processor) {
String mmxUserName = JIDUtil.makeNode(botUserName, appId);
LOGGER.debug("Registering bot with name:{}", mmxUserName);
String botDeviceId = deviceId(appId, botUserName);
AutoRespondingConnection bot = new AutoRespondingConnection(processor);
try {
bot.login(mmxUserName, botDeviceId);
// Set the user's presence
Presence presence = new Presence();
presence.setStatus("Online");
bot.sendPacket(presence);
/*
* Register a device for the bot user
*/
LOGGER.debug("Creating a device for the bot user");
DeviceDAO deviceDAO = getDeviceDAO();
DeviceEntity deviceEntity = deviceDAO.getDevice(botDeviceId, BOT_DEVICE_OS_TYPE, appId);
if (deviceEntity == null) {
//we need to create a new one
DevReg deviceRegistration = new DevReg();
deviceRegistration.setOsType(BOT_DEVICE_OS_TYPE.name());
deviceRegistration.setDisplayName(deviceName(appId, botUserName));
deviceRegistration.setDevId(botDeviceId);
deviceDAO.addDevice(botUserName, appId, deviceRegistration);
LOGGER.debug("Created device with id:{} for bot user:{}", botDeviceId, botUserName);
}
} catch (Throwable e) {
LOGGER.warn("Exception", e);
}
}
示例8: setPresenceAndStatus
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
/**
* Convenience routine to set both presence and verbose status at the same time.
*
* @param newpresence New presence to set to.
* @param newstatus New verbose status.
*/
public void setPresenceAndStatus(PresenceType newpresence, String newstatus) {
Log.debug("Updating status ["+newpresence+","+newstatus+"] for "+this);
if (newpresence == null) {
newpresence = PresenceType.unknown;
}
if (newstatus == null) {
newstatus = "";
}
if (newpresence.equals(PresenceType.unavailable)) {
newstatus = "";
}
if ((!presence.equals(newpresence) && newpresence != PresenceType.unknown) || !verboseStatus.equals(newstatus)) {
Presence p = new Presence();
p.setTo(getManager().getSession().getJID());
p.setFrom(jid);
getManager().getSession().getTransport().setUpPresencePacket(p, newpresence);
if (!newstatus.equals("")) {
p.setStatus(newstatus);
}
if (avatarSet && avatar != null) {
Element vcard = p.addChildElement("x", NameSpace.VCARD_TEMP_X_UPDATE);
vcard.addElement("photo").addCDATA(avatar.getXmppHash());
vcard.addElement("hash").addCDATA(avatar.getXmppHash());
}
getManager().sendPacket(p);
}
presence = newpresence;
verboseStatus = newstatus;
lastActivityTimestamp = new Date().getTime();
lastActivityEvent = verboseStatus;
}
示例9: addNone
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
public List<Presence> addNone(JID jid, MUCRole senderRole) throws ForbiddenException,
ConflictException {
List<Presence> updatedPresences = null;
boolean wasMember = false;
lock.writeLock().lock();
try {
MUCRole.Affiliation oldAffiliation = MUCRole.Affiliation.none;
if (MUCRole.Affiliation.admin != senderRole.getAffiliation()
&& MUCRole.Affiliation.owner != senderRole.getAffiliation()) {
throw new ForbiddenException();
}
// Check that the room always has an owner
if (owners.contains(jid.toBareJID()) && owners.size() == 1) {
throw new ConflictException();
}
wasMember = members.containsKey(jid.toBareJID()) || admins.contains(jid.toBareJID()) || owners.contains(jid.toBareJID());
// Remove the user from ALL the affiliation lists
if (removeOwner(jid.toBareJID())) {
oldAffiliation = MUCRole.Affiliation.owner;
}
else if (removeAdmin(jid.toBareJID())) {
oldAffiliation = MUCRole.Affiliation.admin;
}
else if (removeMember(jid.toBareJID())) {
oldAffiliation = MUCRole.Affiliation.member;
}
else if (removeOutcast(jid.toBareJID())) {
oldAffiliation = MUCRole.Affiliation.outcast;
}
// Remove the affiliation of this user from the DB if the room is persistent
MUCPersistenceManager.removeAffiliationFromDB(this, jid.toBareJID(), oldAffiliation);
}
finally {
lock.writeLock().unlock();
}
// Update the presence with the new affiliation and inform all occupants
try {
MUCRole.Role newRole;
if (isMembersOnly() && wasMember) {
newRole = MUCRole.Role.none;
}
else {
newRole = isModerated() ? MUCRole.Role.visitor : MUCRole.Role.participant;
}
updatedPresences = changeOccupantAffiliation(jid, MUCRole.Affiliation.none, newRole);
if (isMembersOnly() && wasMember) {
// If the room is members-only, remove the user from the room including a status
// code of 321 to indicate that the user was removed because of an affiliation
// change
Element frag;
// Add the status code to the presences that will be sent to the room occupants
for (Presence presence : updatedPresences) {
// Set the presence as an unavailable presence
presence.setType(Presence.Type.unavailable);
presence.setStatus(null);
frag = presence.getChildElement("x", "http://jabber.org/protocol/muc#user");
// Add the status code 321 that indicates that the user was removed because of
// an affiliation change
frag.addElement("status").addAttribute("code", "321");
// Remove the ex-member from the room. If a user has joined the room from
// different client resources, he/she will be kicked from all the client
// resources.
// Effectively kick the occupant from the room
JID actorJID = senderRole.getUserAddress();
kickPresence(presence, actorJID);
}
}
}
catch (NotAllowedException e) {
// We should never receive this exception....in theory
}
return updatedPresences;
}
示例10: addNone
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
public List<Presence> addNone(JID jid, MUCRole senderRole) throws ForbiddenException,
ConflictException {
final JID bareJID = jid.asBareJID();
List<Presence> updatedPresences = Collections.emptyList();
boolean wasMember = false;
lock.writeLock().lock();
try {
MUCRole.Affiliation oldAffiliation = MUCRole.Affiliation.none;
if (MUCRole.Affiliation.admin != senderRole.getAffiliation()
&& MUCRole.Affiliation.owner != senderRole.getAffiliation()) {
throw new ForbiddenException();
}
// Check that the room always has an owner
if (owners.contains(bareJID) && owners.size() == 1) {
throw new ConflictException();
}
wasMember = members.containsKey(bareJID) || admins.contains(bareJID) || owners.contains(bareJID);
// Remove the user from ALL the affiliation lists
if (removeOwner(bareJID)) {
oldAffiliation = MUCRole.Affiliation.owner;
}
else if (removeAdmin(bareJID)) {
oldAffiliation = MUCRole.Affiliation.admin;
}
else if (removeMember(bareJID)) {
oldAffiliation = MUCRole.Affiliation.member;
}
else if (removeOutcast(bareJID)) {
oldAffiliation = MUCRole.Affiliation.outcast;
}
// Remove the affiliation of this user from the DB if the room is persistent
MUCPersistenceManager.removeAffiliationFromDB(this, bareJID, oldAffiliation);
}
finally {
lock.writeLock().unlock();
}
// Update other cluster nodes with new affiliation
CacheFactory.doClusterTask(new AddAffiliation(this, jid.toBareJID(), MUCRole.Affiliation.none));
// Update the presence with the new affiliation and inform all occupants
try {
MUCRole.Role newRole;
if (isMembersOnly() && wasMember) {
newRole = MUCRole.Role.none;
}
else {
newRole = isModerated() ? MUCRole.Role.visitor : MUCRole.Role.participant;
}
updatedPresences = changeOccupantAffiliation(bareJID, MUCRole.Affiliation.none, newRole);
if (isMembersOnly() && wasMember) {
// If the room is members-only, remove the user from the room including a status
// code of 321 to indicate that the user was removed because of an affiliation
// change
Element frag;
// Add the status code to the presences that will be sent to the room occupants
for (Presence presence : updatedPresences) {
// Set the presence as an unavailable presence
presence.setType(Presence.Type.unavailable);
presence.setStatus(null);
frag = presence.getChildElement("x", "http://jabber.org/protocol/muc#user");
// Add the status code 321 that indicates that the user was removed because of
// an affiliation change
frag.addElement("status").addAttribute("code", "321");
// Remove the ex-member from the room. If a user has joined the room from
// different client resources, he/she will be kicked from all the client
// resources.
// Effectively kick the occupant from the room
JID actorJID = senderRole.getUserAddress();
kickPresence(presence, actorJID);
}
}
}
catch (NotAllowedException e) {
// We should never receive this exception....in theory
Log.error(e.getMessage(), e);
}
return updatedPresences;
}