Add support for edited messages (gitter)
This commit is contained in:
parent
fdb57230a3
commit
17b8b86d68
|
@ -2,10 +2,12 @@ package bgitter
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/42wim/matterbridge/bridge/config"
|
"github.com/42wim/matterbridge/bridge/config"
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
"github.com/sromku/go-gitter"
|
"github.com/sromku/go-gitter"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Bgitter struct {
|
type Bgitter struct {
|
||||||
|
@ -71,27 +73,48 @@ func (b *Bgitter) JoinChannel(channel string) error {
|
||||||
}
|
}
|
||||||
users, _ := b.c.GetUsersInRoom(roomID)
|
users, _ := b.c.GetUsersInRoom(roomID)
|
||||||
b.Users = append(b.Users, users...)
|
b.Users = append(b.Users, users...)
|
||||||
|
|
||||||
|
// we need to use (experimental) faye for edits.
|
||||||
|
// streaming API doesn't show edits.
|
||||||
|
if !b.Config.EditDisable {
|
||||||
|
faye := b.c.Faye(roomID)
|
||||||
|
go faye.Listen()
|
||||||
|
go func(stream *gitter.Faye, room string) {
|
||||||
|
for event := range stream.Event {
|
||||||
|
b.handleEvent(event, room)
|
||||||
|
}
|
||||||
|
}(faye, room.Name)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
stream := b.c.Stream(roomID)
|
stream := b.c.Stream(roomID)
|
||||||
go b.c.Listen(stream)
|
go b.c.Listen(stream)
|
||||||
|
|
||||||
go func(stream *gitter.Stream, room string) {
|
go func(stream *gitter.Stream, room string) {
|
||||||
for event := range stream.Event {
|
for event := range stream.Event {
|
||||||
switch ev := event.Data.(type) {
|
b.handleEvent(event, room)
|
||||||
case *gitter.MessageReceived:
|
|
||||||
// check for ZWSP to see if it's not an echo
|
|
||||||
if !strings.HasSuffix(ev.Message.Text, "") {
|
|
||||||
flog.Debugf("Sending message from %s on %s to gateway", ev.Message.From.Username, b.Account)
|
|
||||||
b.Remote <- config.Message{Username: ev.Message.From.Username, Text: ev.Message.Text, Channel: room,
|
|
||||||
Account: b.Account, Avatar: b.getAvatar(ev.Message.From.Username)}
|
|
||||||
}
|
|
||||||
case *gitter.GitterConnectionClosed:
|
|
||||||
flog.Errorf("connection with gitter closed for room %s", room)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}(stream, room.Name)
|
}(stream, room.Name)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *Bgitter) handleEvent(event gitter.Event, room string) {
|
||||||
|
flog.Debugf("event: %#v %#v", event.Data, event.Data.(*gitter.MessageReceived).Message.EditedAt.Sub(time.Now()).String())
|
||||||
|
switch ev := event.Data.(type) {
|
||||||
|
case *gitter.MessageReceived:
|
||||||
|
// check for ZWSP to see if it's not an echo
|
||||||
|
if !strings.HasSuffix(ev.Message.Text, "") {
|
||||||
|
if !ev.Message.EditedAt.IsZero() && !b.Config.EditDisable {
|
||||||
|
ev.Message.Text = ev.Message.Text + b.Config.EditSuffix
|
||||||
|
}
|
||||||
|
flog.Debugf("Sending message from %s on %s to gateway", ev.Message.From.Username, b.Account)
|
||||||
|
b.Remote <- config.Message{Username: ev.Message.From.Username, Text: ev.Message.Text, Channel: room,
|
||||||
|
Account: b.Account, Avatar: b.getAvatar(ev.Message.From.Username)}
|
||||||
|
}
|
||||||
|
case *gitter.GitterConnectionClosed:
|
||||||
|
flog.Errorf("connection with gitter closed for room %s", room)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (b *Bgitter) Send(msg config.Message) error {
|
func (b *Bgitter) Send(msg config.Message) error {
|
||||||
flog.Debugf("Receiving %#v", msg)
|
flog.Debugf("Receiving %#v", msg)
|
||||||
roomID := b.getRoomID(msg.Channel)
|
roomID := b.getRoomID(msg.Channel)
|
||||||
|
|
11
changelog.md
11
changelog.md
|
@ -1,8 +1,17 @@
|
||||||
# v0.12.0
|
# v0.12.0
|
||||||
|
## Changes
|
||||||
|
* gitter: The default support for edited messages enables experimental FAYE support for gitter.
|
||||||
|
If you need stable code add EditDisable=true to your gitter configuration.
|
||||||
|
|
||||||
## New features
|
## New features
|
||||||
* general: add support for edited messages.
|
* general: add support for edited messages.
|
||||||
Add new keyword EditDisable (false/true), default false. Which means by default edited messages will be sent to other bridges.
|
Add new keyword EditDisable (false/true), default false. Which means by default edited messages will be sent to other bridges.
|
||||||
Add new keyword EditSuffix , default "". You can change this eg to "(edited)", this will be appended to every edit message.
|
Add new keyword EditSuffix , default "". You can change this eg to " (edited)", this will be appended to every edit message.
|
||||||
|
|
||||||
|
* discord: Add support for edited messages. See EditDisable/EditSuffix
|
||||||
|
* mattermost: Add support for edited messages. See EditDisable/EditSuffix
|
||||||
|
* telegram: Add support for edited messages. See EditDisable/EditSuffix
|
||||||
|
* gitter: Add support for edited messages. See EditDisable/EditSuffix
|
||||||
|
|
||||||
## Enhancements
|
## Enhancements
|
||||||
* discord: Strip custom emoji metadata (discord). Closes #148
|
* discord: Strip custom emoji metadata (discord). Closes #148
|
||||||
|
|
|
@ -282,6 +282,15 @@ ShowJoinPart=false
|
||||||
#REQUIRED
|
#REQUIRED
|
||||||
Token="Yourtokenhere"
|
Token="Yourtokenhere"
|
||||||
|
|
||||||
|
#Disable sending of edits to other bridges
|
||||||
|
#WARNING: the default uses FAYE which is experimental. If you need stability set EditDisable=true
|
||||||
|
#OPTIONAL (default false)
|
||||||
|
EditDisable=true
|
||||||
|
|
||||||
|
#Message to be appended to every edited message
|
||||||
|
#OPTIONAL (default empty)
|
||||||
|
EditSuffix=" (edited)"
|
||||||
|
|
||||||
#Nicks you want to ignore.
|
#Nicks you want to ignore.
|
||||||
#Messages from those users will not be sent to other bridges.
|
#Messages from those users will not be sent to other bridges.
|
||||||
#OPTIONAL
|
#OPTIONAL
|
||||||
|
|
Loading…
Reference in New Issue