void TConnectionProcessor::received_request(const bts::bitchat::decrypted_message& msg)
{
  try
  {
    if(msg.from_key)
    {
      auto aBook = Profile->get_addressbook();
      fc::optional<bts::addressbook::wallet_contact> optContact;
      optContact = aBook->get_contact_by_public_key(*msg.from_key);

      if(!optContact ||
        (optContact && (*optContact).auth_status != bts::addressbook::authorization_status::i_block))
      {
        auto header = Profile->get_request_db()->store_message(msg, nullptr);
        auto req_msg = msg.as<bts::bitchat::private_contact_request_message>();
        Sink->OnReceivedAuthorizationMessage(req_msg, header);
      }
      else
        ilog("Received auth. message from blocked contact - ignoring");
    }
    else
    {
      elog("Received auth. message with missing sender key - ignoring");
    }
  }
  catch(const fc::exception& e)
  {
    elog("${e}", ("e", e.to_detail_string()));
  }
}
예제 #2
0
bool matchContact(const fc::ecc::public_key& pk, bts::addressbook::wallet_contact* matchedContact)
{
  assert(pk.valid());

  auto address_book = bts::get_profile()->get_addressbook();
  try
  {
    auto c = address_book->get_contact_by_public_key(pk);
    if(c)
    {
      *matchedContact = *c;
      return true;
    }
    else
    {
      *matchedContact = bts::addressbook::wallet_contact();
      matchedContact->public_key = pk;
      return false;
    }
  }
  catch (const fc::exception&)
  {
    *matchedContact = bts::addressbook::wallet_contact();
    matchedContact->public_key = pk;
    return false;
  }
}
void TConnectionProcessor::received_email(const bts::bitchat::decrypted_message& msg)
{
  try
  {
    bool allow = false;
    if(_mail_allow_flag)
    {
      if(isMyIdentity(*msg.from_key))
        allow = true;
      else
      {
        auto aBook = Profile->get_addressbook();
        fc::optional<bts::addressbook::wallet_contact> optContact;

        if(msg.from_key)
          optContact = aBook->get_contact_by_public_key(*msg.from_key);

        if(optContact)
          if((*optContact).auth_status == bts::addressbook::authorization_status::accepted ||
             (*optContact).auth_status == bts::addressbook::authorization_status::accepted_mail)
            allow = true;
      }
    }
    else
      allow = true;

    if(allow)
    {
      auto header = Profile->get_inbox_db()->store_message(msg, nullptr);
      wlog("email stored in database");
      Sink->OnReceivedMailMessage(header, false);
      wlog("gui notified");
      ReceivingMail = false;
    }
    else
    {
      if(_save_spam_flag)
      {
        wlog("email message moved to spam!");
        auto header = Profile->get_spam_db()->store_message(msg, nullptr);
        Sink->OnReceivedMailMessage(header, true);
        ReceivingMail = false;
      }
      else
        wlog("*** email message rejected!");
    }
  }
  catch(const fc::exception& e)
  {
    elog("${e}", ("e", e.to_detail_string()));
  }
}
예제 #4
0
void ContactListEdit::SetCollectedContacts(const IMailProcessor::TRecipientPublicKeys& storage)
  {
  auto profile = bts::get_profile();
  auto aBook = profile->get_addressbook();
  for(const auto& recipient : storage)
    {
    assert(recipient.valid());

    auto contact = aBook->get_contact_by_public_key(recipient);

    if(contact)
      {
      /** Use kID as completion here - it is slight violation against source list but we don't know
          here how it was originally entered (by kID or alias: fName lName)
      */
      QString entryText(toString(*contact));
      addContactEntry(entryText, *contact);
      }
    else
      {
      bool known = false;
      /// If no contact found try one of registered identities.
      std::vector<bts::addressbook::wallet_identity> identities = profile->identities();
      for(const auto& identity : identities)
        {
        assert(identity.public_key.valid());

        if(identity.public_key == recipient)
          {
          QString entryText(toString(identity));
          addContactEntry(entryText, identity);
          known = true;
          break;
          }
        }

      if(known == false)
        {
        /// Some unknown contact. Lets show its public key in the list.
        public_key_address pkAddress(recipient);
        std::string textPK(pkAddress);
        bts::addressbook::wallet_contact wc;
        wc.public_key = recipient;
        addContactEntry(QString(textPK.c_str()), wc);
        }
      }
    }
  }
