mirror of
https://mau.dev/maunium/synapse.git
synced 2024-08-28 21:22:02 +00:00
Start adding storage for new events.
This commit is contained in:
parent
8e2d4c6da5
commit
1118f02689
@ -19,6 +19,9 @@ from synapse.api.events.room import (
|
|||||||
RoomMemberEvent, RoomTopicEvent, FeedbackEvent,
|
RoomMemberEvent, RoomTopicEvent, FeedbackEvent,
|
||||||
# RoomConfigEvent,
|
# RoomConfigEvent,
|
||||||
RoomNameEvent,
|
RoomNameEvent,
|
||||||
|
RoomJoinRulesEvent,
|
||||||
|
RoomPowerLevelsEvent,
|
||||||
|
RoomDefaultLevelEvent,
|
||||||
)
|
)
|
||||||
|
|
||||||
from synapse.util.logutils import log_function
|
from synapse.util.logutils import log_function
|
||||||
@ -129,6 +132,12 @@ class DataStore(RoomMemberStore, RoomStore,
|
|||||||
self._store_room_name_txn(txn, event)
|
self._store_room_name_txn(txn, event)
|
||||||
elif event.type == RoomTopicEvent.TYPE:
|
elif event.type == RoomTopicEvent.TYPE:
|
||||||
self._store_room_topic_txn(txn, event)
|
self._store_room_topic_txn(txn, event)
|
||||||
|
elif event.type == RoomJoinRulesEvent.TYPE:
|
||||||
|
self._store_join_rule(txn, event)
|
||||||
|
elif event.type == RoomPowerLevelsEvent.TYPE:
|
||||||
|
self._store_power_levels(txn, event)
|
||||||
|
elif event.type == RoomDefaultLevelEvent.TYPE:
|
||||||
|
self._store_default_level(txn, event)
|
||||||
|
|
||||||
vals = {
|
vals = {
|
||||||
"topological_ordering": event.depth,
|
"topological_ordering": event.depth,
|
||||||
|
@ -129,6 +129,51 @@ class RoomStore(SQLBaseStore):
|
|||||||
|
|
||||||
defer.returnValue(ret)
|
defer.returnValue(ret)
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
|
def get_room_join_rule(self, room_id):
|
||||||
|
sql = (
|
||||||
|
"SELECT join_rule FROM room_join_rules as r "
|
||||||
|
"INNER JOIN current_state_events as c "
|
||||||
|
"ON r.event_id = c.event_id "
|
||||||
|
"WHERE c.room_id = ? "
|
||||||
|
)
|
||||||
|
|
||||||
|
rows = yield self._execute(None, sql, room_id)
|
||||||
|
|
||||||
|
if len(rows) == 1:
|
||||||
|
defer.returnValue(rows[0][0])
|
||||||
|
else:
|
||||||
|
defer.returnValue(None)
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
|
def get_power_level(self, room_id, user_id):
|
||||||
|
sql = (
|
||||||
|
"SELECT level FROM room_power_levels as r "
|
||||||
|
"INNER JOIN current_state_events as c "
|
||||||
|
"ON r.event_id = c.event_id "
|
||||||
|
"WHERE c.room_id = ? AND r.user_id = ? "
|
||||||
|
)
|
||||||
|
|
||||||
|
rows = yield self._execute(None, sql, room_id, user_id)
|
||||||
|
|
||||||
|
if len(rows) == 1:
|
||||||
|
defer.returnValue(rows[0][0])
|
||||||
|
return
|
||||||
|
|
||||||
|
sql = (
|
||||||
|
"SELECT level FROM room_default_levels as r "
|
||||||
|
"INNER JOIN current_state_events as c "
|
||||||
|
"ON r.event_id = c.event_id "
|
||||||
|
"WHERE c.room_id = ? "
|
||||||
|
)
|
||||||
|
|
||||||
|
rows = yield self._execute(None, sql, room_id)
|
||||||
|
|
||||||
|
if len(rows) == 1:
|
||||||
|
defer.returnValue(rows[0][0])
|
||||||
|
else:
|
||||||
|
defer.returnValue(None)
|
||||||
|
|
||||||
def _store_room_topic_txn(self, txn, event):
|
def _store_room_topic_txn(self, txn, event):
|
||||||
self._simple_insert_txn(
|
self._simple_insert_txn(
|
||||||
txn,
|
txn,
|
||||||
@ -151,6 +196,41 @@ class RoomStore(SQLBaseStore):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _store_join_rule(txn, event):
|
||||||
|
self._simple_insert_txn(
|
||||||
|
txn,
|
||||||
|
"room_join_rules",
|
||||||
|
{
|
||||||
|
"event_id": event.event_id,
|
||||||
|
"room_id": event.room_id,
|
||||||
|
"join_rule": event.join_rule,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
def _store_power_levels(txn, event):
|
||||||
|
for user_id, level in event.content:
|
||||||
|
self._simple_insert_txn(
|
||||||
|
txn,
|
||||||
|
"room_power_levels",
|
||||||
|
{
|
||||||
|
"event_id": event.event_id,
|
||||||
|
"room_id": event.room_id,
|
||||||
|
"user_id": user_id,
|
||||||
|
"level": level
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
def _store_default_level(txn, event):
|
||||||
|
self._simple_insert_txn(
|
||||||
|
txn,
|
||||||
|
"room_default_levels",
|
||||||
|
{
|
||||||
|
"event_id": event.event_id,
|
||||||
|
"room_id": event.room_id,
|
||||||
|
"level": level
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class RoomsTable(Table):
|
class RoomsTable(Table):
|
||||||
table_name = "rooms"
|
table_name = "rooms"
|
||||||
|
@ -96,8 +96,40 @@ CREATE TABLE IF NOT EXISTS rooms(
|
|||||||
creator TEXT
|
creator TEXT
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS room_join_rules(
|
||||||
|
event_id TEXT NOT NULL,
|
||||||
|
room_id TEXT NOT NULL,
|
||||||
|
join_rule TEXT NOT NULL
|
||||||
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS room_join_rules_event_id ON room_join_rules(event_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS room_join_rules_room_id ON room_join_rules(room_id);
|
||||||
|
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS room_power_levels(
|
||||||
|
event_id TEXT NOT NULL,
|
||||||
|
room_id TEXT NOT NULL,
|
||||||
|
user_id TEXT NOT NULL,
|
||||||
|
level INTEGER NOT NULL
|
||||||
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS room_power_levels_event_id ON room_power_levels(event_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS room_power_levels_room_id ON room_power_levels(room_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS room_power_levels_room_user ON room_power_levels(room_id, user_id);
|
||||||
|
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS room_default_levels(
|
||||||
|
event_id TEXT NOT NULL,
|
||||||
|
room_id TEXT NOT NULL,
|
||||||
|
level INTEGER NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS room_default_levels_event_id ON room_default_levels(event_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS room_default_levels_room_id ON room_default_levels(room_id);
|
||||||
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS room_hosts(
|
CREATE TABLE IF NOT EXISTS room_hosts(
|
||||||
room_id TEXT NOT NULL,
|
room_id TEXT NOT NULL,
|
||||||
host TEXT NOT NULL,
|
host TEXT NOT NULL,
|
||||||
CONSTRAINT room_hosts_uniq UNIQUE (room_id, host) ON CONFLICT IGNORE
|
CONSTRAINT room_hosts_uniq UNIQUE (room_id, host) ON CONFLICT IGNORE
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS room_hosts_room_id ON room_hosts (room_id);
|
||||||
|
Loading…
Reference in New Issue
Block a user