@@ -116,23 +116,21 @@ func (gw *Gateway) AddBridge(cfg *config.Bridge) error {
116116 // For some bridges we always add/update the message ID.
117117 // This is necessary as msgIDs will change if a bridge returns
118118 // a different ID in response to edits.
119- values , exists := gw .Messages .Get (ack .ExternalID .Protocol + " " + ack .InternalID .String ())
120119
121- var brMsgIDs []* BrMsgID
122- if exists {
123- // We want to append, not overwrite
124- brMsgIDs = values
120+ // brMsgIDs is always initialized in Router.handleReceive(). However,
121+ // we may still receive a message we don't know about. Maybe matterbridge
122+ // was restarted, or another client is connected on the same account sending
123+ // messages, or the remote server is melting down and dinosaurs are walking
124+ // the Earth...
125+ brMsgIDs , exists := gw .Messages .Get (ack .ExternalID .Protocol + " " + ack .InternalID .String ())
126+
127+ if ! exists {
128+ gw .logger .Warnf ("Unknown message %s has been acked by %s as ID: %s" , ack .InternalID .String (), ack .ExternalID .Protocol , ack .ExternalID .ID )
129+ continue
125130 }
126131
127132 brMsgIDs = append (brMsgIDs , & BrMsgID {ack .DestBridge , ack .ExternalID .Protocol + " " + ack .ExternalID .ID , ack .ExternalID .ChannelID })
128133 gw .Messages .Add (ack .ExternalID .Protocol + " " + ack .InternalID .String (), brMsgIDs )
129-
130- // Just for testing that we added everything correctly
131- // TODO: remove this useless debug log
132- values , _ = gw .Messages .Get (ack .ExternalID .Protocol + " " + ack .InternalID .String ())
133- for _ , id := range values {
134- gw .logger .Warnf (" | %s -> %s (%s)" , ack .InternalID .String (), id .ID , id .ChannelID )
135- }
136134 }
137135 }()
138136
0 commit comments