Explorar o código

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
Gary Kramlich %!s(int64=3) %!d(string=hai) anos
pai
achega
2a7fc8eabf
Modificáronse 1 ficheiros con 10 adicións e 2 borrados
  1. 10 2
      database/portal.go

+ 10 - 2
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)