REFACTOR: fix some SQL queries that were indented with spaces, clean up some stuff

This commit is contained in:
Alessio 2023-12-24 19:22:44 -06:00
parent e1bc6bba98
commit d80a2bd5b1
2 changed files with 82 additions and 64 deletions

View File

@ -570,7 +570,8 @@ func TestLists(t *testing.T) {
// Messages
// --------
func TestMessages(t *testing.T) {
// Loading the index page should work if you're logged in
func TestMessagesIndexPage(t *testing.T) {
assert := assert.New(t)
require := require.New(t)
@ -587,12 +588,23 @@ func TestMessages(t *testing.T) {
require.NoError(err)
assert.Len(cascadia.QueryAll(root, selector(".chat-list .chat")), 2)
assert.Len(cascadia.QueryAll(root, selector(".chat-view .dm-message-and-reacts-container")), 0) // No messages until you click on one
}
// Open a chat room
func TestMessagesRoom(t *testing.T) {
assert := assert.New(t)
require := require.New(t)
// Boilerplate for setting an active user
app := webserver.NewApp(profile)
app.IsScrapingDisabled = true
app.ActiveUser = scraper.User{ID: 1488963321701171204, Handle: "Offline_Twatter"} // Simulate a login
// Chat detail
recorder = httptest.NewRecorder()
recorder := httptest.NewRecorder()
app.ServeHTTP(recorder, httptest.NewRequest("GET", "/messages/1488963321701171204-1178839081222115328", nil))
resp = recorder.Result()
root, err = html.Parse(resp.Body)
resp := recorder.Result()
root, err := html.Parse(resp.Body)
require.NoError(err)
assert.Len(cascadia.QueryAll(root, selector(".chat-list .chat")), 2) // Chat list still renders
assert.Len(cascadia.QueryAll(root, selector("#chat-view .dm-message-and-reacts-container")), 5)

View File

@ -273,7 +273,7 @@ func (p Profile) GetChatRoomContents(id DMChatRoomID) DMChatView {
err = p.DB.Select(&msgs, `
select id, chat_room_id, sender_id, sent_at, request_id, text, in_reply_to_id, embedded_tweet_id
from chat_messages
where chat_room_id = :room_id
where chat_room_id = ?
order by sent_at desc
limit 50
`, room.ID)
@ -288,11 +288,16 @@ func (p Profile) GetChatRoomContents(id DMChatRoomID) DMChatView {
}
// Set last message ID on chat room
if len(ret.MessageIDs) > 0 {
// If there's no messages, it should be OK to have LastMessageID = 0, since this is only used
// to generate previews
room.LastMessageID = ret.MessageIDs[len(ret.MessageIDs)-1]
}
// Put the room in the Trove
ret.Rooms[room.ID] = room
if len(ret.MessageIDs) > 0 {
// Fetch all reaccs
var reaccs []DMReaction
message_ids_copy := make([]interface{}, len(ret.MessageIDs))
@ -338,6 +343,7 @@ func (p Profile) GetChatRoomContents(id DMChatRoomID) DMChatView {
}
p.fill_content(&ret.DMTrove.TweetTrove, UserID(0))
}
return ret
}