MCPcopy
hub / github.com/42wim/matterbridge / handleMessage

Method handleMessage

gateway/handlers.go:191–237  ·  view source on GitHub ↗

handleMessage makes sure the message get sent to the correct bridge/channels. Returns an array of msg ID's

(rmsg *config.Message, dest *bridge.Bridge)

Source from the content-addressed store, hash-verified

189// handleMessage makes sure the message get sent to the correct bridge/channels.
190// Returns an array of msg ID's
191func (gw *Gateway) handleMessage(rmsg *config.Message, dest *bridge.Bridge) []*BrMsgID {
192 var brMsgIDs []*BrMsgID
193
194 // Not all bridges support "user is typing" indications so skip the message
195 // if the targeted bridge does not support it.
196 if rmsg.Event == config.EventUserTyping {
197 if _, ok := bridgemap.UserTypingSupport[dest.Protocol]; !ok {
198 return nil
199 }
200 }
201
202 // if we have an attached file, or other info
203 if rmsg.Extra != nil && len(rmsg.Extra[config.EventFileFailureSize]) != 0 && rmsg.Text == "" {
204 return brMsgIDs
205 }
206
207 if gw.ignoreEvent(rmsg.Event, dest) {
208 return brMsgIDs
209 }
210
211 // broadcast to every out channel (irc QUIT)
212 if rmsg.Channel == "" && rmsg.Event != config.EventJoinLeave {
213 gw.logger.Debug("empty channel")
214 return brMsgIDs
215 }
216
217 // Get the ID of the parent message in thread
218 var canonicalParentMsgID string
219 if rmsg.ParentID != "" && dest.GetBool("PreserveThreading") {
220 canonicalParentMsgID = gw.FindCanonicalMsgID(rmsg.Protocol, rmsg.ParentID)
221 }
222
223 channels := gw.getDestChannel(rmsg, *dest)
224 for idx := range channels {
225 channel := &channels[idx]
226 msgID, err := gw.SendMessage(rmsg, dest, channel, canonicalParentMsgID)
227 if err != nil {
228 gw.logger.Errorf("SendMessage failed: %s", err)
229 continue
230 }
231 if msgID == "" {
232 continue
233 }
234 brMsgIDs = append(brMsgIDs, &BrMsgID{dest, dest.Protocol + " " + msgID, channel.ID})
235 }
236 return brMsgIDs
237}
238
239func (gw *Gateway) handleExtractNicks(msg *config.Message) {
240 var err error

Callers 1

handleReceiveMethod · 0.45

Calls 5

ignoreEventMethod · 0.95
FindCanonicalMsgIDMethod · 0.95
getDestChannelMethod · 0.95
SendMessageMethod · 0.95
GetBoolMethod · 0.65

Tested by

no test coverage detected