undo some changes I made

This commit is contained in:
Annie Elequin 2021-09-17 12:46:17 -04:00
parent a2f0042536
commit da6b214abb
2 changed files with 5 additions and 48 deletions

View File

@ -190,25 +190,6 @@ type Portal struct {
const MaxMessageAgeToCreatePortal = 5 * 60 // 5 minutes
func (portal *Portal) syncDoublePuppetDetailsAfterCreate(source *User) {
doublePuppet := portal.bridge.GetPuppetByCustomMXID(source.MXID)
if doublePuppet == nil {
return
}
source.Conn.Store.ChatsLock.RLock()
chat, ok := source.Conn.Store.Chats[portal.Key.JID]
source.Conn.Store.ChatsLock.RUnlock()
if !ok {
portal.log.Debugln("Not syncing chat mute/tags with %s: chat info not found", source.MXID)
return
}
source.syncChatDoublePuppetDetails(doublePuppet, Chat{
Chat: chat,
Portal: portal,
}, true)
}
func (portal *Portal) handleMessageLoop() {
for msg := range portal.messages {
if len(portal.MXID) == 0 {
@ -222,15 +203,14 @@ func (portal *Portal) handleMessageLoop() {
portal.log.Errorln("Failed to create portal room:", err)
continue
}
portal.syncDoublePuppetDetailsAfterCreate(msg.source)
}
portal.backfillLock.Lock()
portal.handleMessage(msg, false)
portal.handleMessage(msg)
portal.backfillLock.Unlock()
}
}
func (portal *Portal) handleMessage(msg PortalMessage, isBackfill bool) {
func (portal *Portal) handleMessage(msg PortalMessage) {
if len(portal.MXID) == 0 {
portal.log.Warnln("handleMessage called even though portal.MXID is empty")
return
@ -985,11 +965,11 @@ func (portal *Portal) CreateMatrixRoom(user *User) error {
portal.log.Debugln("else: it's not a private chat")
var err error
metadata, err = user.Client.ShowGroup(context.TODO(), groupme.ID(portal.Key.JID))
if err == nil && metadata.Status == 0 {
if err == nil {
portal.Name = metadata.Name
portal.Topic = metadata.Topic
// portal.Topic = metadata.Topic
}
portal.UpdateAvatar(user, nil, false)
portal.UpdateAvatar(user, metadata.ImageURL, false)
}
bridgeInfoStateKey, bridgeInfo := portal.getBridgeInfo()

23
user.go
View File

@ -677,29 +677,6 @@ func (user *User) getDirectChats() map[id.UserID][]id.RoomID {
return res
}
func (user *User) syncChatDoublePuppetDetails(doublePuppet *Puppet, chat Chat, justCreated bool) {
if doublePuppet == nil || doublePuppet.CustomIntent() == nil || len(chat.Portal.MXID) == 0 {
return
}
intent := doublePuppet.CustomIntent()
if chat.UnreadCount == 0 && (justCreated || !user.bridge.Config.Bridge.MarkReadOnlyOnCreate) {
lastMessage := user.bridge.DB.Message.GetLastInChatBefore(chat.Portal.Key, chat.ReceivedAt.Unix())
if lastMessage != nil {
err := intent.MarkReadWithContent(chat.Portal.MXID, lastMessage.MXID, &CustomReadReceipt{DoublePuppet: true})
if err != nil {
user.log.Warnfln("Failed to mark %s in %s as read after backfill: %v", lastMessage.MXID, chat.Portal.MXID, err)
}
}
} else if chat.UnreadCount == -1 {
user.log.Debugfln("Invalid unread count (missing field?) in chat info %+v", chat.Source)
}
if justCreated || !user.bridge.Config.Bridge.TagOnlyOnCreate {
user.updateChatMute(intent, chat.Portal, chat.MutedUntil)
user.updateChatTag(intent, chat.Portal, user.bridge.Config.Bridge.ArchiveTag, chat.IsArchived)
user.updateChatTag(intent, chat.Portal, user.bridge.Config.Bridge.PinnedTag, chat.IsPinned)
}
}
func (user *User) UpdateDirectChats(chats map[id.UserID][]id.RoomID) {
if !user.bridge.Config.Bridge.SyncDirectChatList {
return