change icon from object to string

This commit is contained in:
Hunter Kehoe 2022-07-17 15:40:24 -06:00
parent 04f2535e92
commit 99886d7f66
8 changed files with 23 additions and 77 deletions

View file

@ -39,46 +39,44 @@ const (
sender TEXT NOT NULL,
encoding TEXT NOT NULL,
published INT NOT NULL,
icon_url TEXT NOT NULL,
icon_type TEXT NOT NULL,
icon_size INT NOT NULL
icon TEXT NOT NULL
);
CREATE INDEX IF NOT EXISTS idx_mid ON messages (mid);
CREATE INDEX IF NOT EXISTS idx_topic ON messages (topic);
COMMIT;
`
insertMessageQuery = `
INSERT INTO messages (mid, time, topic, message, title, priority, tags, click, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, encoding, published, icon_url, icon_type, icon_size)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
INSERT INTO messages (mid, time, topic, message, title, priority, tags, click, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, encoding, published, icon)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
`
pruneMessagesQuery = `DELETE FROM messages WHERE time < ? AND published = 1`
selectRowIDFromMessageID = `SELECT id FROM messages WHERE mid = ?` // Do not include topic, see #336 and TestServer_PollSinceID_MultipleTopics
selectMessagesSinceTimeQuery = `
SELECT mid, time, topic, message, title, priority, tags, click, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, encoding, icon_url, icon_type, icon_size
SELECT mid, time, topic, message, title, priority, tags, click, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, encoding, icon
FROM messages
WHERE topic = ? AND time >= ? AND published = 1
ORDER BY time, id
`
selectMessagesSinceTimeIncludeScheduledQuery = `
SELECT mid, time, topic, message, title, priority, tags, click, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, encoding, icon_url, icon_type, icon_size
SELECT mid, time, topic, message, title, priority, tags, click, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, encoding, icon
FROM messages
WHERE topic = ? AND time >= ?
ORDER BY time, id
`
selectMessagesSinceIDQuery = `
SELECT mid, time, topic, message, title, priority, tags, click, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, encoding, icon_url, icon_type, icon_size
SELECT mid, time, topic, message, title, priority, tags, click, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, encoding, icon
FROM messages
WHERE topic = ? AND id > ? AND published = 1
ORDER BY time, id
`
selectMessagesSinceIDIncludeScheduledQuery = `
SELECT mid, time, topic, message, title, priority, tags, click, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, encoding, icon_url, icon_type, icon_size
SELECT mid, time, topic, message, title, priority, tags, click, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, encoding, icon
FROM messages
WHERE topic = ? AND (id > ? OR published = 0)
ORDER BY time, id
`
selectMessagesDueQuery = `
SELECT mid, time, topic, message, title, priority, tags, click, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, encoding, icon_url, icon_type, icon_size
SELECT mid, time, topic, message, title, priority, tags, click, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, encoding, icon
FROM messages
WHERE time <= ? AND published = 0
ORDER BY time, id
@ -183,9 +181,7 @@ const (
// 7 -> 8
migrate7To8AlterMessagesTableQuery = `
ALTER TABLE messages ADD COLUMN icon_url TEXT NOT NULL DEFAULT('');
ALTER TABLE messages ADD COLUMN icon_type TEXT NOT NULL DEFAULT('');
ALTER TABLE messages ADD COLUMN icon_size INT NOT NULL DEFAULT('0');
ALTER TABLE messages ADD COLUMN icon TEXT NOT NULL DEFAULT('');
`
)
@ -258,13 +254,6 @@ func (c *messageCache) addMessages(ms []*message) error {
attachmentExpires = m.Attachment.Expires
attachmentURL = m.Attachment.URL
}
var iconURL, iconType string
var iconSize int64
if m.Icon != nil {
iconURL = m.Icon.URL
iconType = m.Icon.Type
iconSize = m.Icon.Size
}
var actionsStr string
if len(m.Actions) > 0 {
actionsBytes, err := json.Marshal(m.Actions)
@ -292,9 +281,7 @@ func (c *messageCache) addMessages(ms []*message) error {
m.Sender,
m.Encoding,
published,
iconURL,
iconType,
iconSize,
m.Icon,
)
if err != nil {
return err
@ -432,9 +419,9 @@ func readMessages(rows *sql.Rows) ([]*message, error) {
defer rows.Close()
messages := make([]*message, 0)
for rows.Next() {
var timestamp, attachmentSize, attachmentExpires, iconSize int64
var timestamp, attachmentSize, attachmentExpires int64
var priority int
var id, topic, msg, title, tagsStr, click, actionsStr, attachmentName, attachmentType, attachmentURL, sender, encoding, iconURL, iconType string
var id, topic, msg, title, tagsStr, click, actionsStr, attachmentName, attachmentType, attachmentURL, sender, encoding, icon string
err := rows.Scan(
&id,
&timestamp,
@ -452,9 +439,7 @@ func readMessages(rows *sql.Rows) ([]*message, error) {
&attachmentURL,
&sender,
&encoding,
&iconURL,
&iconType,
&iconSize,
&icon,
)
if err != nil {
return nil, err
@ -479,14 +464,6 @@ func readMessages(rows *sql.Rows) ([]*message, error) {
URL: attachmentURL,
}
}
var ico *icon
if iconURL != "" {
ico = &icon{
URL: iconURL,
Type: iconType,
Size: iconSize,
}
}
messages = append(messages, &message{
ID: id,
Time: timestamp,
@ -497,7 +474,7 @@ func readMessages(rows *sql.Rows) ([]*message, error) {
Priority: priority,
Tags: tags,
Click: click,
Icon: ico,
Icon: icon,
Actions: actions,
Attachment: att,
Sender: sender,