Explorar o código

Prevent setting last_read_ts to lower value

Tulir Asokan %!s(int64=3) %!d(string=hai) anos
pai
achega
4bdb130d13
Modificáronse 1 ficheiros con 1 adicións e 1 borrados
  1. 1 1
      database/userportal.go

+ 1 - 1
database/userportal.go

@@ -40,7 +40,7 @@ func (user *User) SetLastReadTS(portal PortalKey, ts time.Time) {
 	if user.db.dialect == "postgres" {
 	if user.db.dialect == "postgres" {
 		_, err = user.db.Exec(`
 		_, err = user.db.Exec(`
 			INSERT INTO user_portal (user_mxid, portal_jid, portal_receiver, last_read_ts) VALUES ($1, $2, $3, $4)
 			INSERT INTO user_portal (user_mxid, portal_jid, portal_receiver, last_read_ts) VALUES ($1, $2, $3, $4)
-			ON CONFLICT (user_mxid, portal_jid, portal_receiver) DO UPDATE SET last_read_ts=$4
+			ON CONFLICT (user_mxid, portal_jid, portal_receiver) DO UPDATE SET last_read_ts=$4 WHERE user_portal.last_read_ts<$4
 		`, user.MXID, portal.JID, portal.Receiver, ts.Unix())
 		`, user.MXID, portal.JID, portal.Receiver, ts.Unix())
 	} else if user.db.dialect == "sqlite3" {
 	} else if user.db.dialect == "sqlite3" {
 		_, err = user.db.Exec(
 		_, err = user.db.Exec(