Inserting message on handleMessage

This commit is contained in:
Brandon Watson 2023-09-11 17:32:11 -05:00
parent 22a9faa3ca
commit d9fc3014b4
2 changed files with 21 additions and 1 deletions

View File

@ -19,6 +19,7 @@ package database
import (
"database/sql"
"errors"
"fmt"
"go.mau.fi/util/dbutil"
"time"
@ -143,3 +144,22 @@ func (msg *Message) Scan(row dbutil.Scannable) *Message {
}
return msg
}
func (msg *Message) Insert() {
query := fmt.Sprintf(`
INSERT INTO message (chat_gmid, chat_receiver, gmid, mxid, sender, timestamp, sent)
VALUES ('%s', '%s', '%s', '%s', '%s', '%d', '%t')
`, msg.Chat.GMID, msg.Chat.Receiver, msg.GMID, msg.MXID, msg.Sender, msg.Timestamp.Unix(), msg.Sent)
_, err := msg.db.Exec(query)
if err != nil {
msg.log.Warnfln("Failed to insert %s: %v", msg.MXID, err)
}
}
//func (msg *Message) Delete() {
// ans := msg.db.Delete(&msg)
// if ans.Error != nil {
// msg.log.Warnfln("Failed to delete %s@%s: %v", msg.Chat, msg.JID, ans.Error)
// }
//}

View File

@ -931,7 +931,7 @@ func (portal *Portal) markHandled(source *User, message *groupme.Message, mxid i
} else {
msg.Sender = message.SenderID
}
// msg.Insert()
msg.Insert()
portal.recentlyHandledLock.Lock()
portal.recentlyHandled[0] = "" //FIFO queue being implemented here //TODO: is this efficent