mirror of
https://github.com/tulir/mautrix-whatsapp
synced 2024-11-17 23:43:10 +01:00
Use partial info from history sync if latest group info not found
This commit is contained in:
parent
d05a79d843
commit
2d90295488
3 changed files with 42 additions and 30 deletions
|
@ -918,7 +918,7 @@ func (handler *CommandHandler) CommandOpen(ce *CommandEvent) {
|
|||
portal.UpdateMatrixRoom(ce.User, info)
|
||||
ce.Reply("Portal room synced.")
|
||||
} else {
|
||||
err = portal.CreateMatrixRoom(ce.User, info)
|
||||
err = portal.CreateMatrixRoom(ce.User, info, true)
|
||||
if err != nil {
|
||||
ce.Reply("Failed to create room: %v", err)
|
||||
} else {
|
||||
|
@ -966,7 +966,7 @@ func (handler *CommandHandler) CommandPM(ce *CommandEvent) {
|
|||
return
|
||||
}
|
||||
}
|
||||
err = portal.CreateMatrixRoom(user, nil)
|
||||
err = portal.CreateMatrixRoom(user, nil, false)
|
||||
if err != nil {
|
||||
ce.Reply("Failed to create portal room: %v", err)
|
||||
return
|
||||
|
|
50
portal.go
50
portal.go
|
@ -209,7 +209,7 @@ func (portal *Portal) handleMessageLoop() {
|
|||
continue
|
||||
}
|
||||
portal.log.Debugln("Creating Matrix room from incoming message")
|
||||
err := portal.CreateMatrixRoom(msg.source, nil)
|
||||
err := portal.CreateMatrixRoom(msg.source, nil, false)
|
||||
if err != nil {
|
||||
portal.log.Errorln("Failed to create portal room:", err)
|
||||
continue
|
||||
|
@ -699,7 +699,7 @@ func (portal *Portal) UpdateTopic(topic string, setBy types.JID, updateInfo bool
|
|||
return false
|
||||
}
|
||||
|
||||
func (portal *Portal) UpdateMetadata(user *User) bool {
|
||||
func (portal *Portal) UpdateMetadata(user *User, groupInfo *types.GroupInfo) bool {
|
||||
if portal.IsPrivateChat() {
|
||||
return false
|
||||
} else if portal.IsStatusBroadcastList() {
|
||||
|
@ -722,19 +722,22 @@ func (portal *Portal) UpdateMetadata(user *User) bool {
|
|||
//update = portal.UpdateTopic(BroadcastTopic, "", nil, false) || update
|
||||
return update
|
||||
}
|
||||
metadata, err := user.Client.GetGroupInfo(portal.Key.JID)
|
||||
if err != nil {
|
||||
portal.log.Errorln("Failed to get group info:", err)
|
||||
return false
|
||||
if groupInfo == nil {
|
||||
var err error
|
||||
groupInfo, err = user.Client.GetGroupInfo(portal.Key.JID)
|
||||
if err != nil {
|
||||
portal.log.Errorln("Failed to get group info:", err)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
portal.SyncParticipants(user, metadata)
|
||||
portal.SyncParticipants(user, groupInfo)
|
||||
update := false
|
||||
update = portal.UpdateName(metadata.Name, metadata.NameSetBy, false) || update
|
||||
update = portal.UpdateTopic(metadata.Topic, metadata.TopicSetBy, false) || update
|
||||
update = portal.UpdateName(groupInfo.Name, groupInfo.NameSetBy, false) || update
|
||||
update = portal.UpdateTopic(groupInfo.Topic, groupInfo.TopicSetBy, false) || update
|
||||
|
||||
portal.RestrictMessageSending(metadata.IsAnnounce)
|
||||
portal.RestrictMetadataChanges(metadata.IsLocked)
|
||||
portal.RestrictMessageSending(groupInfo.IsAnnounce)
|
||||
portal.RestrictMetadataChanges(groupInfo.IsLocked)
|
||||
|
||||
return update
|
||||
}
|
||||
|
@ -782,21 +785,15 @@ func (portal *Portal) ensureUserInvited(user *User) (ok bool) {
|
|||
}
|
||||
|
||||
func (portal *Portal) UpdateMatrixRoom(user *User, groupInfo *types.GroupInfo) bool {
|
||||
if len(portal.MXID) == 0 {
|
||||
return false
|
||||
}
|
||||
portal.log.Infoln("Syncing portal for", user.MXID)
|
||||
|
||||
if len(portal.MXID) == 0 {
|
||||
err := portal.CreateMatrixRoom(user, groupInfo)
|
||||
if err != nil {
|
||||
portal.log.Errorln("Failed to create portal room:", err)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
} else {
|
||||
portal.ensureUserInvited(user)
|
||||
}
|
||||
portal.ensureUserInvited(user)
|
||||
|
||||
update := false
|
||||
update = portal.UpdateMetadata(user) || update
|
||||
update = portal.UpdateMetadata(user, groupInfo) || update
|
||||
if !portal.IsPrivateChat() && !portal.IsBroadcastList() && portal.Avatar == "" {
|
||||
update = portal.UpdateAvatar(user, types.EmptyJID, false) || update
|
||||
}
|
||||
|
@ -1248,7 +1245,7 @@ var BackfillDummyStateEvent = event.Type{Type: "fi.mau.dummy.blank_backfill_stat
|
|||
var BackfillEndDummyEvent = event.Type{Type: "fi.mau.dummy.backfill_end", Class: event.MessageEventType}
|
||||
var PreBackfillDummyEvent = event.Type{Type: "fi.mau.dummy.pre_backfill", Class: event.MessageEventType}
|
||||
|
||||
func (portal *Portal) CreateMatrixRoom(user *User, groupInfo *types.GroupInfo) error {
|
||||
func (portal *Portal) CreateMatrixRoom(user *User, groupInfo *types.GroupInfo, isFullInfo bool) error {
|
||||
portal.roomCreateLock.Lock()
|
||||
defer portal.roomCreateLock.Unlock()
|
||||
if len(portal.MXID) > 0 {
|
||||
|
@ -1299,11 +1296,12 @@ func (portal *Portal) CreateMatrixRoom(user *User, groupInfo *types.GroupInfo) e
|
|||
portal.log.Debugln("Broadcast list is not yet supported, not creating room after all")
|
||||
return fmt.Errorf("broadcast list bridging is currently not supported")
|
||||
} else {
|
||||
if groupInfo == nil {
|
||||
var err error
|
||||
groupInfo, err = user.Client.GetGroupInfo(portal.Key.JID)
|
||||
if groupInfo == nil || !isFullInfo {
|
||||
foundInfo, err := user.Client.GetGroupInfo(portal.Key.JID)
|
||||
if err != nil {
|
||||
portal.log.Warnfln("Failed to get group info through %s: %v", user.JID, err)
|
||||
} else {
|
||||
groupInfo = foundInfo
|
||||
}
|
||||
}
|
||||
if groupInfo != nil {
|
||||
|
|
18
user.go
18
user.go
|
@ -433,7 +433,21 @@ func (user *User) handleHistorySync(evt *waProto.HistorySync) {
|
|||
continue
|
||||
}
|
||||
user.log.Debugln("Creating portal for", portal.Key.JID, "as part of history sync handling")
|
||||
err = portal.CreateMatrixRoom(user, nil)
|
||||
participants := make([]types.GroupParticipant, len(conv.GetParticipant()))
|
||||
for i, pcp := range conv.GetParticipant() {
|
||||
participantJID, _ := types.ParseJID(pcp.GetUserJid())
|
||||
participants[i] = types.GroupParticipant{
|
||||
JID: participantJID,
|
||||
IsAdmin: pcp.GetRank() == waProto.GroupParticipant_ADMIN,
|
||||
IsSuperAdmin: pcp.GetRank() == waProto.GroupParticipant_SUPERADMIN,
|
||||
}
|
||||
}
|
||||
partialInfo := types.GroupInfo{
|
||||
JID: jid,
|
||||
GroupName: types.GroupName{Name: conv.GetName()},
|
||||
Participants: participants,
|
||||
}
|
||||
err = portal.CreateMatrixRoom(user, &partialInfo, false)
|
||||
if err != nil {
|
||||
user.log.Warnfln("Failed to create room for %s during backfill: %v", portal.Key.JID, err)
|
||||
continue
|
||||
|
@ -842,7 +856,7 @@ func (user *User) markSelfReadFull(portal *Portal) {
|
|||
func (user *User) handleGroupCreate(evt *events.JoinedGroup) {
|
||||
portal := user.GetPortalByJID(evt.JID)
|
||||
if len(portal.MXID) == 0 {
|
||||
err := portal.CreateMatrixRoom(user, &evt.GroupInfo)
|
||||
err := portal.CreateMatrixRoom(user, &evt.GroupInfo, true)
|
||||
if err != nil {
|
||||
user.log.Errorln("Failed to create Matrix room after join notification: %v", err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue