forked from Telodendria/Telodendria
[ADD/UNTESTED] Set ServerPart on room creation
Not tested as of now!
This commit is contained in:
parent
9ffa37d7a7
commit
1753c2188b
3 changed files with 27 additions and 10 deletions
26
src/Room.c
26
src/Room.c
|
@ -63,15 +63,22 @@ struct Room
|
|||
};
|
||||
|
||||
static char *
|
||||
GenerateRoomId(void)
|
||||
GenerateRoomId(ServerPart s)
|
||||
{
|
||||
return StrRandom(32); /* TODO: Add extra room info somehow
|
||||
* (I don't feel like theres really a way to
|
||||
* get the server info where we're doing that.) */
|
||||
CommonID cid;
|
||||
char *string;
|
||||
|
||||
cid.sigil = '!';
|
||||
cid.local = StrRandom(32);
|
||||
cid.server = s;
|
||||
string = ParserRecomposeCommonID(cid);
|
||||
Free(cid.local);
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
Room *
|
||||
RoomCreate(Db * db, User *user, RoomCreateRequest * req)
|
||||
RoomCreate(Db * db, User *user, RoomCreateRequest * req, ServerPart s)
|
||||
{
|
||||
Room *room;
|
||||
char *version_string, *full_creator;
|
||||
|
@ -92,9 +99,9 @@ RoomCreate(Db * db, User *user, RoomCreateRequest * req)
|
|||
}
|
||||
room = Malloc(sizeof(Room));
|
||||
room->db = db;
|
||||
room->id = GenerateRoomId(); /* TODO: Check config. */
|
||||
room->creator.hostname = NULL;
|
||||
room->creator.port = NULL;
|
||||
room->creator.hostname = s.hostname ? StrDuplicate(s.hostname) : NULL;
|
||||
room->creator.port = s.port ? StrDuplicate(s.port) : NULL;
|
||||
room->id = GenerateRoomId(s);
|
||||
room->version = version_num;
|
||||
|
||||
room->state_ref = DbCreate(db, 3, "rooms", room->id, "state");
|
||||
|
@ -1350,6 +1357,9 @@ RoomEventSendV1(Room * room, HashMap * event)
|
|||
RoomAddEventV1(room, pdu);
|
||||
valid = true;
|
||||
|
||||
/* If it is a client event, we should make sure that we shout at
|
||||
* every other homeserver about our new event. */
|
||||
|
||||
finish:
|
||||
if (state)
|
||||
{
|
||||
|
|
|
@ -41,12 +41,17 @@ ROUTE_IMPL(RouteCreateRoom, path, argp)
|
|||
Db *db = args->matrixArgs->db;
|
||||
RoomCreateRequest parsed;
|
||||
User *user = NULL;
|
||||
Config cfg;
|
||||
ServerPart server;
|
||||
|
||||
char *token;
|
||||
char *err;
|
||||
|
||||
(void) path;
|
||||
|
||||
ConfigLock(db, &cfg);
|
||||
ParseServerPart(cfg.serverName, &server);
|
||||
|
||||
if (HttpRequestMethodGet(args->context) != HTTP_POST)
|
||||
{
|
||||
err = "Unknown request method.";
|
||||
|
@ -86,7 +91,7 @@ ROUTE_IMPL(RouteCreateRoom, path, argp)
|
|||
JsonFree(request);
|
||||
request = NULL;
|
||||
|
||||
if (!(room = RoomCreate(db, user, &parsed)))
|
||||
if (!(room = RoomCreate(db, user, &parsed, server)))
|
||||
{
|
||||
err = "Couldn't create room.";
|
||||
/* Consider another error status. */
|
||||
|
@ -102,5 +107,7 @@ finish:
|
|||
JsonFree(request);
|
||||
RoomUnlock(room);
|
||||
UserUnlock(user);
|
||||
ConfigUnlock(&cfg);
|
||||
ServerPartFree(server);
|
||||
return response;
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ typedef struct Room Room;
|
|||
* Create a new room in the given database using the given
|
||||
* RoomCreateRequest.
|
||||
*/
|
||||
extern Room * RoomCreate(Db *, User *, RoomCreateRequest *);
|
||||
extern Room * RoomCreate(Db *, User *, RoomCreateRequest *, ServerPart);
|
||||
|
||||
/**
|
||||
* Lock the existing room in the specified database,
|
||||
|
|
Loading…
Reference in a new issue