예제 #5
0
bool ContactView::existContactWithPublicKey (const std::string& public_key_string)
{
   std::string my_public_key = public_key_address( _current_contact.public_key );
   if (public_key_string != my_public_key)
   {
      auto addressbook = bts::get_profile()->get_addressbook();
      if(! public_key_string.size()==0)
      {
         public_key_address key_address(public_key_string);
         auto findContact = addressbook->get_contact_by_public_key( key_address.key );
         if (findContact)
         {
            ui->id_status->setText( tr("This contact is already added to the list") );
            ui->id_status->setStyleSheet("QLabel { color : red; }");
            return true;
         }
      }     
   }
   return false;
}
void TConnectionProcessor::received_text(const bts::bitchat::decrypted_message& msg)
{
  try
  {
    auto aBook = Profile->get_addressbook();
    fc::optional<bts::addressbook::wallet_contact> optContact;

    if(msg.from_key)
      optContact = aBook->get_contact_by_public_key(*msg.from_key);

    if(optContact)
    {
      wlog("Received text from known contact!");
      if(!_chat_allow_flag ||
        (*optContact).auth_status == bts::addressbook::authorization_status::accepted ||
        (*optContact).auth_status == bts::addressbook::authorization_status::accepted_chat)
      {
        Profile->get_chat_db()->store_message(msg, nullptr);
        auto chatMsg = msg.as<bts::bitchat::private_text_message>();
        Sink->OnReceivedChatMessage(*optContact, chatMsg, msg.sig_time);
      }
      else
      {
        wlog("Chat message from known contact rejected!");
      }
    }
    else
    {
      elog("Received chat message from unknown contact/missing sender - ignoring");
    }
  }
  catch(const fc::exception& e)
  {
    elog("${e}", ("e", e.to_detail_string()));
  }
}
예제 #7
0
QString toString(const fc::ecc::public_key& pk, TContactTextFormatting contactFormatting,
  bts::addressbook::contact* matchingContact /*= nullptr*/, bool* isKnownContact /*= nullptr*/)
  {
  assert(pk.valid());

  auto address_book = bts::get_profile()->get_addressbook();
  auto c = address_book->get_contact_by_public_key(pk);
  if (c)
    {
    if(matchingContact != nullptr)
      *matchingContact = *c;
    if(isKnownContact != nullptr)
      *isKnownContact = true;

    switch(contactFormatting)
      {
      case KEYHOTEE_IDENTIFIER:
        return QString(c->dac_id_string.c_str());
      case CONTACT_ALIAS_FULL_NAME:
        return QString(std::string(c->first_name + " " + c->last_name).c_str());
      case FULL_CONTACT_DETAILS:
        return QString(c->get_display_name().c_str());
      default:
        assert(false);
        return QString();
      }
    }
  else
    {
    auto profile = bts::get_profile();
    /// If no contact found try one of registered identities.
    std::vector<bts::addressbook::wallet_identity> identities = profile->identities();
    for(const auto& identity : identities)
      {
      assert(identity.public_key.valid());

      if(identity.public_key == pk)
        {
        if(matchingContact != nullptr)
          *matchingContact = identity;
        if(isKnownContact != nullptr)
          *isKnownContact = true;

        switch(contactFormatting)
          {
          case KEYHOTEE_IDENTIFIER:
            return QString::fromStdString(identity.dac_id_string);
          case CONTACT_ALIAS_FULL_NAME:
            return QString::fromStdString(std::string(identity.first_name + " " + identity.last_name));
          case FULL_CONTACT_DETAILS:
            return QString::fromStdString(identity.get_display_name());
          default:
            assert(false);
            return QString();
          }
        break;
        }
      }

    if(matchingContact != nullptr)
      {
      *matchingContact = bts::addressbook::wallet_contact();
      matchingContact->public_key = pk;
      }

    if(isKnownContact != nullptr)
      *isKnownContact = false;

    /// If code reached this point the publick key is unknown - lets display it as base58
    return QString::fromStdString(pk.to_base58());
    }
  }