|
@@ -19,7 +19,7 @@ type MessageQuery struct {
|
|
}
|
|
}
|
|
|
|
|
|
const (
|
|
const (
|
|
- messageSelect = "SELECT dcid, dc_attachment_id, dc_chan_id, dc_chan_receiver, dc_sender, timestamp, dc_edit_timestamp, dc_thread_id, mxid FROM message"
|
|
|
|
|
|
+ messageSelect = "SELECT dcid, dc_attachment_id, dc_chan_id, dc_chan_receiver, dc_sender, timestamp, dc_edit_timestamp, dc_thread_id, mxid, sender_mxid FROM message"
|
|
)
|
|
)
|
|
|
|
|
|
func (mq *MessageQuery) New() *Message {
|
|
func (mq *MessageQuery) New() *Message {
|
|
@@ -99,11 +99,11 @@ func (mq *MessageQuery) MassInsert(key PortalKey, msgs []Message) {
|
|
if len(msgs) == 0 {
|
|
if len(msgs) == 0 {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- valueStringFormat := "($%d, $%d, $1, $2, $%d, $%d, $%d, $%d, $%d)"
|
|
|
|
|
|
+ valueStringFormat := "($%d, $%d, $1, $2, $%d, $%d, $%d, $%d, $%d, $%d)"
|
|
if mq.db.Dialect == dbutil.SQLite {
|
|
if mq.db.Dialect == dbutil.SQLite {
|
|
valueStringFormat = strings.ReplaceAll(valueStringFormat, "$", "?")
|
|
valueStringFormat = strings.ReplaceAll(valueStringFormat, "$", "?")
|
|
}
|
|
}
|
|
- params := make([]interface{}, 2+len(msgs)*7)
|
|
|
|
|
|
+ params := make([]interface{}, 2+len(msgs)*8)
|
|
placeholders := make([]string, len(msgs))
|
|
placeholders := make([]string, len(msgs))
|
|
params[0] = key.ChannelID
|
|
params[0] = key.ChannelID
|
|
params[1] = key.Receiver
|
|
params[1] = key.Receiver
|
|
@@ -116,7 +116,8 @@ func (mq *MessageQuery) MassInsert(key PortalKey, msgs []Message) {
|
|
params[baseIndex+4] = msg.editTimestampVal()
|
|
params[baseIndex+4] = msg.editTimestampVal()
|
|
params[baseIndex+5] = msg.ThreadID
|
|
params[baseIndex+5] = msg.ThreadID
|
|
params[baseIndex+6] = msg.MXID
|
|
params[baseIndex+6] = msg.MXID
|
|
- placeholders[i] = fmt.Sprintf(valueStringFormat, baseIndex+1, baseIndex+2, baseIndex+3, baseIndex+4, baseIndex+5, baseIndex+6, baseIndex+7)
|
|
|
|
|
|
+ params[baseIndex+7] = msg.SenderMXID.String()
|
|
|
|
+ placeholders[i] = fmt.Sprintf(valueStringFormat, baseIndex+1, baseIndex+2, baseIndex+3, baseIndex+4, baseIndex+5, baseIndex+6, baseIndex+7, baseIndex+8)
|
|
}
|
|
}
|
|
_, err := mq.db.Exec(fmt.Sprintf(messageMassInsertTemplate, strings.Join(placeholders, ", ")), params...)
|
|
_, err := mq.db.Exec(fmt.Sprintf(messageMassInsertTemplate, strings.Join(placeholders, ", ")), params...)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -137,7 +138,8 @@ type Message struct {
|
|
EditTimestamp time.Time
|
|
EditTimestamp time.Time
|
|
ThreadID string
|
|
ThreadID string
|
|
|
|
|
|
- MXID id.EventID
|
|
|
|
|
|
+ MXID id.EventID
|
|
|
|
+ SenderMXID id.UserID
|
|
}
|
|
}
|
|
|
|
|
|
func (m *Message) DiscordProtoChannelID() string {
|
|
func (m *Message) DiscordProtoChannelID() string {
|
|
@@ -151,7 +153,7 @@ func (m *Message) DiscordProtoChannelID() string {
|
|
func (m *Message) Scan(row dbutil.Scannable) *Message {
|
|
func (m *Message) Scan(row dbutil.Scannable) *Message {
|
|
var ts, editTS int64
|
|
var ts, editTS int64
|
|
|
|
|
|
- err := row.Scan(&m.DiscordID, &m.AttachmentID, &m.Channel.ChannelID, &m.Channel.Receiver, &m.SenderID, &ts, &editTS, &m.ThreadID, &m.MXID)
|
|
|
|
|
|
+ err := row.Scan(&m.DiscordID, &m.AttachmentID, &m.Channel.ChannelID, &m.Channel.Receiver, &m.SenderID, &ts, &editTS, &m.ThreadID, &m.MXID, &m.SenderMXID)
|
|
if err != nil {
|
|
if err != nil {
|
|
if !errors.Is(err, sql.ErrNoRows) {
|
|
if !errors.Is(err, sql.ErrNoRows) {
|
|
m.log.Errorln("Database scan failed:", err)
|
|
m.log.Errorln("Database scan failed:", err)
|
|
@@ -173,12 +175,12 @@ func (m *Message) Scan(row dbutil.Scannable) *Message {
|
|
|
|
|
|
const messageInsertQuery = `
|
|
const messageInsertQuery = `
|
|
INSERT INTO message (
|
|
INSERT INTO message (
|
|
- dcid, dc_attachment_id, dc_chan_id, dc_chan_receiver, dc_sender, timestamp, dc_edit_timestamp, dc_thread_id, mxid
|
|
|
|
|
|
+ dcid, dc_attachment_id, dc_chan_id, dc_chan_receiver, dc_sender, timestamp, dc_edit_timestamp, dc_thread_id, mxid, sender_mxid
|
|
)
|
|
)
|
|
- VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
|
|
|
|
|
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
|
|
`
|
|
`
|
|
|
|
|
|
-var messageMassInsertTemplate = strings.Replace(messageInsertQuery, "($1, $2, $3, $4, $5, $6, $7, $8, $9)", "%s", 1)
|
|
|
|
|
|
+var messageMassInsertTemplate = strings.Replace(messageInsertQuery, "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)", "%s", 1)
|
|
|
|
|
|
type MessagePart struct {
|
|
type MessagePart struct {
|
|
AttachmentID string
|
|
AttachmentID string
|
|
@@ -196,11 +198,11 @@ func (m *Message) MassInsertParts(msgs []MessagePart) {
|
|
if len(msgs) == 0 {
|
|
if len(msgs) == 0 {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- valueStringFormat := "($1, $%d, $2, $3, $4, $5, $6, $7, $%d)"
|
|
|
|
|
|
+ valueStringFormat := "($1, $%d, $2, $3, $4, $5, $6, $7, $%d, $8)"
|
|
if m.db.Dialect == dbutil.SQLite {
|
|
if m.db.Dialect == dbutil.SQLite {
|
|
valueStringFormat = strings.ReplaceAll(valueStringFormat, "$", "?")
|
|
valueStringFormat = strings.ReplaceAll(valueStringFormat, "$", "?")
|
|
}
|
|
}
|
|
- params := make([]interface{}, 7+len(msgs)*2)
|
|
|
|
|
|
+ params := make([]interface{}, 8+len(msgs)*2)
|
|
placeholders := make([]string, len(msgs))
|
|
placeholders := make([]string, len(msgs))
|
|
params[0] = m.DiscordID
|
|
params[0] = m.DiscordID
|
|
params[1] = m.Channel.ChannelID
|
|
params[1] = m.Channel.ChannelID
|
|
@@ -209,10 +211,11 @@ func (m *Message) MassInsertParts(msgs []MessagePart) {
|
|
params[4] = m.Timestamp.UnixMilli()
|
|
params[4] = m.Timestamp.UnixMilli()
|
|
params[5] = m.editTimestampVal()
|
|
params[5] = m.editTimestampVal()
|
|
params[6] = m.ThreadID
|
|
params[6] = m.ThreadID
|
|
|
|
+ params[7] = m.SenderMXID.String()
|
|
for i, msg := range msgs {
|
|
for i, msg := range msgs {
|
|
- params[7+i*2] = msg.AttachmentID
|
|
|
|
- params[7+i*2+1] = msg.MXID
|
|
|
|
- placeholders[i] = fmt.Sprintf(valueStringFormat, 7+i*2+1, 7+i*2+2)
|
|
|
|
|
|
+ params[8+i*2] = msg.AttachmentID
|
|
|
|
+ params[8+i*2+1] = msg.MXID
|
|
|
|
+ placeholders[i] = fmt.Sprintf(valueStringFormat, 8+i*2+1, 8+i*2+2)
|
|
}
|
|
}
|
|
_, err := m.db.Exec(fmt.Sprintf(messageMassInsertTemplate, strings.Join(placeholders, ", ")), params...)
|
|
_, err := m.db.Exec(fmt.Sprintf(messageMassInsertTemplate, strings.Join(placeholders, ", ")), params...)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -224,7 +227,7 @@ func (m *Message) MassInsertParts(msgs []MessagePart) {
|
|
func (m *Message) Insert() {
|
|
func (m *Message) Insert() {
|
|
_, err := m.db.Exec(messageInsertQuery,
|
|
_, err := m.db.Exec(messageInsertQuery,
|
|
m.DiscordID, m.AttachmentID, m.Channel.ChannelID, m.Channel.Receiver, m.SenderID,
|
|
m.DiscordID, m.AttachmentID, m.Channel.ChannelID, m.Channel.Receiver, m.SenderID,
|
|
- m.Timestamp.UnixMilli(), m.editTimestampVal(), m.ThreadID, m.MXID)
|
|
|
|
|
|
+ m.Timestamp.UnixMilli(), m.editTimestampVal(), m.ThreadID, m.MXID, m.SenderMXID.String())
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
m.log.Warnfln("Failed to insert %s@%s: %v", m.DiscordID, m.Channel, err)
|
|
m.log.Warnfln("Failed to insert %s@%s: %v", m.DiscordID, m.Channel, err)
|