Store labels for new events

pull/6301/head
Brendan Abolivier 2019-10-29 18:35:49 +00:00
parent 47f767269c
commit fa0dcbc8fa
No known key found for this signature in database
GPG Key ID: 1E015C145F1916CD
2 changed files with 22 additions and 1 deletions

View File

@ -138,3 +138,6 @@ class LimitBlockingTypes(object):
MONTHLY_ACTIVE_USER = "monthly_active_user"
HS_DISABLED = "hs_disabled"
LabelsField = "org.matrix.labels"

View File

@ -29,7 +29,7 @@ from prometheus_client import Counter, Histogram
from twisted.internet import defer
import synapse.metrics
from synapse.api.constants import EventTypes
from synapse.api.constants import EventTypes, LabelsField
from synapse.api.errors import SynapseError
from synapse.events import EventBase # noqa: F401
from synapse.events.snapshot import EventContext # noqa: F401
@ -1490,6 +1490,11 @@ class EventsStore(
self._handle_event_relations(txn, event)
# Store the labels for this event.
labels = event.content.get(LabelsField)
if labels:
self.insert_labels_for_event_txn(txn, event.event_id, labels)
# Insert into the room_memberships table.
self._store_room_members_txn(
txn,
@ -2477,6 +2482,19 @@ class EventsStore(
get_all_updated_current_state_deltas_txn,
)
def insert_labels_for_event_txn(self, txn, event_id, labels):
return self._simple_insert_many_txn(
txn=txn,
table="event_labels",
values=[
{
"event_id": event_id,
"label": label,
}
for label in labels
],
)
AllNewEventsResult = namedtuple(
"AllNewEventsResult",