mirror of
https://github.com/cwinfo/matterbridge.git
synced 2024-11-14 03:50:26 +00:00
Refactor "msg-parent-not-found" to config.ParentIDNotFound (#1347)
This commit is contained in:
parent
1a4717b366
commit
a9d8ac8bc0
@ -29,6 +29,8 @@ const (
|
|||||||
EventNoticeIRC = "notice_irc"
|
EventNoticeIRC = "notice_irc"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const ParentIDNotFound = "msg-parent-not-found"
|
||||||
|
|
||||||
type Message struct {
|
type Message struct {
|
||||||
Text string `json:"text"`
|
Text string `json:"text"`
|
||||||
Channel string `json:"channel"`
|
Channel string `json:"channel"`
|
||||||
@ -45,6 +47,14 @@ type Message struct {
|
|||||||
Extra map[string][]interface{}
|
Extra map[string][]interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m Message) ParentNotFound() bool {
|
||||||
|
return m.ParentID == ParentIDNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m Message) ParentValid() bool {
|
||||||
|
return m.ParentID != "" && !m.ParentNotFound()
|
||||||
|
}
|
||||||
|
|
||||||
type FileInfo struct {
|
type FileInfo struct {
|
||||||
Name string
|
Name string
|
||||||
Data *[]byte
|
Data *[]byte
|
||||||
|
@ -243,7 +243,7 @@ func (b *Bdiscord) Send(msg config.Message) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle prefix hint for unthreaded messages.
|
// Handle prefix hint for unthreaded messages.
|
||||||
if msg.ParentID == "msg-parent-not-found" {
|
if msg.ParentNotFound() {
|
||||||
msg.ParentID = ""
|
msg.ParentID = ""
|
||||||
msg.Text = fmt.Sprintf("[thread]: %s", msg.Text)
|
msg.Text = fmt.Sprintf("[thread]: %s", msg.Text)
|
||||||
}
|
}
|
||||||
@ -297,7 +297,7 @@ func (b *Bdiscord) handleEventBotUser(msg *config.Message, channelID string) (st
|
|||||||
Content: msg.Username + msg.Text,
|
Content: msg.Username + msg.Text,
|
||||||
}
|
}
|
||||||
|
|
||||||
if msg.ParentID != "" && msg.ParentID != "msg-parent-not-found" {
|
if msg.ParentValid() {
|
||||||
m.Reference = &discordgo.MessageReference{
|
m.Reference = &discordgo.MessageReference{
|
||||||
MessageID: msg.ParentID,
|
MessageID: msg.ParentID,
|
||||||
ChannelID: channelID,
|
ChannelID: channelID,
|
||||||
|
@ -122,7 +122,7 @@ func (b *Bmattermost) Send(msg config.Message) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle prefix hint for unthreaded messages.
|
// Handle prefix hint for unthreaded messages.
|
||||||
if msg.ParentID == "msg-parent-not-found" {
|
if msg.ParentNotFound() {
|
||||||
msg.ParentID = ""
|
msg.ParentID = ""
|
||||||
msg.Text = fmt.Sprintf("[thread]: %s", msg.Text)
|
msg.Text = fmt.Sprintf("[thread]: %s", msg.Text)
|
||||||
}
|
}
|
||||||
|
@ -86,13 +86,16 @@ func (b *Bmsteams) JoinChannel(channel config.ChannelInfo) error {
|
|||||||
|
|
||||||
func (b *Bmsteams) Send(msg config.Message) (string, error) {
|
func (b *Bmsteams) Send(msg config.Message) (string, error) {
|
||||||
b.Log.Debugf("=> Receiving %#v", msg)
|
b.Log.Debugf("=> Receiving %#v", msg)
|
||||||
if msg.ParentID != "" && msg.ParentID != "msg-parent-not-found" {
|
if msg.ParentValid() {
|
||||||
return b.sendReply(msg)
|
return b.sendReply(msg)
|
||||||
}
|
}
|
||||||
if msg.ParentID == "msg-parent-not-found" {
|
|
||||||
|
// Handle prefix hint for unthreaded messages.
|
||||||
|
if msg.ParentNotFound() {
|
||||||
msg.ParentID = ""
|
msg.ParentID = ""
|
||||||
msg.Text = fmt.Sprintf("[thread]: %s", msg.Text)
|
msg.Text = fmt.Sprintf("[thread]: %s", msg.Text)
|
||||||
}
|
}
|
||||||
|
|
||||||
ct := b.gc.Teams().ID(b.GetString("TeamID")).Channels().ID(msg.Channel).Messages().Request()
|
ct := b.gc.Teams().ID(b.GetString("TeamID")).Channels().ID(msg.Channel).Messages().Request()
|
||||||
text := msg.Username + msg.Text
|
text := msg.Username + msg.Text
|
||||||
content := &msgraph.ItemBody{Content: &text}
|
content := &msgraph.ItemBody{Content: &text}
|
||||||
|
@ -299,7 +299,7 @@ func (b *Bslack) sendRTM(msg config.Message) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle prefix hint for unthreaded messages.
|
// Handle prefix hint for unthreaded messages.
|
||||||
if msg.ParentID == "msg-parent-not-found" {
|
if msg.ParentNotFound() {
|
||||||
msg.ParentID = ""
|
msg.ParentID = ""
|
||||||
msg.Text = fmt.Sprintf("[thread]: %s", msg.Text)
|
msg.Text = fmt.Sprintf("[thread]: %s", msg.Text)
|
||||||
}
|
}
|
||||||
|
@ -459,9 +459,9 @@ func (gw *Gateway) SendMessage(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if the parentID is still empty and we have a parentID set in the original message
|
// if the parentID is still empty and we have a parentID set in the original message
|
||||||
// this means that we didn't find it in the cache so set it "msg-parent-not-found"
|
// this means that we didn't find it in the cache so set it to a "msg-parent-not-found" constant
|
||||||
if msg.ParentID == "" && rmsg.ParentID != "" {
|
if msg.ParentID == "" && rmsg.ParentID != "" {
|
||||||
msg.ParentID = "msg-parent-not-found"
|
msg.ParentID = config.ParentIDNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
drop, err := gw.modifyOutMessageTengo(rmsg, &msg, dest)
|
drop, err := gw.modifyOutMessageTengo(rmsg, &msg, dest)
|
||||||
|
Loading…
Reference in New Issue
Block a user