本文整理汇总了Java中org.xmpp.packet.Presence.getTo方法的典型用法代码示例。如果您正苦于以下问题:Java Presence.getTo方法的具体用法?Java Presence.getTo怎么用?Java Presence.getTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.xmpp.packet.Presence
的用法示例。
在下文中一共展示了Presence.getTo方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: userAvailable
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
@Override
public void userAvailable(Presence presence) {
// Delete the last unavailable presence of this user since the user is now
// available. Only perform this operation if this is an available presence sent to
// THE SERVER and the presence belongs to a local user.
if (presence.getTo() == null && server.isLocal(presence.getFrom())) {
String username = presence.getFrom().getNode();
if (username == null || !userManager.isRegisteredUser(username)) {
// Ignore anonymous users
return;
}
// Optimization: only delete the unavailable presence information if this
// is the first session created on the server.
if (sessionManager.getSessionCount(username) > 1) {
return;
}
deleteOfflinePresenceFromDB(username);
// Remove data from cache.
offlinePresenceCache.remove(username);
lastActivityCache.remove(username);
}
}
示例2: userAvailable
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
public void userAvailable(Presence presence) {
// Delete the last unavailable presence of this user since the user is now
// available. Only perform this operation if this is an available presence sent to
// THE SERVER and the presence belongs to a local user.
if (presence.getTo() == null && server.isLocal(presence.getFrom())) {
String username = presence.getFrom().getNode();
if (username == null || !userManager.isRegisteredUser(username)) {
// Ignore anonymous users
return;
}
// Optimization: only delete the unavailable presence information if this
// is the first session created on the server.
if (sessionManager.getSessionCount(username) > 1) {
return;
}
deleteOfflinePresenceFromDB(username);
// Remove data from cache.
offlinePresenceCache.remove(username);
lastActivityCache.remove(username);
}
}
示例3: interceptPacket
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed) throws PacketRejectedException {
String type = getSubscriptionType();
if (type.equals(DISABLED)) {
return;
}
if ((packet instanceof Presence) && !incoming && !processed) {
Presence presencePacket = (Presence) packet;
Type presenceType = presencePacket.getType();
if (presenceType != null && presenceType.equals(Presence.Type.subscribe)) {
JID toJID = presencePacket.getTo();
JID fromJID = presencePacket.getFrom();
String toNode = toJID.getNode();
if (whiteList.contains(toNode)) {
return;
}
if (type.equals(ACCEPT)) {
acceptSubscription(toJID, fromJID);
}
if (type.equals(REJECT)) {
rejectSubscription(toJID, fromJID);
}
}
}
}
示例4: remoteUserAvailable
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
public void remoteUserAvailable(Presence presence) {
// Do nothing if server is not enabled
if (!isEnabled()) {
return;
}
JID jidFrom = presence.getFrom();
JID jidTo = presence.getTo();
// Manage the cache of remote presence resources.
Set<JID> remotePresenceSet = knownRemotePresences.get(jidTo.toBareJID());
if (jidFrom.getResource() != null) {
if (remotePresenceSet != null) {
remotePresenceSet.add(jidFrom);
}
else {
remotePresenceSet = new HashSet<JID>();
remotePresenceSet.add(jidFrom);
knownRemotePresences.put(jidTo.toBareJID(), remotePresenceSet);
}
// TODO Check the roster presence subscription to allow or ignore the received presence.
// TODO Directed presences should be ignored when no presence subscription exists
// Send the presence packet recipient's last published items to the remote user.
PEPService pepService = pepServiceManager.getPEPService(jidTo.toBareJID());
if (pepService != null) {
pepService.sendLastPublishedItems(jidFrom);
}
}
}
示例5: remoteUserUnavailable
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
public void remoteUserUnavailable(Presence presence) {
// Do nothing if server is not enabled
if (!isEnabled()) {
return;
}
final JID jidFrom = presence.getFrom();
final JID jidTo = presence.getTo();
// Manage the cache of remote presence resources.
final Set<JID> remotePresenceSet = knownRemotePresences.get(jidTo.toBareJID());
if (remotePresenceSet != null) {
remotePresenceSet.remove(jidFrom);
}
}
示例6: userUnavailable
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
public void userUnavailable(Presence presence) {
// Only save the last presence status and keep track of the time when the user went
// offline if this is an unavailable presence sent to THE SERVER and the presence belongs
// to a local user.
if (presence.getTo() == null && server.isLocal(presence.getFrom())) {
String username = presence.getFrom().getNode();
if (username == null || !userManager.isRegisteredUser(username)) {
// Ignore anonymous users
return;
}
// If the user has any remaining sessions, don't record the offline info.
if (sessionManager.getActiveSessionCount(username) > 0) {
return;
}
String offlinePresence = null;
// Save the last unavailable presence of this user if the presence contains any
// child element such as <status>.
if (!presence.getElement().elements().isEmpty()) {
offlinePresence = presence.toXML();
}
// Keep track of the time when the user went offline
java.util.Date offlinePresenceDate = new java.util.Date();
boolean addedToCache;
if (offlinePresence == null) {
addedToCache = !NULL_STRING.equals(offlinePresenceCache.put(username, NULL_STRING));
}
else {
addedToCache = !offlinePresence.equals(offlinePresenceCache.put(username, offlinePresence));
}
if (!addedToCache) {
return;
}
lastActivityCache.put(username, offlinePresenceDate.getTime());
writeToDatabase(username, offlinePresence, offlinePresenceDate);
}
}
示例7: broadcast
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
public void broadcast(BroadcastPresenceRequest presenceRequest) {
String jid = null;
Presence presence = presenceRequest.getPresence();
JID to = presence.getTo();
Element frag = presence.getChildElement("x", "http://jabber.org/protocol/muc#user");
// Don't include the occupant's JID if the room is semi-anon and the new occupant
// is not a moderator
if (!canAnyoneDiscoverJID()) {
jid = frag.element("item").attributeValue("jid");
}
for (MUCRole occupant : occupantsByFullJID.values()) {
if (!occupant.isLocal()) {
continue;
}
// Don't include the occupant's JID if the room is semi-anon and the new occupant
// is not a moderator
if (!canAnyoneDiscoverJID()) {
if (MUCRole.Role.moderator == occupant.getRole()) {
frag.element("item").addAttribute("jid", jid);
}
else {
frag.element("item").addAttribute("jid", null);
}
}
// Some status codes should only be included in the "self-presence", which is only sent to the user, but not to other occupants.
if (occupant.getPresence().getFrom().equals(to)) {
Presence selfPresence = presence.createCopy();
Element fragSelfPresence = selfPresence.getChildElement("x", "http://jabber.org/protocol/muc#user");
fragSelfPresence.addElement("status").addAttribute("code", "110");
// Only in the context of entering the room status code 100, 201 and 210 should be sent.
// http://xmpp.org/registrar/mucstatus.html
if (presenceRequest.isJoinPresence()) {
boolean isRoomNew = isLocked() && creationDate.getTime() == lockedTime;
if (canAnyoneDiscoverJID()) {
// // XEP-0045: Example 26.
// If the user is entering a room that is non-anonymous (i.e., which informs all occupants of each occupant's full JID as shown above), the service MUST warn the user by including a status code of "100" in the initial presence that the room sends to the new occupant
fragSelfPresence.addElement("status").addAttribute("code", "100");
}
if (isRoomNew) {
fragSelfPresence.addElement("status").addAttribute("code", "201");
}
}
occupant.send(selfPresence);
} else {
occupant.send(presence);
}
}
}
示例8: userUnavailable
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
@Override
public void userUnavailable(Presence presence) {
// Only save the last presence status and keep track of the time when the user went
// offline if this is an unavailable presence sent to THE SERVER and the presence belongs
// to a local user.
if (presence.getTo() == null && server.isLocal(presence.getFrom())) {
String username = presence.getFrom().getNode();
if (username == null || !userManager.isRegisteredUser(username)) {
// Ignore anonymous users
return;
}
// If the user has any remaining sessions, don't record the offline info.
if (sessionManager.getActiveSessionCount(username) > 0) {
return;
}
String offlinePresence = null;
// Save the last unavailable presence of this user if the presence contains any
// child element such as <status>.
if (!presence.getElement().elements().isEmpty()) {
offlinePresence = presence.toXML();
}
// Keep track of the time when the user went offline
java.util.Date offlinePresenceDate = new java.util.Date();
boolean addedToCache;
if (offlinePresence == null) {
addedToCache = !NULL_STRING.equals(offlinePresenceCache.put(username, NULL_STRING));
}
else {
addedToCache = !offlinePresence.equals(offlinePresenceCache.put(username, offlinePresence));
}
if (!addedToCache) {
return;
}
lastActivityCache.put(username, offlinePresenceDate.getTime());
writeToDatabase(username, offlinePresence, offlinePresenceDate);
}
}
示例9: userAvailable
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
public void userAvailable(Presence presence) throws UserNotFoundException {
// Delete the last unavailable presence of this user since the user is now
// available. Only perform this operation if this is an available presence sent to
// THE SERVER and the presence belongs to a local user.
if (presence.getTo() == null && server.isLocal(presence.getFrom())) {
String username = presence.getFrom().getNode();
if (username == null || !userManager.isRegisteredUser(username)) {
// Ignore anonymous users
return;
}
// Optimization: only delete the unavailable presence information if this
// is the first session created on the server.
if (sessionManager.getSessionCount(username) > 1) {
return;
}
deleteOfflinePresenceFromDB(username);
// Remove data from cache.
offlinePresenceCache.remove(username);
lastActivityCache.remove(username);
}
else
{
//update here,change by zhang tianhao
//check the dnd show
/*presence from="[email protected]/iPhone.bcloud" to="g3chat.magicont.com">
<show>dnd</show>
<status>good!:nanjing:40.842310:111.748847</status>
<c xmlns="http://jabber.org/protocol/caps" hash="sha-1" node="http://code.google.com/p/xmppframework" ver="VyOFcFX6+YNmKssVXSBKGFP0BS4="/>
</presence>
*/
String userName = presence.getFrom().getNode();
String showString = presence.getShow().toString();
if(showString.equalsIgnoreCase("dnd"))
{
String StatusString = presence.getStatus().toString();
String s1[] = StatusString.split(":");
if(s1.length == 4)
{
String cityName = s1[1];
if(!cityName.isEmpty())
{
String latitude = s1[2];
String longitude = s1[3];
//update G3Chat user
UserManager.getUserProvider().setCityName(userName, cityName,latitude,longitude);
// userManager.getUserProvider().setCityName(username, cityName);
}
}
}
}
}
示例10: userUnavailable
import org.xmpp.packet.Presence; //导入方法依赖的package包/类
public void userUnavailable(Presence presence) {
// Only save the last presence status and keep track of the time when the user went
// offline if this is an unavailable presence sent to THE SERVER and the presence belongs
// to a local user.
if (presence.getTo() == null && server.isLocal(presence.getFrom())) {
String username = presence.getFrom().getNode();
if (username == null || !userManager.isRegisteredUser(username)) {
// Ignore anonymous users
return;
}
// If the user has any remaining sessions, don't record the offline info.
if (sessionManager.getActiveSessionCount(username) > 0) {
return;
}
String offlinePresence = null;
// Save the last unavailable presence of this user if the presence contains any
// child element such as <status>.
if (!presence.getElement().elements().isEmpty()) {
offlinePresence = presence.toXML();
}
// Keep track of the time when the user went offline
java.util.Date offlinePresenceDate = new java.util.Date();
boolean addedToCache;
if (offlinePresence == null) {
addedToCache = !NULL_STRING.equals(offlinePresenceCache.put(username, NULL_STRING));
}
else {
addedToCache = !offlinePresence.equals(offlinePresenceCache.put(username, offlinePresence));
}
if (!addedToCache) {
return;
}
lastActivityCache.put(username, offlinePresenceDate.getTime());
// Insert data into the database.
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(INSERT_OFFLINE_PRESENCE);
pstmt.setString(1, username);
if (offlinePresence != null) {
DbConnectionManager.setLargeTextField(pstmt, 2, offlinePresence);
}
else {
pstmt.setNull(2, Types.VARCHAR);
}
pstmt.setString(3, StringUtils.dateToMillis(offlinePresenceDate));
pstmt.execute();
}
catch (SQLException sqle) {
Log.error("Error storing offline presence of user: " + username, sqle);
}
finally {
DbConnectionManager.closeConnection(pstmt, con);
}
}
}