Update the fix when using Facebook Menu to log out in a FeedDialog.

This commit is contained in:
AlanGusLive 2016-01-23 15:07:54 +01:00
Родитель 4bc7b1ebef
Коммит 0337b1a000
5 изменённых файлов: 176 добавлений и 118 удалений

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

@ -44,29 +44,29 @@ using namespace Windows::UI::Xaml::Navigation;
Dialogs::Dialogs()
{
InitializeComponent();
SetValue(_defaultViewModelProperty, ref new Platform::Collections::Map<String^, Object^>(std::less<String^>()));
auto navigationHelper = ref new Common::NavigationHelper(this);
SetValue(_navigationHelperProperty, navigationHelper);
navigationHelper->LoadState += ref new Common::LoadStateEventHandler(this, &Dialogs::LoadState);
navigationHelper->SaveState += ref new Common::SaveStateEventHandler(this, &Dialogs::SaveState);
InitializeComponent();
SetValue(_defaultViewModelProperty, ref new Platform::Collections::Map<String^, Object^>(std::less<String^>()));
auto navigationHelper = ref new Common::NavigationHelper(this);
SetValue(_navigationHelperProperty, navigationHelper);
navigationHelper->LoadState += ref new Common::LoadStateEventHandler(this, &Dialogs::LoadState);
navigationHelper->SaveState += ref new Common::SaveStateEventHandler(this, &Dialogs::SaveState);
}
DependencyProperty^ Dialogs::_defaultViewModelProperty =
DependencyProperty::Register("DefaultViewModel",
TypeName(IObservableMap<String^, Object^>::typeid), TypeName(Dialogs::typeid), nullptr);
TypeName(IObservableMap<String^, Object^>::typeid), TypeName(Dialogs::typeid), nullptr);
/// <summary>
/// Used as a trivial view model.
/// </summary>
IObservableMap<String^, Object^>^ Dialogs::DefaultViewModel::get()
{
return safe_cast<IObservableMap<String^, Object^>^>(GetValue(_defaultViewModelProperty));
return safe_cast<IObservableMap<String^, Object^>^>(GetValue(_defaultViewModelProperty));
}
DependencyProperty^ Dialogs::_navigationHelperProperty =
DependencyProperty::Register("NavigationHelper",
TypeName(Common::NavigationHelper::typeid), TypeName(Dialogs::typeid), nullptr);
TypeName(Common::NavigationHelper::typeid), TypeName(Dialogs::typeid), nullptr);
/// <summary>
/// Gets an implementation of <see cref="NavigationHelper"/> designed to be
@ -74,7 +74,7 @@ TypeName(Common::NavigationHelper::typeid), TypeName(Dialogs::typeid), nullptr);
/// </summary>
Common::NavigationHelper^ Dialogs::NavigationHelper::get()
{
return safe_cast<Common::NavigationHelper^>(GetValue(_navigationHelperProperty));
return safe_cast<Common::NavigationHelper^>(GetValue(_navigationHelperProperty));
}
#pragma region Navigation support
@ -90,12 +90,12 @@ Common::NavigationHelper^ Dialogs::NavigationHelper::get()
void Dialogs::OnNavigatedTo(NavigationEventArgs^ e)
{
NavigationHelper->OnNavigatedTo(e);
NavigationHelper->OnNavigatedTo(e);
}
void Dialogs::OnNavigatedFrom(NavigationEventArgs^ e)
{
NavigationHelper->OnNavigatedFrom(e);
NavigationHelper->OnNavigatedFrom(e);
}
#pragma endregion
@ -113,8 +113,8 @@ void Dialogs::OnNavigatedFrom(NavigationEventArgs^ e)
/// session. The state will be null the first time a page is visited.</param>
void Dialogs::LoadState(Object^ sender, Common::LoadStateEventArgs^ e)
{
(void) sender; // Unused parameter
(void) e; // Unused parameter
(void)sender; // Unused parameter
(void)e; // Unused parameter
}
/// <summary>
@ -125,61 +125,61 @@ void Dialogs::LoadState(Object^ sender, Common::LoadStateEventArgs^ e)
/// <param name="sender">The source of the event; typically <see cref="NavigationHelper"/></param>
/// <param name="e">Event data that provides an empty dictionary to be populated with
/// serializable state.</param>
void Dialogs::SaveState(Object^ sender, Common::SaveStateEventArgs^ e){
(void) sender; // Unused parameter
(void) e; // Unused parameter
void Dialogs::SaveState(Object^ sender, Common::SaveStateEventArgs^ e) {
(void)sender; // Unused parameter
(void)e; // Unused parameter
}
void Dialogs::Feed_Click(
Object^ sender,
Object^ sender,
RoutedEventArgs^ e
)
{
FBSession^ s = FBSession::ActiveSession;
if (s->AccessTokenData == nullptr)
{
OutputDebugString(L"User is not logged (access token was deleted).\n");
}
else
{
PropertySet^ params = ref new PropertySet();
params->Insert(L"caption", L"I love Brussels Sprouts!");
params->Insert(L"link", L"https://en.wikipedia.org/wiki/Brussels_sprout");
params->Insert(L"description", L"Om Nom Nom!");
if (!s->LoggedIn)
{
OutputDebugString(L"The user is no longer logged in.\n");
}
else
{
PropertySet^ params = ref new PropertySet();
params->Insert(L"caption", L"I love Brussels Sprouts!");
params->Insert(L"link", L"https://en.wikipedia.org/wiki/Brussels_sprout");
params->Insert(L"description", L"Om Nom Nom!");
create_task(s->ShowFeedDialogAsync(params))
.then([=](FBResult^ DialogResponse)
{
OutputDebugString(L"Showed 'Feed' dialog.\n");
});
}
create_task(s->ShowFeedDialogAsync(params))
.then([=](FBResult^ DialogResponse)
{
OutputDebugString(L"Showed 'Feed' dialog.\n");
});
}
}
void Dialogs::AppRequests_Click(
Object^ sender,
Object^ sender,
RoutedEventArgs^ e
)
{
FBSession^ s = FBSession::ActiveSession;
if (s->AccessTokenData == nullptr)
{
OutputDebugString(L"User is not logged (access token was deleted).\n");
}
else
{
PropertySet^ params = ref new PropertySet();
if (!s->LoggedIn)
{
OutputDebugString(L"The user is no longer logged in.\n");
}
else
{
PropertySet^ params = ref new PropertySet();
params->Insert(L"title", L"I love Brussels Sprouts!");
params->Insert(L"message", L"Om Nom Nom!");
params->Insert(L"title", L"I love Brussels Sprouts!");
params->Insert(L"message", L"Om Nom Nom!");
create_task(s->ShowRequestsDialogAsync(params))
.then([=](FBResult^ DialogResponse)
{
OutputDebugString(L"Showed 'Requests' dialog.\n");
});
}
create_task(s->ShowRequestsDialogAsync(params))
.then([=](FBResult^ DialogResponse)
{
OutputDebugString(L"Showed 'Requests' dialog.\n");
});
}
}

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

@ -41,37 +41,53 @@ using namespace Windows::UI::Xaml::Navigation;
Dialogs::Dialogs()
{
InitializeComponent();
InitializeComponent();
}
void LoginCpp::Dialogs::FeedDialogButton_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
FBSession^ s = FBSession::ActiveSession;
PropertySet^ params = ref new PropertySet();
params->Insert(L"caption", L"I love Brussels Sprouts!");
params->Insert(L"link", L"https://en.wikipedia.org/wiki/Brussels_sprout");
params->Insert(L"description", L"Om Nom Nom!");
create_task(s->ShowFeedDialogAsync(params))
.then([=](FBResult^ Response)
if (!s->LoggedIn)
{
OutputDebugString(L"Showed 'Feed' dialog.\n");
});
OutputDebugString(L"The user is no longer logged in.\n");
}
else
{
PropertySet^ params = ref new PropertySet();
params->Insert(L"caption", L"I love Brussels Sprouts!");
params->Insert(L"link", L"https://en.wikipedia.org/wiki/Brussels_sprout");
params->Insert(L"description", L"Om Nom Nom!");
create_task(s->ShowFeedDialogAsync(params))
.then([=](FBResult^ Response)
{
OutputDebugString(L"Showed 'Feed' dialog.\n");
});
}
}
void LoginCpp::Dialogs::AppRequestsButton_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
FBSession^ s = FBSession::ActiveSession;
PropertySet^ params = ref new PropertySet();
params->Insert(L"title", L"I love Brussels Sprouts!");
params->Insert(L"message", L"Om Nom Nom!");
create_task(s->ShowRequestsDialogAsync(params))
.then([=](FBResult^ Response)
if (!s->LoggedIn)
{
OutputDebugString(L"Showed 'Requests' dialog.\n");
});
OutputDebugString(L"The user is no longer logged in.\n");
}
else
{
PropertySet^ params = ref new PropertySet();
params->Insert(L"title", L"I love Brussels Sprouts!");
params->Insert(L"message", L"Om Nom Nom!");
create_task(s->ShowRequestsDialogAsync(params))
.then([=](FBResult^ Response)
{
OutputDebugString(L"Showed 'Requests' dialog.\n");
});
}
}

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

