Fix user locks & change return strings to blah.blah.blah
This commit is contained in:
parent
9abd013e91
commit
7da97dbeb6
6 changed files with 56 additions and 49 deletions
|
|
@ -14,23 +14,24 @@ public class Requests
|
|||
{
|
||||
if (!Account.Utils.IsUserLocal(username2, out string domain)) //federation
|
||||
{
|
||||
SemaphoreSlim userLock = Account.Utils.GetUserLock(id);
|
||||
await userLock.WaitAsync();
|
||||
try
|
||||
{
|
||||
username2 = username2.Split(":")[0];
|
||||
string remoteId2 = await Federation.Sender.GetUserId(username2, domain);
|
||||
await Fs.WriteFile(ACCOUNTS_DATA_DIR + $"/{id}/dminvites/sent/{remoteId2};{domain}", []); //only save sent while federating
|
||||
return await Federation.Sender.DmInvite(id, domain, remoteId2);
|
||||
}
|
||||
finally
|
||||
{
|
||||
userLock.Release();
|
||||
}
|
||||
|
||||
username2 = username2.Split(":")[0];
|
||||
string remoteId2 = await Federation.Sender.GetUserId(username2, domain);
|
||||
await Fs.WriteFile(ACCOUNTS_DATA_DIR + $"/{id}/dminvites/sent/{remoteId2};{domain}", []); //only save sent while federating
|
||||
return await Federation.Sender.DmInvite(id, domain, remoteId2);
|
||||
|
||||
}
|
||||
username2 = username2.Split(":")[0];
|
||||
string id2 = await Account.Utils.IdFromName(username2);
|
||||
|
||||
if (id2 == "0")
|
||||
{
|
||||
return "error:user.not.found";
|
||||
}
|
||||
|
||||
if (id2 == id)
|
||||
{
|
||||
return "error:cant.invite.urself";
|
||||
}
|
||||
SemaphoreSlim userLock2 = Account.Utils.GetUserLock(id2);
|
||||
await userLock2.WaitAsync();
|
||||
|
||||
|
|
@ -39,7 +40,7 @@ public class Requests
|
|||
string inviteFile = ACCOUNTS_DATA_DIR + $"/{id2}/dminvites/recv/{id};{DOMAIN}";
|
||||
if (Fs.Exists(inviteFile))
|
||||
{
|
||||
return "User already invited";
|
||||
return "info:user.already.invited";
|
||||
}
|
||||
|
||||
await Fs.WriteFile(inviteFile, Encoding.UTF8.GetBytes("0"));
|
||||
|
|
@ -52,7 +53,7 @@ public class Requests
|
|||
userLock2.Release();
|
||||
}
|
||||
|
||||
return "User invited";
|
||||
return "success:user.invited";
|
||||
}
|
||||
|
||||
public static async Task<string> DmCreate(string id, string body)
|
||||
|
|
@ -93,7 +94,7 @@ public class Requests
|
|||
{
|
||||
if (!await Federation.Sender.HasSentDmInvite(id2, domain, id))
|
||||
{
|
||||
return "You can't create a DM without an invitation";
|
||||
return "error:cant.create.dm.without.invitation";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -123,7 +124,7 @@ public class Requests
|
|||
startingMessage.timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
|
||||
startingMessage.type = "larp.info";
|
||||
startingMessage.content =
|
||||
"At the beginning of a DM, you should always verify that the person you're talking to is the intended recipient";
|
||||
"dm.begin.notice";
|
||||
startingMessage.key = ""; //no key == NOT encrypted
|
||||
startingMessage.pervious = "";
|
||||
|
||||
|
|
@ -169,10 +170,10 @@ public class Requests
|
|||
catch (Exception e)
|
||||
{
|
||||
|
||||
return "Failed to accept DM. Ask for another invite";
|
||||
return "error:failed.accept.dm";
|
||||
}
|
||||
|
||||
return "DM accepted";
|
||||
return "success:dm.accepted";
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -181,6 +182,6 @@ public class Requests
|
|||
{
|
||||
createLock.Release();
|
||||
}
|
||||
return "You can't create a DM without an invitation";
|
||||
return "error:cant.create.dm.without.invitation";
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue