Expose full windows notification content (#156)

This commit is contained in:
Paul Liu 2017-05-22 16:37:51 -07:00 коммит произвёл Jason Sandlin
Родитель f9245f6a71
Коммит 0a7f5a8f4d
4 изменённых файлов: 44 добавлений и 17 удалений

Просмотреть файл

@ -53,27 +53,35 @@ public:
/// <summary>
/// Returns the xbox user id for the WNS event
/// </summary>
const string_t& xbox_user_id() const { return m_xbox_user_id; }
_XSAPIIMP const string_t& xbox_user_id() const { return m_xbox_user_id; }
/// <summary>
/// Returns the notification type
/// </summary>
const string_t& notification_type() const { return m_notification_type; }
_XSAPIIMP const string_t& notification_type() const { return m_notification_type; }
/// <summary>
/// Returns the full notification content
/// </summary>
_XSAPIIMP const string_t& notification_content() const { return m_notification_content; }
/// <summary>
/// Internal function
/// </summary>
xbox_live_wns_event_args(
_In_ string_t xbox_user_id,
_In_ string_t notification_type
_In_ string_t notification_type,
_In_ string_t notification_content
) :
m_xbox_user_id(std::move(xbox_user_id)),
m_notification_type(std::move(notification_type))
m_notification_type(std::move(notification_type)),
m_notification_content(std::move(notification_content))
{}
private:
string_t m_xbox_user_id;
string_t m_notification_type;
string_t m_notification_content;
};
class xbox_live_services_settings : public std::enable_shared_from_this<xbox_live_services_settings>
@ -153,7 +161,7 @@ public:
/// <summary>
/// Internal function
/// </summary>
void _Raise_wns_event(_In_ const string_t& xbox_user_id, _In_ const string_t& nofitication_type);
void _Raise_wns_event(_In_ const string_t& xbox_user_id, _In_ const string_t& nofitication_type, _In_ const string_t& content);
/// <summary>
/// Internal function

Просмотреть файл

@ -120,23 +120,31 @@ notification_service_windows::on_push_notification_recieved(
std::error_code errc;
if (args && args->RawNotification && args->RawNotification->Content)
{
auto parsedJson = web::json::value::parse(args->RawNotification->Content->Data(), errc);
string_t content = args->RawNotification->Content->Data();
auto parsedJson = web::json::value::parse(content, errc);
auto xboxLiveNotificationJson = utils::extract_json_field(parsedJson, _T("xboxLiveNotification"), errc, false);
auto notificationTypeString = utils::extract_json_string(xboxLiveNotificationJson, _T("notificationType"), errc);
auto xuid = utils::extract_json_string(xboxLiveNotificationJson, _T("userXuid"), errc);
LOGS_INFO << "Received WNS notification, type: " << notificationTypeString << ", xuid: " << xuid;
get_xsapi_singleton()->s_xboxServiceSettingsSingleton->_Raise_wns_event(xuid, notificationTypeString);
if (!errc && utils::str_icmp(notificationTypeString, _T("spop")) == 0)
if (!errc)
{
auto contextItor = m_userContexts.find(xuid);
if (contextItor != m_userContexts.end() && contextItor->second != nullptr && contextItor->second->user() != nullptr)
LOGS_INFO << "Received WNS notification, type: " << notificationTypeString << ", xuid: " << xuid;
get_xsapi_singleton()->s_xboxServiceSettingsSingleton->_Raise_wns_event(xuid, notificationTypeString, content);
if (utils::str_icmp(notificationTypeString, _T("spop")) == 0)
{
contextItor->second->refresh_token();
auto contextItor = m_userContexts.find(xuid);
if (contextItor != m_userContexts.end() && contextItor->second != nullptr && contextItor->second->user() != nullptr)
{
contextItor->second->refresh_token();
}
}
}
else
{
LOGS_ERROR << "Receiving WNS notification error: " << errc.value() << ", message: " << errc.message();
}
}
}

Просмотреть файл

@ -119,11 +119,11 @@ void xbox_live_services_settings::_Raise_logging_event(_In_ xbox_services_diagno
}
}
void xbox_live_services_settings::_Raise_wns_event(_In_ const string_t& xbox_user_id, _In_ const string_t& notification_type)
void xbox_live_services_settings::_Raise_wns_event(_In_ const string_t& xbox_user_id, _In_ const string_t& notification_type, const string_t& content)
{
std::lock_guard<std::mutex> lock(m_wnsEventLock);
xbox_live_wns_event_args arg(xbox_user_id, notification_type);
xbox_live_wns_event_args arg(xbox_user_id, notification_type, content);
for (auto& handler : m_wnsHandlers)
{
XSAPI_ASSERT(handler.second != nullptr);

Просмотреть файл

@ -32,6 +32,14 @@ Game::Game(const std::shared_ptr<DX::DeviceResources>& deviceResources) :
m_deviceResources->RegisterDeviceNotify(this);
m_sceneRenderer = std::unique_ptr<Renderer>(new Renderer(m_deviceResources));
m_user = std::make_shared< xbox::services::system::xbox_live_user >();
xbox::services::system::xbox_live_services_settings::get_singleton_instance()->add_wns_handler([this](xbox::services::system::xbox_live_wns_event_args args)
{
Log(L"WNS notification received.");
Log(L" type:" + args.notification_type());
Log(L" xuid:" + args.xbox_user_id());
Log(L" content:" + args.notification_content());
});
}
void Game::RegisterInputKeys()
@ -553,6 +561,7 @@ void Game::HandleSignInResult(
switch (result.status())
{
case xbox::services::system::sign_in_status::success:
Log(L"xuid: "+ m_user->xbox_user_id());
m_xboxLiveContext = std::make_shared< xbox::services::xbox_live_context >(m_user);
AddUserToSocialManager(m_user);
Log(L"Sign in succeeded");
@ -598,7 +607,9 @@ void Game::SignIn()
}
else
{
pThis->Log(L"Failed signing in.");
std::stringstream ss;
ss << "Failed signing in" << t.err().value() << " ,msg: " << t.err_message();
pThis->Log(utility::conversions::to_utf16string(ss.str()));
}
}, task_continuation_context::use_current());