Skip to content

Commit

Permalink
bug_: fix resend type for private group messages (#5258)
Browse files Browse the repository at this point in the history
* chore_: bump go-waku

* fix_: fix resend type for private group messages

---------

Co-authored-by: Richard Ramos <info@richardramos.me>
  • Loading branch information
cammellos and richard-ramos committed May 30, 2024
1 parent fb88f54 commit 0061c56
Show file tree
Hide file tree
Showing 33 changed files with 341 additions and 1,441 deletions.
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ require (
github.com/schollz/peerdiscovery v1.7.0
github.com/siphiuel/lc-proxy-wrapper v0.0.0-20230516150924-246507cee8c7
github.com/urfave/cli/v2 v2.27.2
github.com/waku-org/go-waku v0.8.1-0.20240507175626-19d27befd98b
github.com/waku-org/go-waku v0.8.1-0.20240529181619-d1cb6b0eaa7f
github.com/wk8/go-ordered-map/v2 v2.1.7
github.com/yeqown/go-qrcode/v2 v2.2.1
github.com/yeqown/go-qrcode/writer/standard v1.2.1
Expand Down Expand Up @@ -189,8 +189,6 @@ require (
github.com/libp2p/go-cidranger v1.1.0 // indirect
github.com/libp2p/go-flow-metrics v0.1.0 // indirect
github.com/libp2p/go-libp2p-asn-util v0.3.0 // indirect
github.com/libp2p/go-libp2p-mplex v0.9.0 // indirect
github.com/libp2p/go-mplex v0.7.0 // indirect
github.com/libp2p/go-msgio v0.3.0 // indirect
github.com/libp2p/go-nat v0.2.0 // indirect
github.com/libp2p/go-netroute v0.2.1 // indirect
Expand Down
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1362,15 +1362,11 @@ github.com/libp2p/go-libp2p v0.32.2 h1:s8GYN4YJzgUoyeYNPdW7JZeZ5Ee31iNaIBfGYMAY4
github.com/libp2p/go-libp2p v0.32.2/go.mod h1:E0LKe+diV/ZVJVnOJby8VC5xzHF0660osg71skcxJvk=
github.com/libp2p/go-libp2p-asn-util v0.3.0 h1:gMDcMyYiZKkocGXDQ5nsUQyquC9+H+iLEQHwOCZ7s8s=
github.com/libp2p/go-libp2p-asn-util v0.3.0/go.mod h1:B1mcOrKUE35Xq/ASTmQ4tN3LNzVVaMNmq2NACuqyB9w=
github.com/libp2p/go-libp2p-mplex v0.9.0 h1:R58pDRAmuBXkYugbSSXR9wrTX3+1pFM1xP2bLuodIq8=
github.com/libp2p/go-libp2p-mplex v0.9.0/go.mod h1:ro1i4kuwiFT+uMPbIDIFkcLs1KRbNp0QwnUXM+P64Og=
github.com/libp2p/go-libp2p-pubsub v0.10.1 h1:/RqOZpEtAolsr8/9CC8KqROJSOZeu7lK7fPftn4MwNg=
github.com/libp2p/go-libp2p-pubsub v0.10.1/go.mod h1:1OxbaT/pFRO5h+Dpze8hdHQ63R0ke55XTs6b6NwLLkw=
github.com/libp2p/go-libp2p-testing v0.12.0 h1:EPvBb4kKMWO29qP4mZGyhVzUyR25dvfUIK5WDu6iPUA=
github.com/libp2p/go-libp2p-testing v0.12.0/go.mod h1:KcGDRXyN7sQCllucn1cOOS+Dmm7ujhfEyXQL5lvkcPg=
github.com/libp2p/go-maddr-filter v0.1.0/go.mod h1:VzZhTXkMucEGGEOSKddrwGiOv0tUhgnKqNEmIAz/bPU=
github.com/libp2p/go-mplex v0.7.0 h1:BDhFZdlk5tbr0oyFq/xv/NPGfjbnrsDam1EvutpBDbY=
github.com/libp2p/go-mplex v0.7.0/go.mod h1:rW8ThnRcYWft/Jb2jeORBmPd6xuG3dGxWN/W168L9EU=
github.com/libp2p/go-msgio v0.3.0 h1:mf3Z8B1xcFN314sWX+2vOTShIE0Mmn2TXn3YCUQGNj0=
github.com/libp2p/go-msgio v0.3.0/go.mod h1:nyRM819GmVaF9LX3l03RMh10QdOroF++NBbxAb0mmDM=
github.com/libp2p/go-nat v0.2.0 h1:Tyz+bUFAYqGyJ/ppPPymMGbIgNRH+WqC5QrT5fKrrGk=
Expand Down Expand Up @@ -2142,8 +2138,8 @@ github.com/waku-org/go-discover v0.0.0-20240506173252-4912704efdc5 h1:4K3IS97Jry
github.com/waku-org/go-discover v0.0.0-20240506173252-4912704efdc5/go.mod h1:eBHgM6T4EG0RZzxpxKy+rGz/6Dw2Nd8DWxS0lm9ESDw=
github.com/waku-org/go-libp2p-rendezvous v0.0.0-20240110193335-a67d1cc760a0 h1:R4YYx2QamhBRl/moIxkDCNW+OP7AHbyWLBygDc/xIMo=
github.com/waku-org/go-libp2p-rendezvous v0.0.0-20240110193335-a67d1cc760a0/go.mod h1:EhZP9fee0DYjKH/IOQvoNSy1tSHp2iZadsHGphcAJgY=
github.com/waku-org/go-waku v0.8.1-0.20240507175626-19d27befd98b h1:2NR0UCjuuAFmnkhsvlCKn7PTs4JxUjSq4s7lSWaG0ek=
github.com/waku-org/go-waku v0.8.1-0.20240507175626-19d27befd98b/go.mod h1:yXnWChXRKTb+NhALbFysluxgSwuxeTF2rhanDJkIx+k=
github.com/waku-org/go-waku v0.8.1-0.20240529181619-d1cb6b0eaa7f h1:KiDqcxmCi74BGDZzkGT5T83QhEL/rPrUbEiJWOuiuU4=
github.com/waku-org/go-waku v0.8.1-0.20240529181619-d1cb6b0eaa7f/go.mod h1:yXnWChXRKTb+NhALbFysluxgSwuxeTF2rhanDJkIx+k=
github.com/waku-org/go-zerokit-rln v0.1.14-0.20240102145250-fa738c0bdf59 h1:jisj+OCI6QydLtFq3Pyhu49wl9ytPN7oAHjMfepHDrA=
github.com/waku-org/go-zerokit-rln v0.1.14-0.20240102145250-fa738c0bdf59/go.mod h1:1PdBdPzyTaKt3VnpAHk3zj+r9dXPFOr3IHZP9nFle6E=
github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230916172309-ee0ee61dde2b h1:KgZVhsLkxsj5gb/FfndSCQu6VYwALrCOgYI3poR95yE=
Expand Down
13 changes: 13 additions & 0 deletions protocol/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,19 @@ func (c *Chat) IsActivePersonalChat() bool {
return c.Active && (c.OneToOne() || c.PrivateGroupChat() || c.Public()) && c.CommunityID == ""
}

// DefaultResendType returns the resend type for a chat.
// This function currently infers the ResendType from the chat type.
// Note that specific message might have different resent types. At times
// some messages dictate their ResendType based on their own properties and
// context, rather than the chat type it is associated with.
func (c *Chat) DefaultResendType() common.ResendType {
if c.OneToOne() || c.PrivateGroupChat() {
return common.ResendTypeDataSync
}

return common.ResendTypeRawMessage
}

func (c *Chat) shouldBeSynced() bool {
isPublicChat := !c.Timeline() && !c.ProfileUpdates() && c.Public()
return isPublicChat || c.OneToOne() || c.PrivateGroupChat()
Expand Down
41 changes: 41 additions & 0 deletions protocol/chat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,47 @@ func (s *ChatTestSuite) TestUpdateFirstMessageTimestamp() {
setAndCheck(100, true, 100)
}

func (s *ChatTestSuite) TestDefaultResendType() {
testID := "some-id"
testCases := []struct {
Name string
ExpectedResendType common.ResendType
Chat Chat
}{
{
Name: "one to one chat",
ExpectedResendType: common.ResendTypeDataSync,
Chat: Chat{
ID: testID,
ChatType: ChatTypeOneToOne,
},
},
{
Name: "private group chat",
ExpectedResendType: common.ResendTypeDataSync,
Chat: Chat{
ID: testID,
ChatType: ChatTypePrivateGroupChat,
},
},
{
Name: "community chat",
ExpectedResendType: common.ResendTypeRawMessage,
Chat: Chat{
ID: testID,
ChatType: ChatTypeCommunityChat,
},
},
}

for _, tc := range testCases {
s.Run(tc.Name, func() {
s.Require().Equal(tc.ExpectedResendType, tc.Chat.DefaultResendType())
})
}

}

func (s *ChatTestSuite) TestDeepLink() {
chat := &Chat{
CommunityID: "0x02b1188c997e666cd5505ffd5c4b5fdbe3084b78a486d8e709da3b32ad3708a89e",
Expand Down
5 changes: 1 addition & 4 deletions protocol/messenger.go
Original file line number Diff line number Diff line change
Expand Up @@ -2382,10 +2382,7 @@ func (m *Messenger) sendChatMessage(ctx context.Context, message *common.Message
SendPushNotification: m.featureFlags.PushNotifications,
Payload: encodedMessage,
MessageType: protobuf.ApplicationMetadataMessage_CHAT_MESSAGE,
ResendType: common.ResendTypeRawMessage,
}
if chat.ChatType == ChatTypeOneToOne {
rawMessage.ResendType = common.ResendTypeDataSync
ResendType: chat.DefaultResendType(),
}

// We want to save the raw message before dispatching it, to avoid race conditions
Expand Down
2 changes: 1 addition & 1 deletion protocol/messenger_messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func (m *Messenger) DeleteMessageAndSend(ctx context.Context, messageID string)
Payload: encodedMessage,
MessageType: protobuf.ApplicationMetadataMessage_DELETE_MESSAGE,
SkipGroupMessageWrap: true,
ResendType: GetResendTypeForChat(chat),
ResendType: chat.DefaultResendType(),
}

_, err = m.dispatchMessage(ctx, rawMessage)
Expand Down
2 changes: 1 addition & 1 deletion protocol/messenger_pin_messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (m *Messenger) sendPinMessage(ctx context.Context, message *common.PinMessa
Payload: encodedMessage,
MessageType: protobuf.ApplicationMetadataMessage_PIN_MESSAGE,
SkipGroupMessageWrap: true,
ResendType: GetResendTypeForChat(chat),
ResendType: chat.DefaultResendType(),
}
_, err = m.dispatchMessage(ctx, rawMessage)
if err != nil {
Expand Down
16 changes: 0 additions & 16 deletions protocol/messenger_util.go

This file was deleted.

1 change: 0 additions & 1 deletion vendor/github.com/libp2p/go-libp2p-mplex/.gitignore

This file was deleted.

21 changes: 0 additions & 21 deletions vendor/github.com/libp2p/go-libp2p-mplex/LICENSE

This file was deleted.

11 changes: 0 additions & 11 deletions vendor/github.com/libp2p/go-libp2p-mplex/README.md

This file was deleted.

48 changes: 0 additions & 48 deletions vendor/github.com/libp2p/go-libp2p-mplex/conn.go

This file was deleted.

64 changes: 0 additions & 64 deletions vendor/github.com/libp2p/go-libp2p-mplex/stream.go

This file was deleted.

30 changes: 0 additions & 30 deletions vendor/github.com/libp2p/go-libp2p-mplex/transport.go

This file was deleted.

3 changes: 0 additions & 3 deletions vendor/github.com/libp2p/go-libp2p-mplex/version.json

This file was deleted.

21 changes: 0 additions & 21 deletions vendor/github.com/libp2p/go-mplex/LICENSE

This file was deleted.

27 changes: 0 additions & 27 deletions vendor/github.com/libp2p/go-mplex/README.md

This file was deleted.

Loading

0 comments on commit 0061c56

Please sign in to comment.