Compare commits
2 commits
eb2388a290
...
f7be24e615
| Author | SHA1 | Date | |
|---|---|---|---|
| f7be24e615 | |||
| 841dfdd37d |
3 changed files with 69 additions and 2 deletions
|
|
@ -852,6 +852,15 @@ 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;
|
||||||
|
|
|
||||||
|
|
@ -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}\": {{ \"timestamp\": {content}, \"receiver\": \"{userId}\" }}");
|
groupBuilder.Append($"\"{groupId};{userId}\": {{ \"timestamp\": {content}, \"receiver\": \"{userId}\", \"groupId\": \"{groupId}\" }}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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}\": {{ \"timestamp\": {content}, \"sender\": \"{userId}\" }}");
|
groupBuilder.Append($"\"{groupId};{userId}\": {{ \"timestamp\": {content}, \"sender\": \"{userId}\", \"groupId\": \"{groupId}\" }}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
groupBuilder.Append("}");
|
groupBuilder.Append("}");
|
||||||
|
|
|
||||||
|
|
@ -519,4 +519,62 @@ 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";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue