De-duplicate objects in the Telematrix import
This commit is contained in:
@@ -38,8 +38,14 @@ telematrix.close()
|
|||||||
telematrix_db_engine.dispose()
|
telematrix_db_engine.dispose()
|
||||||
|
|
||||||
portals = {}
|
portals = {}
|
||||||
|
chats = {}
|
||||||
|
messages = {}
|
||||||
|
puppets = {}
|
||||||
|
|
||||||
for chat_link in chat_links:
|
for chat_link in chat_links:
|
||||||
|
if type(chat_link.tg_room) is str:
|
||||||
|
print("Expected tg_room to be a number, got a string. Ignoring %s" % chat_link.tg_room)
|
||||||
|
continue
|
||||||
if chat_link.tg_room >= 0:
|
if chat_link.tg_room >= 0:
|
||||||
print("Unexpected unprefixed telegram chat ID: %s, ignoring..." % chat_link.tg_room)
|
print("Unexpected unprefixed telegram chat ID: %s, ignoring..." % chat_link.tg_room)
|
||||||
continue
|
continue
|
||||||
@@ -55,11 +61,9 @@ for chat_link in chat_links:
|
|||||||
|
|
||||||
portal = Portal(tgid=tgid, tg_receiver=tgid, peer_type=peer_type, megagroup=megagroup,
|
portal = Portal(tgid=tgid, tg_receiver=tgid, peer_type=peer_type, megagroup=megagroup,
|
||||||
mxid=chat_link.matrix_room)
|
mxid=chat_link.matrix_room)
|
||||||
portals[chat_link.tg_room] = portal
|
|
||||||
mxtg.add(portal)
|
|
||||||
|
|
||||||
bot_chat = BotChat(id=tgid, type=peer_type)
|
bot_chat = BotChat(id=tgid, type=peer_type)
|
||||||
mxtg.add(bot_chat)
|
portals[chat_link.tg_room] = portal
|
||||||
|
chats[tgid] = bot_chat
|
||||||
|
|
||||||
for tm_msg in messages:
|
for tm_msg in messages:
|
||||||
try:
|
try:
|
||||||
@@ -70,8 +74,18 @@ for tm_msg in messages:
|
|||||||
tg_space = portal.tgid if portal.peer_type == "channel" else args.bot_id
|
tg_space = portal.tgid if portal.peer_type == "channel" else args.bot_id
|
||||||
message = Message(mxid=tm_msg.matrix_event_id, mx_room=tm_msg.matrix_room_id,
|
message = Message(mxid=tm_msg.matrix_event_id, mx_room=tm_msg.matrix_room_id,
|
||||||
tgid=tm_msg.tg_message_id, tg_space=tg_space)
|
tgid=tm_msg.tg_message_id, tg_space=tg_space)
|
||||||
mxtg.add(message)
|
messages[tm_msg.matrix_event_id] = message
|
||||||
|
|
||||||
|
for user in tg_users:
|
||||||
|
puppets[user.tg_id] = Puppet(id=user.tg_id, displayname=user.name, displayname_source=args.bot_id)
|
||||||
|
|
||||||
|
for k, v in portals.items():
|
||||||
|
mxtg.add(v)
|
||||||
|
for k, v in chats.items():
|
||||||
|
mxtg.add(v)
|
||||||
|
for k, v in messages.items():
|
||||||
|
mxtg.add(v)
|
||||||
|
for k, v in puppets.items():
|
||||||
|
mxtg.add(v)
|
||||||
|
|
||||||
mxtg.add_all(Puppet(id=user.tg_id, displayname=user.name, displayname_source=args.bot_id)
|
|
||||||
for user in tg_users)
|
|
||||||
mxtg.commit()
|
mxtg.commit()
|
||||||
|
|||||||
Reference in New Issue
Block a user