Thumbnail

rani/matterbridge.git

Clone URL: https://git.buni.party/rani/matterbridge.git

commit a4f303cd635a7e12d89beca402993636c1b8feb4 Author: Joseph Mansy <36427684+yousefmansy1@users.noreply.github.com> Date: Thu Mar 09 13:10:09 2023 +0000 Fix rate-overlimit issue when there are more than 5 whatsapp channels in a single account (whatsapp) (#1998) Resolves #1844 diff --git a/bridge/whatsappmulti/whatsapp.go b/bridge/whatsappmulti/whatsapp.go index 6798d82..e943fc8 100644 --- a/bridge/whatsappmulti/whatsapp.go +++ b/bridge/whatsappmulti/whatsapp.go @@ -3511 +3512 @@ 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 { @@ -1266 +12711 @@ 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 @@ -17111 +1776 @@ 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) @@ -1837 +1847 @@ 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   } @@ -1927 +1937 @@ 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)   } @@ -2017 +2027 @@ 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)