diff --git a/database/message.go b/database/message.go index 4e23b2b..a8d8fba 100644 --- a/database/message.go +++ b/database/message.go @@ -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) +// } +//} diff --git a/portal.go b/portal.go index 57905d9..beda107 100644 --- a/portal.go +++ b/portal.go @@ -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