Tons of works on dm's.

They mostly work including display names and avatars. However that's about all
they do right now.
This commit is contained in:
Gary Kramlich
2022-01-31 04:53:21 -06:00
parent f20d204dd7
commit c1bb55d3cf
11 changed files with 329 additions and 86 deletions

View File

@@ -26,7 +26,7 @@ type Portal struct {
func (p *Portal) Scan(row Scannable) *Portal {
var mxid, avatarURL, firstEventID sql.NullString
err := row.Scan(&p.Key.ID, &p.Key.ChannelID, &mxid, &p.Name, &p.Topic, &p.Avatar, &avatarURL, &firstEventID)
err := row.Scan(&p.Key.ChannelID, &p.Key.Receiver, &mxid, &p.Name, &p.Topic, &p.Avatar, &avatarURL, &firstEventID)
if err != nil {
if err != sql.ErrNoRows {
p.log.Errorln("Database scan failed:", err)
@@ -44,10 +44,10 @@ func (p *Portal) Scan(row Scannable) *Portal {
func (p *Portal) Insert() {
query := "INSERT INTO portal" +
" (id, mxid, channel_id, name, topic, avatar, avatar_url, first_event_id)" +
" (channel_id, receiver, mxid, name, topic, avatar, avatar_url, first_event_id)" +
" VALUES ($1, $2, $3, $4, $5, $6, $7, $8)"
_, err := p.db.Exec(query, p.Key.ID, p.MXID, p.Key.ChannelID,
_, err := p.db.Exec(query, p.Key.ChannelID, p.Key.Receiver, p.MXID,
p.Name, p.Topic, p.Avatar, p.AvatarURL.String(), p.FirstEventID.String())
if err != nil {
@@ -58,11 +58,11 @@ func (p *Portal) Insert() {
func (p *Portal) Update() {
query := "UPDATE portal SET" +
" mxid=$1, name=$2, topic=$3, avatar=$4, avatar_url=$5, first_event_id=$6" +
" WHERE id=$7 AND channel_id=$8"
" WHERE channel_id=$7 AND receiver=$8"
_, err := p.db.Exec(query, p.MXID, p.Name, p.Topic, p.Avatar,
p.AvatarURL.String(), p.FirstEventID.String(), p.Key.ID,
p.Key.ChannelID)
p.AvatarURL.String(), p.FirstEventID.String(), p.Key.ChannelID,
p.Key.Receiver)
if err != nil {
p.log.Warnfln("Failed to update %s: %v", p.Key, err)