Fix rate-overlimit issue when there are more than 5 whatsapp channels in a single account (whatsapp) (#1998)

Resolves #1844
This commit is contained in:
Joseph Mansy 2023-03-09 13:10:09 -08:00 committed by GitHub
parent 2b236f3ff7
commit 3a4bdd7c56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -40,6 +40,7 @@ type Bwhatsapp struct {
contacts map[types.JID]types.ContactInfo contacts map[types.JID]types.ContactInfo
users map[string]types.ContactInfo users map[string]types.ContactInfo
userAvatars map[string]string userAvatars map[string]string
joinedGroups []*types.GroupInfo
} }
type Replyable struct { type Replyable struct {
@ -126,6 +127,11 @@ func (b *Bwhatsapp) Connect() error {
return errors.New("failed to get contacts: " + err.Error()) return errors.New("failed to get contacts: " + err.Error())
} }
b.joinedGroups, err = b.wc.GetJoinedGroups()
if err != nil {
return errors.New("failed to get list of joined groups: " + err.Error())
}
b.startedAt = time.Now() b.startedAt = time.Now()
// map all the users // map all the users
@ -171,11 +177,6 @@ func (b *Bwhatsapp) Disconnect() error {
func (b *Bwhatsapp) JoinChannel(channel config.ChannelInfo) error { func (b *Bwhatsapp) JoinChannel(channel config.ChannelInfo) error {
byJid := isGroupJid(channel.Name) byJid := isGroupJid(channel.Name)
groups, err := b.wc.GetJoinedGroups()
if err != nil {
return err
}
// verify if we are member of the given group // verify if we are member of the given group
if byJid { if byJid {
gJID, err := types.ParseJID(channel.Name) gJID, err := types.ParseJID(channel.Name)
@ -183,7 +184,7 @@ func (b *Bwhatsapp) JoinChannel(channel config.ChannelInfo) error {
return err return err
} }
for _, group := range groups { for _, group := range b.joinedGroups {
if group.JID == gJID { if group.JID == gJID {
return nil return nil
} }
@ -192,7 +193,7 @@ func (b *Bwhatsapp) JoinChannel(channel config.ChannelInfo) error {
foundGroups := []string{} foundGroups := []string{}
for _, group := range groups { for _, group := range b.joinedGroups {
if group.Name == channel.Name { if group.Name == channel.Name {
foundGroups = append(foundGroups, group.Name) foundGroups = append(foundGroups, group.Name)
} }
@ -201,7 +202,7 @@ func (b *Bwhatsapp) JoinChannel(channel config.ChannelInfo) error {
switch len(foundGroups) { switch len(foundGroups) {
case 0: case 0:
// didn't match any group - print out possibilites // didn't match any group - print out possibilites
for _, group := range groups { for _, group := range b.joinedGroups {
b.Log.Infof("%s %s", group.JID, group.Name) b.Log.Infof("%s %s", group.JID, group.Name)
} }
return fmt.Errorf("please specify group's JID from the list above instead of the name '%s'", channel.Name) return fmt.Errorf("please specify group's JID from the list above instead of the name '%s'", channel.Name)