You are here

function messaging_account_build_destination in Messaging 7

Same name and namespace in other branches
  1. 6.4 messaging.module \messaging_account_build_destination()

Build destination object from user account (and create destination if not exists)

1 call to messaging_account_build_destination()
Messaging_Methods_Tests::testMessagingMethods in tests/messaging_methods.test
Test message sending callbacks for enabled plug-ins

File

./messaging.module, line 266

Code

function messaging_account_build_destination($account, $method = NULL, $address = NULL) {
  if ($account->uid) {
    if ($method && !$address) {
      $address = messaging_user_destination($account, $method);
    }
    if ($method && $address) {
      return Messaging_Destination::create_method($method, $address, $account->uid);
    }
    elseif (($fallback = messaging_method_default($account)) && $fallback != $method) {

      // Retry with new method
      return messaging_account_build_destination($account, $fallback);
    }
  }
  elseif ($method && $address) {

    // Anonymous users
    // @todo check the address doesn't belong to any user ???
    return Messaging_Destination::create_method($method, $address, 0);
  }
}