@ -44,29 +44,29 @@ using namespace Windows::UI::Xaml::Navigation;
Dialogs::Dialogs()
{
InitializeComponent();
SetValue(_defaultViewModelProperty, ref new Platform::Collections::Map<String^, Object^>(std::less<String^>()));
auto navigationHelper = ref new Common::NavigationHelper(this);
SetValue(_navigationHelperProperty, navigationHelper);
navigationHelper->LoadState += ref new Common::LoadStateEventHandler(this, &Dialogs::LoadState);
navigationHelper->SaveState += ref new Common::SaveStateEventHandler(this, &Dialogs::SaveState);
InitializeComponent();
SetValue(_defaultViewModelProperty, ref new Platform::Collections::Map<String^, Object^>(std::less<String^>()));
auto navigationHelper = ref new Common::NavigationHelper(this);
SetValue(_navigationHelperProperty, navigationHelper);
navigationHelper->LoadState += ref new Common::LoadStateEventHandler(this, &Dialogs::LoadState);
navigationHelper->SaveState += ref new Common::SaveStateEventHandler(this, &Dialogs::SaveState);
}
DependencyProperty^ Dialogs::_defaultViewModelProperty =
DependencyProperty::Register("DefaultViewModel",
TypeName(IObservableMap<String^, Object^>::typeid), TypeName(Dialogs::typeid), nullptr);
TypeName(IObservableMap<String^, Object^>::typeid), TypeName(Dialogs::typeid), nullptr);
/// <summary>
/// Used as a trivial view model.
/// </summary>
IObservableMap<String^, Object^>^ Dialogs::DefaultViewModel::get()
{
return safe_cast<IObservableMap<String^, Object^>^>(GetValue(_defaultViewModelProperty));
return safe_cast<IObservableMap<String^, Object^>^>(GetValue(_defaultViewModelProperty));
}
DependencyProperty^ Dialogs::_navigationHelperProperty =
DependencyProperty::Register("NavigationHelper",
TypeName(Common::NavigationHelper::typeid), TypeName(Dialogs::typeid), nullptr);
TypeName(Common::NavigationHelper::typeid), TypeName(Dialogs::typeid), nullptr);
/// <summary>
/// Gets an implementation of <see cref="NavigationHelper"/> designed to be
@ -74,7 +74,7 @@ TypeName(Common::NavigationHelper::typeid), TypeName(Dialogs::typeid), nullptr);
/// </summary>
Common::NavigationHelper^ Dialogs::NavigationHelper::get()
{
return safe_cast<Common::NavigationHelper^>(GetValue(_navigationHelperProperty));
return safe_cast<Common::NavigationHelper^>(GetValue(_navigationHelperProperty));
}
#pragma region Navigation support
@ -90,12 +90,12 @@ Common::NavigationHelper^ Dialogs::NavigationHelper::get()
void Dialogs::OnNavigatedTo(NavigationEventArgs^ e)
{
NavigationHelper->OnNavigatedTo(e);
NavigationHelper->OnNavigatedTo(e);
}
void Dialogs::OnNavigatedFrom(NavigationEventArgs^ e)
{
NavigationHelper->OnNavigatedFrom(e);
NavigationHelper->OnNavigatedFrom(e);
}
#pragma endregion
@ -113,8 +113,8 @@ void Dialogs::OnNavigatedFrom(NavigationEventArgs^ e)
/// session. The state will be null the first time a page is visited.</param>
void Dialogs::LoadState(Object^ sender, Common::LoadStateEventArgs^ e)
{
(void) sender; // Unused parameter
(void) e; // Unused parameter
(void)sender; // Unused parameter
(void)e; // Unused parameter
}
/// <summary>
@ -125,45 +125,60 @@ void Dialogs::LoadState(Object^ sender, Common::LoadStateEventArgs^ e)
/// <param name="sender">The source of the event; typically <see cref="NavigationHelper"/></param>
/// <param name="e">Event data that provides an empty dictionary to be populated with
/// serializable state.</param>
void Dialogs::SaveState(Object^ sender, Common::SaveStateEventArgs^ e){
(void) sender; // Unused parameter
(void) e; // Unused parameter
void Dialogs::SaveState(Object^ sender, Common::SaveStateEventArgs^ e) {
(void)sender; // Unused parameter
(void)e; // Unused parameter
}
void Dialogs::Feed_Click(
Object^ sender,
Object^ sender,
RoutedEventArgs^ e
)
{
FBSession^ s = FBSession::ActiveSession;
PropertySet^ params = ref new PropertySet();
params->Insert(L"caption", L"I love Brussels Sprouts!");
params->Insert(L"link", L"https://en.wikipedia.org/wiki/Brussels_sprout");
params->Insert(L"description", L"Om Nom Nom!");
create_task(s->ShowFeedDialogAsync(params))
.then([=](FBResult^ Response)
if (!s->LoggedIn)
{
OutputDebugString(L"Showed 'Feed' dialog.\n");
});
OutputDebugString(L"The user is no longer logged in.\n");
}
else
{
PropertySet^ params = ref new PropertySet();
params->Insert(L"caption", L"I love Brussels Sprouts!");
params->Insert(L"link", L"https://en.wikipedia.org/wiki/Brussels_sprout");
params->Insert(L"description", L"Om Nom Nom!");
create_task(s->ShowFeedDialogAsync(params))
.then([=](FBResult^ Response)
{
OutputDebugString(L"Showed 'Feed' dialog.\n");
});
}
}
void Dialogs::AppRequests_Click(
Object^ sender,
Object^ sender,
RoutedEventArgs^ e
)
{
FBSession^ s = FBSession::ActiveSession;
PropertySet^ params = ref new PropertySet();
params->Insert(L"title", L"I love Brussels Sprouts!");
params->Insert(L"message", L"Om Nom Nom!");
create_task(s->ShowRequestsDialogAsync(params))
.then([=](FBResult^ Response)
if (!s->LoggedIn)
{
OutputDebugString(L"Showed 'Requests' dialog.\n");
});
OutputDebugString(L"The user is no longer logged in.\n");
}
else
{
PropertySet^ params = ref new PropertySet();
params->Insert(L"title", L"I love Brussels Sprouts!");
params->Insert(L"message", L"Om Nom Nom!");
create_task(s->ShowRequestsDialogAsync(params))
.then([=](FBResult^ Response)
{
OutputDebugString(L"Showed 'Requests' dialog.\n");
});
}
}

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

