mirror of
https://github.com/cwinfo/matterbridge.git
synced 2024-11-26 00:51:36 +00:00
Add support for mattermost threading (#627)
This commit is contained in:
parent
5193634a52
commit
b33b50987b
@ -104,6 +104,7 @@ func (b *Bmattermost) handleMatterClient(messages chan *config.Message) {
|
|||||||
Channel: message.Channel,
|
Channel: message.Channel,
|
||||||
Text: message.Text,
|
Text: message.Text,
|
||||||
ID: message.Post.Id,
|
ID: message.Post.Id,
|
||||||
|
ParentID: message.Post.ParentId,
|
||||||
Extra: make(map[string][]interface{}),
|
Extra: make(map[string][]interface{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,7 +164,7 @@ func (b *Bmattermost) handleUploadFile(msg *config.Message) (string, error) {
|
|||||||
if b.GetBool("PrefixMessagesWithNick") {
|
if b.GetBool("PrefixMessagesWithNick") {
|
||||||
msg.Text = msg.Username + msg.Text
|
msg.Text = msg.Username + msg.Text
|
||||||
}
|
}
|
||||||
res, err = b.mc.PostMessageWithFiles(channelID, msg.Text, []string{id})
|
res, err = b.mc.PostMessageWithFiles(channelID, msg.Text, msg.ParentID, []string{id})
|
||||||
}
|
}
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,7 @@ func (b *Bmattermost) Send(msg config.Message) (string, error) {
|
|||||||
// Upload a file if it exists
|
// Upload a file if it exists
|
||||||
if msg.Extra != nil {
|
if msg.Extra != nil {
|
||||||
for _, rmsg := range helper.HandleExtra(&msg, b.General) {
|
for _, rmsg := range helper.HandleExtra(&msg, b.General) {
|
||||||
if _, err := b.mc.PostMessage(b.mc.GetChannelId(rmsg.Channel, b.TeamID), rmsg.Username+rmsg.Text); err != nil {
|
if _, err := b.mc.PostMessage(b.mc.GetChannelId(rmsg.Channel, b.TeamID), rmsg.Username+rmsg.Text, msg.ParentID); err != nil {
|
||||||
b.Log.Errorf("PostMessage failed: %s", err)
|
b.Log.Errorf("PostMessage failed: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -144,5 +144,5 @@ func (b *Bmattermost) Send(msg config.Message) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Post normal message
|
// Post normal message
|
||||||
return b.mc.PostMessage(b.mc.GetChannelId(msg.Channel, b.TeamID), msg.Text)
|
return b.mc.PostMessage(b.mc.GetChannelId(msg.Channel, b.TeamID), msg.Text, msg.ParentID)
|
||||||
}
|
}
|
||||||
|
@ -146,8 +146,8 @@ func (m *MMClient) GetPublicLinks(filenames []string) []string {
|
|||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MMClient) PostMessage(channelId string, text string) (string, error) { //nolint:golint
|
func (m *MMClient) PostMessage(channelId string, text string, rootId string) (string, error) { //nolint:golint
|
||||||
post := &model.Post{ChannelId: channelId, Message: text}
|
post := &model.Post{ChannelId: channelId, Message: text, RootId: rootId}
|
||||||
res, resp := m.Client.CreatePost(post)
|
res, resp := m.Client.CreatePost(post)
|
||||||
if resp.Error != nil {
|
if resp.Error != nil {
|
||||||
return "", resp.Error
|
return "", resp.Error
|
||||||
@ -155,8 +155,8 @@ func (m *MMClient) PostMessage(channelId string, text string) (string, error) {
|
|||||||
return res.Id, nil
|
return res.Id, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MMClient) PostMessageWithFiles(channelId string, text string, fileIds []string) (string, error) { //nolint:golint
|
func (m *MMClient) PostMessageWithFiles(channelId string, text string, rootId string, fileIds []string) (string, error) { //nolint:golint
|
||||||
post := &model.Post{ChannelId: channelId, Message: text, FileIds: fileIds}
|
post := &model.Post{ChannelId: channelId, Message: text, RootId: rootId, FileIds: fileIds}
|
||||||
res, resp := m.Client.CreatePost(post)
|
res, resp := m.Client.CreatePost(post)
|
||||||
if resp.Error != nil {
|
if resp.Error != nil {
|
||||||
return "", resp.Error
|
return "", resp.Error
|
||||||
@ -173,11 +173,11 @@ func (m *MMClient) SearchPosts(query string) *model.PostList {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SendDirectMessage sends a direct message to specified user
|
// SendDirectMessage sends a direct message to specified user
|
||||||
func (m *MMClient) SendDirectMessage(toUserId string, msg string) { //nolint:golint
|
func (m *MMClient) SendDirectMessage(toUserId string, msg string, rootId string) { //nolint:golint
|
||||||
m.SendDirectMessageProps(toUserId, msg, nil)
|
m.SendDirectMessageProps(toUserId, msg, rootId, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MMClient) SendDirectMessageProps(toUserId string, msg string, props map[string]interface{}) { //nolint:golint
|
func (m *MMClient) SendDirectMessageProps(toUserId string, msg string, rootId string, props map[string]interface{}) { //nolint:golint
|
||||||
m.log.Debugf("SendDirectMessage to %s, msg %s", toUserId, msg)
|
m.log.Debugf("SendDirectMessage to %s, msg %s", toUserId, msg)
|
||||||
// create DM channel (only happens on first message)
|
// create DM channel (only happens on first message)
|
||||||
_, resp := m.Client.CreateDirectChannel(m.User.Id, toUserId)
|
_, resp := m.Client.CreateDirectChannel(m.User.Id, toUserId)
|
||||||
@ -194,7 +194,7 @@ func (m *MMClient) SendDirectMessageProps(toUserId string, msg string, props map
|
|||||||
|
|
||||||
// build & send the message
|
// build & send the message
|
||||||
msg = strings.Replace(msg, "\r", "", -1)
|
msg = strings.Replace(msg, "\r", "", -1)
|
||||||
post := &model.Post{ChannelId: m.GetChannelId(channelName, m.Team.Id), Message: msg, Props: props}
|
post := &model.Post{ChannelId: m.GetChannelId(channelName, m.Team.Id), Message: msg, RootId: rootId, Props: props}
|
||||||
m.Client.CreatePost(post)
|
m.Client.CreatePost(post)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user