Allow user to configure whether his/her own messages should be bridged or not

master
Hugo Thunnissen 4 years ago
parent 1a7eb2c659
commit 6025be4fb1

@ -59,3 +59,18 @@ func (b *BridgeContext) MessageWasSent(ID string) bool {
return sent
}
func (b *BridgeContext) ShouldMessageBeSent(info whatsapp.MessageInfo) bool {
// Skip if the message has already been sent
if b.MessageWasSent(info.Id) {
return false
}
// send if not from user
if !info.FromMe {
return true
}
// If from user, only send when it is enabled in the config
return b.Config.App.ShowFromMe
}

@ -9,6 +9,7 @@ import (
type AppConfig struct {
DataFolder string `yaml:"data_folder"`
UserAddress string `yaml:"user"`
ShowFromMe bool `yaml:"show_from_me"`
}
type Config struct {

@ -18,7 +18,7 @@ type MessageAction func() error
func MakeTextMessageAction(b *BridgeContext, m whatsapp.TextMessage) MessageAction {
return func() error {
if b.MessageWasSent(m.Info.Id) {
if !b.ShouldMessageBeSent(m.Info) {
return nil
}
@ -43,7 +43,7 @@ func MakeTextMessageAction(b *BridgeContext, m whatsapp.TextMessage) MessageActi
func MakeImageMessageAction(b *BridgeContext, m whatsapp.ImageMessage) MessageAction {
return func() error {
if b.MessageWasSent(m.Info.Id) {
if !b.ShouldMessageBeSent(m.Info) {
return nil
}
@ -84,7 +84,7 @@ func MakeImageMessageAction(b *BridgeContext, m whatsapp.ImageMessage) MessageAc
func MakeDocumentMessageAction(b *BridgeContext, m whatsapp.DocumentMessage) MessageAction {
return func() error {
if b.MessageWasSent(m.Info.Id) {
if !b.ShouldMessageBeSent(m.Info) {
return nil
}
@ -125,7 +125,7 @@ func MakeDocumentMessageAction(b *BridgeContext, m whatsapp.DocumentMessage) Mes
func MakeAudioMessageAction(b *BridgeContext, m whatsapp.AudioMessage) MessageAction {
return func() error {
if b.MessageWasSent(m.Info.Id) {
if !b.ShouldMessageBeSent(m.Info) {
return nil
}
@ -166,7 +166,7 @@ func MakeAudioMessageAction(b *BridgeContext, m whatsapp.AudioMessage) MessageAc
func MakeVideoMessageAction(b *BridgeContext, m whatsapp.VideoMessage) MessageAction {
return func() error {
if b.MessageWasSent(m.Info.Id) {
if !b.ShouldMessageBeSent(m.Info) {
return nil
}
@ -207,7 +207,7 @@ func MakeVideoMessageAction(b *BridgeContext, m whatsapp.VideoMessage) MessageAc
func MakeContactMessageAction(b *BridgeContext, m whatsapp.ContactMessage) MessageAction {
return func() error {
if b.MessageWasSent(m.Info.Id) {
if !b.ShouldMessageBeSent(m.Info) {
return nil
}

Loading…
Cancel
Save