client: Make the room messages callback more specific.

This commit is contained in:
Damir Jelić 2019-06-10 15:52:22 +02:00
parent 1db93a731f
commit 71e672a431
2 changed files with 9 additions and 4 deletions

View File

@ -24,8 +24,9 @@ from jsonschema import Draft4Validator, FormatChecker, validators
from nio import (AsyncClient, ClientConfig, EncryptionError, KeysQueryResponse,
KeyVerificationEvent, KeyVerificationKey, KeyVerificationMac,
KeyVerificationStart, LocalProtocolError, MegolmEvent,
RoomEncryptedEvent, RoomMessage, SyncResponse,
RoomContextError)
RoomEncryptedEvent, SyncResponse,
RoomContextError, RoomMessageText, RoomMessageMedia,
RoomEncryptedMedia, RoomTopicEvent, RoomNameEvent)
from nio.crypto import Sas
from nio.store import SqliteStore
@ -144,7 +145,8 @@ class PanClient(AsyncClient):
)
self.add_event_callback(
self.store_message_cb,
RoomMessage
(RoomMessageText, RoomMessageMedia, RoomEncryptedMedia,
RoomTopicEvent, RoomNameEvent)
)
self.key_verificatins_tasks = []
self.key_request_tasks = []

View File

@ -15,7 +15,8 @@
import datetime
import tantivy
from nio import RoomMessageText, RoomNameEvent, RoomTopicEvent
from nio import (RoomMessageText, RoomNameEvent, RoomTopicEvent,
RoomMessageMedia, RoomEncryptedMedia)
def sanitize_room_id(room_id):
@ -118,6 +119,8 @@ class Index:
if isinstance(event, RoomMessageText):
doc.add_text(self.body_field, event.body)
elif isinstance(event, (RoomMessageMedia, RoomEncryptedMedia)):
doc.add_text(self.body_field, event.body)
elif isinstance(event, RoomNameEvent):
doc.add_text(self.name_field, event.name)
elif isinstance(event, RoomTopicEvent):