SendMessage sends a message (with specified parentID) to the channel on the selected destination bridge and returns a message ID or an error.
( rmsg *config.Message, dest *bridge.Bridge, channel *config.ChannelInfo, canonicalParentMsgID string, )
| 431 | // SendMessage sends a message (with specified parentID) to the channel on the selected |
| 432 | // destination bridge and returns a message ID or an error. |
| 433 | func (gw *Gateway) SendMessage( |
| 434 | rmsg *config.Message, |
| 435 | dest *bridge.Bridge, |
| 436 | channel *config.ChannelInfo, |
| 437 | canonicalParentMsgID string, |
| 438 | ) (string, error) { |
| 439 | msg := *rmsg |
| 440 | // Only send the avatar download event to ourselves. |
| 441 | if msg.Event == config.EventAvatarDownload { |
| 442 | if channel.ID != getChannelID(rmsg) { |
| 443 | return "", nil |
| 444 | } |
| 445 | } else { |
| 446 | // do not send to ourself for any other event |
| 447 | if channel.ID == getChannelID(rmsg) { |
| 448 | return "", nil |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | // Only send irc notices to irc |
| 453 | if msg.Event == config.EventNoticeIRC && dest.Protocol != "irc" { |
| 454 | return "", nil |
| 455 | } |
| 456 | |
| 457 | // Too noisy to log like other events |
| 458 | debugSendMessage := "" |
| 459 | if msg.Event != config.EventUserTyping { |
| 460 | debugSendMessage = fmt.Sprintf("=> Sending %#v from %s (%s) to %s (%s)", msg, msg.Account, rmsg.Channel, dest.Account, channel.Name) |
| 461 | } |
| 462 | |
| 463 | msg.Channel = channel.Name |
| 464 | msg.Avatar = gw.modifyAvatar(rmsg, dest) |
| 465 | msg.Username = gw.modifyUsername(rmsg, dest) |
| 466 | |
| 467 | // exclude file delete event as the msg ID here is the native file ID that needs to be deleted |
| 468 | if msg.Event != config.EventFileDelete { |
| 469 | msg.ID = gw.getDestMsgID(rmsg.Protocol+" "+rmsg.ID, dest, channel) |
| 470 | } |
| 471 | |
| 472 | // for api we need originchannel as channel |
| 473 | if dest.Protocol == apiProtocol { |
| 474 | msg.Channel = rmsg.Channel |
| 475 | } |
| 476 | |
| 477 | msg.ParentID = gw.getDestMsgID(canonicalParentMsgID, dest, channel) |
| 478 | if msg.ParentID == "" { |
| 479 | msg.ParentID = strings.Replace(canonicalParentMsgID, dest.Protocol+" ", "", 1) |
| 480 | } |
| 481 | |
| 482 | // if the parentID is still empty and we have a parentID set in the original message |
| 483 | // this means that we didn't find it in the cache so set it to a "msg-parent-not-found" constant |
| 484 | if msg.ParentID == "" && rmsg.ParentID != "" { |
| 485 | msg.ParentID = config.ParentIDNotFound |
| 486 | } |
| 487 | |
| 488 | drop, err := gw.modifyOutMessageTengo(rmsg, &msg, dest) |
| 489 | if err != nil { |
| 490 | gw.logger.Errorf("modifySendMessageTengo: %s", err) |
no test coverage detected