1using UnityEngine;
2using PM.horizOn.Cloud.Core;
3using PM.horizOn.Cloud.Manager;
4
5// Existing SDK/project configuration and authenticated player session required.
6// Call RunReviewedAction explicitly after reviewing this example and its data.
7// 시간 초과나 충돌 후 새로 읽고 의도를 확인하세요. 새 리비전으로 자동 재시도하지 마세요.
8public sealed class FriendsDemo : MonoBehaviour
9{
10 public async void RunReviewedAction()
11 {
12 var sessionUser = UserManager.Instance.CurrentUser;
13 if (sessionUser == null || !sessionUser.IsValid()) return;
14 var userId = UserManager.Instance.CurrentUser.UserId;
15 var manager = FriendsManager.Instance;
16 var loaded = await manager.GetFriends(userId);
17 if (!loaded.IsSuccess) { Debug.LogWarning(loaded.ErrorCode); return; }
18 Debug.Log(loaded.Data.friendCode); // Public identifier, not a credential.
19 foreach (var friend in loaded.Data.friends)
20 Debug.Log(friend.display.name + ": " + (friend.lastActiveAt ?? "unknown"));
21
22 // Invoke only after the player explicitly reviews this snapshot and chooses an action.
23 async System.Threading.Tasks.Task ApplyReviewed(string action, string targetUserId,
24 long expectedRevision, string requestId = null)
25 {
26 var result = action switch {
27 "request" => await manager.SendRequest(userId, targetUserId, expectedRevision),
28 "accept" => await manager.AcceptRequest(userId, targetUserId, expectedRevision, requestId),
29 "decline" => await manager.DeclineRequest(userId, targetUserId, expectedRevision, requestId),
30 "cancel" => await manager.CancelRequest(userId, targetUserId, expectedRevision, requestId),
31 "remove" => await manager.RemoveFriend(userId, targetUserId, expectedRevision),
32 "block" => await manager.BlockPlayer(userId, targetUserId, expectedRevision),
33 "unblock" => await manager.UnblockPlayer(userId, targetUserId, expectedRevision),
34 _ => throw new System.ArgumentException("Unknown action")
35 };
36 if (!result.IsSuccess) {
37 Debug.LogWarning(result.ErrorCode); // Timeout/409: reload and reconcile; do not repeat automatically.
38 return;
39 }
40 Debug.Log(result.Data.revision); // Replace the whole displayed snapshot.
41 }
42 // Accept/decline: original incoming requestId. Cancel: original outgoing requestId.
43 // Never replace expectedRevision on an uncertain retry. A new request is a new identity.
44 // FindPlayer(userId, exactUuidOrHCode) never searches names or emails.
45 // Last login is nullable, never an online flag. No hidden polling timer.
46 }
47}