25 lines
873 B
Python
25 lines
873 B
Python
from .utils import get_or_create as goc
|
|
import .models
|
|
from .chatlib import Listener as _l, Event as _e
|
|
|
|
# Default handlers will be given two parts each:
|
|
# 1) Mould the raw event into a parsed event (update internal state)
|
|
# 2) Identify event chains and dump them into the queue.
|
|
# I really don't recommend removing them. (But I won't stop you.)
|
|
|
|
def sync_f(client,event):
|
|
blob=event.raw_data
|
|
# This event never really gets any processed data in it.
|
|
for status in ['join','leave','invite']:
|
|
roomlist=blob.get('rooms',{status:{}}).get(status,{})
|
|
for rid,room in roomlist.items():
|
|
client.event_queue.add(_e('m.room',{'id':rid,'state':status},room))
|
|
sync=_l('m.sync',sync_f)
|
|
|
|
def room_f(client,event):
|
|
blob=event.raw_data
|
|
rid=event.data['id']
|
|
room=goc(lambda x:x.id==rid,client.account.rooms,models.Room(rid))
|
|
event.data=room
|
|
room.name=
|
|
room=_l('m.room',room_f) |