Skip to content

Commit

Permalink
chore: Enable automatic room migration to direct chats in custompuppe…
Browse files Browse the repository at this point in the history
…t.go
  • Loading branch information
dodosan-89 committed Aug 2, 2024
1 parent 22017f9 commit 4e0c503
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
36 changes: 36 additions & 0 deletions custompuppet.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,39 @@ func (user *User) tryAutomaticDoublePuppeting() {
user.zlog.Info().Msg("Successfully automatically enabled double puppet")
}
}

func contains(slice []id.RoomID, item id.RoomID) bool {
for _, s := range slice {
if s == item {
return true
}
}
return false
}

func (user *User) tryAutomaticRoomMigrationToDirectChats() {
user.zlog.Debug().Msg("Trying to automatically migrate rooms to direct chats")

if !user.bridge.Config.Bridge.SyncDirectChatList {
user.zlog.Debug().Msg("Automatic room migration not enabled")
return
}

user.zlog.Debug().Msg("Automatic room migration enabled")

portals:= user.bridge.GetAllPortals()
directs:= user.getDirectChats()
userId:= user.GetMXID()
usersDirects:= directs[userId]
roomsToMigrate:= []id.RoomID{}

for _, portal:= range portals {
if !contains(usersDirects, portal.MXID) {
roomsToMigrate = append(roomsToMigrate, portal.MXID)
}
}

user.UpdateDirectChats(map[id.UserID][]id.RoomID{userId: roomsToMigrate})

user.zlog.Info().Msg("Successfully automatically migrated rooms to direct chats")
}
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ func (br *IMBridge) Start() {
br.ZLog.Debug().Msg("Finding bridge user")
br.user = br.loadDBUser()
br.user.tryAutomaticDoublePuppeting()
br.user.tryAutomaticRoomMigrationToDirectChats()

// If this bridge is in OnlyBackfill mode, then only run the backfill
// queue and the IPC listener, and not the new message listeners.
Expand Down

0 comments on commit 4e0c503

Please sign in to comment.