optimizations and bug fixes:
- Fixed directory cache bug in Fs - Optimized DmId creation - Optimized most splits
This commit is contained in:
parent
1e40db62a4
commit
ab89f07493
5 changed files with 117 additions and 110 deletions
|
|
@ -65,15 +65,22 @@ public class Requests
|
|||
|
||||
public static async Task<string> DmInvite(string id, string targetId)
|
||||
{
|
||||
if (!Account.Utils.IsUserLocal(targetId, out string domain)) //federation
|
||||
bool isLocal = Account.Utils.IsUserLocal(targetId, out string domain);
|
||||
string tId = Account.Utils.GetIdFromUsernameWD(targetId);
|
||||
|
||||
string checkDmId = Account.Utils.GetDmId(id, DOMAIN, tId, domain);
|
||||
if (Fs.Exists($"{ROOMS_DIR}/dms/{DOMAIN}/{checkDmId}"))
|
||||
{
|
||||
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);
|
||||
|
||||
return "error:dm.already.exists";
|
||||
}
|
||||
targetId = targetId.Split(":")[0];
|
||||
string id2 = targetId;
|
||||
|
||||
if (!isLocal) //federation
|
||||
{
|
||||
await Fs.WriteFile(ACCOUNTS_DATA_DIR + $"/{id}/dminvites/sent/{tId};{domain}", Encoding.UTF8.GetBytes(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString()));
|
||||
return await Federation.Sender.DmInvite(id, domain, tId);
|
||||
}
|
||||
|
||||
string id2 = tId;
|
||||
if (id2 == "0" || string.IsNullOrEmpty(id2))
|
||||
{
|
||||
return "error:user.not.found";
|
||||
|
|
@ -108,14 +115,16 @@ public class Requests
|
|||
|
||||
public static async Task<string> DmInviteRevoke(string id, string targetId)
|
||||
{
|
||||
if (!Account.Utils.IsUserLocal(targetId, out string domain)) //federation
|
||||
bool isLocal = Account.Utils.IsUserLocal(targetId, out string domain);
|
||||
string tId = Account.Utils.GetIdFromUsernameWD(targetId);
|
||||
|
||||
if (!isLocal) //federation
|
||||
{
|
||||
targetId = targetId.Split(":")[0];
|
||||
Fs.DeleteFile(ACCOUNTS_DATA_DIR + $"/{id}/dminvites/sent/{targetId};{domain}");
|
||||
return await Federation.Sender.DmInviteRevoke(id, domain, targetId);
|
||||
Fs.DeleteFile(ACCOUNTS_DATA_DIR + $"/{id}/dminvites/sent/{tId};{domain}");
|
||||
return await Federation.Sender.DmInviteRevoke(id, domain, tId);
|
||||
}
|
||||
targetId = targetId.Split(":")[0];
|
||||
string id2 = targetId;
|
||||
|
||||
string id2 = tId;
|
||||
if (id2 == "0" || string.IsNullOrEmpty(id2)) return "error:user.not.found";
|
||||
|
||||
SemaphoreSlim userLock2 = Account.Utils.GetUserLock(id2);
|
||||
|
|
@ -135,14 +144,16 @@ public class Requests
|
|||
|
||||
public static async Task<string> DmInviteDecline(string id, string targetId)
|
||||
{
|
||||
if (!Account.Utils.IsUserLocal(targetId, out string domain)) //federation
|
||||
bool isLocal = Account.Utils.IsUserLocal(targetId, out string domain);
|
||||
string tId = Account.Utils.GetIdFromUsernameWD(targetId);
|
||||
|
||||
if (!isLocal) //federation
|
||||
{
|
||||
targetId = targetId.Split(":")[0];
|
||||
Fs.DeleteFile(ACCOUNTS_DATA_DIR + $"/{id}/dminvites/recv/{targetId};{domain}");
|
||||
return await Federation.Sender.DmInviteDecline(id, domain, targetId);
|
||||
Fs.DeleteFile(ACCOUNTS_DATA_DIR + $"/{id}/dminvites/recv/{tId};{domain}");
|
||||
return await Federation.Sender.DmInviteDecline(id, domain, tId);
|
||||
}
|
||||
targetId = targetId.Split(":")[0];
|
||||
string id2 = targetId;
|
||||
|
||||
string id2 = tId;
|
||||
if (id2 == "0" || string.IsNullOrEmpty(id2)) return "error:user.not.found";
|
||||
|
||||
SemaphoreSlim userLock2 = Account.Utils.GetUserLock(id2);
|
||||
|
|
@ -172,15 +183,19 @@ public class Requests
|
|||
|
||||
string targetId = serializedBody.string1;
|
||||
bool isUserLocal = Account.Utils.IsUserLocal(targetId, out string domain);
|
||||
string id2;
|
||||
string id2 = Account.Utils.GetIdFromUsernameWD(targetId);
|
||||
|
||||
targetId = targetId.Split(":")[0];
|
||||
id2 = targetId;
|
||||
if (id2 == "0" || string.IsNullOrEmpty(id2))
|
||||
{
|
||||
return "error:user.not.found";
|
||||
}
|
||||
|
||||
string checkDmId = Account.Utils.GetDmId(id, DOMAIN, id2, domain);
|
||||
if (Fs.Exists($"{ROOMS_DIR}/dms/{DOMAIN}/{checkDmId}"))
|
||||
{
|
||||
return "error:dm.already.exists";
|
||||
}
|
||||
|
||||
Universal2String keys = JsonSerializer.Deserialize( //we need to pull keys before we do anything, because if user do NOT have them, dm creation will crash
|
||||
await Account.Utils.GetUserKeys(id),
|
||||
AppJsonSerializerContext.Default.Universal2String
|
||||
|
|
@ -214,9 +229,7 @@ public class Requests
|
|||
|
||||
|
||||
//best dmId creation ever
|
||||
List<string> users = new List<string>(){$"{id};{DOMAIN}", $"{id2};{domain}"};
|
||||
users.Sort();
|
||||
string dmId = $"{users[0]}_{users[1]}";
|
||||
string dmId = checkDmId;
|
||||
|
||||
|
||||
Fs.CreateDirectory($"{ROOMS_DIR}/dms/{DOMAIN}/{dmId}/members");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue