public void removeContact(String jidString) throws SmackException.NotLoggedInException, InterruptedException, SmackException.NotConnectedException, XMPPException.XMPPErrorException, SmackException.NoResponseException, XmppStringprepException { Roster roster = Roster.getInstanceFor(XMPPSession.getInstance().getXMPPConnection()); if (!roster.isLoaded()) { roster.reloadAndWait(); } BareJid jid = JidCreate.bareFrom(jidString); roster.removeEntry(roster.getEntry(jid)); Presence presence = new Presence(Presence.Type.unsubscribe); presence.setTo(JidCreate.from(jidString)); XMPPSession.getInstance().sendStanza(presence); }
public void addContact(String jidString) throws SmackException.NotLoggedInException, InterruptedException, SmackException.NotConnectedException, XMPPException.XMPPErrorException, SmackException.NoResponseException, XmppStringprepException { Roster roster = Roster.getInstanceFor(XMPPSession.getInstance().getXMPPConnection()); if (!roster.isLoaded()) { roster.reloadAndWait(); } BareJid jid = JidCreate.bareFrom(jidString); String name = XMPPUtils.fromJIDToUserName(jidString); String[] groups = new String[]{"Buddies"}; roster.createEntry(jid, name, groups); roster.sendSubscriptionRequest(jid); }
@SuppressLint("NewApi") @Override protected void onDestroy() { // XMPP.getInstance().getConnection(acitiviy).getRoster() // .removeRosterListener(rosterListener); Roster.getInstanceFor(XMPP.getInstance().getConnection(acitiviy)).removeRosterListener(rosterListener); ChatManager.getInstanceFor(XMPP.getInstance().getConnection(acitiviy)) .removeChatListener(chatListener); if (chat != null && messageListener != null) { chat.removeMessageListener(messageListener); } if (popupWindow != null) { popupWindow.dismiss(); } if (emoticonsCover != null) { emoticonsCover.setVisibility(View.GONE); } // actionBar.setIcon(R.drawable.ic_launcher); super.onDestroy(); }
/** * creates a list of all RosterEntries * @return the rosterEntryArray */ public RosterEntry[] listRoster(){ try{ // get the roster and if it is not loaded reload it Roster roster = Roster.getInstanceFor(connection); if (!roster.isLoaded()) roster.reloadAndWait(); RosterEntry[] result = new RosterEntry[roster.getEntries().size()]; int i = 0; // loop through all roster entries and append them to the array for (RosterEntry entry: roster.getEntries()){ result[i++] = entry; } return result; }catch (Exception e){ e.printStackTrace(); } return new RosterEntry[0]; }
@Override public void run(){ Roster roster = xmppManager.getRoster(); if (roster != null && !roster.isLoaded()) try{ roster.reloadAndWait(); Log.d("SERVICE_DEBUG", "reloaded roster"); }catch (Exception e){ Log.e("SERVICE_ERROR", "Couldn't load the roster"); e.printStackTrace(); } if (roster != null){ Collection<RosterEntry> entries = roster.getEntries(); for (RosterEntry entry : entries) presenceReceived(roster.getPresence(entry.getUser())); roster.addRosterListener(rosterListener); } }
/** * Remove all connection & packet listeners and disconnect XMPP connection. */ public void disconnect() { if (null != connection && connection.isConnected()) { // Remove listeners Roster.getInstanceFor(connection).removeRosterListener(onlineRosterListener); connection.removeAsyncStanzaListener(packetListener); connection.removeAsyncStanzaListener(taskStatusListener); connection.removeAsyncStanzaListener(policyStatusListener); connection.removeAsyncStanzaListener(registrationListener); connection.removeAsyncStanzaListener(userSessionListener); connection.removeAsyncStanzaListener(missingPluginListener); connection.removeAsyncStanzaListener(policyListener); connection.removeAsyncStanzaListener(connectionListener); connection.removeAsyncStanzaListener(reqAggrementListener); connection.removeAsyncStanzaListener(aggrementStatusListener); connection.removeAsyncStanzaListener(scriptResultListener); connection.removeConnectionListener(connectionListener); logger.debug("Listeners are removed."); PingManager.getInstanceFor(connection).setPingInterval(-1); logger.debug("Disabled ping manager"); connection.disconnect(); logger.info("Successfully closed XMPP connection."); } }
@Override public void authenticated(XMPPConnection connection, boolean resumed) { if (resumed) { Logger.debug(TAG, "authenticated after resumption"); } else { Logger.debug(TAG, "authenticated"); } XmppService.setConnected(true); try { sendPendingMessages(); Roster.getInstanceFor(mConnection).reload(); } catch (Exception exc) { Logger.info(TAG, "Failed to automatically send pending messages on authentication"); } }
private void rebuildRoster() { Roster roster = Roster.getInstanceFor(mConnection); if (roster == null) { Logger.info(TAG, "no roster, skipping rebuild roster"); return; } Set<RosterEntry> entries = roster.getEntries(); ArrayList<XmppRosterEntry> newRoster = new ArrayList<>(entries.size()); for (RosterEntry entry : entries) { XmppRosterEntry newEntry = getRosterEntryFor(roster, entry); newRoster.add(newEntry); } Collections.sort(newRoster); XmppService.setRosterEntries(newRoster); XmppServiceBroadcastEventEmitter.broadcastRosterChanged(); }
private XmppRosterEntry getRosterEntryFor(Roster roster, RosterEntry entry) { XmppRosterEntry newEntry = new XmppRosterEntry(); newEntry.setXmppJID(entry.getUser()) .setAlias(entry.getName()) .setAvatar(getCachedAvatar(entry.getUser())); if (newEntry.getAvatar() == null) { newEntry.setAvatar(getAvatarFor(entry.getUser())); } Presence presence = roster.getPresence(entry.getUser()); newEntry.setAvailable(presence.isAvailable()) .setPresenceMode(presence.getMode().ordinal()) .setPersonalMessage(presence.getStatus()); newEntry.setUnreadMessages(mMessagesProvider.countUnreadMessages(mAccount.getXmppJid(), entry.getUser())); return newEntry; }
@Override public void onRosterLoaded(Roster roster) { final MessageCenterService service = mService.get(); if (service == null) return; final Handler handler = service.mHandler; if (handler != null) { handler.post(new Runnable() { @Override public void run() { // send pending subscription replies service.sendPendingSubscriptionReplies(); // resend failed and pending messages service.resendPendingMessages(false, false); // resend failed and pending received receipts service.resendPendingReceipts(); // roster has been loaded service.broadcast(MessageCenterService.ACTION_ROSTER_LOADED); } }); } }
private void broadcastPresence(Roster roster, RosterEntry entry, BareJid jid, String id) { // this method might be called async final LocalBroadcastManager lbm = mLocalBroadcastManager; if (lbm == null) return; Intent i; // entry present and not pending subscription if (isRosterEntrySubscribed(entry) || Authenticator.isSelfJID(this, jid)) { // roster entry found, look for presence Presence presence = roster.getPresence(jid); i = PresenceListener.createIntent(this, presence, entry); } else { // null type indicates no roster entry found or not authorized i = new Intent(ACTION_PRESENCE); i.putExtra(EXTRA_FROM, jid.toString()); } // to keep track of request-reply i.putExtra(EXTRA_PACKET_ID, id); lbm.sendBroadcast(i); }
public static void initialize(Context context) { if (!sInitialized) { disableSmackDefault(); InputStream is = context.getResources().openRawResource(R.raw.service); ProviderManager.addLoader(new ProviderFileLoader(is)); try { is.close(); } catch (IOException ignored) { } // FIXME these got to be fixed somehow (VCard4 is not even used anymore) ProviderManager.addIQProvider(VCard4.ELEMENT_NAME, VCard4.NAMESPACE, new VCard4.Provider()); ProviderManager.addIQProvider(ServerlistCommand.ELEMENT_NAME, ServerlistCommand.NAMESPACE, new ServerlistCommand.ResultProvider()); // do not append Smack version VersionManager.setAutoAppendSmackVersion(false); // we want to manually handle roster stuff Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.manual); sInitialized = true; } }
public void connect(String hostname, int port, String username, String password) throws Exception { purgeTask("reconnect"); this.hostname = hostname; this.serviceName = hostname; this.port = port; this.username = username; this.password = password; Builder builder = XMPPTCPConnectionConfiguration.builder(); builder.setUsernameAndPassword(username, password); builder.setServiceName(serviceName); builder.setServiceName(hostname); builder.setPort(port); builder.setSecurityMode(SecurityMode.disabled); builder.setDebuggerEnabled(true); XMPPTCPConnectionConfiguration config = builder.build(); connection = new XMPPTCPConnection(config); connection.connect().login(); roster = Roster.getInstanceFor(connection); chatManager = ChatManager.getInstanceFor(connection); roster.addRosterListener(this); isConnected = true; // not worth it - always empty right after connect // getContactList(); broadcastState(); }
public boolean addToRoster(JID jid, String name) { if (!this.isConnected()) { LOGGER.info("not connected"); return false; } if (!jid.isValid()) { LOGGER.warning("invalid JID: " + jid); return false; } try { // also sends presence subscription request Roster.getInstanceFor(mConn).createEntry(jid.toBareSmack(), name, null); } catch (SmackException.NotLoggedInException | SmackException.NoResponseException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | InterruptedException ex) { LOGGER.log(Level.WARNING, "can't add contact to roster", ex); return false; } return true; }
public boolean removeFromRoster(JID jid) { if (!this.isConnected()) { LOGGER.info("not connected"); return false; } Roster roster = Roster.getInstanceFor(mConn); RosterEntry entry = roster.getEntry(jid.toBareSmack()); if (entry == null) { LOGGER.info("can't find roster entry for jid: "+jid); return true; } try { // blocking roster.removeEntry(entry); } catch (SmackException.NotLoggedInException | SmackException.NoResponseException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | InterruptedException ex) { LOGGER.log(Level.WARNING, "can't remove contact from roster", ex); return false; } return true; }
public void updateRosterEntry(JID jid, String newName) { if (!this.isConnected()) { LOGGER.info("not connected"); return; } Roster roster = Roster.getInstanceFor(mConn); RosterEntry entry = roster.getEntry(jid.toBareSmack()); if (entry == null) { LOGGER.warning("can't find roster entry for jid: "+jid); return; } try { entry.setName(newName); } catch (SmackException.NotConnectedException | SmackException.NoResponseException | XMPPException.XMPPErrorException | InterruptedException ex) { LOGGER.log(Level.WARNING, "can't set name for entry", ex); } }
@Override public void newConnection(XMPPConnection connection) { mConnection = connection; mRoster = Roster.getInstanceFor(connection); mRoster.addRosterListener(this); mRoster.addSubscribeListener(new SubscribeListener() { @Override public SubscribeAnswer processSubscribe(Jid from, Presence subscribeRequest) { Set<EntityBareJid> masterJids = mSettings.getMasterJids(); for (EntityBareJid masterJid : masterJids) { if (masterJid.equals(from)) { return SubscribeAnswer.Approve; } } return SubscribeAnswer.Deny; } }); }
public void notifyAboutNewMasterAddress(final EntityBareJid newMasterAddress) { final XMPPConnection connection = getConnection(); if (connection == null || !connection.isAuthenticated()) { return; } final Roster roster = Roster.getInstanceFor(connection); Async.go(new ThrowingRunnable() { @Override public void runOrThrow() throws NotLoggedInException, NotConnectedException, FeatureNotSupportedException, InterruptedException { if (roster.isSubscriptionPreApprovalSupported()) { roster.preApprove(newMasterAddress); } RosterUtil.askForSubscriptionIfRequired(roster, newMasterAddress); } }); }
public void removeAllContacts() throws SmackException.NotLoggedInException, InterruptedException, SmackException.NotConnectedException, XMPPException.XMPPErrorException, SmackException.NoResponseException { Roster roster = Roster.getInstanceFor(XMPPSession.getInstance().getXMPPConnection()); if (!roster.isLoaded()) { roster.reloadAndWait(); } for (RosterEntry entry : roster.getEntries()) { roster.removeEntry(entry); Presence presence = new Presence(Presence.Type.unsubscribe); presence.setTo(entry.getJid()); XMPPSession.getInstance().sendStanza(presence); } }
public HashMap<Jid, Presence.Type> getContacts() throws SmackException.NotLoggedInException, InterruptedException, SmackException.NotConnectedException { Roster roster = Roster.getInstanceFor(XMPPSession.getInstance().getXMPPConnection()); if (!roster.isLoaded()) { roster.reloadAndWait(); } String groupName = "Buddies"; RosterGroup group = roster.getGroup(groupName); if (group == null) { roster.createGroup(groupName); group = roster.getGroup(groupName); } HashMap<Jid, Presence.Type> buddies = new HashMap<>(); List<RosterEntry> entries = group.getEntries(); for (RosterEntry entry : entries) { BareJid jid = entry.getJid(); Presence.Type status = roster.getPresence(jid).getType(); buddies.put(jid, status); } return buddies; }
public HashMap<Jid, Presence.Type> getContactsWithSubscriptionPending() throws SmackException.NotLoggedInException, InterruptedException, SmackException.NotConnectedException { Roster roster = Roster.getInstanceFor(XMPPSession.getInstance().getXMPPConnection()); if (!roster.isLoaded()) { roster.reloadAndWait(); } String groupName = "Buddies"; RosterGroup group = roster.getGroup(groupName); if (group == null) { roster.createGroup(groupName); group = roster.getGroup(groupName); } HashMap<Jid, Presence.Type> buddiesPending = new HashMap<>(); List<RosterEntry> entries = group.getEntries(); for (RosterEntry entry : entries) { if (entry.isSubscriptionPending()) { BareJid jid = entry.getJid(); Presence.Type status = roster.getPresence(jid).getType(); buddiesPending.put(jid, status); } } return buddiesPending; }
/** * returns the roster for the current connection * * @return the roster and null if the roster cannot be accessed */ public Roster getRoster(){ if (connection != null && connection.isConnected()){ Log.d("DEBUG", "Success: returning roster."); return Roster.getInstanceFor(connection); }else{ Log.d("DEBUG", "Couldn't get the roster: No connection."); return null; } }
@Override public void entriesAdded(Collection<String> collection){ Roster roster = xmppManager.getRoster(); Collection<RosterEntry> entries = roster.getEntries(); for (RosterEntry entry : entries) presenceReceived(roster.getPresence(entry.getUser())); }
@Override public void entriesUpdated(Collection<String> collection){ Roster roster = xmppManager.getRoster(); Collection<RosterEntry> entries = roster.getEntries(); for (RosterEntry entry : entries) presenceReceived(roster.getPresence(entry.getUser())); }
/** * Check if given recipient is whether online or not. * * @param jid * @return true iff the provided JID is not null or empty and it is online. */ public boolean isRecipientOnline(String jid) { boolean isOnline = false; if (jid != null && !jid.isEmpty()) { String jidFinal = getFullJid(jid); Presence presence = Roster.getInstanceFor(connection).getPresence(jidFinal); if (presence != null) { isOnline = presence.isAvailable(); } } return isOnline; }
/** * Get online users from roster and store in onlineUsers */ private void getInitialOnlineUsers() { Roster roster = Roster.getInstanceFor(connection); Collection<RosterEntry> entries = roster.getEntries(); if (entries != null && !entries.isEmpty()) { for (RosterEntry entry : entries) { String jid = entry.getUser(); Presence presence = roster.getPresence(jid); if (presence != null) { XMPPError xmppError = presence.getError(); if (xmppError != null) { logger.error(xmppError.getDescriptiveText()); } else { try { if (presence.getType() == Type.available) { onlineUsers.add(jid.substring(0, jid.indexOf('@'))); } else if (presence.getType() == Type.unavailable) { onlineUsers.remove(jid.substring(0, jid.indexOf('@'))); } } catch (Exception e) { logger.error(e.getMessage(), e); } } } } } logger.debug("Online users: {}", onlineUsers.toString()); }
public void connect() throws IOException, XMPPException, SmackException { if (mConnection == null) { createConnection(); } if (!mConnection.isConnected()) { Logger.info(TAG, "Connecting to " + mAccount.getHost() + ":" + mAccount.getPort()); mConnection.connect(); Roster roster = Roster.getInstanceFor(mConnection); roster.removeRosterListener(this); roster.addRosterListener(this); roster.setSubscriptionMode(Roster.SubscriptionMode.accept_all); roster.setRosterLoadedAtLogin(true); } if (!mConnection.isAuthenticated()) { Logger.info(TAG, "Authenticating " + mAccount.getXmppJid()); mConnection.login(); PingManager.setDefaultPingInterval(XmppService.DEFAULT_PING_INTERVAL); PingManager pingManager = PingManager.getInstanceFor(mConnection); pingManager.registerPingFailedListener(this); ChatManager chatManager = ChatManager.getInstanceFor(mConnection); chatManager.removeChatListener(this); chatManager.addChatListener(this); DeliveryReceiptManager receipts = DeliveryReceiptManager.getInstanceFor(mConnection); receipts.setAutoReceiptMode(DeliveryReceiptManager.AutoReceiptMode.always); receipts.autoAddDeliveryReceiptRequests(); } mOwnAvatar = getAvatarFor(""); }
public void addContact(String remoteAccount, String alias) { try { Roster.getInstanceFor(mConnection).createEntry(remoteAccount, alias, null); XmppServiceBroadcastEventEmitter.broadcastContactAdded(remoteAccount); } catch (Exception exc) { Logger.error(TAG, "Error while adding contact: " + remoteAccount, exc); XmppServiceBroadcastEventEmitter.broadcastContactAddError(remoteAccount); } }
public void removeContact(String remoteAccount) { try { Roster roster = Roster.getInstanceFor(mConnection); RosterEntry entry = roster.getEntry(remoteAccount); roster.removeEntry(entry); clearConversationsWith(remoteAccount); XmppServiceBroadcastEventEmitter.broadcastContactRemoved(remoteAccount); } catch (Exception exc) { Logger.error(TAG, "Error while removing contact: " + remoteAccount, exc); } }
public void renameContact(String remoteAccount, String newAlias) { try { Roster roster = Roster.getInstanceFor(mConnection); RosterEntry entry = roster.getEntry(remoteAccount); entry.setName(newAlias); XmppServiceBroadcastEventEmitter.broadcastContactRenamed(remoteAccount, newAlias); } catch (Exception exc) { Logger.error(TAG, "Error while renaming contact: " + remoteAccount, exc); } }
@Override public void reconnectionSuccessful() { Logger.debug(TAG, "reconnection is successful"); XmppService.setConnected(true); try { sendPendingMessages(); Roster.getInstanceFor(mConnection).reload(); } catch (Exception exc) { Logger.info(TAG, "Failed to automatically send pending messages after reconnection"); } }
@Override public void entriesUpdated(Collection<String> addresses) { if (addresses == null || addresses.isEmpty()) { return; } Roster roster = Roster.getInstanceFor(mConnection); if (roster == null) { Logger.info(TAG, "entriesUpdated - No roster instance, skipping rebuild roster"); return; } ArrayList<XmppRosterEntry> entries = getRosterEntries(); if (entries == null || entries.isEmpty()) { Logger.info(TAG, "entriesUpdated - No roster entries. Skipping rebuild roster"); return; } for (String destination : addresses) { destination = getXmppJid(destination); RosterEntry entry = roster.getEntry(destination); XmppRosterEntry xmppRosterEntry = getRosterEntryFor(roster, entry); int index = entries.indexOf(xmppRosterEntry); if (index < 0) { entries.add(xmppRosterEntry); } else { entries.set(index, xmppRosterEntry); } } Collections.sort(entries); XmppServiceBroadcastEventEmitter.broadcastRosterChanged(); }
@Override public void entriesDeleted(Collection<String> addresses) { if (addresses == null || addresses.isEmpty()) { return; } for (String destination : addresses) { destination = getXmppJid(destination); sendUnsubscriptionRequestTo(destination); Roster roster = Roster.getInstanceFor(mConnection); if (roster == null) { Logger.info(TAG, "presenceChanged - No roster instance, skipping rebuild roster"); return; } ArrayList<XmppRosterEntry> entries = getRosterEntries(); if (entries == null || entries.isEmpty()) { Logger.info(TAG, "presenceChanged - No roster entries. Skipping rebuild roster"); return; } int index = entries.indexOf(new XmppRosterEntry().setXmppJID(destination)); if (index >= 0) { entries.remove(index); } } XmppServiceBroadcastEventEmitter.broadcastRosterChanged(); }
@Override public void presenceChanged(Presence presence) { Roster roster = Roster.getInstanceFor(mConnection); if (roster == null) { Logger.info(TAG, "presenceChanged - No roster instance, skipping rebuild roster"); return; } ArrayList<XmppRosterEntry> entries = getRosterEntries(); if (entries == null || entries.isEmpty()) { Logger.info(TAG, "presenceChanged - No roster entries. Skipping rebuild roster"); return; } String from = getXmppJid(presence.getFrom()); int index = entries.indexOf(new XmppRosterEntry().setXmppJID(from)); if (index < 0) { Logger.info(TAG, "Presence from " + from + " which is not in the roster. Skipping rebuild roster"); return; } Presence rosterPresence = roster.getPresence(from); entries.get(index) .setAvailable(rosterPresence.isAvailable()) .setPresenceMode(rosterPresence.getMode().ordinal()) .setPersonalMessage(rosterPresence.getStatus()); Collections.sort(entries); XmppServiceBroadcastEventEmitter.broadcastRosterChanged(); }
/** * Sends a roster to userID. All the entries of the roster will be sent to the * target user. * * @param roster the roster to send * @param targetUserID the user that will receive the roster entries * @throws NotConnectedException */ public void send(Roster roster, String targetUserID) throws NotConnectedException { // Create a new message to send the roster Message msg = new Message(targetUserID); // Create a RosterExchange Package and add it to the message RosterExchange rosterExchange = new RosterExchange(roster); msg.addExtension(rosterExchange); XMPPConnection connection = weakRefConnection.get(); // Send the message that contains the roster connection.sendStanza(msg); }
/** * Creates a new roster exchange package with the entries specified in roster. * * @param roster the roster to send to other XMPP entity. */ public RosterExchange(Roster roster) { // Add all the roster entries to the new RosterExchange for (RosterEntry rosterEntry : roster.getEntries()) { this.addRosterEntry(rosterEntry); } }
@Override public void onRosterLoaded(Roster roster) { Set<RosterEntry> entries = roster.getEntries(); LOGGER.info("loading "+entries.size()+" entries"); mHandler.onLoaded(entries.stream() .map(KonRosterListener::clientToModel) .collect(Collectors.toList())); mLoaded = true; }
public PresenceListener(Roster roster, RosterHandler handler) { mRoster = roster; mHandler = handler; ProviderManager.addExtensionProvider( PublicKeyPresence.ELEMENT_NAME, PublicKeyPresence.NAMESPACE, new PublicKeyPresence.Provider()); ProviderManager.addExtensionProvider( PresenceSignature.ELEMENT_NAME, PresenceSignature.NAMESPACE, new PresenceSignature.Provider()); }
private XmppIotDataControl(Context context) { mContext = context.getApplicationContext(); mXmppManager = XmppManager.getInstance(mContext); mSettings = Settings.getInstance(mContext); mXmppManager.addXmppConnectionStatusListener((ma) -> { Roster roster = Roster.getInstanceFor(ma.getConnection()); roster.addSubscribeListener((from, subRequest) -> { if (!mSettings.isIdentityModeApp()) return null; if (!mSettings.isMutualSubscriptionModeEnabled()) return null; if (from.equals(mSettings.getThingJid())) { return SubscribeListener.SubscribeAnswer.Approve; } return null; }); ma.addListener(new AbstractManagedXmppConnectionListener() { @Override public void authenticated(XMPPConnection connection, boolean resumed) { withMainActivity((ma) -> setGuiElements(ma, true)); if (resumed) return; if (!mSettings.isIdentityModeApp()) return; final EntityBareJid thingJid = mSettings.getThingJid(); XmppManager.emptyRoster(connection, thingJid); if (thingJid == null) return; IoTProvisioningManager provisioningManager = IoTProvisioningManager.getInstanceFor(connection); if (!provisioningManager.iAmFriendOf(thingJid)) { withMainActivity((ma) -> Toast.makeText(ma, "Trying to befriend " + thingJid, Toast.LENGTH_SHORT).show()); try { provisioningManager.sendFriendshipRequest(thingJid); } catch (SmackException.NotConnectedException | InterruptedException e) { LOGGER.log(Level.WARNING, "Could not befriend thing", e); } } else { LOGGER.info("We are already a friend of " + thingJid + ". Not sending friendship request."); } provisioningManager.addBecameFriendListener((friend, presence) -> { if (!mSettings.isIdentityModeApp()) return; withMainActivity((c) -> Toast.makeText(c, "We are now a friend of " + friend, Toast.LENGTH_SHORT).show()); }); provisioningManager.addWasUnfriendedListener((friend, presence) -> { if (!mSettings.isIdentityModeApp()) return; withMainActivity((c) -> Toast.makeText(c, "We are no longer a friend of " + friend, Toast.LENGTH_SHORT).show()); }); } @Override public void terminated() { withMainActivity((ma) -> setGuiElements(ma, false)); } }); }); }