@@ -30,14 +30,14 @@ const (
3030type Bwhatsapp struct {
3131 * bridge.Config
3232
33- startedAt time.Time
34- wc * whatsmeow.Client
35- contacts map [types.JID ]types.ContactInfo
36- users map [string ]types.ContactInfo
37- userAvatars map [string ]string
38- joinedGroups []* types.GroupInfo
33+ startedAt time.Time
34+ wc * whatsmeow.Client
35+ contacts map [types.JID ]types.ContactInfo
36+ users map [string ]types.ContactInfo
37+ userAvatars map [string ]string
38+ joinedGroups []* types.GroupInfo
3939 subscribedNewsletters []* types.NewsletterMetadata
40- newsletterNames map [string ]string
40+ newsletterNames map [string ]string
4141}
4242
4343type Replyable struct {
@@ -64,17 +64,8 @@ func New(cfg *bridge.Config) bridge.Bridger {
6464 return b
6565}
6666
67- func (b * Bwhatsapp ) whatsappHandlePanic () {
68- r := recover ()
69- if r != nil {
70- b .Log .Warnf ("Recovered from panic: %#v" , r )
71- }
72- }
73-
7467// Connect to WhatsApp. Required implementation of the Bridger interface
7568func (b * Bwhatsapp ) Connect () error {
76- defer b .whatsappHandlePanic ()
77-
7869 device , err := b .getDevice ()
7970 if err != nil {
8071 return err
@@ -201,8 +192,6 @@ func (b *Bwhatsapp) Disconnect() error {
201192// Required implementation of the Bridger interface
202193// https://github.com/42wim/matterbridge/blob/2cfd880cdb0df29771bf8f31df8d990ab897889d/bridge/bridge.go#L11-L16
203194func (b * Bwhatsapp ) JoinChannel (channel config.ChannelInfo ) error {
204- defer b .whatsappHandlePanic ()
205-
206195 b .RLock ()
207196 subscribedNewsletters := b .subscribedNewsletters
208197 joinedGroups := b .joinedGroups
@@ -434,16 +423,12 @@ func (b *Bwhatsapp) PostAudioMessage(msg config.Message, filetype string) (strin
434423
435424// Send a message from the bridge to WhatsApp
436425func (b * Bwhatsapp ) Send (msg config.Message ) (string , error ) {
437- defer b .whatsappHandlePanic ()
438-
439426 groupJID , _ := types .ParseJID (msg .Channel )
440427
441428 // WhatsApp channels (newsletters) are read-only for subscribers;
442429 // only the channel owner or admin can post. Check role before sending.
443430 if groupJID .Server == types .NewsletterServer {
444431 b .RLock ()
445- defer b .RUnlock ()
446-
447432 found , canSend := false , false
448433 for _ , nl := range b .subscribedNewsletters {
449434 if nl .ID == groupJID {
@@ -456,6 +441,7 @@ func (b *Bwhatsapp) Send(msg config.Message) (string, error) {
456441 break
457442 }
458443 }
444+ b .RUnlock ()
459445
460446 if ! found {
461447 b .Log .Warnf ("Cannot send to unknown newsletter %s: not in subscribed list" , groupJID )
0 commit comments