Skip to content

Commit 0061c56

Browse files
bug_: fix resend type for private group messages (#5258)
* chore_: bump go-waku * fix_: fix resend type for private group messages --------- Co-authored-by: Richard Ramos <[email protected]>
1 parent fb88f54 commit 0061c56

33 files changed

+341
-1441
lines changed

go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ require (
9393
github.com/schollz/peerdiscovery v1.7.0
9494
github.com/siphiuel/lc-proxy-wrapper v0.0.0-20230516150924-246507cee8c7
9595
github.com/urfave/cli/v2 v2.27.2
96-
github.com/waku-org/go-waku v0.8.1-0.20240507175626-19d27befd98b
96+
github.com/waku-org/go-waku v0.8.1-0.20240529181619-d1cb6b0eaa7f
9797
github.com/wk8/go-ordered-map/v2 v2.1.7
9898
github.com/yeqown/go-qrcode/v2 v2.2.1
9999
github.com/yeqown/go-qrcode/writer/standard v1.2.1
@@ -189,8 +189,6 @@ require (
189189
github.com/libp2p/go-cidranger v1.1.0 // indirect
190190
github.com/libp2p/go-flow-metrics v0.1.0 // indirect
191191
github.com/libp2p/go-libp2p-asn-util v0.3.0 // indirect
192-
github.com/libp2p/go-libp2p-mplex v0.9.0 // indirect
193-
github.com/libp2p/go-mplex v0.7.0 // indirect
194192
github.com/libp2p/go-msgio v0.3.0 // indirect
195193
github.com/libp2p/go-nat v0.2.0 // indirect
196194
github.com/libp2p/go-netroute v0.2.1 // indirect

go.sum

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,15 +1362,11 @@ github.com/libp2p/go-libp2p v0.32.2 h1:s8GYN4YJzgUoyeYNPdW7JZeZ5Ee31iNaIBfGYMAY4
13621362
github.com/libp2p/go-libp2p v0.32.2/go.mod h1:E0LKe+diV/ZVJVnOJby8VC5xzHF0660osg71skcxJvk=
13631363
github.com/libp2p/go-libp2p-asn-util v0.3.0 h1:gMDcMyYiZKkocGXDQ5nsUQyquC9+H+iLEQHwOCZ7s8s=
13641364
github.com/libp2p/go-libp2p-asn-util v0.3.0/go.mod h1:B1mcOrKUE35Xq/ASTmQ4tN3LNzVVaMNmq2NACuqyB9w=
1365-
github.com/libp2p/go-libp2p-mplex v0.9.0 h1:R58pDRAmuBXkYugbSSXR9wrTX3+1pFM1xP2bLuodIq8=
1366-
github.com/libp2p/go-libp2p-mplex v0.9.0/go.mod h1:ro1i4kuwiFT+uMPbIDIFkcLs1KRbNp0QwnUXM+P64Og=
13671365
github.com/libp2p/go-libp2p-pubsub v0.10.1 h1:/RqOZpEtAolsr8/9CC8KqROJSOZeu7lK7fPftn4MwNg=
13681366
github.com/libp2p/go-libp2p-pubsub v0.10.1/go.mod h1:1OxbaT/pFRO5h+Dpze8hdHQ63R0ke55XTs6b6NwLLkw=
13691367
github.com/libp2p/go-libp2p-testing v0.12.0 h1:EPvBb4kKMWO29qP4mZGyhVzUyR25dvfUIK5WDu6iPUA=
13701368
github.com/libp2p/go-libp2p-testing v0.12.0/go.mod h1:KcGDRXyN7sQCllucn1cOOS+Dmm7ujhfEyXQL5lvkcPg=
13711369
github.com/libp2p/go-maddr-filter v0.1.0/go.mod h1:VzZhTXkMucEGGEOSKddrwGiOv0tUhgnKqNEmIAz/bPU=
1372-
github.com/libp2p/go-mplex v0.7.0 h1:BDhFZdlk5tbr0oyFq/xv/NPGfjbnrsDam1EvutpBDbY=
1373-
github.com/libp2p/go-mplex v0.7.0/go.mod h1:rW8ThnRcYWft/Jb2jeORBmPd6xuG3dGxWN/W168L9EU=
13741370
github.com/libp2p/go-msgio v0.3.0 h1:mf3Z8B1xcFN314sWX+2vOTShIE0Mmn2TXn3YCUQGNj0=
13751371
github.com/libp2p/go-msgio v0.3.0/go.mod h1:nyRM819GmVaF9LX3l03RMh10QdOroF++NBbxAb0mmDM=
13761372
github.com/libp2p/go-nat v0.2.0 h1:Tyz+bUFAYqGyJ/ppPPymMGbIgNRH+WqC5QrT5fKrrGk=
@@ -2142,8 +2138,8 @@ github.com/waku-org/go-discover v0.0.0-20240506173252-4912704efdc5 h1:4K3IS97Jry
21422138
github.com/waku-org/go-discover v0.0.0-20240506173252-4912704efdc5/go.mod h1:eBHgM6T4EG0RZzxpxKy+rGz/6Dw2Nd8DWxS0lm9ESDw=
21432139
github.com/waku-org/go-libp2p-rendezvous v0.0.0-20240110193335-a67d1cc760a0 h1:R4YYx2QamhBRl/moIxkDCNW+OP7AHbyWLBygDc/xIMo=
21442140
github.com/waku-org/go-libp2p-rendezvous v0.0.0-20240110193335-a67d1cc760a0/go.mod h1:EhZP9fee0DYjKH/IOQvoNSy1tSHp2iZadsHGphcAJgY=
2145-
github.com/waku-org/go-waku v0.8.1-0.20240507175626-19d27befd98b h1:2NR0UCjuuAFmnkhsvlCKn7PTs4JxUjSq4s7lSWaG0ek=
2146-
github.com/waku-org/go-waku v0.8.1-0.20240507175626-19d27befd98b/go.mod h1:yXnWChXRKTb+NhALbFysluxgSwuxeTF2rhanDJkIx+k=
2141+
github.com/waku-org/go-waku v0.8.1-0.20240529181619-d1cb6b0eaa7f h1:KiDqcxmCi74BGDZzkGT5T83QhEL/rPrUbEiJWOuiuU4=
2142+
github.com/waku-org/go-waku v0.8.1-0.20240529181619-d1cb6b0eaa7f/go.mod h1:yXnWChXRKTb+NhALbFysluxgSwuxeTF2rhanDJkIx+k=
21472143
github.com/waku-org/go-zerokit-rln v0.1.14-0.20240102145250-fa738c0bdf59 h1:jisj+OCI6QydLtFq3Pyhu49wl9ytPN7oAHjMfepHDrA=
21482144
github.com/waku-org/go-zerokit-rln v0.1.14-0.20240102145250-fa738c0bdf59/go.mod h1:1PdBdPzyTaKt3VnpAHk3zj+r9dXPFOr3IHZP9nFle6E=
21492145
github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230916172309-ee0ee61dde2b h1:KgZVhsLkxsj5gb/FfndSCQu6VYwALrCOgYI3poR95yE=

protocol/chat.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,19 @@ func (c *Chat) IsActivePersonalChat() bool {
288288
return c.Active && (c.OneToOne() || c.PrivateGroupChat() || c.Public()) && c.CommunityID == ""
289289
}
290290

291+
// DefaultResendType returns the resend type for a chat.
292+
// This function currently infers the ResendType from the chat type.
293+
// Note that specific message might have different resent types. At times
294+
// some messages dictate their ResendType based on their own properties and
295+
// context, rather than the chat type it is associated with.
296+
func (c *Chat) DefaultResendType() common.ResendType {
297+
if c.OneToOne() || c.PrivateGroupChat() {
298+
return common.ResendTypeDataSync
299+
}
300+
301+
return common.ResendTypeRawMessage
302+
}
303+
291304
func (c *Chat) shouldBeSynced() bool {
292305
isPublicChat := !c.Timeline() && !c.ProfileUpdates() && c.Public()
293306
return isPublicChat || c.OneToOne() || c.PrivateGroupChat()

protocol/chat_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,47 @@ func (s *ChatTestSuite) TestUpdateFirstMessageTimestamp() {
163163
setAndCheck(100, true, 100)
164164
}
165165

166+
func (s *ChatTestSuite) TestDefaultResendType() {
167+
testID := "some-id"
168+
testCases := []struct {
169+
Name string
170+
ExpectedResendType common.ResendType
171+
Chat Chat
172+
}{
173+
{
174+
Name: "one to one chat",
175+
ExpectedResendType: common.ResendTypeDataSync,
176+
Chat: Chat{
177+
ID: testID,
178+
ChatType: ChatTypeOneToOne,
179+
},
180+
},
181+
{
182+
Name: "private group chat",
183+
ExpectedResendType: common.ResendTypeDataSync,
184+
Chat: Chat{
185+
ID: testID,
186+
ChatType: ChatTypePrivateGroupChat,
187+
},
188+
},
189+
{
190+
Name: "community chat",
191+
ExpectedResendType: common.ResendTypeRawMessage,
192+
Chat: Chat{
193+
ID: testID,
194+
ChatType: ChatTypeCommunityChat,
195+
},
196+
},
197+
}
198+
199+
for _, tc := range testCases {
200+
s.Run(tc.Name, func() {
201+
s.Require().Equal(tc.ExpectedResendType, tc.Chat.DefaultResendType())
202+
})
203+
}
204+
205+
}
206+
166207
func (s *ChatTestSuite) TestDeepLink() {
167208
chat := &Chat{
168209
CommunityID: "0x02b1188c997e666cd5505ffd5c4b5fdbe3084b78a486d8e709da3b32ad3708a89e",

protocol/messenger.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2382,10 +2382,7 @@ func (m *Messenger) sendChatMessage(ctx context.Context, message *common.Message
23822382
SendPushNotification: m.featureFlags.PushNotifications,
23832383
Payload: encodedMessage,
23842384
MessageType: protobuf.ApplicationMetadataMessage_CHAT_MESSAGE,
2385-
ResendType: common.ResendTypeRawMessage,
2386-
}
2387-
if chat.ChatType == ChatTypeOneToOne {
2388-
rawMessage.ResendType = common.ResendTypeDataSync
2385+
ResendType: chat.DefaultResendType(),
23892386
}
23902387

23912388
// We want to save the raw message before dispatching it, to avoid race conditions

protocol/messenger_messages.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ func (m *Messenger) DeleteMessageAndSend(ctx context.Context, messageID string)
235235
Payload: encodedMessage,
236236
MessageType: protobuf.ApplicationMetadataMessage_DELETE_MESSAGE,
237237
SkipGroupMessageWrap: true,
238-
ResendType: GetResendTypeForChat(chat),
238+
ResendType: chat.DefaultResendType(),
239239
}
240240

241241
_, err = m.dispatchMessage(ctx, rawMessage)

protocol/messenger_pin_messages.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (m *Messenger) sendPinMessage(ctx context.Context, message *common.PinMessa
5656
Payload: encodedMessage,
5757
MessageType: protobuf.ApplicationMetadataMessage_PIN_MESSAGE,
5858
SkipGroupMessageWrap: true,
59-
ResendType: GetResendTypeForChat(chat),
59+
ResendType: chat.DefaultResendType(),
6060
}
6161
_, err = m.dispatchMessage(ctx, rawMessage)
6262
if err != nil {

protocol/messenger_util.go

Lines changed: 0 additions & 16 deletions
This file was deleted.

vendor/github.com/libp2p/go-libp2p-mplex/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

vendor/github.com/libp2p/go-libp2p-mplex/LICENSE

Lines changed: 0 additions & 21 deletions
This file was deleted.

vendor/github.com/libp2p/go-libp2p-mplex/README.md

Lines changed: 0 additions & 11 deletions
This file was deleted.

vendor/github.com/libp2p/go-libp2p-mplex/conn.go

Lines changed: 0 additions & 48 deletions
This file was deleted.

vendor/github.com/libp2p/go-libp2p-mplex/stream.go

Lines changed: 0 additions & 64 deletions
This file was deleted.

vendor/github.com/libp2p/go-libp2p-mplex/transport.go

Lines changed: 0 additions & 30 deletions
This file was deleted.

vendor/github.com/libp2p/go-libp2p-mplex/version.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

vendor/github.com/libp2p/go-mplex/LICENSE

Lines changed: 0 additions & 21 deletions
This file was deleted.

vendor/github.com/libp2p/go-mplex/README.md

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)