mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-02 09:06:06 -04:00
Combine SpamCheckerApi
with the more generic ModuleApi
. (#8464)
Lots of different module apis is not easy to maintain. Rather than adding yet another ModuleApi(hs, hs.get_auth_handler()) incantation, first add an hs.get_module_api() method and use it where possible.
This commit is contained in:
parent
01f82bfe32
commit
4f0637346a
10 changed files with 51 additions and 58 deletions
|
@ -12,19 +12,8 @@
|
|||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
import logging
|
||||
from enum import Enum
|
||||
|
||||
from twisted.internet import defer
|
||||
|
||||
from synapse.storage.state import StateFilter
|
||||
|
||||
MYPY = False
|
||||
if MYPY:
|
||||
import synapse.server
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class RegistrationBehaviour(Enum):
|
||||
"""
|
||||
|
@ -34,35 +23,3 @@ class RegistrationBehaviour(Enum):
|
|||
ALLOW = "allow"
|
||||
SHADOW_BAN = "shadow_ban"
|
||||
DENY = "deny"
|
||||
|
||||
|
||||
class SpamCheckerApi:
|
||||
"""A proxy object that gets passed to spam checkers so they can get
|
||||
access to rooms and other relevant information.
|
||||
"""
|
||||
|
||||
def __init__(self, hs: "synapse.server.HomeServer"):
|
||||
self.hs = hs
|
||||
|
||||
self._store = hs.get_datastore()
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def get_state_events_in_room(self, room_id: str, types: tuple) -> defer.Deferred:
|
||||
"""Gets state events for the given room.
|
||||
|
||||
Args:
|
||||
room_id: The room ID to get state events in.
|
||||
types: The event type and state key (using None
|
||||
to represent 'any') of the room state to acquire.
|
||||
|
||||
Returns:
|
||||
twisted.internet.defer.Deferred[list(synapse.events.FrozenEvent)]:
|
||||
The filtered state events in the room.
|
||||
"""
|
||||
state_ids = yield defer.ensureDeferred(
|
||||
self._store.get_filtered_current_state_ids(
|
||||
room_id=room_id, state_filter=StateFilter.from_types(types)
|
||||
)
|
||||
)
|
||||
state = yield defer.ensureDeferred(self._store.get_events(state_ids.values()))
|
||||
return state.values()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue