From 6476978a2e0cc5bed80c65af7c5e34cef04d5da9 Mon Sep 17 00:00:00 2001 From: Philipp Heckel Date: Sun, 11 Sep 2022 16:31:39 -0400 Subject: [PATCH] Move things --- server/message_cache.go | 22 +++++++++++----------- server/server_firebase.go | 2 +- server/types.go | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/server/message_cache.go b/server/message_cache.go index f37e5a9..a2f49e7 100644 --- a/server/message_cache.go +++ b/server/message_cache.go @@ -30,6 +30,7 @@ const ( priority INT NOT NULL, tags TEXT NOT NULL, click TEXT NOT NULL, + icon TEXT NOT NULL, actions TEXT NOT NULL, attachment_name TEXT NOT NULL, attachment_type TEXT NOT NULL, @@ -38,45 +39,44 @@ const ( attachment_url TEXT NOT NULL, sender TEXT NOT NULL, encoding TEXT NOT NULL, - published INT NOT NULL, - icon TEXT NOT NULL + published INT 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) + INSERT INTO messages (mid, time, topic, message, title, priority, tags, click, icon, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, encoding, published) 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 + SELECT mid, time, topic, message, title, priority, tags, click, icon, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, encoding 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 + SELECT mid, time, topic, message, title, priority, tags, click, icon, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, encoding 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 + SELECT mid, time, topic, message, title, priority, tags, click, icon, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, encoding 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 + SELECT mid, time, topic, message, title, priority, tags, click, icon, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, encoding 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 + SELECT mid, time, topic, message, title, priority, tags, click, icon, actions, attachment_name, attachment_type, attachment_size, attachment_expires, attachment_url, sender, encoding FROM messages WHERE time <= ? AND published = 0 ORDER BY time, id @@ -272,6 +272,7 @@ func (c *messageCache) addMessages(ms []*message) error { m.Priority, tags, m.Click, + m.Icon, actionsStr, attachmentName, attachmentType, @@ -281,7 +282,6 @@ func (c *messageCache) addMessages(ms []*message) error { m.Sender, m.Encoding, published, - m.Icon, ) if err != nil { return err @@ -421,7 +421,7 @@ func readMessages(rows *sql.Rows) ([]*message, error) { for rows.Next() { var timestamp, attachmentSize, attachmentExpires int64 var priority int - var id, topic, msg, title, tagsStr, click, actionsStr, attachmentName, attachmentType, attachmentURL, sender, encoding, icon string + var id, topic, msg, title, tagsStr, click, icon, actionsStr, attachmentName, attachmentType, attachmentURL, sender, encoding string err := rows.Scan( &id, ×tamp, @@ -431,6 +431,7 @@ func readMessages(rows *sql.Rows) ([]*message, error) { &priority, &tagsStr, &click, + &icon, &actionsStr, &attachmentName, &attachmentType, @@ -439,7 +440,6 @@ func readMessages(rows *sql.Rows) ([]*message, error) { &attachmentURL, &sender, &encoding, - &icon, ) if err != nil { return nil, err diff --git a/server/server_firebase.go b/server/server_firebase.go index ec3e611..15d7895 100644 --- a/server/server_firebase.go +++ b/server/server_firebase.go @@ -148,10 +148,10 @@ func toFirebaseMessage(m *message, auther auth.Auther) (*messaging.Message, erro "priority": fmt.Sprintf("%d", m.Priority), "tags": strings.Join(m.Tags, ","), "click": m.Click, + "icon": m.Icon, "title": m.Title, "message": m.Message, "encoding": m.Encoding, - "icon": m.Icon, } if len(m.Actions) > 0 { actions, err := json.Marshal(m.Actions) diff --git a/server/types.go b/server/types.go index 7a5badf..b502dcd 100644 --- a/server/types.go +++ b/server/types.go @@ -29,9 +29,9 @@ type message struct { Priority int `json:"priority,omitempty"` Tags []string `json:"tags,omitempty"` Click string `json:"click,omitempty"` + Icon string `json:"icon,omitempty"` Actions []*action `json:"actions,omitempty"` Attachment *attachment `json:"attachment,omitempty"` - Icon string `json:"icon,omitempty"` PollID string `json:"poll_id,omitempty"` Sender string `json:"-"` // IP address of uploader, used for rate limiting Encoding string `json:"encoding,omitempty"` // empty for raw UTF-8, or "base64" for encoded bytes @@ -73,9 +73,9 @@ type publishMessage struct { Priority int `json:"priority"` Tags []string `json:"tags"` Click string `json:"click"` + Icon string `json:"icon"` Actions []action `json:"actions"` Attach string `json:"attach"` - Icon string `json:"icon"` Filename string `json:"filename"` Email string `json:"email"` Delay string `json:"delay"`