diff options
author | Joseph Mansy <36427684+yousefmansy1@users.noreply.github.com> | 2023-03-09 13:10:09 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-09 22:10:09 +0100 |
commit | 3a4bdd7c561c1f8bf0cadcae755e690f3443a75c (patch) | |
tree | 404088a56bf103e9bd67288ab20632ae535ac453 /bridge | |
parent | 2b236f3ff7460f785794fefb60fe987a92357366 (diff) | |
download | matterbridge-msglm-3a4bdd7c561c1f8bf0cadcae755e690f3443a75c.tar.gz matterbridge-msglm-3a4bdd7c561c1f8bf0cadcae755e690f3443a75c.tar.bz2 matterbridge-msglm-3a4bdd7c561c1f8bf0cadcae755e690f3443a75c.zip |
Fix rate-overlimit issue when there are more than 5 whatsapp channels in a single account (whatsapp) (#1998)
Resolves #1844
Diffstat (limited to 'bridge')
-rw-r--r-- | bridge/whatsappmulti/whatsapp.go | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/bridge/whatsappmulti/whatsapp.go b/bridge/whatsappmulti/whatsapp.go index 6798d827..e943fc86 100644 --- a/bridge/whatsappmulti/whatsapp.go +++ b/bridge/whatsappmulti/whatsapp.go @@ -35,11 +35,12 @@ const ( type Bwhatsapp struct { *bridge.Config - startedAt time.Time - wc *whatsmeow.Client - contacts map[types.JID]types.ContactInfo - users map[string]types.ContactInfo - userAvatars map[string]string + startedAt time.Time + wc *whatsmeow.Client + contacts map[types.JID]types.ContactInfo + users map[string]types.ContactInfo + userAvatars map[string]string + joinedGroups []*types.GroupInfo } type Replyable struct { @@ -126,6 +127,11 @@ func (b *Bwhatsapp) Connect() 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() // map all the users @@ -171,11 +177,6 @@ func (b *Bwhatsapp) Disconnect() error { func (b *Bwhatsapp) JoinChannel(channel config.ChannelInfo) error { byJid := isGroupJid(channel.Name) - groups, err := b.wc.GetJoinedGroups() - if err != nil { - return err - } - // verify if we are member of the given group if byJid { gJID, err := types.ParseJID(channel.Name) @@ -183,7 +184,7 @@ func (b *Bwhatsapp) JoinChannel(channel config.ChannelInfo) error { return err } - for _, group := range groups { + for _, group := range b.joinedGroups { if group.JID == gJID { return nil } @@ -192,7 +193,7 @@ func (b *Bwhatsapp) JoinChannel(channel config.ChannelInfo) error { foundGroups := []string{} - for _, group := range groups { + for _, group := range b.joinedGroups { if group.Name == channel.Name { foundGroups = append(foundGroups, group.Name) } @@ -201,7 +202,7 @@ func (b *Bwhatsapp) JoinChannel(channel config.ChannelInfo) error { switch len(foundGroups) { case 0: // 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) } return fmt.Errorf("please specify group's JID from the list above instead of the name '%s'", channel.Name) |