Skip to content

Commit

Permalink
Only set force RCS flag if chat has had e2ee tombstone
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Jun 13, 2024
1 parent 56bfc10 commit 2c373db
Show file tree
Hide file tree
Showing 10 changed files with 217 additions and 109 deletions.
17 changes: 10 additions & 7 deletions database/portal.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ func newPortal(qh *dbutil.QueryHelper[*Portal]) *Portal {
}

const (
getAllPortalsQuery = "SELECT id, receiver, self_user, other_user, type, mxid, name, name_set, encrypted, in_space FROM portal"
getAllPortalsQuery = "SELECT id, receiver, self_user, other_user, type, send_mode, force_rcs, mxid, name, name_set, encrypted, in_space FROM portal"
getAllPortalsForUserQuery = getAllPortalsQuery + " WHERE receiver=$1"
getPortalByKeyQuery = getAllPortalsQuery + " WHERE id=$1 AND receiver=$2"
getPortalByOtherUserQuery = getAllPortalsQuery + " WHERE other_user=$1 AND receiver=$2"
getPortalByMXIDQuery = getAllPortalsQuery + " WHERE mxid=$1"
insertPortalQuery = `
INSERT INTO portal (id, receiver, self_user, other_user, type, mxid, name, name_set, encrypted, in_space)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
INSERT INTO portal (id, receiver, self_user, other_user, type, send_mode, force_rcs, mxid, name, name_set, encrypted, in_space)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)
`
updatePortalQuery = `
UPDATE portal
SET self_user=$3, other_user=$4, type=$5, mxid=$6, name=$7, name_set=$8, encrypted=$9, in_space=$10
SET self_user=$3, other_user=$4, type=$5, send_mode=$6, force_rcs=$7, mxid=$8, name=$9, name_set=$10, encrypted=$11, in_space=$12
WHERE id=$1 AND receiver=$2
`
deletePortalQuery = "DELETE FROM portal WHERE id=$1 AND receiver=$2"
Expand Down Expand Up @@ -96,6 +96,8 @@ type Portal struct {
MXID id.RoomID

Type gmproto.ConversationType
SendMode gmproto.ConversationSendMode
ForceRCS bool
Name string
NameSet bool
Encrypted bool
Expand All @@ -104,15 +106,16 @@ type Portal struct {

func (portal *Portal) Scan(row dbutil.Scannable) (*Portal, error) {
var mxid, selfUserID, otherUserID sql.NullString
var convType int
var convType, sendMode int
err := row.Scan(
&portal.ID, &portal.Receiver, &selfUserID, &otherUserID, &convType, &mxid,
&portal.ID, &portal.Receiver, &selfUserID, &otherUserID, &convType, &sendMode, &portal.ForceRCS, &mxid,
&portal.Name, &portal.NameSet, &portal.Encrypted, &portal.InSpace,
)
if err != nil {
return nil, err
}
portal.Type = gmproto.ConversationType(convType)
portal.SendMode = gmproto.ConversationSendMode(sendMode)
portal.MXID = id.RoomID(mxid.String)
portal.OutgoingID = selfUserID.String
portal.OtherUserID = otherUserID.String
Expand All @@ -122,7 +125,7 @@ func (portal *Portal) Scan(row dbutil.Scannable) (*Portal, error) {
func (portal *Portal) sqlVariables() []any {
return []any{
portal.ID, portal.Receiver, dbutil.StrPtr(portal.OutgoingID), dbutil.StrPtr(portal.OtherUserID),
int(portal.Type), dbutil.StrPtr(portal.MXID),
int(portal.Type), int(portal.SendMode), portal.ForceRCS, dbutil.StrPtr(portal.MXID),
portal.Name, portal.NameSet, portal.Encrypted, portal.InSpace,
}
}
Expand Down
4 changes: 3 additions & 1 deletion database/upgrades/00-latest-revision.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- v0 -> v9: Latest revision
-- v0 -> v10 (compatible with v9+): Latest revision

CREATE TABLE "user" (
-- only: postgres
Expand Down Expand Up @@ -44,6 +44,8 @@ CREATE TABLE portal (
self_user TEXT,
other_user TEXT,
type INTEGER NOT NULL,
send_mode INTEGER NOT NULL,
force_rcs BOOLEAN NOT NULL DEFAULT false,
mxid TEXT UNIQUE,
name TEXT NOT NULL,
name_set BOOLEAN NOT NULL DEFAULT false,
Expand Down
3 changes: 3 additions & 0 deletions database/upgrades/10-send-mode.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- v10 (compatible with v9+): Store send mode for portals
ALTER TABLE portal ADD COLUMN send_mode INTEGER NOT NULL DEFAULT 0;
ALTER TABLE portal ADD COLUMN force_rcs BOOLEAN NOT NULL DEFAULT false;
6 changes: 3 additions & 3 deletions libgm/gmproto/client.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified libgm/gmproto/client.pb.raw
Binary file not shown.
2 changes: 1 addition & 1 deletion libgm/gmproto/client.proto
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ message SendMessageRequest {
MessagePayload messagePayload = 3;
settings.SIMPayload SIMPayload = 4;
string tmpID = 5;
bool isRCS = 6; // not sure
bool forceRCS = 6;
ReplyPayload reply = 8;
}

Expand Down
Loading

0 comments on commit 2c373db

Please sign in to comment.