use of org.jivesoftware.smack.roster.RosterEntry in project Spark by igniterealtime.
the class ContactList method switchAllUserOfflineNoGroupEntry.
/**
* Switches all Users to Offline and Creates an Icon in the CommandBar
*/
private synchronized void switchAllUserOfflineNoGroupEntry(final boolean onError) {
SwingWorker worker = new SwingWorker() {
@Override
public Object construct() {
_reconnectpanelicon.getPanel().add(_reconnectpanelicon.getButton(), 0);
_reconnectpanelicon.getPanel().revalidate();
_reconnectpanelicon.setClosedOnError(onError);
final Collection<RosterEntry> roster = Roster.getInstanceFor(SparkManager.getConnection()).getEntries();
for (RosterEntry r : roster) {
Presence p = new Presence(Presence.Type.unavailable);
moveToOfflineGroup(p, r.getUser());
}
return true;
}
};
worker.start();
}
use of org.jivesoftware.smack.roster.RosterEntry in project Spark by igniterealtime.
the class SubscriptionDialog method invoke.
public void invoke(final String jid) throws SmackException.NotConnectedException {
this.jid = jid;
final Roster roster = Roster.getInstanceFor(SparkManager.getConnection());
// If User is already in roster, do not show.
RosterEntry entry = roster.getEntry(jid);
if (entry != null && entry.getType() == RosterPacket.ItemType.to) {
Presence response = new Presence(Presence.Type.subscribed);
response.setTo(jid);
SparkManager.getConnection().sendStanza(response);
return;
}
String message = Res.getString("message.approve.subscription", UserManager.unescapeJID(jid));
Transport transport = TransportUtils.getTransport(XmppStringUtils.parseDomain(jid));
Icon icon = null;
if (transport != null) {
icon = transport.getIcon();
}
TitlePanel messageLabel = new TitlePanel("", message, icon, true);
// Add Message Label
mainPanel.add(messageLabel, new GridBagConstraints(0, 0, 6, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
UserManager userManager = SparkManager.getUserManager();
String username = userManager.getNickname(userManager.getFullJID(jid));
username = username == null ? XmppStringUtils.parseLocalpart(UserManager.unescapeJID(jid)) : username;
usernameLabelValue.setText(UserManager.unescapeJID(jid));
nicknameField.setText(username);
acceptButton.addActionListener(e -> {
if (!rosterBox.isSelected()) {
Presence response = new Presence(Presence.Type.subscribed);
response.setTo(jid);
try {
SparkManager.getConnection().sendStanza(response);
} catch (SmackException.NotConnectedException e1) {
Log.warning("Unable to send stanza accepting subscription from " + jid, e1);
}
dialog.dispose();
return;
}
boolean addEntry = addEntry();
if (addEntry) {
Presence response = new Presence(Presence.Type.subscribed);
response.setTo(jid);
try {
SparkManager.getConnection().sendStanza(response);
} catch (SmackException.NotConnectedException e1) {
Log.warning("Unable to send stanza accepting subscription from " + jid, e1);
}
} else {
dialog.dispose();
}
});
denyButton.addActionListener(e -> {
// Send subscribed
unsubscribeAndClose();
});
viewInfoButton.addActionListener(e -> SparkManager.getVCardManager().viewProfile(jid, mainPanel));
dialog = new JFrame(Res.getString("title.subscription.request")) {
private static final long serialVersionUID = 5713933518069623228L;
public Dimension getPreferredSize() {
final Dimension dim = super.getPreferredSize();
dim.width = 400;
return dim;
}
};
dialog.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
dialog.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
super.windowClosing(e);
unsubscribeAndClose();
}
});
KeyStroke key = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
ActionListener action = e -> unsubscribeAndClose();
dialog.getRootPane().registerKeyboardAction(action, key, JComponent.WHEN_FOCUSED);
dialog.setIconImage(SparkManager.getApplicationImage().getImage());
dialog.getContentPane().add(mainPanel);
dialog.pack();
dialog.setLocationRelativeTo(SparkManager.getMainWindow());
if (SparkManager.getMainWindow().isFocused()) {
dialog.setState(Frame.NORMAL);
dialog.setVisible(true);
} else if (!SparkManager.getMainWindow().isVisible() || !SparkManager.getMainWindow().isFocused()) {
if (Spark.isWindows()) {
dialog.setFocusable(false);
dialog.setState(Frame.ICONIFIED);
}
SparkManager.getNativeManager().flashWindowStopOnFocus(dialog);
dialog.setVisible(true);
}
}
use of org.jivesoftware.smack.roster.RosterEntry in project Spark by igniterealtime.
the class WorkgroupRosterTree method buildFromRoster.
private void buildFromRoster() {
final Roster roster = Roster.getInstanceFor(SparkManager.getConnection());
roster.addRosterListener(new RosterListener() {
public void rosterModified() {
}
public void entriesAdded(Collection collection) {
}
public void entriesUpdated(Collection collection) {
}
public void entriesDeleted(Collection collection) {
}
public void presenceChanged(Presence presence) {
changePresence(presence.getFrom(), presence);
}
});
for (RosterGroup group : roster.getGroups()) {
if (workgroupList.contains(group.getName())) {
continue;
}
final JiveTreeNode groupNode = new JiveTreeNode(group.getName(), true);
groupNode.setAllowsChildren(true);
if (group.getEntryCount() > 0) {
rootNode.add(groupNode);
}
for (RosterEntry entry : group.getEntries()) {
String name = entry.getName();
if (name == null) {
name = entry.getUser();
}
if (exclusionList.contains(entry.getUser())) {
continue;
}
final JiveTreeNode entryNode = new JiveTreeNode(name, false);
final Presence usersPresence = roster.getPresence(entry.getUser());
addressMap.put(entryNode, entry.getUser());
if (PresenceManager.isAvailable(usersPresence)) {
groupNode.add(entryNode);
} else if (showUnavailableAgents) {
groupNode.add(entryNode);
}
changePresence(entry.getUser(), usersPresence);
final DefaultTreeModel model = (DefaultTreeModel) rosterTree.getModel();
model.nodeStructureChanged(groupNode);
}
}
}
use of org.jivesoftware.smack.roster.RosterEntry in project Zom-Android by zom.
the class XmppConnection method makeContact.
private Contact makeContact(String address) {
Contact contact = null;
// load from roster if we don't have the contact
RosterEntry rEntry = null;
try {
if (mConnection != null)
rEntry = mRoster.getEntry(JidCreate.bareFrom(address));
if (rEntry != null) {
XmppAddress xAddress = new XmppAddress(address);
String name = rEntry.getName();
if (name == null)
name = xAddress.getUser();
// TODO we should check the type from here
contact = new Contact(xAddress, name, Imps.Contacts.TYPE_NORMAL);
} else {
XmppAddress xAddress = new XmppAddress(address);
contact = new Contact(xAddress, xAddress.getUser(), Imps.Contacts.TYPE_NORMAL);
}
} catch (XmppStringprepException xe) {
// nothing return null;
}
return contact;
}
use of org.jivesoftware.smack.roster.RosterEntry in project xabber-android by redsolution.
the class RosterManager method removeGroup.
/**
* Requests to remove group from all contacts in account.
*/
public void removeGroup(AccountJid account, String groupName) throws NetworkException {
final Roster roster = getRoster(account);
if (roster == null) {
return;
}
final org.jivesoftware.smack.roster.RosterGroup group = roster.getGroup(groupName);
if (group == null) {
return;
}
Application.getInstance().runInBackgroundUserRequest(new Runnable() {
@Override
public void run() {
for (RosterEntry entry : group.getEntries()) {
try {
group.removeEntry(entry);
} catch (SmackException.NoResponseException e) {
Application.getInstance().onError(R.string.CONNECTION_FAILED);
} catch (SmackException.NotConnectedException e) {
Application.getInstance().onError(R.string.NOT_CONNECTED);
} catch (XMPPException.XMPPErrorException e) {
Application.getInstance().onError(R.string.XMPP_EXCEPTION);
} catch (InterruptedException e) {
LogManager.exception(LOG_TAG, e);
}
}
}
});
}
Aggregations