Add "user/dm/invite/revoke" and "user/dm/invite/decline"
This commit is contained in:
parent
017eb2501b
commit
69ccfd3421
5 changed files with 158 additions and 32 deletions
|
|
@ -10,20 +10,18 @@ namespace LarpixServer.Room;
|
|||
public class Requests
|
||||
{
|
||||
public static SemaphoreSlim createLock = new SemaphoreSlim(1, 1);
|
||||
public static async Task<string> DmInvite(string id, string username2)
|
||||
public static async Task<string> DmInvite(string id, string targetId)
|
||||
{
|
||||
if (!Account.Utils.IsUserLocal(username2, out string domain)) //federation
|
||||
if (!Account.Utils.IsUserLocal(targetId, out string domain)) //federation
|
||||
{
|
||||
|
||||
username2 = username2.Split(":")[0];
|
||||
string remoteId2 = await Federation.Sender.GetUserId(username2, domain);
|
||||
await Fs.WriteFile(ACCOUNTS_DATA_DIR + $"/{id}/dminvites/sent/{remoteId2};{domain}", Encoding.UTF8.GetBytes(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString()));
|
||||
return await Federation.Sender.DmInvite(id, domain, remoteId2);
|
||||
targetId = targetId.Split(":")[0];
|
||||
await Fs.WriteFile(ACCOUNTS_DATA_DIR + $"/{id}/dminvites/sent/{targetId};{domain}", Encoding.UTF8.GetBytes(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString()));
|
||||
return await Federation.Sender.DmInvite(id, domain, targetId);
|
||||
|
||||
}
|
||||
username2 = username2.Split(":")[0];
|
||||
string id2 = await Account.Utils.IdFromName(username2);
|
||||
if (id2 == "0")
|
||||
targetId = targetId.Split(":")[0];
|
||||
string id2 = targetId;
|
||||
if (id2 == "0" || string.IsNullOrEmpty(id2))
|
||||
{
|
||||
return "error:user.not.found";
|
||||
}
|
||||
|
|
@ -54,28 +52,80 @@ public class Requests
|
|||
|
||||
return "success:user.invited";
|
||||
}
|
||||
|
||||
public static async Task<string> DmInviteRevoke(string id, string targetId)
|
||||
{
|
||||
if (!Account.Utils.IsUserLocal(targetId, out string domain)) //federation
|
||||
{
|
||||
targetId = targetId.Split(":")[0];
|
||||
Fs.DeleteFile(ACCOUNTS_DATA_DIR + $"/{id}/dminvites/sent/{targetId};{domain}");
|
||||
return await Federation.Sender.DmInviteRevoke(id, domain, targetId);
|
||||
}
|
||||
targetId = targetId.Split(":")[0];
|
||||
string id2 = targetId;
|
||||
if (id2 == "0" || string.IsNullOrEmpty(id2)) return "error:user.not.found";
|
||||
|
||||
SemaphoreSlim userLock2 = Account.Utils.GetUserLock(id2);
|
||||
await userLock2.WaitAsync();
|
||||
try
|
||||
{
|
||||
Fs.DeleteFile(ACCOUNTS_DATA_DIR + $"/{id2}/dminvites/recv/{id}");
|
||||
Fs.DeleteFile(ACCOUNTS_DATA_DIR + $"/{id}/dminvites/sent/{id2}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
userLock2.Release();
|
||||
}
|
||||
|
||||
return "success:invite.revoked";
|
||||
}
|
||||
|
||||
public static async Task<string> DmInviteDecline(string id, string targetId)
|
||||
{
|
||||
if (!Account.Utils.IsUserLocal(targetId, out string domain)) //federation
|
||||
{
|
||||
targetId = targetId.Split(":")[0];
|
||||
Fs.DeleteFile(ACCOUNTS_DATA_DIR + $"/{id}/dminvites/recv/{targetId};{domain}");
|
||||
return await Federation.Sender.DmInviteDecline(id, domain, targetId);
|
||||
}
|
||||
targetId = targetId.Split(":")[0];
|
||||
string id2 = targetId;
|
||||
if (id2 == "0" || string.IsNullOrEmpty(id2)) return "error:user.not.found";
|
||||
|
||||
SemaphoreSlim userLock2 = Account.Utils.GetUserLock(id2);
|
||||
await userLock2.WaitAsync();
|
||||
try
|
||||
{
|
||||
Fs.DeleteFile(ACCOUNTS_DATA_DIR + $"/{id}/dminvites/recv/{id2}");
|
||||
Fs.DeleteFile(ACCOUNTS_DATA_DIR + $"/{id2}/dminvites/sent/{id}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
userLock2.Release();
|
||||
}
|
||||
|
||||
return "success:invite.declined";
|
||||
}
|
||||
|
||||
public static async Task<string> DmCreate(string id, string body)
|
||||
{
|
||||
await createLock.WaitAsync();
|
||||
try
|
||||
{
|
||||
Universal3String serializedBody = JsonSerializer.Deserialize( //1 is ID2 nameWD, 2 is creators dm key, 3 is key for ID2
|
||||
Universal3String serializedBody = JsonSerializer.Deserialize( //1 is targetId, 2 is creators dm key, 3 is key for ID2
|
||||
body,
|
||||
AppJsonSerializerContext.Default.Universal3String
|
||||
);
|
||||
|
||||
string username2 = serializedBody.string1;
|
||||
bool isUserLocal = Account.Utils.IsUserLocal(username2, out string domain);
|
||||
|
||||
string targetId = serializedBody.string1;
|
||||
bool isUserLocal = Account.Utils.IsUserLocal(targetId, out string domain);
|
||||
string id2;
|
||||
username2 = username2.Split(":")[0];
|
||||
if (isUserLocal)
|
||||
|
||||
targetId = targetId.Split(":")[0];
|
||||
id2 = targetId;
|
||||
if (id2 == "0" || string.IsNullOrEmpty(id2))
|
||||
{
|
||||
id2 = await Account.Utils.IdFromName(username2);
|
||||
}
|
||||
else //get id from federation
|
||||
{
|
||||
id2 = await Federation.Sender.GetUserId(username2, domain);
|
||||
return "error:user.not.found";
|
||||
}
|
||||
|
||||
if (isUserLocal)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue