Forward only user-typing messages if supported by protocol (#832)

Fixes issue #814.

This is a somewhat hacky way of achieving the required goal but it seems
like this is the least problematic way of getting there.

We might want to redesign some bridge information later such that we
have a standardised way of specifying what is and what isn't supported
by each chat protocol / bridge.
This commit is contained in:
Duco van Amstel 2019-05-30 14:00:40 +01:00 committed by Wim
parent 3724cc3a15
commit b79bf7d414
2 changed files with 45 additions and 30 deletions

View File

@ -3,35 +3,41 @@ package bridgemap
import ( import (
"github.com/42wim/matterbridge/bridge" "github.com/42wim/matterbridge/bridge"
"github.com/42wim/matterbridge/bridge/api" "github.com/42wim/matterbridge/bridge/api"
"github.com/42wim/matterbridge/bridge/discord" bdiscord "github.com/42wim/matterbridge/bridge/discord"
"github.com/42wim/matterbridge/bridge/gitter" bgitter "github.com/42wim/matterbridge/bridge/gitter"
"github.com/42wim/matterbridge/bridge/irc" birc "github.com/42wim/matterbridge/bridge/irc"
"github.com/42wim/matterbridge/bridge/matrix" bmatrix "github.com/42wim/matterbridge/bridge/matrix"
"github.com/42wim/matterbridge/bridge/mattermost" bmattermost "github.com/42wim/matterbridge/bridge/mattermost"
"github.com/42wim/matterbridge/bridge/rocketchat" brocketchat "github.com/42wim/matterbridge/bridge/rocketchat"
"github.com/42wim/matterbridge/bridge/slack" bslack "github.com/42wim/matterbridge/bridge/slack"
"github.com/42wim/matterbridge/bridge/sshchat" bsshchat "github.com/42wim/matterbridge/bridge/sshchat"
"github.com/42wim/matterbridge/bridge/steam" bsteam "github.com/42wim/matterbridge/bridge/steam"
"github.com/42wim/matterbridge/bridge/telegram" btelegram "github.com/42wim/matterbridge/bridge/telegram"
"github.com/42wim/matterbridge/bridge/whatsapp" bwhatsapp "github.com/42wim/matterbridge/bridge/whatsapp"
"github.com/42wim/matterbridge/bridge/xmpp" bxmpp "github.com/42wim/matterbridge/bridge/xmpp"
"github.com/42wim/matterbridge/bridge/zulip" bzulip "github.com/42wim/matterbridge/bridge/zulip"
) )
var FullMap = map[string]bridge.Factory{ var (
"api": api.New, FullMap = map[string]bridge.Factory{
"discord": bdiscord.New, "api": api.New,
"gitter": bgitter.New, "discord": bdiscord.New,
"irc": birc.New, "gitter": bgitter.New,
"mattermost": bmattermost.New, "irc": birc.New,
"matrix": bmatrix.New, "mattermost": bmattermost.New,
"rocketchat": brocketchat.New, "matrix": bmatrix.New,
"slack-legacy": bslack.NewLegacy, "rocketchat": brocketchat.New,
"slack": bslack.New, "slack-legacy": bslack.NewLegacy,
"sshchat": bsshchat.New, "slack": bslack.New,
"steam": bsteam.New, "sshchat": bsshchat.New,
"telegram": btelegram.New, "steam": bsteam.New,
"whatsapp": bwhatsapp.New, "telegram": btelegram.New,
"xmpp": bxmpp.New, "whatsapp": bwhatsapp.New,
"zulip": bzulip.New, "xmpp": bxmpp.New,
} "zulip": bzulip.New,
}
UserTypingSupport = map[string]struct{}{
"slack": {},
}
)

View File

@ -14,6 +14,7 @@ import (
"github.com/42wim/matterbridge/bridge" "github.com/42wim/matterbridge/bridge"
"github.com/42wim/matterbridge/bridge/config" "github.com/42wim/matterbridge/bridge/config"
"github.com/42wim/matterbridge/gateway/bridgemap"
) )
// handleEventFailure handles failures and reconnects bridges. // handleEventFailure handles failures and reconnects bridges.
@ -190,6 +191,14 @@ func (gw *Gateway) ignoreEvent(event string, dest *bridge.Bridge) bool {
func (gw *Gateway) handleMessage(rmsg *config.Message, dest *bridge.Bridge) []*BrMsgID { func (gw *Gateway) handleMessage(rmsg *config.Message, dest *bridge.Bridge) []*BrMsgID {
var brMsgIDs []*BrMsgID var brMsgIDs []*BrMsgID
// Not all bridges support "user is typing" indications so skip the message
// if the targeted bridge does not support it.
if rmsg.Event == config.EventUserTyping {
if _, ok := bridgemap.UserTypingSupport[dest.Protocol]; !ok {
return nil
}
}
// if we have an attached file, or other info // if we have an attached file, or other info
if rmsg.Extra != nil && len(rmsg.Extra[config.EventFileFailureSize]) != 0 && rmsg.Text == "" { if rmsg.Extra != nil && len(rmsg.Extra[config.EventFileFailureSize]) != 0 && rmsg.Text == "" {
return brMsgIDs return brMsgIDs