Skip to content

Commit 2c373db

Browse files
committed
Only set force RCS flag if chat has had e2ee tombstone
1 parent 56bfc10 commit 2c373db

10 files changed

+217
-109
lines changed

database/portal.go

+10-7
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,18 @@ func newPortal(qh *dbutil.QueryHelper[*Portal]) *Portal {
3737
}
3838

3939
const (
40-
getAllPortalsQuery = "SELECT id, receiver, self_user, other_user, type, mxid, name, name_set, encrypted, in_space FROM portal"
40+
getAllPortalsQuery = "SELECT id, receiver, self_user, other_user, type, send_mode, force_rcs, mxid, name, name_set, encrypted, in_space FROM portal"
4141
getAllPortalsForUserQuery = getAllPortalsQuery + " WHERE receiver=$1"
4242
getPortalByKeyQuery = getAllPortalsQuery + " WHERE id=$1 AND receiver=$2"
4343
getPortalByOtherUserQuery = getAllPortalsQuery + " WHERE other_user=$1 AND receiver=$2"
4444
getPortalByMXIDQuery = getAllPortalsQuery + " WHERE mxid=$1"
4545
insertPortalQuery = `
46-
INSERT INTO portal (id, receiver, self_user, other_user, type, mxid, name, name_set, encrypted, in_space)
47-
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
46+
INSERT INTO portal (id, receiver, self_user, other_user, type, send_mode, force_rcs, mxid, name, name_set, encrypted, in_space)
47+
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)
4848
`
4949
updatePortalQuery = `
5050
UPDATE portal
51-
SET self_user=$3, other_user=$4, type=$5, mxid=$6, name=$7, name_set=$8, encrypted=$9, in_space=$10
51+
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
5252
WHERE id=$1 AND receiver=$2
5353
`
5454
deletePortalQuery = "DELETE FROM portal WHERE id=$1 AND receiver=$2"
@@ -96,6 +96,8 @@ type Portal struct {
9696
MXID id.RoomID
9797

9898
Type gmproto.ConversationType
99+
SendMode gmproto.ConversationSendMode
100+
ForceRCS bool
99101
Name string
100102
NameSet bool
101103
Encrypted bool
@@ -104,15 +106,16 @@ type Portal struct {
104106

105107
func (portal *Portal) Scan(row dbutil.Scannable) (*Portal, error) {
106108
var mxid, selfUserID, otherUserID sql.NullString
107-
var convType int
109+
var convType, sendMode int
108110
err := row.Scan(
109-
&portal.ID, &portal.Receiver, &selfUserID, &otherUserID, &convType, &mxid,
111+
&portal.ID, &portal.Receiver, &selfUserID, &otherUserID, &convType, &sendMode, &portal.ForceRCS, &mxid,
110112
&portal.Name, &portal.NameSet, &portal.Encrypted, &portal.InSpace,
111113
)
112114
if err != nil {
113115
return nil, err
114116
}
115117
portal.Type = gmproto.ConversationType(convType)
118+
portal.SendMode = gmproto.ConversationSendMode(sendMode)
116119
portal.MXID = id.RoomID(mxid.String)
117120
portal.OutgoingID = selfUserID.String
118121
portal.OtherUserID = otherUserID.String
@@ -122,7 +125,7 @@ func (portal *Portal) Scan(row dbutil.Scannable) (*Portal, error) {
122125
func (portal *Portal) sqlVariables() []any {
123126
return []any{
124127
portal.ID, portal.Receiver, dbutil.StrPtr(portal.OutgoingID), dbutil.StrPtr(portal.OtherUserID),
125-
int(portal.Type), dbutil.StrPtr(portal.MXID),
128+
int(portal.Type), int(portal.SendMode), portal.ForceRCS, dbutil.StrPtr(portal.MXID),
126129
portal.Name, portal.NameSet, portal.Encrypted, portal.InSpace,
127130
}
128131
}

database/upgrades/00-latest-revision.sql

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- v0 -> v9: Latest revision
1+
-- v0 -> v10 (compatible with v9+): Latest revision
22

33
CREATE TABLE "user" (
44
-- only: postgres
@@ -44,6 +44,8 @@ CREATE TABLE portal (
4444
self_user TEXT,
4545
other_user TEXT,
4646
type INTEGER NOT NULL,
47+
send_mode INTEGER NOT NULL,
48+
force_rcs BOOLEAN NOT NULL DEFAULT false,
4749
mxid TEXT UNIQUE,
4850
name TEXT NOT NULL,
4951
name_set BOOLEAN NOT NULL DEFAULT false,

database/upgrades/10-send-mode.sql

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-- v10 (compatible with v9+): Store send mode for portals
2+
ALTER TABLE portal ADD COLUMN send_mode INTEGER NOT NULL DEFAULT 0;
3+
ALTER TABLE portal ADD COLUMN force_rcs BOOLEAN NOT NULL DEFAULT false;

libgm/gmproto/client.pb.go

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libgm/gmproto/client.pb.raw

6 Bytes
Binary file not shown.

libgm/gmproto/client.proto

+1-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ message SendMessageRequest {
255255
MessagePayload messagePayload = 3;
256256
settings.SIMPayload SIMPayload = 4;
257257
string tmpID = 5;
258-
bool isRCS = 6; // not sure
258+
bool forceRCS = 6;
259259
ReplyPayload reply = 8;
260260
}
261261

0 commit comments

Comments
 (0)