Compare commits

..

No commits in common. "f7be24e61511caedc69cc5a1ec49b8504e77aaf4" and "eb2388a290f546c8ea07dba92b7d1e1caea9b785" have entirely different histories.

3 changed files with 2 additions and 69 deletions

View file

@ -852,15 +852,6 @@ public static async Task Auth(HttpContext context, Func<Task> next, IQueryCollec
await context.Response.WriteAsync(Encryption.Encryption.EncryptString(await Room.Groups.GroupJoin(id, payload.string1, payload.string2), password)); await context.Response.WriteAsync(Encryption.Encryption.EncryptString(await Room.Groups.GroupJoin(id, payload.string1, payload.string2), password));
break; break;
} }
case "group/leave":
{
Universal2String payload = JsonSerializer.Deserialize(
serializedBody.string2,
AppJsonSerializerContext.Default.Universal2String
);
await context.Response.WriteAsync(Encryption.Encryption.EncryptString(await Room.Groups.GroupLeave(id, payload.string1), password));
break;
}
case "group/members": case "group/members":
await context.Response.WriteAsync(Encryption.Encryption.EncryptString(await Room.Groups.GroupMembers(id, serializedBody.string2), password)); await context.Response.WriteAsync(Encryption.Encryption.EncryptString(await Room.Groups.GroupMembers(id, serializedBody.string2), password));
break; break;

View file

@ -256,7 +256,7 @@ public class Utils
string content = Encoding.UTF8.GetString(await Fs.ReadFile($"{path}/{invite}")); string content = Encoding.UTF8.GetString(await Fs.ReadFile($"{path}/{invite}"));
if (!first) groupBuilder.Append(','); if (!first) groupBuilder.Append(',');
first = false; first = false;
groupBuilder.Append($"\"{groupId};{userId}\": {{ \"timestamp\": {content}, \"receiver\": \"{userId}\", \"groupId\": \"{groupId}\" }}"); groupBuilder.Append($"\"{groupId}\": {{ \"timestamp\": {content}, \"receiver\": \"{userId}\" }}");
} }
} }
groupBuilder.Append("}"); groupBuilder.Append("}");
@ -297,7 +297,7 @@ public class Utils
string content = Encoding.UTF8.GetString(await Fs.ReadFile($"{path}/{invite}")); string content = Encoding.UTF8.GetString(await Fs.ReadFile($"{path}/{invite}"));
if (!first) groupBuilder.Append(','); if (!first) groupBuilder.Append(',');
first = false; first = false;
groupBuilder.Append($"\"{groupId};{userId}\": {{ \"timestamp\": {content}, \"sender\": \"{userId}\", \"groupId\": \"{groupId}\" }}"); groupBuilder.Append($"\"{groupId}\": {{ \"timestamp\": {content}, \"sender\": \"{userId}\" }}");
} }
} }
groupBuilder.Append("}"); groupBuilder.Append("}");

View file

@ -519,62 +519,4 @@ public class Groups
await Fs.WriteFile(path, contentBytes); await Fs.WriteFile(path, contentBytes);
return "success:storage.entry.updated"; return "success:storage.entry.updated";
} }
public static async Task<string> GroupLeave(string userId, string groupId)
{
string[] parts = groupId.Split(';');
string id = parts[0];
string domain = parts.Length > 1 ? parts[1] : Utils.Utils.DOMAIN;
string groupPath = $"{Utils.Utils.ROOMS_DIR}/groups/{domain}/{id}";
if (!Fs.Exists(groupPath))
return "error:group.not.found";
string memberPath = $"{groupPath}/members/{userId};{Utils.Utils.DOMAIN}";
if (!Fs.Exists(memberPath))
return "error:not.a.member";
await Room.Requests.createLock.WaitAsync();
try
{
// Remove from members
Fs.DeleteFile(memberPath);
// Remove group from user's groups
string userGroupPath = $"{Utils.Utils.ACCOUNTS_DATA_DIR}/{userId}/groups/{id};{domain}";
if (Fs.Exists(userGroupPath))
{
Fs.DeleteFile(userGroupPath);
}
// Require new key
await Fs.WriteFile($"{groupPath}/keys/newrequired", Encoding.UTF8.GetBytes("true"));
// Add info message
Message msg = new();
msg.attachment = "";
msg.author = userId;
msg.timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
msg.type = "larp.info.leave";
msg.content = "{blah(group.left)}";
msg.key = "";
msg.pervious = "";
msg.responded = "";
ulong msgId = 0;
if (Fs.Exists($"{groupPath}/messages/last"))
{
msgId = ulong.Parse(Encoding.UTF8.GetString(await Fs.ReadFile($"{groupPath}/messages/last")));
msgId++;
}
await Fs.WriteFile($"{groupPath}/messages/last", Encoding.UTF8.GetBytes(msgId.ToString()));
await Fs.WriteFile($"{groupPath}/messages/{msgId}", Encoding.UTF8.GetBytes(JsonSerializer.Serialize(msg, AppJsonSerializerContext.Default.Message)));
}
finally
{
Room.Requests.createLock.Release();
}
return "success";
}
} }