-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathBlockUserManager.cs
More file actions
118 lines (104 loc) · 3.64 KB
/
BlockUserManager.cs
File metadata and controls
118 lines (104 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Copyright (c) Meta Platforms, Inc. and affiliates.
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Oculus.Platform;
using Oculus.Platform.Models;
using UnityEngine;
namespace Meta.Multiplayer.Core
{
/// <summary>
/// Manages the blocked users for the current user. It uses the Blocked Users API from Oculus Platform to fetch
/// the blocked users list and then uses the blocking flow.
/// https://developer.oculus.com/documentation/unity/ps-blockingsdk/
/// </summary>
public class BlockUserManager
{
private static BlockUserManager s_instance;
public static BlockUserManager Instance
{
get
{
s_instance ??= new BlockUserManager();
return s_instance;
}
}
private HashSet<ulong> m_blockedUsers = new();
private BlockUserManager()
{
}
public async Task Initialize()
{
var message = await Users.GetBlockedUsers().Gen();
Debug.Log("EXTRACTING BLOCKED USER DATA");
if (message.IsError)
{
Debug.Log("Could not get the list of users blocked!");
Debug.LogError(message.GetError());
return;
}
while (message != null)
{
var blockedUsers = message.GetBlockedUserList();
foreach (var user in blockedUsers)
{
Debug.Log("Blocked User: " + user.Id);
_ = m_blockedUsers.Add(user.Id);
}
message = blockedUsers.HasNextPage ?
await Users.GetNextBlockedUserListPage(blockedUsers).Gen() :
null;
}
}
public bool IsUserBlocked(ulong userId)
{
return m_blockedUsers.Contains(userId);
}
public async void BlockUser(ulong userId, Action<ulong> onUserBlockedSuccessful = null)
{
if (m_blockedUsers.Contains(userId))
{
Debug.LogError($"{userId} is already blocked");
return;
}
var message = await Users.LaunchBlockFlow(userId).Gen();
if (message.IsError)
{
Debug.Log("Error when trying to block the user");
Debug.LogError(message.Data);
}
else
{
Debug.Log("Got result: DidBlock = " + message.Data.DidBlock + " DidCancel = " + message.Data.DidCancel);
if (message.Data.DidBlock)
{
_ = m_blockedUsers.Add(userId);
onUserBlockedSuccessful?.Invoke(userId);
}
}
}
public async void UnblockUser(ulong userId, Action<ulong> onUserUnblockedSuccessful = null)
{
if (!m_blockedUsers.Contains(userId))
{
Debug.LogError($"{userId} is already unblocked");
return;
}
var message = await Users.LaunchUnblockFlow(userId).Gen();
if (message.IsError)
{
Debug.Log("Error when trying to block the user");
Debug.LogError(message.Data);
}
else
{
Debug.Log("Got result: DidUnblock = " + message.Data.DidUnblock + " DidCancel = " + message.Data.DidCancel);
if (message.Data.DidUnblock)
{
_ = m_blockedUsers.Remove(userId);
onUserUnblockedSuccessful?.Invoke(userId);
}
}
}
}
}