Make participant deduplication less hacky
This commit is contained in:
parent
e81339183e
commit
3e0e5d703f
4 changed files with 17 additions and 39 deletions
|
@ -2020,7 +2020,7 @@ type Participant struct {
|
||||||
AvatarHexColor string `protobuf:"bytes,5,opt,name=avatarHexColor,proto3" json:"avatarHexColor,omitempty"`
|
AvatarHexColor string `protobuf:"bytes,5,opt,name=avatarHexColor,proto3" json:"avatarHexColor,omitempty"`
|
||||||
IsMe bool `protobuf:"varint,6,opt,name=isMe,proto3" json:"isMe,omitempty"`
|
IsMe bool `protobuf:"varint,6,opt,name=isMe,proto3" json:"isMe,omitempty"`
|
||||||
Muted *Muted `protobuf:"bytes,7,opt,name=muted,proto3" json:"muted,omitempty"`
|
Muted *Muted `protobuf:"bytes,7,opt,name=muted,proto3" json:"muted,omitempty"`
|
||||||
SomeInt int64 `protobuf:"varint,8,opt,name=someInt,proto3" json:"someInt,omitempty"`
|
IsVisible bool `protobuf:"varint,8,opt,name=isVisible,proto3" json:"isVisible,omitempty"`
|
||||||
ContactID string `protobuf:"bytes,10,opt,name=contactID,proto3" json:"contactID,omitempty"`
|
ContactID string `protobuf:"bytes,10,opt,name=contactID,proto3" json:"contactID,omitempty"`
|
||||||
Bs int64 `protobuf:"varint,14,opt,name=bs,proto3" json:"bs,omitempty"`
|
Bs int64 `protobuf:"varint,14,opt,name=bs,proto3" json:"bs,omitempty"`
|
||||||
FormattedNumber string `protobuf:"bytes,15,opt,name=formattedNumber,proto3" json:"formattedNumber,omitempty"`
|
FormattedNumber string `protobuf:"bytes,15,opt,name=formattedNumber,proto3" json:"formattedNumber,omitempty"`
|
||||||
|
@ -2102,11 +2102,11 @@ func (x *Participant) GetMuted() *Muted {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *Participant) GetSomeInt() int64 {
|
func (x *Participant) GetIsVisible() bool {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.SomeInt
|
return x.IsVisible
|
||||||
}
|
}
|
||||||
return 0
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *Participant) GetContactID() string {
|
func (x *Participant) GetContactID() string {
|
||||||
|
|
Binary file not shown.
|
@ -183,7 +183,7 @@ message Participant {
|
||||||
string avatarHexColor = 5;
|
string avatarHexColor = 5;
|
||||||
bool isMe = 6;
|
bool isMe = 6;
|
||||||
Muted muted = 7;
|
Muted muted = 7;
|
||||||
int64 someInt = 8;
|
bool isVisible = 8;
|
||||||
string contactID = 10;
|
string contactID = 10;
|
||||||
int64 bs = 14;
|
int64 bs = 14;
|
||||||
string formattedNumber = 15;
|
string formattedNumber = 15;
|
||||||
|
|
46
portal.go
46
portal.go
|
@ -905,6 +905,14 @@ func (portal *Portal) getIntent(ctx context.Context, source *User, participant s
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return intent
|
return intent
|
||||||
|
} else if portal.IsPrivateChat() {
|
||||||
|
if participant != portal.OtherUserID {
|
||||||
|
zerolog.Ctx(ctx).Warn().
|
||||||
|
Str("participant_id", participant).
|
||||||
|
Str("portal_other_user_id", portal.OtherUserID).
|
||||||
|
Msg("Got unexpected participant ID for message in DM portal, forcing to main intent")
|
||||||
|
}
|
||||||
|
return portal.MainIntent()
|
||||||
} else {
|
} else {
|
||||||
puppet := source.GetPuppetByID(participant, "")
|
puppet := source.GetPuppetByID(participant, "")
|
||||||
if puppet == nil {
|
if puppet == nil {
|
||||||
|
@ -1291,44 +1299,14 @@ func (portal *Portal) SyncParticipants(ctx context.Context, source *User, metada
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
} else if participant.ID.Number == "" {
|
} else if participant.ID.Number == "" {
|
||||||
portal.zlog.Warn().Interface("participant", participant).Msg("No number found in non-self participant entry")
|
portal.zlog.Warn().Any("participant", participant).Msg("No number found in non-self participant entry")
|
||||||
|
continue
|
||||||
|
} else if !participant.IsVisible {
|
||||||
|
portal.zlog.Debug().Any("participant", participant).Msg("Ignoring fake participant")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
filteredParticipants = append(filteredParticipants, participant)
|
filteredParticipants = append(filteredParticipants, participant)
|
||||||
}
|
}
|
||||||
if len(filteredParticipants) > 1 && !metadata.IsGroupChat {
|
|
||||||
var bestParticipant *gmproto.Participant
|
|
||||||
var foundMultiple bool
|
|
||||||
for _, participant := range filteredParticipants {
|
|
||||||
if participant.GetSomeInt() == 1 &&
|
|
||||||
// TODO this name check may be unnecessary (and is even more hacky)
|
|
||||||
(participant.GetFullName() == metadata.GetName() ||
|
|
||||||
participant.GetFormattedNumber() == metadata.GetName() ||
|
|
||||||
strings.TrimPrefix(participant.GetID().GetNumber(), "+") == strings.TrimPrefix(metadata.GetName(), "+")) {
|
|
||||||
if bestParticipant != nil {
|
|
||||||
foundMultiple = true
|
|
||||||
break
|
|
||||||
} else {
|
|
||||||
bestParticipant = participant
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if foundMultiple {
|
|
||||||
portal.zlog.Warn().
|
|
||||||
Any("participants", filteredParticipants).
|
|
||||||
Msg("Didn't apply hacky deduplication to DM participants: found multiple matches")
|
|
||||||
} else if bestParticipant != nil {
|
|
||||||
portal.zlog.Debug().
|
|
||||||
Any("participants", filteredParticipants).
|
|
||||||
Any("chosen_participant", bestParticipant).
|
|
||||||
Msg("Applied hacky deduplication to DM participants")
|
|
||||||
filteredParticipants = []*gmproto.Participant{bestParticipant}
|
|
||||||
} else {
|
|
||||||
portal.zlog.Warn().
|
|
||||||
Any("participants", filteredParticipants).
|
|
||||||
Msg("Didn't apply hacky deduplication to DM participants: no match found")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for _, participant := range filteredParticipants {
|
for _, participant := range filteredParticipants {
|
||||||
puppet := source.GetPuppetByID(participant.ID.ParticipantID, participant.ID.Number)
|
puppet := source.GetPuppetByID(participant.ID.ParticipantID, participant.ID.Number)
|
||||||
if puppet == nil {
|
if puppet == nil {
|
||||||
|
|
Loading…
Reference in a new issue