use of eu.siacs.conversations.xmpp.Jid in project Conversations by siacs.
the class MessageGenerator method confirm.
public MessagePacket confirm(final Message message) {
final boolean groupChat = message.getConversation().getMode() == Conversational.MODE_MULTI;
final Jid to = message.getCounterpart();
final MessagePacket packet = new MessagePacket();
packet.setType(groupChat ? MessagePacket.TYPE_GROUPCHAT : MessagePacket.TYPE_CHAT);
packet.setTo(groupChat ? to.asBareJid() : to);
final Element displayed = packet.addChild("displayed", "urn:xmpp:chat-markers:0");
if (groupChat) {
final String stanzaId = message.getServerMsgId();
if (stanzaId != null) {
displayed.setAttribute("id", stanzaId);
} else {
displayed.setAttribute("sender", to.toString());
displayed.setAttribute("id", message.getRemoteMsgId());
}
} else {
displayed.setAttribute("id", message.getRemoteMsgId());
}
packet.addChild("store", "urn:xmpp:hints");
return packet;
}
use of eu.siacs.conversations.xmpp.Jid in project Conversations by siacs.
the class MucDetailsContextMenuHelper method onContextItemSelected.
public static boolean onContextItemSelected(MenuItem item, User user, XmppActivity activity, final String fingerprint) {
final Conversation conversation = user.getConversation();
final XmppConnectionService.OnAffiliationChanged onAffiliationChanged = activity instanceof XmppConnectionService.OnAffiliationChanged ? (XmppConnectionService.OnAffiliationChanged) activity : null;
Jid jid = user.getRealJid();
switch(item.getItemId()) {
case R.id.action_contact_details:
final Jid realJid = user.getRealJid();
final Account account = conversation.getAccount();
final Contact contact = realJid == null ? null : account.getRoster().getContact(realJid);
if (contact != null) {
activity.switchToContactDetails(contact, fingerprint);
}
return true;
case R.id.start_conversation:
startConversation(user, activity);
return true;
case R.id.give_admin_privileges:
activity.xmppConnectionService.changeAffiliationInConference(conversation, jid, MucOptions.Affiliation.ADMIN, onAffiliationChanged);
return true;
case R.id.give_membership:
case R.id.remove_admin_privileges:
case R.id.revoke_owner_privileges:
activity.xmppConnectionService.changeAffiliationInConference(conversation, jid, MucOptions.Affiliation.MEMBER, onAffiliationChanged);
return true;
case R.id.give_owner_privileges:
activity.xmppConnectionService.changeAffiliationInConference(conversation, jid, MucOptions.Affiliation.OWNER, onAffiliationChanged);
return true;
case R.id.remove_membership:
activity.xmppConnectionService.changeAffiliationInConference(conversation, jid, MucOptions.Affiliation.NONE, onAffiliationChanged);
return true;
case R.id.remove_from_room:
removeFromRoom(user, activity, onAffiliationChanged);
return true;
case R.id.ban_from_conference:
activity.xmppConnectionService.changeAffiliationInConference(conversation, jid, MucOptions.Affiliation.OUTCAST, onAffiliationChanged);
if (user.getRole() != MucOptions.Role.NONE) {
activity.xmppConnectionService.changeRoleInConference(conversation, user.getName(), MucOptions.Role.NONE);
}
return true;
case R.id.send_private_message:
if (activity instanceof ConversationsActivity) {
ConversationFragment conversationFragment = ConversationFragment.get(activity);
if (conversationFragment != null) {
conversationFragment.privateMessageWith(user.getFullJid());
return true;
}
}
activity.privateMsgInMuc(conversation, user.getName());
return true;
case R.id.invite:
if (user.getAffiliation().ranks(MucOptions.Affiliation.MEMBER)) {
activity.xmppConnectionService.directInvite(conversation, jid.asBareJid());
} else {
activity.xmppConnectionService.invite(conversation, jid);
}
return true;
default:
return false;
}
}
use of eu.siacs.conversations.xmpp.Jid in project Conversations by siacs.
the class ShareUtil method copyLinkToClipboard.
public static void copyLinkToClipboard(XmppActivity activity, Message message) {
String body = message.getMergedBody().toString();
Matcher xmppPatternMatcher = Patterns.XMPP_PATTERN.matcher(body);
if (xmppPatternMatcher.find()) {
try {
Jid jid = new XmppUri(body.substring(xmppPatternMatcher.start(), xmppPatternMatcher.end())).getJid();
if (activity.copyTextToClipboard(jid.asBareJid().toString(), R.string.account_settings_jabber_id)) {
Toast.makeText(activity, R.string.jabber_id_copied_to_clipboard, Toast.LENGTH_SHORT).show();
}
return;
} catch (Exception e) {
e.printStackTrace();
return;
}
}
Matcher webUrlPatternMatcher = Patterns.AUTOLINK_WEB_URL.matcher(body);
if (webUrlPatternMatcher.find()) {
String url = body.substring(webUrlPatternMatcher.start(), webUrlPatternMatcher.end());
if (activity.copyTextToClipboard(url, R.string.web_address)) {
Toast.makeText(activity, R.string.url_copied_to_clipboard, Toast.LENGTH_SHORT).show();
}
}
}
use of eu.siacs.conversations.xmpp.Jid in project Conversations by siacs.
the class JingleConnectionManager method getPrimaryCandidate.
void getPrimaryCandidate(final Account account, final boolean initiator, final OnPrimaryCandidateFound listener) {
if (Config.DISABLE_PROXY_LOOKUP) {
listener.onPrimaryCandidateFound(false, null);
return;
}
if (!this.primaryCandidates.containsKey(account.getJid().asBareJid())) {
final Jid proxy = account.getXmppConnection().findDiscoItemByFeature(Namespace.BYTE_STREAMS);
if (proxy != null) {
IqPacket iq = new IqPacket(IqPacket.TYPE.GET);
iq.setTo(proxy);
iq.query(Namespace.BYTE_STREAMS);
account.getXmppConnection().sendIqPacket(iq, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(Account account, IqPacket packet) {
final Element streamhost = packet.query().findChild("streamhost", Namespace.BYTE_STREAMS);
final String host = streamhost == null ? null : streamhost.getAttribute("host");
final String port = streamhost == null ? null : streamhost.getAttribute("port");
if (host != null && port != null) {
try {
JingleCandidate candidate = new JingleCandidate(nextRandomId(), true);
candidate.setHost(host);
candidate.setPort(Integer.parseInt(port));
candidate.setType(JingleCandidate.TYPE_PROXY);
candidate.setJid(proxy);
candidate.setPriority(655360 + (initiator ? 30 : 0));
primaryCandidates.put(account.getJid().asBareJid(), candidate);
listener.onPrimaryCandidateFound(true, candidate);
} catch (final NumberFormatException e) {
listener.onPrimaryCandidateFound(false, null);
}
} else {
listener.onPrimaryCandidateFound(false, null);
}
}
});
} else {
listener.onPrimaryCandidateFound(false, null);
}
} else {
listener.onPrimaryCandidateFound(true, this.primaryCandidates.get(account.getJid().asBareJid()));
}
}
use of eu.siacs.conversations.xmpp.Jid in project Conversations by siacs.
the class JingleConnectionManager method deliverPacket.
public void deliverPacket(final Account account, final JinglePacket packet) {
final String sessionId = packet.getSessionId();
if (sessionId == null) {
respondWithJingleError(account, packet, "unknown-session", "item-not-found", "cancel");
return;
}
final AbstractJingleConnection.Id id = AbstractJingleConnection.Id.of(account, packet);
final AbstractJingleConnection existingJingleConnection = connections.get(id);
if (existingJingleConnection != null) {
existingJingleConnection.deliverPacket(packet);
} else if (packet.getAction() == JinglePacket.Action.SESSION_INITIATE) {
final Jid from = packet.getFrom();
final Content content = packet.getJingleContent();
final String descriptionNamespace = content == null ? null : content.getDescriptionNamespace();
final AbstractJingleConnection connection;
if (FileTransferDescription.NAMESPACES.contains(descriptionNamespace)) {
connection = new JingleFileTransferConnection(this, id, from);
} else if (Namespace.JINGLE_APPS_RTP.equals(descriptionNamespace) && isUsingClearNet(account)) {
final boolean sessionEnded = this.terminatedSessions.asMap().containsKey(PersistableSessionId.of(id));
final boolean stranger = isWithStrangerAndStrangerNotificationsAreOff(account, id.with);
if (isBusy() || sessionEnded || stranger) {
Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": rejected session with " + id.with + " because busy. sessionEnded=" + sessionEnded + ", stranger=" + stranger);
mXmppConnectionService.sendIqPacket(account, packet.generateResponse(IqPacket.TYPE.RESULT), null);
final JinglePacket sessionTermination = new JinglePacket(JinglePacket.Action.SESSION_TERMINATE, id.sessionId);
sessionTermination.setTo(id.with);
sessionTermination.setReason(Reason.BUSY, null);
mXmppConnectionService.sendIqPacket(account, sessionTermination, null);
return;
}
connection = new JingleRtpConnection(this, id, from);
} else {
respondWithJingleError(account, packet, "unsupported-info", "feature-not-implemented", "cancel");
return;
}
connections.put(id, connection);
mXmppConnectionService.updateConversationUi();
connection.deliverPacket(packet);
} else {
Log.d(Config.LOGTAG, "unable to route jingle packet: " + packet);
respondWithJingleError(account, packet, "unknown-session", "item-not-found", "cancel");
}
}
Aggregations