Exemplo n.º 1
0
  private void addToRoster(String userJid, String username) {

    RosterContact rc = new RosterContact();
    rc.setJid(userJid);
    rc.setUsername(username);

    // Add Online to Roster
    XMPPRosterStorage rs = new XMPPRosterStorage();
    rs.addEntry(rc, XMPPConnectionHandler.getInstance().getConnection());

    // Add to Roster DB
    DbRosterRepository rosterRepository = new DbRosterRepository(context);
    if (!rosterRepository.containsRosterEntry(rc)) {

      rosterRepository.createRosterEntry(rc);
    }
  }
Exemplo n.º 2
0
  @Override
  public void onReceive(Context context, Intent intent) {

    this.context = context;

    String sender = intent.getStringExtra("subscribeSender");

    boolean inRoster = false;
    DbRosterRepository rosterRepo = new DbRosterRepository(context);
    List<RosterContact> rosterList = rosterRepo.getAllRosterEntrys();

    for (RosterContact rc : rosterList) {

      if (rc.getJid().equals(sender) || sender.contains(rc.getJid())) {

        inRoster = true;
      }
    }

    if (!inRoster) {

      DbPhoneBookRepository contactRepository = new DbPhoneBookRepository(context);
      List<HandyContact> handyContactList = contactRepository.getAllContacts();

      for (HandyContact hc : handyContactList) {

        if (sender.contains(HelperFunctions.getInstance().cleanNumber(hc.getNumber()))) {

          addToRoster(sender, hc.getName());
          showNotification(hc);
          break;
        } else {

          Log.d(TAG, sender + " nicht in der Kontaktliste.");
        }
      }
    }
  }