add "user/invites/sent" and "user/invites/received" requests
This commit is contained in:
parent
33833c60ef
commit
93fd8312da
4 changed files with 49 additions and 11 deletions
|
|
@ -535,6 +535,18 @@ public class Requests
|
||||||
{
|
{
|
||||||
switch (serializedBody.string1)
|
switch (serializedBody.string1)
|
||||||
{
|
{
|
||||||
|
case "user/invites/sent":
|
||||||
|
await context.Response.WriteAsync(
|
||||||
|
Encryption.Encryption.EncryptString(
|
||||||
|
await Utils.GetUserSentInvites(id)
|
||||||
|
, password));
|
||||||
|
break;
|
||||||
|
case "user/invites/received":
|
||||||
|
await context.Response.WriteAsync(
|
||||||
|
Encryption.Encryption.EncryptString(
|
||||||
|
await Utils.GetUserReceivedInvites(id)
|
||||||
|
, password));
|
||||||
|
break;
|
||||||
case "user/key/update":
|
case "user/key/update":
|
||||||
await context.Response.WriteAsync(
|
await context.Response.WriteAsync(
|
||||||
Encryption.Encryption.EncryptString(
|
Encryption.Encryption.EncryptString(
|
||||||
|
|
|
||||||
|
|
@ -180,6 +180,35 @@ public class Utils
|
||||||
await Fs.WriteFile(path, Encoding.UTF8.GetBytes(newPassword));
|
await Fs.WriteFile(path, Encoding.UTF8.GetBytes(newPassword));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async Task<string> GetUserSentInvites(string id)
|
||||||
|
{
|
||||||
|
string path = $"{ACCOUNTS_DATA_DIR}/{id}/dminvites/sent";
|
||||||
|
if (!Fs.Exists(path))
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
string[] invites = Fs.ReadDirectory(path);
|
||||||
|
if (invites.Length == 0)
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return string.Join(",", invites);
|
||||||
|
}
|
||||||
|
public static async Task<string> GetUserReceivedInvites(string id)
|
||||||
|
{
|
||||||
|
string path = $"{ACCOUNTS_DATA_DIR}/{id}/dminvites/recv";
|
||||||
|
if (!Fs.Exists(path))
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
string[] invites = Fs.ReadDirectory(path);
|
||||||
|
if (invites.Length == 0)
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return string.Join(",", invites);
|
||||||
|
}
|
||||||
|
|
||||||
public static async Task UpdateUserKeys(string id, string body)
|
public static async Task UpdateUserKeys(string id, string body)
|
||||||
{
|
{
|
||||||
if (!Fs.Exists($"{ACCOUNTS_DATA_DIR}/{id}/secret"))
|
if (!Fs.Exists($"{ACCOUNTS_DATA_DIR}/{id}/secret"))
|
||||||
|
|
@ -250,7 +279,7 @@ public class Utils
|
||||||
string dms = "{";
|
string dms = "{";
|
||||||
foreach (var dmfile in Fs.ReadDirectory(path))
|
foreach (var dmfile in Fs.ReadDirectory(path))
|
||||||
{
|
{
|
||||||
dms += $"{Encoding.UTF8.GetString(await Fs.ReadFile(dmfile))},";
|
dms += $"{Encoding.UTF8.GetString(await Fs.ReadFile($"{path}/{dmfile}"))},";
|
||||||
}
|
}
|
||||||
|
|
||||||
return dms.Substring(0, dms.Length - 1) + "}";
|
return dms.Substring(0, dms.Length - 1) + "}";
|
||||||
|
|
|
||||||
|
|
@ -356,7 +356,7 @@ public class Fs
|
||||||
return Array.Empty<string>();
|
return Array.Empty<string>();
|
||||||
}
|
}
|
||||||
|
|
||||||
directoryData = Directory.GetFileSystemEntries(path, "*", SearchOption.TopDirectoryOnly);
|
directoryData = Directory.GetFileSystemEntries(path, "*", SearchOption.TopDirectoryOnly).Select(Path.GetFileName).ToArray();
|
||||||
dirCache[path] = directoryData;
|
dirCache[path] = directoryData;
|
||||||
return directoryData;
|
return directoryData;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,16 +37,14 @@ public class Requests
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string inviteFile = ACCOUNTS_DATA_DIR + $"/{id2}/dminvites/recv/{id};{DOMAIN}";
|
string inviteFile = ACCOUNTS_DATA_DIR + $"/{id2}/dminvites/recv/{id}";
|
||||||
if (Fs.Exists(inviteFile))
|
if (Fs.Exists(inviteFile))
|
||||||
{
|
{
|
||||||
return "info:user.already.invited";
|
return "info:user.already.invited";
|
||||||
}
|
}
|
||||||
|
|
||||||
await Fs.WriteFile(inviteFile, Encoding.UTF8.GetBytes("0"));
|
await Fs.WriteFile(inviteFile, Encoding.UTF8.GetBytes("0"));
|
||||||
|
await Fs.WriteFile(ACCOUNTS_DATA_DIR + $"/{id}/dminvites/sent/{id2}", []); //we should also save that this user invited someone, because listing sent invites is cool
|
||||||
//im not saving this like ts is litterally local scenario
|
|
||||||
//await Fs.WriteFile(inviteSentFile, []); //we should also save that this user invited someone, because this will act as dm accept verification while federating
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|
@ -81,14 +79,13 @@ public class Requests
|
||||||
|
|
||||||
if (isUserLocal)
|
if (isUserLocal)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
string inviteSentFile = ACCOUNTS_DATA_DIR + $"/{id2}/dminvites/sent/{id};{DOMAIN}";
|
string inviteSentFile = ACCOUNTS_DATA_DIR + $"/{id2}/dminvites/sent/{id}";
|
||||||
if (!Fs.Exists(inviteSentFile))
|
if (!Fs.Exists(inviteSentFile))
|
||||||
{
|
{
|
||||||
return "You can't create a DM without an invitation";
|
return "error:cant.create.dm.without.invitation";
|
||||||
}
|
}
|
||||||
Fs.DeleteFile(inviteSentFile);
|
Fs.DeleteFile(inviteSentFile);
|
||||||
*/ // local scenario, there is no need to check sent
|
|
||||||
}
|
}
|
||||||
else //check sent on federated server
|
else //check sent on federated server
|
||||||
{
|
{
|
||||||
|
|
@ -98,7 +95,7 @@ public class Requests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string inviteFile = ACCOUNTS_DATA_DIR + $"/{id}/dminvites/recv/{id2};{domain}";
|
string inviteFile = $"{ACCOUNTS_DATA_DIR}/{id}/dminvites/recv/{id2}" + (isUserLocal ? "" : $";{domain}");
|
||||||
if (Fs.Exists(inviteFile))
|
if (Fs.Exists(inviteFile))
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue