private void TrackPurchase() { var builder = PurchaseData.CreateBuilder(); builder.WithProductId(_productId); builder.WithProductTitle(_productTitle); builder.WithPriceCurrency(_priceCurrency); builder.WithPrice(float.Parse(_priceStr)); if (_productTypeStr.Equals("item")) { builder.WithProductType(PurchaseData.ProductType.Item); } else { builder.WithProductType(PurchaseData.ProductType.Subscription); } builder.WithPurchaseDate(DateTime.Now); builder.WithPurchaseId(System.Guid.NewGuid().ToString()); if (GetSocial.TrackPurchaseEvent(builder.Build())) { _console.LogD("Purchase was tracked."); } else { _console.LogD("Purchase tracking failed."); }; }
void DrawMainSection() { DemoGuiUtils.DrawButton(_pnEnabled ? "Disable Push Notifications" : "Enable Push Notifications", TogglePNEnabled, style: GSStyles.Button); DemoGuiUtils.DrawButton("Change Language", () => _currentSection = SettingsSubSection.ChooseLanguage, style: GSStyles.Button); DemoGuiUtils.DrawButton("Print Device Identifier", () => _console.LogD("Device ID: " + GetSocial.Device.Identifier), style: GSStyles.Button); DemoGuiUtils.DrawButton("Set Global Error Listener", () => { var result = GetSocial.SetGlobalErrorListener(OnGlobalError); if (result) { _console.LogD("Successfully set global error listener"); } else { _console.LogE("Failed to set global error listener"); } }, style: GSStyles.Button); DemoGuiUtils.DrawButton("Remove Global Error Listener", () => { var result = GetSocial.RemoveGlobalErrorListener(); if (result) { _console.LogD("Successfully removed global error listener"); } else { _console.LogE("Failed to remove global error listener"); } }, style: GSStyles.Button); }
private void GetReferralData() { GetSocial.GetReferralData( referralData => { var logMessage = String.Empty; if (referralData != null) { logMessage += string.Format("Token: {0}\n", referralData.Token); logMessage += string.Format("Referrer user id: {0}\n", referralData.ReferrerUserId); logMessage += string.Format("Referrer channel: {0}\n", referralData.ReferrerChannelId); logMessage += string.Format("Is first match: {0}\n", referralData.IsFirstMatch); logMessage += string.Format("Is guarateed match: {0}\n", referralData.IsGuaranteedMatch); logMessage += "Referral Link params:\n" + referralData.ReferralLinkParams.ToDebugString(); } else { logMessage += "No referral data retrieved"; } _console.LogD("Referral data: \n" + logMessage); }, error => _console.LogE(string.Format("Failed to get referral data: {0}", error.Message)) ); }
private void OnUserAvatarClicked(User publicUser) { if (GetSocial.GetCurrentUser().Id.Equals(publicUser.Id)) { var popup = new MNPopup("Action", "Choose Action"); popup.AddAction("Show My Feed", () => OpenUserGlobalFeed(publicUser)); popup.AddAction("Cancel", () => { }); popup.Show(); } else { Communities.IsFriend(UserId.Create(publicUser.Id), isFriend => { if (isFriend) { var popup = new MNPopup("Action", "Choose Action"); popup.AddAction("Show " + publicUser.DisplayName + " Feed", () => OpenUserGlobalFeed(publicUser)); popup.AddAction("Remove from Friends", () => RemoveFriend(publicUser)); popup.AddAction("Cancel", () => { }); popup.Show(); } else { var popup = new MNPopup("Action", "Choose Action"); popup.AddAction("Show " + publicUser.DisplayName + " Feed", () => OpenUserGlobalFeed(publicUser)); popup.AddAction("Add to Friends", () => AddFriend(publicUser)); popup.AddAction("Cancel", () => { }); popup.Show(); } }, error => _console.LogE("Failed to check if friends with " + publicUser.DisplayName + ", error:" + error.Message)); } }
private void ShowActions(Activity activity) { var popup = Dialog().WithTitle("Actions"); popup.AddAction("Info", () => _console.LogD(activity.ToString())); popup.AddAction("Author", () => ShowActions(activity.Author)); popup.AddAction("Details View", () => Details(activity)); popup.AddAction("React", () => React(activity)); popup.AddAction("Reactions", () => ListReactions(activity)); if (!Comments) { popup.AddAction("Comments", () => ShowComments(activity)); popup.AddAction("Post Comment", () => PostComment(activity)); } if (activity.Author.Id.Equals(GetSocial.GetCurrentUser().Id)) { popup.AddAction("Edit", () => Edit(activity)); } else { popup.AddAction("Report as Spam", () => Report(activity, ReportingReason.Spam, "This activity is spam!")); popup.AddAction("Report as Inappropriate", () => Report(activity, ReportingReason.InappropriateContent, "This activity is inappropriate!")); } popup.AddAction("Cancel", () => { }); popup.Show(); }
private new void ShowActions(User user) { var popup = Dialog().WithTitle("Actions"); // Follow and friend functions are not available if `user` is current user if (!user.Id.Equals(GetSocial.GetCurrentUser().Id)) { if (_follows.ContainsKey(user.Id) && _follows[user.Id]) { popup.AddAction("Unfollow", () => Unfollow(user)); } else { popup.AddAction("Follow", () => Follow(user)); } if (_areFriends.ContainsKey(user.Id) && _areFriends[user.Id]) { popup.AddAction("Remove Friend", () => RemoveFriend(user)); } else { popup.AddAction("Add Friend", () => AddFriend(user)); } } popup.AddAction("Info", () => Print(user)); popup.AddAction("Followers", () => Followers(user)); popup.AddAction("Friends", () => Friends(user)); popup.AddAction("Feed", () => Feed(user)); popup.AddAction("All posts by", () => AllPosts(user)); popup.AddAction("Followed Topics", () => Topics(user)); popup.AddAction("Cancel", () => { }); popup.Show(); }
private Action OpenActivityDetailsFunc(bool showFeed) { return(() => { GetSocial.GetActivities(ActivitiesQuery.PostsForGlobalFeed().WithLimit(1), (posts) => { if (posts.Count == 0) { _console.LogW("No activities, post something to global feed!"); return; } #pragma warning disable 0618 GetSocialUi.CreateActivityDetailsView(posts.First().Id) .SetWindowTitle("Unity Global") .SetViewStateCallbacks(() => _console.LogD("Activity details opened"), () => _console.LogD("Activity details closed")) .SetButtonActionListener(OnActivityActionClicked) .SetActionListener(OnAction) .SetShowActivityFeedView(showFeed) .SetUiActionListener((action, pendingAction) => { Debug.Log("Action invoked: " + action); pendingAction(); }) .Show(); #pragma warning restore 0618 }, (error) => _console.LogE("Failed to get activities, error: " + error.Message)); }); }
void GetGlobalFeedAnnouncements() { GetSocial.GetGlobalFeedAnnouncements(announcements => { _console.LogD("Global feed announcements count: " + announcements.Count); _console.LogD(announcements.ToPrettyString()); }, OnError); }
void newFriend(string userId) { GetSocial.GetUserById(userId, user => { DemoUtils.ShowPopup("You have a new friend!", user.DisplayName + " is now your friend."); }, error => { _console.LogE("Failed to get user: "******", code: " + error.ErrorCode); }); }
public static void ClaimPromoCode(string code) { GetSocial.ClaimPromoCode(code, promoCode => { ShowFullInfoWithoutActions(promoCode, "Claim Promo Code"); }, error => { ShowAlert("Claim Promo Code", "Failed to claim promo code: " + error.Message); }); }
void GetLikers() { GetSocial.GetActivityLikers(_activityId, 0, 5, likers => { _console.LogD(string.Format("[{0}] Activity likers count: {1}", _activityId, likers.Count)); _console.LogD(likers.ToPrettyString()); }, OnError); }
void CreateInviteLink() { _console.LogD("Creating invite link..."); GetSocial.CreateInviteLink(null, (string inviteLink) => _console.LogD("Created invite link: " + inviteLink), error => _console.LogE(string.Format("Failed to create invite link: {0}", error.Message)) ); }
void SetLanguage(string languageCode) { var result = GetSocial.SetLanguage(languageCode); _console.LogD(result ? string.Format("Successfully set language to '{0}", GetSocial.GetLanguage()) : string.Format("Failed set language, current is '{0}'", GetSocial.GetLanguage())); }
void GetFeednnouncements() { GetSocial.GetAnnouncements(_feed, announcements => { _console.LogD(string.Format("[{0}] Feed announcements count: {1}", _feed, announcements.Count)); _console.LogD(announcements.ToPrettyString()); }, OnError); }
public void FetchCurrentUserData() { _currentUser = GetSocial.GetCurrentUser(); _avatar = Resources.Load <Texture2D> ("GUI/default_demo_avatar"); if (!string.IsNullOrEmpty(_currentUser?.AvatarUrl)) { StartCoroutine(DownloadAvatar(_currentUser.AvatarUrl)); } }
void LikeActivity() { GetSocial.LikeActivity(_activityId, _isLiked, activity => { _console.LogD(string.Format("Liked/Unliked [{0}] content: {1}", _activityId, activity.ToString())); }, OnError); }
private void OnMentionClicked(string mention) { if (mention == MentionShortcuts.App) { DemoUtils.ShowPopup("Mention", "Application mention clicked."); return; } GetSocial.GetUserById(mention, OnUserAvatarClicked, error => _console.LogE("Failed to get user details, error:" + error.Message)); }
private void OnApplicationPause(bool pauseStatus) { if (!pauseStatus) { GetSocial.WhenInitialized(() => { if (_latestChatId != null) { ShowChat(); } else { GetSocial.GetReferralData( data => { var referralToken = ""; var message = "Referral data: " + data; string promoCode = null; if (data == null) { message = "No referral data"; } else { promoCode = data.ReferralLinkParams.ContainsKey(LinkParams.KeyPromoCode) ? data.ReferralLinkParams[LinkParams.KeyPromoCode] : null; referralToken = data.Token; } if (!referralToken.Equals(_latestReferralData)) { // show popup only if chat is not shown if (_latestChatId == null) { if (promoCode != null) { message += "\n\nPROMO CODE: " + promoCode; } var popup = new MNPopup("Referral Data", message); popup.AddAction("OK", () => { }); if (promoCode != null) { popup.AddAction("Claim Promo Code", () => PromoCodesSection.ClaimPromoCode(promoCode)); } popup.Show(); } _console.LogD(message); _latestReferralData = referralToken; } }, error => _console.LogE("Failed to get referral data: " + error.Message) ); } }); } else { GetSocialUi.CloseView(false); } }
void SendCustomInvite(string channelId) { _console.LogD(string.Format("Sending custom {0} invite...", channelId)); GetSocial.SendInvite(channelId, CustomInviteContent, LinkParams, () => _console.LogD("Successfully sent invite"), () => _console.LogW("Sending invite cancelled"), error => _console.LogE(string.Format("Failed to send invite: {0}", error.Message)) ); }
private void LoadInfoAndShow(string code) { GetSocial.GetPromoCode(code, promoCode => { ShowFullInfo(promoCode); }, error => { ShowAlert("Promo Code Info", "Failed to get promo code: " + error.Message); _console.LogE(string.Format("Failed to get promo code: {0}", error.Message), showImmediately: false); }); }
void GetMyGlobalActivities() { var query = ActivitiesQuery.PostsForGlobalFeed().WithLimit(5).FilterByUser(GetSocial.User.Id); GetSocial.GetActivities(query, posts => { _console.LogD("Global feed posts count: " + posts.Count); _console.LogD(posts.ToPrettyString()); }, OnError); }
void GetFriendsGlobalActivities() { var query = ActivitiesQuery.PostsForGlobalFeed().WithLimit(5).FriendsFeed(true); GetSocial.GetActivities(query, posts => { _console.LogD("Global feed posts count: " + posts.Count); _console.LogD(posts.ToPrettyString()); }, OnError); }
void GetFeedActivitiesNoFilter() { var query = ActivitiesQuery.PostsForFeed(_feed).WithLimit(5); GetSocial.GetActivities(query, posts => { _console.LogD(string.Format("[{0}] Feed posts count: {1}", _feed, posts.Count)); _console.LogD(posts.ToPrettyString()); }, OnError); }
void RemoveFacebookUserIdentityInternal() { GetSocial.GetCurrentUser().RemoveIdentity(AuthIdentityProvider.Facebook, () => { _console.LogD("Successfully removed Facebook user identity"); demoController.FetchCurrentUserData(); }, error => _console.LogE("Removing Facebook identity failed, reason: " + error)); }
void GetFeedComments() { var query = ActivitiesQuery.CommentsToPost(_activityId).WithLimit(5); GetSocial.GetActivities(query, comments => { _console.LogD(string.Format("[{0}] Feed comments count: {1}", _feed, comments.Count)); _console.LogD(comments.ToPrettyString()); }, OnError); }
private MNPopup.MNPopupAction _ReportActivityById(ReportingReason reportingReason) { return(() => { GetSocial.ReportActivity(_activityId, reportingReason, () => { _console.LogD(string.Format("Activity {0} reported as {1}!", _activityId, reportingReason)); }, OnError); }); }
private void GetPromoCode() { GetSocial.GetPromoCode(_promoCode, promoCode => { ShowFullInfoWithoutActions(promoCode, "Get Promo Code"); }, error => { ShowAlert("Get Promo Code", "Failed to get promo code: " + error.Message); _console.LogE(string.Format("Failed to get promo code: {0}", error.Message), showImmediately: false); }); }
private void TrackCustomEvent(string eventName, Dictionary <string, string> eventProperties) { if (GetSocial.TrackCustomEvent(eventName, eventProperties)) { _console.LogD("Custom event was tracked"); } else { _console.LogD("Failed to track custom event."); }; }
void SwitchToCustomIdentityUser() { GetSocial.SwitchUser( Identity.Custom(CustomProviderId, _customUserId, _customProviderToken), () => { _console.LogD("Successfully switched to Custom provider user"); demoController.FetchCurrentUserData(); }, error => _console.LogE("Switching to custom provider user failed, reason: " + error)); }
private void GetReferredUsersV2() { var query = _referredEvent.Length == 0 ? ReferralUsersQuery.AllUsers() : ReferralUsersQuery.UsersForEvent(_referredEvent); GetSocial.GetReferredUsers(query, referralUsers => { DemoUtils.ShowPopup("Referred Users", GetReferralUsersInfo(referralUsers)); }, error => { _console.LogE(string.Format("Failed to get referred users: {0}", error.Message)); }); }