当前位置: 首页 > 工具软件 > JID > 使用案例 >

java jid_Java Jid.toBareJid方法代碼示例

双元魁
2023-12-01

import eu.siacs.conversations.xmpp.jid.Jid; //導入方法依賴的package包/類

public void parseContactPresence(final PresencePacket packet, final Account account) {

final PresenceGenerator mPresenceGenerator = mXmppConnectionService.getPresenceGenerator();

final Jid from = packet.getFrom();

if (from == null) {

return;

}

final String type = packet.getAttribute("type");

final Contact contact = account.getRoster().getContact(from);

if (type == null) {

String presence = from.isBareJid() ? "" : from.getResourcepart();

contact.setPresenceName(packet.findChildContent("nick", "http://jabber.org/protocol/nick"));

Avatar avatar = Avatar.parsePresence(packet.findChild("x", "vcard-temp:x:update"));

if (avatar != null && !contact.isSelf()) {

avatar.owner = from.toBareJid();

if (mXmppConnectionService.getFileBackend().isAvatarCached(avatar)) {

if (contact.setAvatar(avatar)) {

mXmppConnectionService.getAvatarService().clear(contact);

mXmppConnectionService.updateConversationUi();

mXmppConnectionService.updateRosterUi();

}

} else {

mXmppConnectionService.fetchAvatar(account, avatar);

}

}

int sizeBefore = contact.getPresences().size();

contact.updatePresence(presence, Presences.parseShow(packet.findChild("show")));

PgpEngine pgp = mXmppConnectionService.getPgpEngine();

Element x = packet.findChild("x", "jabber:x:signed");

if (pgp != null && x != null) {

Element status = packet.findChild("status");

String msg = status != null ? status.getContent() : "";

contact.setPgpKeyId(pgp.fetchKeyId(account, msg, x.getContent()));

}

boolean online = sizeBefore < contact.getPresences().size();

updateLastseen(packet, account, false);

mXmppConnectionService.onContactStatusChanged.onContactStatusChanged(contact, online);

} else if (type.equals("unavailable")) {

if (from.isBareJid()) {

contact.clearPresences();

} else {

contact.removePresence(from.getResourcepart());

}

mXmppConnectionService.onContactStatusChanged.onContactStatusChanged(contact, false);

} else if (type.equals("subscribe")) {

if (contact.getOption(Contact.Options.PREEMPTIVE_GRANT)) {

mXmppConnectionService.sendPresencePacket(account,

mPresenceGenerator.sendPresenceUpdatesTo(contact));

} else {

contact.setOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST);

final Conversation conversation = mXmppConnectionService.findOrCreateConversation(

account, contact.getJid().toBareJid(), false);

final String statusMessage = packet.findChildContent("status");

if (statusMessage != null

&& !statusMessage.isEmpty()

&& conversation.countMessages() == 0) {

conversation.add(new Message(

conversation,

statusMessage,

Message.ENCRYPTION_NONE,

Message.STATUS_RECEIVED

));

}

}

}

mXmppConnectionService.updateRosterUi();

}

 类似资料: