From 09ba5ee455bda97604d2c6b8610dc7b1166dd828 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 16 Apr 2020 15:45:07 -0700 Subject: [PATCH] ircd::m::join: Unify condition for bootstrap; fix bootstrap on invite. --- matrix/room_join.cc | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/matrix/room_join.cc b/matrix/room_join.cc index 2cc448abb..5caa6cd6a 100644 --- a/matrix/room_join.cc +++ b/matrix/room_join.cc @@ -8,6 +8,11 @@ // copyright notice and this permission notice is present in all copies. The // full license for this software is available in the LICENSE file. +namespace ircd::m +{ + static bool need_bootstrap(const room::id &); +} + ircd::m::event::id::buf ircd::m::join(const room::alias &room_alias, const user::id &user_id) @@ -23,7 +28,7 @@ ircd::m::join(const room::alias &room_alias, m::room_id(room_alias) }; - if(!exists(room_id)) + if(need_bootstrap(room_id)) { m::event::id::buf ret; m::room::bootstrap @@ -53,7 +58,7 @@ ircd::m::join(const m::room &room, }; // Branch for when nothing is known about the room. - if(!exists(room)) + if(need_bootstrap(room)) { // The bootstrap condcts a blocking make_join and issues a join // event, returning the event_id; afterward asynchronously it will @@ -135,3 +140,19 @@ ircd::m::join(const m::room &room, return commit(room, event, content); } + +bool +ircd::m::need_bootstrap(const room::id &room_id) +{ + // We have nothing for the room + if(!exists(room_id)) + return true; + + // No users are currently joined from this server; + //TODO: bootstrap shouldn't have to be used to re-sync a room where we have + //TODO: some partial state, so this condition should be eliminated. + if(local_joined(room_id) == 0) + return true; + + return false; +}