Fix chat messages/reactions breaking if you save the same one twice
This commit is contained in:
parent
369616aeec
commit
7dcb0ff84e
@ -93,6 +93,7 @@ func (p Profile) SaveChatMessage(m scraper.DMMessage) error {
|
||||
_, err := p.DB.NamedExec(`
|
||||
insert into chat_messages (id, chat_room_id, sender_id, sent_at, request_id, in_reply_to_id, text)
|
||||
values (:id, :chat_room_id, :sender_id, :sent_at, :request_id, :in_reply_to_id, :text)
|
||||
on conflict do nothing
|
||||
`, m,
|
||||
)
|
||||
if err != nil {
|
||||
@ -100,13 +101,15 @@ func (p Profile) SaveChatMessage(m scraper.DMMessage) error {
|
||||
}
|
||||
|
||||
for _, reacc := range m.Reactions {
|
||||
fmt.Println(reacc)
|
||||
_, err = p.DB.NamedExec(`
|
||||
insert into chat_message_reactions (id, message_id, sender_id, sent_at, emoji)
|
||||
values (:id, :message_id, :sender_id, :sent_at, :emoji)
|
||||
on conflict do nothing
|
||||
`, reacc,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error saving message reaction (message %d, reacc %d): %#v\n %w", m.ID, reacc.ID, m, err)
|
||||
return fmt.Errorf("Error saving message reaction (message %d, reacc %d): %#v\n %w", m.ID, reacc.ID, reacc, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@ -4,9 +4,6 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
// "math/rand"
|
||||
// "time"
|
||||
|
||||
"github.com/go-test/deep"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@ -104,9 +101,9 @@ func TestSaveAndLoadChatMessage(t *testing.T) {
|
||||
require := require.New(t)
|
||||
profile_path := "test_profiles/TestDMs"
|
||||
profile := create_or_load_profile(profile_path)
|
||||
message := create_dummy_chat_message()
|
||||
|
||||
// Save it
|
||||
message := create_dummy_chat_message()
|
||||
err := profile.SaveChatMessage(message)
|
||||
require.NoError(err)
|
||||
|
||||
@ -117,4 +114,8 @@ func TestSaveAndLoadChatMessage(t *testing.T) {
|
||||
if diff := deep.Equal(message, new_message); diff != nil {
|
||||
t.Error(diff)
|
||||
}
|
||||
|
||||
// Scraping the same message again shouldn't break
|
||||
err = profile.SaveChatMessage(message)
|
||||
require.NoError(err)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user