matrix+irc: improve support for IRC NOTICE/[matrix] m.notice
Fixes: #1393.
This commit is contained in:
@@ -27,7 +27,7 @@ const (
|
||||
EventAPIConnected = "api_connected"
|
||||
EventUserTyping = "user_typing"
|
||||
EventGetChannelMembers = "get_channel_members"
|
||||
EventNoticeIRC = "notice_irc"
|
||||
EventNotice = "notice"
|
||||
)
|
||||
|
||||
const ParentIDNotFound = "msg-parent-not-found"
|
||||
|
||||
@@ -201,7 +201,7 @@ func (b *Birc) handlePrivMsg(client *girc.Client, event girc.Event) {
|
||||
|
||||
// set NOTICE event
|
||||
if event.Command == "NOTICE" {
|
||||
rmsg.Event = config.EventNoticeIRC
|
||||
rmsg.Event = config.EventNotice
|
||||
}
|
||||
|
||||
// strip action, we made an event if it was an action
|
||||
|
||||
@@ -255,7 +255,7 @@ func (b *Birc) doSend() {
|
||||
switch msg.Event {
|
||||
case config.EventUserAction:
|
||||
b.i.Cmd.Action(msg.Channel, username+msg.Text)
|
||||
case config.EventNoticeIRC:
|
||||
case config.EventNotice:
|
||||
b.Log.Debugf("Sending notice to channel %s", msg.Channel)
|
||||
b.i.Cmd.Notice(msg.Channel, username+msg.Text)
|
||||
default:
|
||||
|
||||
@@ -150,6 +150,7 @@ func (b *Bmatrix) handleMemberChange(ev *event.Event) {
|
||||
}
|
||||
}
|
||||
|
||||
//nolint: funlen
|
||||
func (b *Bmatrix) handleMessage(rmsg config.Message, ev *event.Event) {
|
||||
msg := ev.Content.AsMessage()
|
||||
if msg == nil {
|
||||
@@ -169,10 +170,10 @@ func (b *Bmatrix) handleMessage(rmsg config.Message, ev *event.Event) {
|
||||
rmsg.Avatar = avatarURL
|
||||
}
|
||||
|
||||
// Do we have a /me action
|
||||
//nolint: exhaustive
|
||||
switch msg.MsgType {
|
||||
case event.MsgEmote:
|
||||
// Do we have a /me action
|
||||
rmsg.Event = config.EventUserAction
|
||||
case event.MsgImage, event.MsgVideo, event.MsgFile:
|
||||
// Do we have attachments? (we only allow images, videos or files msgtypes)
|
||||
@@ -180,6 +181,9 @@ func (b *Bmatrix) handleMessage(rmsg config.Message, ev *event.Event) {
|
||||
if err != nil {
|
||||
b.Log.Errorf("download failed: %#v", err)
|
||||
}
|
||||
case event.MsgNotice:
|
||||
// Support for IRC NOTICE commands/[matrix] m.notice
|
||||
rmsg.Event = config.EventNotice
|
||||
default:
|
||||
if msg.RelatesTo == nil {
|
||||
break
|
||||
|
||||
@@ -195,6 +195,7 @@ func (b *Bmatrix) Start() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
//nolint: funlen,gocognit,gocyclo
|
||||
func (b *Bmatrix) Send(msg config.Message) (string, error) {
|
||||
b.Log.Debugf("=> Sending %#v", msg)
|
||||
|
||||
@@ -305,7 +306,7 @@ func (b *Bmatrix) Send(msg config.Message) (string, error) {
|
||||
}
|
||||
|
||||
// Use notices to send join/leave events
|
||||
if msg.Event == config.EventJoinLeave {
|
||||
if msg.Event == config.EventJoinLeave || msg.Event == config.EventNotice {
|
||||
m.MsgType = event.MsgNotice
|
||||
} else {
|
||||
m.MsgType = event.MsgText
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
//go:build !noirc
|
||||
// +build !noirc
|
||||
|
||||
package bridgemap
|
||||
@@ -8,4 +9,5 @@ import (
|
||||
|
||||
func init() {
|
||||
FullMap["irc"] = birc.New
|
||||
NoticeSupport["irc"] = struct{}{}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
//go:build !nomatrix
|
||||
// +build !nomatrix
|
||||
|
||||
package bridgemap
|
||||
@@ -9,4 +10,5 @@ import (
|
||||
func init() {
|
||||
FullMap["matrix"] = bmatrix.New
|
||||
UserTypingSupport["matrix"] = struct{}{}
|
||||
NoticeSupport["matrix"] = struct{}{}
|
||||
}
|
||||
|
||||
@@ -7,4 +7,5 @@ import (
|
||||
var (
|
||||
FullMap = map[string]bridge.Factory{}
|
||||
UserTypingSupport = map[string]struct{}{}
|
||||
NoticeSupport = map[string]struct{}{}
|
||||
)
|
||||
|
||||
@@ -450,11 +450,6 @@ func (gw *Gateway) SendMessage(
|
||||
}
|
||||
}
|
||||
|
||||
// Only send irc notices to irc
|
||||
if msg.Event == config.EventNoticeIRC && dest.Protocol != "irc" {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
// Too noisy to log like other events
|
||||
debugSendMessage := ""
|
||||
if msg.Event != config.EventUserTyping {
|
||||
|
||||
@@ -199,6 +199,17 @@ func (gw *Gateway) handleMessage(rmsg *config.Message, dest *bridge.Bridge) []*B
|
||||
}
|
||||
}
|
||||
|
||||
if rmsg.Event == config.EventNotice {
|
||||
if _, ok := bridgemap.NoticeSupport[dest.Protocol]; !ok {
|
||||
// we are forced to clone the pointer, as `rmsg` is re-used across calls to handleMessage
|
||||
newMsg := *rmsg
|
||||
// if the destination doesn't support IRC/Matrix 'notices',
|
||||
// emit a normal message
|
||||
newMsg.Event = ""
|
||||
rmsg = &newMsg
|
||||
}
|
||||
}
|
||||
|
||||
// if we have an attached file, or other info
|
||||
if rmsg.Extra != nil && len(rmsg.Extra[config.EventFileFailureSize]) != 0 && rmsg.Text == "" {
|
||||
return brMsgIDs
|
||||
|
||||
Reference in New Issue
Block a user