@ -64,6 +64,11 @@ L"\"OAuthException\", \"code\": 4201, " \
L"\"error_user_msg\": \"User canceled the Dialog flow\"" \
L"}}";
const wchar_t* ErrorObjectJsonLogout = L"{\"error\": {\"message\": " \
L"\"Operation Canceled\", \"type\": " \
L"\"OAuthException\", \"code\": 4202, " \
L"\"error_user_msg\": \"User logged out\"" \
L"}}";
#ifdef _DEBUG
void DebugPrintLine(
@ -401,10 +406,10 @@ bool FacebookDialog::IsLoginSuccessRedirect(
}
bool FacebookDialog::IsLogoutRedirect(
Uri^ Response
)
Uri^ Response
)
{
return (String::CompareOrdinal(Response->Path, FACEBOOK_LOGOUT_PATH) == 0);
return (String::CompareOrdinal(Response->Path, FACEBOOK_LOGOUT_PATH) == 0);
}
bool FacebookDialog::IsDialogCloseRedirect(
@ -471,17 +476,17 @@ void FacebookDialog::dialogWebView_FeedNavStarting(
_dialogResponse = ref new FBResult(err);
}
}
else if (IsLogoutRedirect(e->Uri))
{
UninitDialog();
else if (IsLogoutRedirect(e->Uri))
{
UninitDialog();
DebugPrintLine(L"Feed response is " + e->Uri->DisplayUri);
FBSession^ sess = FBSession::ActiveSession;
sess->LogoutAsync();
DebugPrintLine(L"Feed response is " + e->Uri->DisplayUri);
FBSession^ sess = FBSession::ActiveSession;
sess->LogoutAsync();
FBError^ err = FBError::FromJson(ref new String(ErrorObjectJson));
_dialogResponse = ref new FBResult(err);
}
FBError^ err = FBError::FromJson(ref new String(ErrorObjectJsonLogout));
_dialogResponse = ref new FBResult(err);
}
else if (IsDialogCloseRedirect(e->Uri))
{
UninitDialog();
@ -516,6 +521,17 @@ void FacebookDialog::dialogWebView_RequestNavStarting(
_dialogResponse = ref new FBResult(err);
}
}
else if (IsLogoutRedirect(e->Uri))
{
UninitDialog();
DebugPrintLine(L"Request response is " + e->Uri->DisplayUri);
FBSession^ sess = FBSession::ActiveSession;
sess->LogoutAsync();
FBError^ err = FBError::FromJson(ref new String(ErrorObjectJsonLogout));
_dialogResponse = ref new FBResult(err);
}
else if (IsDialogCloseRedirect(e->Uri))
{
UninitDialog();
@ -543,6 +559,17 @@ void FacebookDialog::dialogWebView_SendNavStarting(
_dialogResponse = ref new FBResult(ref new FBSendRequest());
}
else if (IsLogoutRedirect(e->Uri))
{
UninitDialog();
DebugPrintLine(L"Request response is " + e->Uri->DisplayUri);
FBSession^ sess = FBSession::ActiveSession;
sess->LogoutAsync();
FBError^ err = FBError::FromJson(ref new String(ErrorObjectJsonLogout));
_dialogResponse = ref new FBResult(err);
}
else if (IsDialogCloseRedirect(e->Uri))
{
dialogWebBrowser->Stop();

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

@ -128,9 +128,9 @@ namespace winsdkfb
Windows::Foundation::Uri^ Response
);
bool IsLogoutRedirect(
Windows::Foundation::Uri^ Response
);
bool IsLogoutRedirect(
Windows::Foundation::Uri^ Response
);
bool IsDialogCloseRedirect(
Windows::Foundation::Uri^ Response