@@ -69,8 +69,8 @@ func (gw *Gateway) FindCanonicalMsgID(protocol string, externalID string) *xid.I
6969 // TODO: should we check if the mapping exists here? or is this method
7070 // only used when we're 100% sure?
7171 externalIDs , _ := gw .Messages .Peek (internalID )
72- for _ , downstreamMsgObj := range externalIDs {
73- if externalID == downstreamMsgObj .ID {
72+ for _ , brMsgId := range externalIDs {
73+ if brMsgId . br . Protocol == protocol && brMsgId .ID == externalID {
7474 return & internalID
7575 }
7676 }
@@ -99,43 +99,9 @@ func (gw *Gateway) AddBridge(cfg *config.Bridge) error {
9999
100100 br .HttpClient = http_client
101101
102- // The channel to receive message IDs is shared with the
103- // bridges, but is not kept in the gateway.
104- messageAck := make (chan bridge.MessageSent , 100 )
105- // Start listening for sent message acknowledgements
106- go func () {
107- for ack := range messageAck {
108- gw .logger .Warnf ("Message %s has been acked by %s as ID: %s" , ack .InternalID .String (), ack .DestBridge .Protocol , ack .ExternalID .ID )
109- // TODO 2026: this was a comment in the previous ID handling. Not
110- // sure what to do about ID changing on edit????
111- //
112- // Only add the message ID if it doesn't already exist
113- //
114- // For some bridges we always add/update the message ID.
115- // This is necessary as msgIDs will change if a bridge returns
116- // a different ID in response to edits.
117-
118- // brMsgIDs is always initialized in Router.handleReceive(). However,
119- // we may still receive a message we don't know about. Maybe matterbridge
120- // was restarted, or another client is connected on the same account sending
121- // messages, or the remote server is melting down and dinosaurs are walking
122- // the Earth...
123- brMsgIDs , exists := gw .Messages .Get (ack .InternalID )
124-
125- if ! exists {
126- gw .logger .Warnf ("Unknown message %s has been acked by %s as ID: %s" , ack .InternalID .String (), ack .DestBridge .Protocol , ack .ExternalID .ID )
127- continue
128- }
129-
130- brMsgIDs = append (brMsgIDs , & BrMsgID {ack .DestBridge , ack .DestBridge .Protocol + " " + ack .ExternalID .ID , ack .ExternalID .ChannelID })
131- gw .Messages .Add (ack .InternalID , brMsgIDs )
132- }
133- }()
134-
135102 brconfig := & bridge.Config {
136- Remote : gw .Message ,
137- MessageSentAck : messageAck ,
138- Bridge : br ,
103+ Remote : gw .Message ,
104+ Bridge : br ,
139105 }
140106 // add the actual bridger for this protocol to this bridge using the bridgeMap
141107 if _ , ok := gw .Router .BridgeMap [br .Protocol ]; ! ok {
@@ -220,19 +186,19 @@ func (gw *Gateway) SendMessage(
220186 }
221187
222188 defer func (t time.Time ) {
223- gw .logger .Debugf ("=> Send from %s (%s) to %s (%s) took %s" , msg .Account , rmsg .Channel , dest .Account , channel .Name , time .Since (t ))
189+ gw .logger .Debugf ("=> Send from %s (%s) to %s (%s) took %s" , msg .Account , rmsg .Channel , dest .Account , channel .Name , time .Since (t ))
224190 }(time .Now ())
225191
226192 mID , err := dest .Send (msg )
227193 if err != nil {
228- return mID , err
194+ return mID , err
229195 }
230196
231197 // append the message ID (mID) from this bridge (dest) to our brMsgIDs slice
232198 if mID != "" {
233- gw .logger .Debugf ("mID %s: %s" , dest .Account , mID )
234- return mID , nil
235- // brMsgIDs = append(brMsgIDs, &BrMsgID{dest, dest.Protocol + " " + mID, channel.ID})
199+ gw .logger .Debugf ("mID %s: %s" , dest .Account , mID )
200+ return mID , nil
201+ // brMsgIDs = append(brMsgIDs, &BrMsgID{dest, dest.Protocol + " " + mID, channel.ID})
236202 }
237203 return "" , nil
238204}
0 commit comments