WIP
This commit is contained in:
45
user.go
45
user.go
@@ -617,32 +617,35 @@ func (user *User) syncPortals(createAll bool) {
|
||||
}
|
||||
|
||||
for _, chat := range chats {
|
||||
//var inCommunity, ok bool
|
||||
//if inCommunity, ok = existingKeys[chat.Portal.Key]; !ok || !inCommunity {
|
||||
//var inSpace, ok bool
|
||||
//if inSpace, ok = existingKeys[chat.Portal.Key]; !ok || !inCommunity {
|
||||
// inCommunity = user.addPortalToCommunity(chat.Portal)
|
||||
// if chat.Portal.IsPrivateChat() {
|
||||
// puppet := user.bridge.GetPuppetByGMID(chat.Portal.Key.GMID)
|
||||
// user.addPuppetToCommunity(puppet)
|
||||
// user.ad.addPuppetToCommunity(puppet)
|
||||
// }
|
||||
//}
|
||||
portalKeys = append(portalKeys, chat.Portal.Key)
|
||||
}
|
||||
user.log.Infoln("Read chat list, updating user-portal mapping")
|
||||
|
||||
err := user.SetPortalKeys(portalKeys)
|
||||
err := user.SetPortalKeys(portalKeys) //user.SetPortalKeys(portalKeys)
|
||||
if err != nil {
|
||||
user.log.Warnln("Failed to update user-portal mapping:", err)
|
||||
}
|
||||
sort.Sort(chats)
|
||||
_ = user.bridge.Config.Bridge.SyncDirectChatList
|
||||
|
||||
limit := user.bridge.Config.Bridge.HistorySync.MaxInitialConversations
|
||||
if limit < 0 {
|
||||
limit = len(chats)
|
||||
}
|
||||
user.log.Infoln("Syncing portals")
|
||||
|
||||
wg := sync.WaitGroup{}
|
||||
for i, chat := range chats {
|
||||
|
||||
wg.Add(1)
|
||||
go func(chat Chat, i int) {
|
||||
create := (int64(chat.LastMessageTime) >= user.lastReconnection && user.lastReconnection > 0) || i < len(chats)
|
||||
create := (int64(chat.LastMessageTime) >= user.lastReconnection && user.lastReconnection > 0) || i < limit
|
||||
if len(chat.Portal.MXID) > 0 || create || createAll {
|
||||
chat.Portal.Sync(user, chat.Group)
|
||||
//err := chat.Portal.BackfillHistory(user, chat.LastMessageTime)
|
||||
@@ -665,34 +668,6 @@ func (user *User) syncPortals(createAll bool) {
|
||||
}
|
||||
}
|
||||
|
||||
func (user *User) SetPortalKeys(newKeys []database.PortalKey) error {
|
||||
//database
|
||||
//tx := user.db.Begin()
|
||||
//ans := tx.Where("user_jid = ?", *user.jidPtr()).Delete(UserPortal{})
|
||||
//
|
||||
//if ans.Error != nil {
|
||||
// _ = tx.Rollback()
|
||||
// return ans.Error
|
||||
//}
|
||||
//
|
||||
//for _, key := range newKeys {
|
||||
// ans = tx.Create(&UserPortal{
|
||||
// UserJID: *user.jidPtr(),
|
||||
// PortalJID: key.JID,
|
||||
// PortalReceiver: key.Receiver,
|
||||
// InCommunity: key.InCommunity,
|
||||
// })
|
||||
// if ans.Error != nil {
|
||||
// _ = tx.Rollback()
|
||||
// return ans.Error
|
||||
// }
|
||||
//}
|
||||
|
||||
println("portalkey transaction complete")
|
||||
return nil
|
||||
//return tx.Commit().Error
|
||||
}
|
||||
|
||||
func (user *User) getDirectChats() map[id.UserID][]id.RoomID {
|
||||
res := make(map[id.UserID][]id.RoomID)
|
||||
privateChats := user.bridge.DB.Portal.FindPrivateChats(user.GMID)
|
||||
|
||||
Reference in New Issue
Block a user