You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
898 B

from mongoengine import DateTimeField, Document, DynamicField, StringField, BooleanField
class Message(Document):
room_id = StringField(r'!.+:.+', required=True)
event_id = StringField(r'\$.+', required=True, unique_with='room_id')
sender = StringField(r'@.+:.+', required=True)
user_id = StringField(r'@.+:.+', required=False)
messageType = StringField(r'm\.room\.message', db_field='type', required=True)
timestamp = DateTimeField(required=True)
content = DynamicField(required=True)
verified = BooleanField(required=False)
decrypted = BooleanField(required=False)
def is_image(self):
return self.content.get('msgtype') == 'm.image'
def image_url(self):
return self.content['url'] if self.is_image() else None
def thumbnail_url(self):
return self.content['url'] if self.is_image() else None