From 2a7fc8eabf15f0a7c79c323838804d44fa46f1d6 Mon Sep 17 00:00:00 2001 From: Gary Kramlich Date: Thu, 7 Apr 2022 13:46:51 -0500 Subject: [PATCH] Make sure to properly set NULL for portal.mxid if we don't have one. When this gets set to empty string it causes primary key to fail and cascades into other issues like the inability to deduplicate messages. Refs #26 --- database/portal.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/database/portal.go b/database/portal.go index b21d298..663651b 100644 --- a/database/portal.go +++ b/database/portal.go @@ -51,13 +51,21 @@ func (p *Portal) Scan(row Scannable) *Portal { return p } +func (p *Portal) mxidPtr() *id.RoomID { + if p.MXID != "" { + return &p.MXID + } + + return nil +} + func (p *Portal) Insert() { query := "INSERT INTO portal" + " (channel_id, receiver, mxid, name, topic, avatar, avatar_url," + " type, dmuser, first_event_id)" + " VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)" - _, err := p.db.Exec(query, p.Key.ChannelID, p.Key.Receiver, p.MXID, + _, err := p.db.Exec(query, p.Key.ChannelID, p.Key.Receiver, p.mxidPtr(), p.Name, p.Topic, p.Avatar, p.AvatarURL.String(), p.Type, p.DMUser, p.FirstEventID.String()) @@ -72,7 +80,7 @@ func (p *Portal) Update() { " dmuser=$7, first_event_id=$8" + " WHERE channel_id=$9 AND receiver=$10" - _, err := p.db.Exec(query, p.MXID, p.Name, p.Topic, p.Avatar, + _, err := p.db.Exec(query, p.mxidPtr(), p.Name, p.Topic, p.Avatar, p.AvatarURL.String(), p.Type, p.DMUser, p.FirstEventID.String(), p.Key.ChannelID, p.Key.Receiver)