2020-11-18 09:16:51 +00:00
|
|
|
package protocol
|
|
|
|
|
|
|
|
import (
|
2021-01-11 10:32:51 +00:00
|
|
|
"bytes"
|
2020-11-18 09:16:51 +00:00
|
|
|
"context"
|
|
|
|
"crypto/ecdsa"
|
2021-07-22 17:41:49 +00:00
|
|
|
"encoding/json"
|
2020-11-18 09:16:51 +00:00
|
|
|
"errors"
|
2021-08-06 15:40:23 +00:00
|
|
|
"fmt"
|
2020-11-18 09:16:51 +00:00
|
|
|
"io/ioutil"
|
feat: introduce messenger APIs to extract discord channels
As part of the new Discord <-> Status Community Import functionality,
we're adding an API that extracts all discord categories and channels
from a previously exported discord export file.
These APIs can be used in clients to show the user what categories and
channels will be imported later on.
There are two APIs:
1. `Messenger.ExtractDiscordCategoriesAndChannels(filesToimport
[]string) (*MessengerResponse, map[string]*discord.ImportError)`
This takes a list of exported discord export (JSON) files (typically one per
channel), reads them, and extracts the categories and channels into
dedicated data structures (`[]DiscordChannel` and `[]DiscordCategory`)
It also returns the oldest message timestamp found in all extracted
channels.
The API is synchronous and returns the extracted data as
a `*MessengerResponse`. This allows to make the API available
status-go's RPC interface.
The error case is a `map[string]*discord.ImportError` where each key
is a file path of a JSON file that we tried to extract data from, and
the value a `discord.ImportError` which holds an error message and an
error code, allowing for distinguishing between "critical" errors and
"non-critical" errors.
2. `Messenger.RequestExtractDiscordCategoriesAndChannels(filesToImport
[]string)`
This is the asynchronous counterpart to
`ExtractDiscordCategoriesAndChannels`. The reason this API has been
added is because discord servers can have a lot of message and
channel data, which causes `ExtractDiscordCategoriesAndChannels` to
block the thread for too long, making apps potentially feel like they
are stuck.
This API runs inside a go routine, eventually calls
`ExtractDiscordCategoriesAndChannels`, and then emits a newly
introduced `DiscordCategoriesAndChannelsExtractedSignal` that clients
can react to.
Failure of extraction has to be determined by the
`discord.ImportErrors` emitted by the signal.
**A note about exported discord history files**
We expect users to export their discord histories via the
[DiscordChatExporter](https://github.com/Tyrrrz/DiscordChatExporter/wiki/GUI%2C-CLI-and-Formats-explained#exportguild)
tool. The tool allows to export the data in different formats, such as
JSON, HTML and CSV.
We expect users to have their data exported as JSON.
Closes: https://github.com/status-im/status-desktop/issues/6690
2022-07-13 09:33:53 +00:00
|
|
|
"os"
|
2020-11-18 09:16:51 +00:00
|
|
|
"strings"
|
|
|
|
"testing"
|
2022-06-01 07:55:48 +00:00
|
|
|
"time"
|
2020-11-18 09:16:51 +00:00
|
|
|
|
2022-11-07 17:30:00 +00:00
|
|
|
"github.com/golang/protobuf/proto"
|
2020-11-18 09:16:51 +00:00
|
|
|
"github.com/google/uuid"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
|
2022-07-08 10:25:46 +00:00
|
|
|
"github.com/status-im/status-go/account/generator"
|
2020-11-18 09:16:51 +00:00
|
|
|
gethbridge "github.com/status-im/status-go/eth-node/bridge/geth"
|
|
|
|
"github.com/status-im/status-go/eth-node/crypto"
|
|
|
|
"github.com/status-im/status-go/eth-node/types"
|
2022-07-08 10:25:46 +00:00
|
|
|
"github.com/status-im/status-go/multiaccounts"
|
2022-03-23 18:47:00 +00:00
|
|
|
"github.com/status-im/status-go/multiaccounts/settings"
|
2021-07-22 17:41:49 +00:00
|
|
|
"github.com/status-im/status-go/params"
|
2020-11-18 09:16:51 +00:00
|
|
|
"github.com/status-im/status-go/protocol/common"
|
2021-01-11 10:32:51 +00:00
|
|
|
"github.com/status-im/status-go/protocol/communities"
|
feat: introduce messenger APIs to extract discord channels
As part of the new Discord <-> Status Community Import functionality,
we're adding an API that extracts all discord categories and channels
from a previously exported discord export file.
These APIs can be used in clients to show the user what categories and
channels will be imported later on.
There are two APIs:
1. `Messenger.ExtractDiscordCategoriesAndChannels(filesToimport
[]string) (*MessengerResponse, map[string]*discord.ImportError)`
This takes a list of exported discord export (JSON) files (typically one per
channel), reads them, and extracts the categories and channels into
dedicated data structures (`[]DiscordChannel` and `[]DiscordCategory`)
It also returns the oldest message timestamp found in all extracted
channels.
The API is synchronous and returns the extracted data as
a `*MessengerResponse`. This allows to make the API available
status-go's RPC interface.
The error case is a `map[string]*discord.ImportError` where each key
is a file path of a JSON file that we tried to extract data from, and
the value a `discord.ImportError` which holds an error message and an
error code, allowing for distinguishing between "critical" errors and
"non-critical" errors.
2. `Messenger.RequestExtractDiscordCategoriesAndChannels(filesToImport
[]string)`
This is the asynchronous counterpart to
`ExtractDiscordCategoriesAndChannels`. The reason this API has been
added is because discord servers can have a lot of message and
channel data, which causes `ExtractDiscordCategoriesAndChannels` to
block the thread for too long, making apps potentially feel like they
are stuck.
This API runs inside a go routine, eventually calls
`ExtractDiscordCategoriesAndChannels`, and then emits a newly
introduced `DiscordCategoriesAndChannelsExtractedSignal` that clients
can react to.
Failure of extraction has to be determined by the
`discord.ImportErrors` emitted by the signal.
**A note about exported discord history files**
We expect users to export their discord histories via the
[DiscordChatExporter](https://github.com/Tyrrrz/DiscordChatExporter/wiki/GUI%2C-CLI-and-Formats-explained#exportguild)
tool. The tool allows to export the data in different formats, such as
JSON, HTML and CSV.
We expect users to have their data exported as JSON.
Closes: https://github.com/status-im/status-desktop/issues/6690
2022-07-13 09:33:53 +00:00
|
|
|
"github.com/status-im/status-go/protocol/discord"
|
2022-11-07 17:30:00 +00:00
|
|
|
"github.com/status-im/status-go/protocol/encryption"
|
2021-08-06 15:40:23 +00:00
|
|
|
"github.com/status-im/status-go/protocol/encryption/multidevice"
|
2020-11-18 09:16:51 +00:00
|
|
|
"github.com/status-im/status-go/protocol/protobuf"
|
2021-01-11 10:32:51 +00:00
|
|
|
"github.com/status-im/status-go/protocol/requests"
|
2022-09-27 20:27:20 +00:00
|
|
|
"github.com/status-im/status-go/protocol/sqlite"
|
2020-11-18 09:16:51 +00:00
|
|
|
"github.com/status-im/status-go/protocol/tt"
|
|
|
|
"github.com/status-im/status-go/waku"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMessengerCommunitiesSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(MessengerCommunitiesSuite))
|
|
|
|
}
|
|
|
|
|
|
|
|
type MessengerCommunitiesSuite struct {
|
|
|
|
suite.Suite
|
2022-08-23 16:30:19 +00:00
|
|
|
admin *Messenger
|
2020-11-18 09:16:51 +00:00
|
|
|
bob *Messenger
|
|
|
|
alice *Messenger
|
|
|
|
// If one wants to send messages between different instances of Messenger,
|
|
|
|
// a single Waku service should be shared.
|
|
|
|
shh types.Waku
|
|
|
|
logger *zap.Logger
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerCommunitiesSuite) SetupTest() {
|
|
|
|
s.logger = tt.MustCreateTestLogger()
|
|
|
|
|
|
|
|
config := waku.DefaultConfig
|
|
|
|
config.MinimumAcceptedPoW = 0
|
|
|
|
shh := waku.New(&config, s.logger)
|
|
|
|
s.shh = gethbridge.NewGethWakuWrapper(shh)
|
2021-07-09 13:19:33 +00:00
|
|
|
s.Require().NoError(shh.Start())
|
2020-11-18 09:16:51 +00:00
|
|
|
|
2022-08-23 16:30:19 +00:00
|
|
|
s.admin = s.newMessenger()
|
2020-12-22 11:00:13 +00:00
|
|
|
s.bob = s.newMessenger()
|
|
|
|
s.alice = s.newMessenger()
|
2022-08-23 16:30:19 +00:00
|
|
|
_, err := s.admin.Start()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
_, err = s.bob.Start()
|
2021-01-14 22:15:13 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
_, err = s.alice.Start()
|
|
|
|
s.Require().NoError(err)
|
2020-11-18 09:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerCommunitiesSuite) TearDownTest() {
|
2022-08-23 16:30:19 +00:00
|
|
|
s.Require().NoError(s.admin.Shutdown())
|
2020-11-18 09:16:51 +00:00
|
|
|
s.Require().NoError(s.bob.Shutdown())
|
|
|
|
s.Require().NoError(s.alice.Shutdown())
|
|
|
|
_ = s.logger.Sync()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerCommunitiesSuite) newMessengerWithOptions(shh types.Waku, privateKey *ecdsa.PrivateKey, options []Option) *Messenger {
|
|
|
|
m, err := NewMessenger(
|
2021-11-03 12:38:37 +00:00
|
|
|
"Test",
|
2020-11-18 09:16:51 +00:00
|
|
|
privateKey,
|
|
|
|
&testNode{shh: shh},
|
|
|
|
uuid.New().String(),
|
2022-01-12 16:02:01 +00:00
|
|
|
nil,
|
2023-03-10 12:53:40 +00:00
|
|
|
nil,
|
2020-11-18 09:16:51 +00:00
|
|
|
options...,
|
|
|
|
)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
err = m.Init()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2021-07-22 17:41:49 +00:00
|
|
|
config := params.NodeConfig{
|
|
|
|
NetworkID: 10,
|
|
|
|
DataDir: "test",
|
|
|
|
}
|
|
|
|
|
|
|
|
networks := json.RawMessage("{}")
|
2022-03-23 18:47:00 +00:00
|
|
|
setting := settings.Settings{
|
2021-07-22 17:41:49 +00:00
|
|
|
Address: types.HexToAddress("0x1122334455667788990011223344556677889900"),
|
|
|
|
AnonMetricsShouldSend: false,
|
|
|
|
CurrentNetwork: "mainnet_rpc",
|
|
|
|
DappsAddress: types.HexToAddress("0x1122334455667788990011223344556677889900"),
|
|
|
|
InstallationID: "d3efcff6-cffa-560e-a547-21d3858cbc51",
|
|
|
|
KeyUID: "0x1122334455667788990011223344556677889900",
|
|
|
|
LatestDerivedPath: 0,
|
|
|
|
Name: "Test",
|
|
|
|
Networks: &networks,
|
|
|
|
PhotoPath: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAIAAACRXR/mAAAAjklEQVR4nOzXwQmFMBAAUZXUYh32ZB32ZB02sxYQQSZGsod55/91WFgSS0RM+SyjA56ZRZhFmEWYRRT6h+M6G16zrxv6fdJpmUWYRbxsYr13dKfanpN0WmYRZhGzXz6AWYRZRIfbaX26fT9Jk07LLMIsosPt9I/dTDotswizCG+nhFmEWYRZhFnEHQAA///z1CFkYamgfQAAAABJRU5ErkJggg==",
|
|
|
|
PreviewPrivacy: false,
|
|
|
|
PublicKey: "0x04112233445566778899001122334455667788990011223344556677889900112233445566778899001122334455667788990011223344556677889900",
|
|
|
|
SigningPhrase: "yurt joey vibe",
|
|
|
|
SendPushNotifications: true,
|
|
|
|
ProfilePicturesVisibility: 1,
|
|
|
|
DefaultSyncPeriod: 86400,
|
|
|
|
UseMailservers: true,
|
|
|
|
LinkPreviewRequestEnabled: true,
|
|
|
|
SendStatusUpdates: true,
|
|
|
|
WalletRootAddress: types.HexToAddress("0x1122334455667788990011223344556677889900")}
|
|
|
|
|
2022-03-23 18:47:00 +00:00
|
|
|
_ = m.settings.CreateSettings(setting, config)
|
2021-07-22 17:41:49 +00:00
|
|
|
|
2020-11-18 09:16:51 +00:00
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerCommunitiesSuite) newMessengerWithKey(shh types.Waku, privateKey *ecdsa.PrivateKey) *Messenger {
|
2022-07-08 10:25:46 +00:00
|
|
|
tmpfile, err := ioutil.TempFile("", "accounts-tests-")
|
2020-11-18 09:16:51 +00:00
|
|
|
s.Require().NoError(err)
|
2022-07-08 10:25:46 +00:00
|
|
|
madb, err := multiaccounts.InitializeDB(tmpfile.Name())
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
acc := generator.NewAccount(privateKey, nil)
|
|
|
|
iai := acc.ToIdentifiedAccountInfo("")
|
2020-11-18 09:16:51 +00:00
|
|
|
|
|
|
|
options := []Option{
|
|
|
|
WithCustomLogger(s.logger),
|
2022-09-27 20:27:20 +00:00
|
|
|
WithDatabaseConfig(":memory:", "somekey", sqlite.ReducedKDFIterationsNumber),
|
2022-07-08 10:25:46 +00:00
|
|
|
WithMultiAccounts(madb),
|
|
|
|
WithAccount(iai.ToMultiAccount()),
|
2020-11-18 09:16:51 +00:00
|
|
|
WithDatasync(),
|
|
|
|
}
|
|
|
|
return s.newMessengerWithOptions(shh, privateKey, options)
|
|
|
|
}
|
|
|
|
|
2020-12-22 11:00:13 +00:00
|
|
|
func (s *MessengerCommunitiesSuite) newMessenger() *Messenger {
|
2020-11-18 09:16:51 +00:00
|
|
|
privateKey, err := crypto.GenerateKey()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
return s.newMessengerWithKey(s.shh, privateKey)
|
|
|
|
}
|
|
|
|
|
2022-07-19 09:31:52 +00:00
|
|
|
func (s *MessengerCommunitiesSuite) TestCreateCommunity() {
|
|
|
|
description := &requests.CreateCommunity{
|
|
|
|
Membership: protobuf.CommunityPermissions_NO_MEMBERSHIP,
|
|
|
|
Name: "status",
|
|
|
|
Color: "#ffffff",
|
|
|
|
Description: "status community description",
|
|
|
|
}
|
|
|
|
response, err := s.bob.CreateCommunity(description, true)
|
|
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
|
|
|
s.Require().Len(response.Communities(), 1)
|
|
|
|
s.Require().Len(response.Chats(), 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerCommunitiesSuite) TestCreateCommunity_WithoutDefaultChannel() {
|
|
|
|
|
|
|
|
description := &requests.CreateCommunity{
|
|
|
|
Membership: protobuf.CommunityPermissions_NO_MEMBERSHIP,
|
|
|
|
Name: "status",
|
|
|
|
Color: "#ffffff",
|
|
|
|
Description: "status community description",
|
|
|
|
}
|
|
|
|
response, err := s.bob.CreateCommunity(description, false)
|
|
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
|
|
|
s.Require().Len(response.Communities(), 1)
|
|
|
|
s.Require().Len(response.Chats(), 0)
|
|
|
|
}
|
|
|
|
|
2020-11-18 09:16:51 +00:00
|
|
|
func (s *MessengerCommunitiesSuite) TestRetrieveCommunity() {
|
2020-12-22 11:00:13 +00:00
|
|
|
alice := s.newMessenger()
|
2020-11-18 09:16:51 +00:00
|
|
|
|
2021-01-11 10:32:51 +00:00
|
|
|
description := &requests.CreateCommunity{
|
|
|
|
Membership: protobuf.CommunityPermissions_NO_MEMBERSHIP,
|
|
|
|
Name: "status",
|
|
|
|
Color: "#ffffff",
|
|
|
|
Description: "status community description",
|
2020-11-18 09:16:51 +00:00
|
|
|
}
|
|
|
|
|
2022-07-19 09:31:52 +00:00
|
|
|
response, err := s.bob.CreateCommunity(description, true)
|
2020-11-18 09:16:51 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
2021-01-11 10:32:51 +00:00
|
|
|
s.Require().Len(response.Communities(), 1)
|
2022-03-08 15:25:00 +00:00
|
|
|
s.Require().Len(response.CommunitiesSettings(), 1)
|
2022-05-10 13:25:08 +00:00
|
|
|
s.Require().Len(response.Chats(), 1)
|
2022-03-08 15:25:00 +00:00
|
|
|
|
2021-01-11 10:32:51 +00:00
|
|
|
community := response.Communities()[0]
|
2022-03-08 15:25:00 +00:00
|
|
|
communitySettings := response.CommunitiesSettings()[0]
|
|
|
|
|
|
|
|
s.Require().Equal(communitySettings.CommunityID, community.IDString())
|
|
|
|
s.Require().Equal(communitySettings.HistoryArchiveSupportEnabled, false)
|
2020-11-18 09:16:51 +00:00
|
|
|
|
|
|
|
// Send an community message
|
|
|
|
chat := CreateOneToOneChat(common.PubkeyToHex(&alice.identity.PublicKey), &alice.identity.PublicKey, s.alice.transport)
|
|
|
|
|
|
|
|
inputMessage := &common.Message{}
|
|
|
|
inputMessage.ChatId = chat.ID
|
|
|
|
inputMessage.Text = "some text"
|
|
|
|
inputMessage.CommunityID = community.IDString()
|
|
|
|
|
2021-01-11 10:32:51 +00:00
|
|
|
err = s.bob.SaveChat(chat)
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err)
|
2020-11-18 09:16:51 +00:00
|
|
|
_, err = s.bob.SendChatMessage(context.Background(), inputMessage)
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err)
|
2020-11-18 09:16:51 +00:00
|
|
|
|
|
|
|
// Pull message and make sure org is received
|
|
|
|
err = tt.RetryWithBackOff(func() error {
|
|
|
|
response, err = alice.RetrieveAll()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-01-11 10:32:51 +00:00
|
|
|
if len(response.Communities()) == 0 {
|
2020-11-18 09:16:51 +00:00
|
|
|
return errors.New("community not received")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
communities, err := alice.Communities()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(communities, 2)
|
2021-01-11 10:32:51 +00:00
|
|
|
s.Require().Len(response.Communities(), 1)
|
2021-06-03 13:11:55 +00:00
|
|
|
s.Require().Len(response.Messages(), 1)
|
|
|
|
s.Require().Equal(community.IDString(), response.Messages()[0].CommunityID)
|
2020-11-18 09:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerCommunitiesSuite) TestJoinCommunity() {
|
2021-07-22 17:41:49 +00:00
|
|
|
ctx := context.Background()
|
2021-01-11 10:32:51 +00:00
|
|
|
|
|
|
|
description := &requests.CreateCommunity{
|
|
|
|
Membership: protobuf.CommunityPermissions_NO_MEMBERSHIP,
|
|
|
|
Name: "status",
|
|
|
|
Color: "#ffffff",
|
|
|
|
Description: "status community description",
|
2020-11-18 09:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create an community chat
|
2022-07-19 09:31:52 +00:00
|
|
|
response, err := s.bob.CreateCommunity(description, true)
|
2020-11-18 09:16:51 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
2021-01-11 10:32:51 +00:00
|
|
|
s.Require().Len(response.Communities(), 1)
|
2022-03-08 15:25:00 +00:00
|
|
|
s.Require().Len(response.CommunitiesSettings(), 1)
|
2020-11-18 09:16:51 +00:00
|
|
|
|
2022-03-08 15:25:00 +00:00
|
|
|
communitySettings := response.CommunitiesSettings()[0]
|
2021-01-11 10:32:51 +00:00
|
|
|
community := response.Communities()[0]
|
2020-11-18 09:16:51 +00:00
|
|
|
|
2022-03-08 15:25:00 +00:00
|
|
|
s.Require().Equal(communitySettings.CommunityID, community.IDString())
|
|
|
|
s.Require().Equal(communitySettings.HistoryArchiveSupportEnabled, false)
|
|
|
|
|
2020-11-18 09:16:51 +00:00
|
|
|
orgChat := &protobuf.CommunityChat{
|
|
|
|
Permissions: &protobuf.CommunityPermissions{
|
|
|
|
Access: protobuf.CommunityPermissions_NO_MEMBERSHIP,
|
|
|
|
},
|
|
|
|
Identity: &protobuf.ChatIdentity{
|
|
|
|
DisplayName: "status-core",
|
2021-10-04 13:02:25 +00:00
|
|
|
Emoji: "😎",
|
2020-11-18 09:16:51 +00:00
|
|
|
Description: "status-core community chat",
|
|
|
|
},
|
|
|
|
}
|
2021-01-11 10:32:51 +00:00
|
|
|
response, err = s.bob.CreateCommunityChat(community.ID(), orgChat)
|
2020-11-18 09:16:51 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
2021-01-11 10:32:51 +00:00
|
|
|
s.Require().Len(response.Communities(), 1)
|
2021-10-06 10:08:17 +00:00
|
|
|
s.Require().Len(response.Chats(), 1)
|
2020-11-18 09:16:51 +00:00
|
|
|
|
2021-01-11 10:32:51 +00:00
|
|
|
createdChat := response.Chats()[0]
|
2020-11-18 09:16:51 +00:00
|
|
|
s.Require().Equal(community.IDString(), createdChat.CommunityID)
|
|
|
|
s.Require().Equal(orgChat.Identity.DisplayName, createdChat.Name)
|
2021-10-04 13:02:25 +00:00
|
|
|
s.Require().Equal(orgChat.Identity.Emoji, createdChat.Emoji)
|
2020-11-18 09:16:51 +00:00
|
|
|
s.Require().NotEmpty(createdChat.ID)
|
|
|
|
s.Require().Equal(ChatTypeCommunityChat, createdChat.ChatType)
|
|
|
|
s.Require().True(createdChat.Active)
|
|
|
|
s.Require().NotEmpty(createdChat.Timestamp)
|
|
|
|
s.Require().True(strings.HasPrefix(createdChat.ID, community.IDString()))
|
|
|
|
|
2021-05-23 13:34:17 +00:00
|
|
|
// Make sure the changes are reflect in the community
|
|
|
|
community = response.Communities()[0]
|
|
|
|
|
|
|
|
var chatIds []string
|
|
|
|
for k := range community.Chats() {
|
|
|
|
chatIds = append(chatIds, k)
|
|
|
|
}
|
|
|
|
category := &requests.CreateCommunityCategory{
|
|
|
|
CommunityID: community.ID(),
|
|
|
|
CategoryName: "category-name",
|
|
|
|
ChatIDs: chatIds,
|
|
|
|
}
|
|
|
|
|
|
|
|
response, err = s.bob.CreateCommunityCategory(category)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
|
|
|
s.Require().Len(response.Communities(), 1)
|
|
|
|
s.Require().Len(response.Communities()[0].Categories(), 1)
|
|
|
|
|
2020-11-18 09:16:51 +00:00
|
|
|
// Make sure the changes are reflect in the community
|
2021-01-11 10:32:51 +00:00
|
|
|
community = response.Communities()[0]
|
2020-11-18 09:16:51 +00:00
|
|
|
chats := community.Chats()
|
2022-05-10 13:25:08 +00:00
|
|
|
s.Require().Len(chats, 2)
|
2020-11-18 09:16:51 +00:00
|
|
|
|
|
|
|
// Send an community message
|
|
|
|
chat := CreateOneToOneChat(common.PubkeyToHex(&s.alice.identity.PublicKey), &s.alice.identity.PublicKey, s.bob.transport)
|
|
|
|
|
|
|
|
inputMessage := &common.Message{}
|
|
|
|
inputMessage.ChatId = chat.ID
|
|
|
|
inputMessage.Text = "some text"
|
|
|
|
inputMessage.CommunityID = community.IDString()
|
|
|
|
|
2021-01-11 10:32:51 +00:00
|
|
|
err = s.bob.SaveChat(chat)
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err)
|
2020-11-18 09:16:51 +00:00
|
|
|
_, err = s.bob.SendChatMessage(context.Background(), inputMessage)
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err)
|
2020-11-18 09:16:51 +00:00
|
|
|
|
|
|
|
// Pull message and make sure org is received
|
|
|
|
err = tt.RetryWithBackOff(func() error {
|
|
|
|
response, err = s.alice.RetrieveAll()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-01-11 10:32:51 +00:00
|
|
|
if len(response.Communities()) == 0 {
|
2020-11-18 09:16:51 +00:00
|
|
|
return errors.New("community not received")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
communities, err := s.alice.Communities()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(communities, 2)
|
2021-01-11 10:32:51 +00:00
|
|
|
s.Require().Len(response.Communities(), 1)
|
2021-06-03 13:11:55 +00:00
|
|
|
s.Require().Len(response.Messages(), 1)
|
|
|
|
s.Require().Equal(community.IDString(), response.Messages()[0].CommunityID)
|
2020-11-18 09:16:51 +00:00
|
|
|
|
|
|
|
// We join the org
|
2021-07-22 17:41:49 +00:00
|
|
|
response, err = s.alice.JoinCommunity(ctx, community.ID())
|
2020-11-18 09:16:51 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
2021-01-11 10:32:51 +00:00
|
|
|
s.Require().Len(response.Communities(), 1)
|
|
|
|
s.Require().True(response.Communities()[0].Joined())
|
2022-05-10 13:25:08 +00:00
|
|
|
s.Require().Len(response.Chats(), 2)
|
2021-05-23 13:34:17 +00:00
|
|
|
s.Require().Len(response.Communities()[0].Categories(), 1)
|
|
|
|
|
|
|
|
var categoryID string
|
|
|
|
for k := range response.Communities()[0].Categories() {
|
|
|
|
categoryID = k
|
|
|
|
}
|
2020-11-18 09:16:51 +00:00
|
|
|
|
|
|
|
// The chat should be created
|
2022-05-13 14:02:38 +00:00
|
|
|
|
|
|
|
found := false
|
|
|
|
for _, createdChat := range response.Chats() {
|
|
|
|
if orgChat.Identity.DisplayName == createdChat.Name {
|
|
|
|
found = true
|
|
|
|
s.Require().Equal(community.IDString(), createdChat.CommunityID)
|
|
|
|
s.Require().Equal(orgChat.Identity.DisplayName, createdChat.Name)
|
|
|
|
s.Require().Equal(orgChat.Identity.Emoji, createdChat.Emoji)
|
|
|
|
s.Require().NotEmpty(createdChat.ID)
|
|
|
|
s.Require().Equal(ChatTypeCommunityChat, createdChat.ChatType)
|
|
|
|
s.Require().Equal(categoryID, createdChat.CategoryID)
|
|
|
|
s.Require().True(createdChat.Active)
|
|
|
|
s.Require().NotEmpty(createdChat.Timestamp)
|
|
|
|
s.Require().True(strings.HasPrefix(createdChat.ID, community.IDString()))
|
|
|
|
}
|
2022-05-13 06:54:55 +00:00
|
|
|
}
|
2022-05-13 14:02:38 +00:00
|
|
|
s.Require().True(found)
|
2020-11-18 09:16:51 +00:00
|
|
|
|
|
|
|
// Create another org chat
|
|
|
|
orgChat = &protobuf.CommunityChat{
|
|
|
|
Permissions: &protobuf.CommunityPermissions{
|
|
|
|
Access: protobuf.CommunityPermissions_NO_MEMBERSHIP,
|
|
|
|
},
|
|
|
|
Identity: &protobuf.ChatIdentity{
|
|
|
|
DisplayName: "status-core-ui",
|
2021-10-04 13:02:25 +00:00
|
|
|
Emoji: "👍",
|
2020-11-18 09:16:51 +00:00
|
|
|
Description: "status-core-ui community chat",
|
|
|
|
},
|
|
|
|
}
|
2021-01-11 10:32:51 +00:00
|
|
|
response, err = s.bob.CreateCommunityChat(community.ID(), orgChat)
|
2020-11-18 09:16:51 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
2021-01-11 10:32:51 +00:00
|
|
|
s.Require().Len(response.Communities(), 1)
|
|
|
|
s.Require().Len(response.Chats(), 1)
|
2020-11-18 09:16:51 +00:00
|
|
|
|
2021-10-06 11:44:24 +00:00
|
|
|
var actualChat *Chat
|
2020-11-18 09:16:51 +00:00
|
|
|
// Pull message, this time it should be received as advertised automatically
|
|
|
|
err = tt.RetryWithBackOff(func() error {
|
|
|
|
response, err = s.alice.RetrieveAll()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-10-06 10:08:35 +00:00
|
|
|
if len(response.Communities()) != 1 {
|
2020-11-18 09:16:51 +00:00
|
|
|
return errors.New("community not received")
|
|
|
|
}
|
2021-10-06 11:44:24 +00:00
|
|
|
|
|
|
|
for _, c := range response.Chats() {
|
|
|
|
if c.Name == orgChat.Identity.DisplayName {
|
|
|
|
actualChat = c
|
|
|
|
return nil
|
|
|
|
}
|
2021-10-06 10:08:35 +00:00
|
|
|
}
|
2021-10-06 11:44:24 +00:00
|
|
|
return errors.New("chat not found")
|
2020-11-18 09:16:51 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
communities, err = s.alice.Communities()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(communities, 2)
|
2021-01-11 10:32:51 +00:00
|
|
|
s.Require().Len(response.Communities(), 1)
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NotNil(actualChat)
|
2021-10-06 10:08:35 +00:00
|
|
|
s.Require().Equal(community.IDString(), actualChat.CommunityID)
|
|
|
|
s.Require().Equal(orgChat.Identity.DisplayName, actualChat.Name)
|
|
|
|
s.Require().Equal(orgChat.Identity.Emoji, actualChat.Emoji)
|
|
|
|
s.Require().NotEmpty(actualChat.ID)
|
|
|
|
s.Require().Equal(ChatTypeCommunityChat, actualChat.ChatType)
|
|
|
|
s.Require().True(actualChat.Active)
|
|
|
|
s.Require().NotEmpty(actualChat.Timestamp)
|
|
|
|
s.Require().True(strings.HasPrefix(actualChat.ID, community.IDString()))
|
2020-11-18 09:16:51 +00:00
|
|
|
|
|
|
|
// We leave the org
|
2021-01-11 10:32:51 +00:00
|
|
|
response, err = s.alice.LeaveCommunity(community.ID())
|
2020-11-18 09:16:51 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
2021-01-11 10:32:51 +00:00
|
|
|
s.Require().Len(response.Communities(), 1)
|
|
|
|
s.Require().False(response.Communities()[0].Joined())
|
2022-05-10 13:25:08 +00:00
|
|
|
s.Require().Len(response.RemovedChats(), 3)
|
2020-11-18 09:16:51 +00:00
|
|
|
}
|
|
|
|
|
2022-08-23 16:30:19 +00:00
|
|
|
func (s *MessengerCommunitiesSuite) createCommunity() *communities.Community {
|
2022-07-08 10:25:46 +00:00
|
|
|
description := &requests.CreateCommunity{
|
|
|
|
Membership: protobuf.CommunityPermissions_NO_MEMBERSHIP,
|
|
|
|
Name: "status",
|
|
|
|
Color: "#ffffff",
|
|
|
|
Description: "status community description",
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create an community chat
|
2022-08-23 16:30:19 +00:00
|
|
|
response, err := s.admin.CreateCommunity(description, true)
|
2022-07-08 10:25:46 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
|
|
|
|
|
|
|
community := response.Communities()[0]
|
|
|
|
orgChat := &protobuf.CommunityChat{
|
|
|
|
Permissions: &protobuf.CommunityPermissions{
|
|
|
|
Access: protobuf.CommunityPermissions_NO_MEMBERSHIP,
|
|
|
|
},
|
|
|
|
Identity: &protobuf.ChatIdentity{
|
|
|
|
DisplayName: "status-core",
|
|
|
|
Emoji: "😎",
|
|
|
|
Description: "status-core community chat",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-08-23 16:30:19 +00:00
|
|
|
response, err = s.admin.CreateCommunityChat(community.ID(), orgChat)
|
2022-07-08 10:25:46 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
|
|
|
|
2022-08-23 16:30:19 +00:00
|
|
|
return community
|
|
|
|
}
|
2022-07-08 10:25:46 +00:00
|
|
|
|
2022-08-23 16:30:19 +00:00
|
|
|
func (s *MessengerCommunitiesSuite) advertiseCommunityTo(community *communities.Community, user *Messenger) {
|
|
|
|
chat := CreateOneToOneChat(common.PubkeyToHex(&user.identity.PublicKey), &user.identity.PublicKey, user.transport)
|
2022-07-08 10:25:46 +00:00
|
|
|
|
2022-08-23 16:30:19 +00:00
|
|
|
inputMessage := &common.Message{}
|
|
|
|
inputMessage.ChatId = chat.ID
|
|
|
|
inputMessage.Text = "some text"
|
|
|
|
inputMessage.CommunityID = community.IDString()
|
2022-07-08 10:25:46 +00:00
|
|
|
|
2022-08-23 16:30:19 +00:00
|
|
|
err := s.admin.SaveChat(chat)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
_, err = s.admin.SendChatMessage(context.Background(), inputMessage)
|
|
|
|
s.Require().NoError(err)
|
2022-07-08 10:25:46 +00:00
|
|
|
|
2022-08-23 16:30:19 +00:00
|
|
|
// Ensure community is received
|
|
|
|
err = tt.RetryWithBackOff(func() error {
|
|
|
|
response, err := user.RetrieveAll()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(response.Communities()) == 0 {
|
|
|
|
return errors.New("community not received")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
s.Require().NoError(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerCommunitiesSuite) joinCommunity(community *communities.Community, user *Messenger) {
|
|
|
|
// Request to join the community
|
|
|
|
request := &requests.RequestToJoinCommunity{CommunityID: community.ID()}
|
|
|
|
response, err := user.RequestToJoinCommunity(request)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
|
|
|
s.Require().Len(response.RequestsToJoinCommunity, 1)
|
2022-10-25 22:06:20 +00:00
|
|
|
s.Require().Len(response.ActivityCenterNotifications(), 1)
|
|
|
|
|
|
|
|
notification := response.ActivityCenterNotifications()[0]
|
|
|
|
s.Require().NotNil(notification)
|
|
|
|
s.Require().Equal(notification.Type, ActivityCenterNotificationTypeCommunityRequest)
|
|
|
|
s.Require().Equal(notification.MembershipStatus, ActivityCenterMembershipStatusPending)
|
2022-08-23 16:30:19 +00:00
|
|
|
|
|
|
|
// Retrieve and accept join request
|
|
|
|
err = tt.RetryWithBackOff(func() error {
|
|
|
|
response, err := s.admin.RetrieveAll()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(response.Communities()) == 0 {
|
2022-10-25 22:06:20 +00:00
|
|
|
return errors.New("no communities in response (accept join request)")
|
2022-08-23 16:30:19 +00:00
|
|
|
}
|
|
|
|
if !response.Communities()[0].HasMember(&user.identity.PublicKey) {
|
|
|
|
return errors.New("user not accepted")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
// Retrieve join request response
|
|
|
|
err = tt.RetryWithBackOff(func() error {
|
|
|
|
response, err := user.RetrieveAll()
|
2022-10-25 22:06:20 +00:00
|
|
|
|
2022-08-23 16:30:19 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(response.Communities()) == 0 {
|
2022-10-25 22:06:20 +00:00
|
|
|
return errors.New("no communities in response (join request response)")
|
2022-08-23 16:30:19 +00:00
|
|
|
}
|
|
|
|
if !response.Communities()[0].HasMember(&user.identity.PublicKey) {
|
|
|
|
return errors.New("user not a member")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
s.Require().NoError(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerCommunitiesSuite) TestCommunityContactCodeAdvertisement() {
|
|
|
|
community := s.createCommunity()
|
|
|
|
s.advertiseCommunityTo(community, s.bob)
|
|
|
|
s.advertiseCommunityTo(community, s.alice)
|
|
|
|
|
|
|
|
s.joinCommunity(community, s.bob)
|
|
|
|
s.joinCommunity(community, s.alice)
|
2022-07-08 10:25:46 +00:00
|
|
|
|
|
|
|
// Trigger ContactCodeAdvertisement
|
2023-03-30 10:18:13 +00:00
|
|
|
err := s.bob.SetDisplayName("bobby")
|
2022-07-08 10:25:46 +00:00
|
|
|
s.Require().NoError(err)
|
2022-08-23 16:30:19 +00:00
|
|
|
err = s.bob.SetBio("I like P2P chats")
|
2022-08-05 11:22:35 +00:00
|
|
|
s.Require().NoError(err)
|
2022-07-08 10:25:46 +00:00
|
|
|
|
2022-08-23 16:30:19 +00:00
|
|
|
// Ensure alice receives bob's ContactCodeAdvertisement
|
2022-07-08 10:25:46 +00:00
|
|
|
err = tt.RetryWithBackOff(func() error {
|
2022-08-23 16:30:19 +00:00
|
|
|
response, err := s.alice.RetrieveAll()
|
2022-07-08 10:25:46 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(response.Contacts) == 0 {
|
|
|
|
return errors.New("no contacts in response")
|
|
|
|
}
|
2022-08-23 16:30:19 +00:00
|
|
|
if response.Contacts[0].DisplayName != "bobby" {
|
2022-07-08 10:25:46 +00:00
|
|
|
return errors.New("display name was not updated")
|
|
|
|
}
|
2022-08-05 11:22:35 +00:00
|
|
|
if response.Contacts[0].Bio != "I like P2P chats" {
|
|
|
|
return errors.New("bio was not updated")
|
|
|
|
}
|
2022-07-08 10:25:46 +00:00
|
|
|
return nil
|
|
|
|
})
|
|
|
|
s.Require().NoError(err)
|
|
|
|
}
|
|
|
|
|
2021-01-11 10:32:51 +00:00
|
|
|
func (s *MessengerCommunitiesSuite) TestInviteUsersToCommunity() {
|
|
|
|
description := &requests.CreateCommunity{
|
|
|
|
Membership: protobuf.CommunityPermissions_NO_MEMBERSHIP,
|
|
|
|
Name: "status",
|
|
|
|
Color: "#ffffff",
|
|
|
|
Description: "status community description",
|
2020-11-18 09:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create an community chat
|
2022-07-19 09:31:52 +00:00
|
|
|
response, err := s.bob.CreateCommunity(description, true)
|
2020-11-18 09:16:51 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
2021-01-11 10:32:51 +00:00
|
|
|
s.Require().Len(response.Communities(), 1)
|
2021-03-31 16:23:45 +00:00
|
|
|
s.Require().True(response.Communities()[0].HasMember(&s.bob.identity.PublicKey))
|
|
|
|
s.Require().True(response.Communities()[0].IsMemberAdmin(&s.bob.identity.PublicKey))
|
2020-11-18 09:16:51 +00:00
|
|
|
|
2021-01-11 10:32:51 +00:00
|
|
|
community := response.Communities()[0]
|
2020-11-18 09:16:51 +00:00
|
|
|
|
2021-01-11 10:32:51 +00:00
|
|
|
response, err = s.bob.InviteUsersToCommunity(
|
|
|
|
&requests.InviteUsersToCommunity{
|
|
|
|
CommunityID: community.ID(),
|
|
|
|
Users: []types.HexBytes{common.PubkeyToHexBytes(&s.alice.identity.PublicKey)},
|
|
|
|
},
|
|
|
|
)
|
2020-11-18 09:16:51 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
2021-01-11 10:32:51 +00:00
|
|
|
s.Require().Len(response.Communities(), 1)
|
2020-11-18 09:16:51 +00:00
|
|
|
|
2021-01-11 10:32:51 +00:00
|
|
|
community = response.Communities()[0]
|
2020-11-18 09:16:51 +00:00
|
|
|
s.Require().True(community.HasMember(&s.alice.identity.PublicKey))
|
|
|
|
|
|
|
|
// Pull message and make sure org is received
|
|
|
|
err = tt.RetryWithBackOff(func() error {
|
|
|
|
response, err = s.alice.RetrieveAll()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-01-11 10:32:51 +00:00
|
|
|
if len(response.Communities()) == 0 {
|
2020-11-18 09:16:51 +00:00
|
|
|
return errors.New("community not received")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
communities, err := s.alice.Communities()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(communities, 2)
|
2021-01-11 10:32:51 +00:00
|
|
|
s.Require().Len(response.Communities(), 1)
|
2020-11-18 09:16:51 +00:00
|
|
|
|
2021-01-11 10:32:51 +00:00
|
|
|
community = response.Communities()[0]
|
2020-11-18 09:16:51 +00:00
|
|
|
s.Require().True(community.HasMember(&s.alice.identity.PublicKey))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerCommunitiesSuite) TestPostToCommunityChat() {
|
2021-01-11 10:32:51 +00:00
|
|
|
description := &requests.CreateCommunity{
|
|
|
|
Membership: protobuf.CommunityPermissions_INVITATION_ONLY,
|
|
|
|
Name: "status",
|
|
|
|
Color: "#ffffff",
|
|
|
|
Description: "status community description",
|
2022-05-27 09:14:40 +00:00
|
|
|
Encrypted: true,
|
2020-11-18 09:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create an community chat
|
2022-07-19 09:31:52 +00:00
|
|
|
response, err := s.bob.CreateCommunity(description, true)
|
2020-11-18 09:16:51 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
2021-01-11 10:32:51 +00:00
|
|
|
s.Require().Len(response.Communities(), 1)
|
2022-05-13 13:44:26 +00:00
|
|
|
s.Require().Len(response.Communities()[0].Chats(), 1)
|
|
|
|
s.Require().Len(response.Chats(), 1)
|
2020-11-18 09:16:51 +00:00
|
|
|
|
2021-01-11 10:32:51 +00:00
|
|
|
community := response.Communities()[0]
|
2020-11-18 09:16:51 +00:00
|
|
|
|
|
|
|
// Create chat
|
|
|
|
orgChat := &protobuf.CommunityChat{
|
|
|
|
Permissions: &protobuf.CommunityPermissions{
|
|
|
|
Access: protobuf.CommunityPermissions_NO_MEMBERSHIP,
|
|
|
|
},
|
|
|
|
Identity: &protobuf.ChatIdentity{
|
|
|
|
DisplayName: "status-core",
|
|
|
|
Description: "status-core community chat",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-01-11 10:32:51 +00:00
|
|
|
response, err = s.bob.CreateCommunityChat(community.ID(), orgChat)
|
2020-11-18 09:16:51 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
2021-01-11 10:32:51 +00:00
|
|
|
s.Require().Len(response.Communities(), 1)
|
2022-05-13 13:44:26 +00:00
|
|
|
s.Require().Len(response.Communities()[0].Chats(), 2)
|
2021-01-11 10:32:51 +00:00
|
|
|
s.Require().Len(response.Chats(), 1)
|
2020-11-18 09:16:51 +00:00
|
|
|
|
2021-01-11 10:32:51 +00:00
|
|
|
response, err = s.bob.InviteUsersToCommunity(
|
|
|
|
&requests.InviteUsersToCommunity{
|
|
|
|
CommunityID: community.ID(),
|
|
|
|
Users: []types.HexBytes{common.PubkeyToHexBytes(&s.alice.identity.PublicKey)},
|
|
|
|
},
|
|
|
|
)
|
2020-11-18 09:16:51 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
2021-01-11 10:32:51 +00:00
|
|
|
s.Require().Len(response.Communities(), 1)
|
2020-11-18 09:16:51 +00:00
|
|
|
|
2021-01-11 10:32:51 +00:00
|
|
|
community = response.Communities()[0]
|
2020-11-18 09:16:51 +00:00
|
|
|
s.Require().True(community.HasMember(&s.alice.identity.PublicKey))
|
|
|
|
|
|
|
|
// Pull message and make sure org is received
|
|
|
|
err = tt.RetryWithBackOff(func() error {
|
|
|
|
response, err = s.alice.RetrieveAll()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-01-11 10:32:51 +00:00
|
|
|
if len(response.Communities()) == 0 {
|
2020-11-18 09:16:51 +00:00
|
|
|
return errors.New("community not received")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
communities, err := s.alice.Communities()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(communities, 2)
|
2021-01-11 10:32:51 +00:00
|
|
|
s.Require().Len(response.Communities(), 1)
|
2020-11-18 09:16:51 +00:00
|
|
|
|
2022-05-27 09:14:40 +00:00
|
|
|
communityID := response.Communities()[0].ID()
|
|
|
|
s.Require().Equal(communityID, community.ID())
|
|
|
|
|
2021-07-22 17:41:49 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
|
2020-11-18 09:16:51 +00:00
|
|
|
// We join the org
|
2021-07-22 17:41:49 +00:00
|
|
|
response, err = s.alice.JoinCommunity(ctx, community.ID())
|
2020-11-18 09:16:51 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
2021-01-11 10:32:51 +00:00
|
|
|
s.Require().Len(response.Communities(), 1)
|
2022-05-13 13:44:26 +00:00
|
|
|
s.Require().Len(response.Communities()[0].Chats(), 2)
|
2021-01-11 10:32:51 +00:00
|
|
|
s.Require().True(response.Communities()[0].Joined())
|
2022-05-10 13:25:08 +00:00
|
|
|
s.Require().Len(response.Chats(), 2)
|
2020-11-18 09:16:51 +00:00
|
|
|
|
2022-05-10 13:25:08 +00:00
|
|
|
chatID := response.Chats()[1].ID
|
2020-11-18 09:16:51 +00:00
|
|
|
inputMessage := &common.Message{}
|
|
|
|
inputMessage.ChatId = chatID
|
|
|
|
inputMessage.ContentType = protobuf.ChatMessage_TEXT_PLAIN
|
|
|
|
inputMessage.Text = "some text"
|
|
|
|
|
2021-07-22 17:41:49 +00:00
|
|
|
_, err = s.alice.SendChatMessage(ctx, inputMessage)
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err)
|
2020-11-18 09:16:51 +00:00
|
|
|
|
|
|
|
// Pull message and make sure org is received
|
|
|
|
err = tt.RetryWithBackOff(func() error {
|
|
|
|
response, err = s.bob.RetrieveAll()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-06-03 13:11:55 +00:00
|
|
|
if len(response.messages) == 0 {
|
2020-11-18 09:16:51 +00:00
|
|
|
return errors.New("message not received")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
s.Require().NoError(err)
|
2021-06-03 13:11:55 +00:00
|
|
|
s.Require().Len(response.Messages(), 1)
|
2022-09-05 12:08:44 +00:00
|
|
|
s.Require().Equal(inputMessage.Text, response.Messages()[0].Text)
|
2022-05-13 13:44:26 +00:00
|
|
|
|
|
|
|
// check if response contains the chat we're interested in
|
|
|
|
// we use this instead of checking just the length of the chat because
|
|
|
|
// a CommunityDescription message might be received in the meantime due to syncing
|
|
|
|
// hence response.Chats() might contain the general chat, and the new chat;
|
|
|
|
// or only the new chat if the CommunityDescription message has not arrived
|
|
|
|
found := false
|
|
|
|
for _, chat := range response.Chats() {
|
|
|
|
if chat.ID == chatID {
|
|
|
|
found = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s.Require().True(found)
|
2020-11-18 09:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerCommunitiesSuite) TestImportCommunity() {
|
2021-07-22 17:41:49 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
|
2021-01-11 10:32:51 +00:00
|
|
|
description := &requests.CreateCommunity{
|
|
|
|
Membership: protobuf.CommunityPermissions_NO_MEMBERSHIP,
|
|
|
|
Name: "status",
|
|
|
|
Color: "#ffffff",
|
|
|
|
Description: "status community description",
|
2020-11-18 09:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create an community chat
|
2022-07-19 09:31:52 +00:00
|
|
|
response, err := s.bob.CreateCommunity(description, true)
|
2020-11-18 09:16:51 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
2021-01-11 10:32:51 +00:00
|
|
|
s.Require().Len(response.Communities(), 1)
|
2022-03-08 15:25:00 +00:00
|
|
|
s.Require().Len(response.CommunitiesSettings(), 1)
|
2022-07-01 13:54:02 +00:00
|
|
|
s.Require().True(response.Communities()[0].Joined())
|
|
|
|
s.Require().True(response.Communities()[0].IsAdmin())
|
2020-11-18 09:16:51 +00:00
|
|
|
|
2021-01-11 10:32:51 +00:00
|
|
|
community := response.Communities()[0]
|
2022-03-08 15:25:00 +00:00
|
|
|
communitySettings := response.CommunitiesSettings()[0]
|
|
|
|
|
|
|
|
s.Require().Equal(communitySettings.CommunityID, community.IDString())
|
|
|
|
s.Require().Equal(communitySettings.HistoryArchiveSupportEnabled, false)
|
2020-11-18 09:16:51 +00:00
|
|
|
|
2021-05-23 13:34:17 +00:00
|
|
|
category := &requests.CreateCommunityCategory{
|
|
|
|
CommunityID: community.ID(),
|
|
|
|
CategoryName: "category-name",
|
|
|
|
ChatIDs: []string{},
|
|
|
|
}
|
|
|
|
|
|
|
|
response, err = s.bob.CreateCommunityCategory(category)
|
2022-03-28 10:10:40 +00:00
|
|
|
s.Require().NoError(err)
|
2021-05-23 13:34:17 +00:00
|
|
|
community = response.Communities()[0]
|
|
|
|
|
2021-01-11 10:32:51 +00:00
|
|
|
privateKey, err := s.bob.ExportCommunity(community.ID())
|
2020-11-18 09:16:51 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2021-07-22 17:41:49 +00:00
|
|
|
_, err = s.alice.ImportCommunity(ctx, privateKey)
|
2020-11-18 09:16:51 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
// Invite user on bob side
|
|
|
|
newUser, err := crypto.GenerateKey()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2021-01-11 10:32:51 +00:00
|
|
|
_, err = s.bob.InviteUsersToCommunity(
|
|
|
|
&requests.InviteUsersToCommunity{
|
|
|
|
CommunityID: community.ID(),
|
|
|
|
Users: []types.HexBytes{common.PubkeyToHexBytes(&newUser.PublicKey)},
|
|
|
|
},
|
|
|
|
)
|
2020-11-18 09:16:51 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
// Pull message and make sure org is received
|
|
|
|
err = tt.RetryWithBackOff(func() error {
|
|
|
|
response, err = s.alice.RetrieveAll()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-01-11 10:32:51 +00:00
|
|
|
if len(response.Communities()) == 0 {
|
2020-11-18 09:16:51 +00:00
|
|
|
return errors.New("community not received")
|
|
|
|
}
|
2022-07-01 13:54:02 +00:00
|
|
|
if !response.Communities()[0].IsAdmin() {
|
|
|
|
return errors.New("isn't admin despite import")
|
|
|
|
}
|
2020-11-18 09:16:51 +00:00
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
}
|
2021-01-11 10:32:51 +00:00
|
|
|
|
2022-09-21 10:50:56 +00:00
|
|
|
func (s *MessengerCommunitiesSuite) TestRolesAfterImportCommunity() {
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
description := &requests.CreateCommunity{
|
|
|
|
Membership: protobuf.CommunityPermissions_NO_MEMBERSHIP,
|
|
|
|
Name: "status",
|
|
|
|
Color: "#ffffff",
|
|
|
|
Description: "status community description",
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a community chat
|
|
|
|
response, err := s.bob.CreateCommunity(description, true)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
|
|
|
s.Require().Len(response.Communities(), 1)
|
|
|
|
s.Require().Len(response.CommunitiesSettings(), 1)
|
|
|
|
s.Require().True(response.Communities()[0].Joined())
|
|
|
|
s.Require().True(response.Communities()[0].IsAdmin())
|
|
|
|
s.Require().True(response.Communities()[0].IsMemberAdmin(&s.bob.identity.PublicKey))
|
|
|
|
s.Require().False(response.Communities()[0].IsMemberAdmin(&s.alice.identity.PublicKey))
|
|
|
|
|
|
|
|
community := response.Communities()[0]
|
|
|
|
communitySettings := response.CommunitiesSettings()[0]
|
|
|
|
|
|
|
|
s.Require().Equal(communitySettings.CommunityID, community.IDString())
|
|
|
|
s.Require().Equal(communitySettings.HistoryArchiveSupportEnabled, false)
|
|
|
|
|
|
|
|
category := &requests.CreateCommunityCategory{
|
|
|
|
CommunityID: community.ID(),
|
|
|
|
CategoryName: "category-name",
|
|
|
|
ChatIDs: []string{},
|
|
|
|
}
|
|
|
|
|
|
|
|
response, err = s.bob.CreateCommunityCategory(category)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
community = response.Communities()[0]
|
|
|
|
|
|
|
|
privateKey, err := s.bob.ExportCommunity(community.ID())
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
response, err = s.alice.ImportCommunity(ctx, privateKey)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().True(response.Communities()[0].IsMemberAdmin(&s.alice.identity.PublicKey))
|
|
|
|
}
|
|
|
|
|
2021-01-11 10:32:51 +00:00
|
|
|
func (s *MessengerCommunitiesSuite) TestRequestAccess() {
|
2021-07-22 17:41:49 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
|
2021-01-11 10:32:51 +00:00
|
|
|
description := &requests.CreateCommunity{
|
|
|
|
Membership: protobuf.CommunityPermissions_ON_REQUEST,
|
|
|
|
Name: "status",
|
|
|
|
Color: "#ffffff",
|
|
|
|
Description: "status community description",
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create an community chat
|
2022-07-19 09:31:52 +00:00
|
|
|
response, err := s.bob.CreateCommunity(description, true)
|
2021-01-11 10:32:51 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
|
|
|
s.Require().Len(response.Communities(), 1)
|
|
|
|
|
|
|
|
community := response.Communities()[0]
|
|
|
|
|
|
|
|
chat := CreateOneToOneChat(common.PubkeyToHex(&s.alice.identity.PublicKey), &s.alice.identity.PublicKey, s.alice.transport)
|
|
|
|
|
|
|
|
s.Require().NoError(s.bob.SaveChat(chat))
|
|
|
|
|
|
|
|
message := buildTestMessage(*chat)
|
|
|
|
message.CommunityID = community.IDString()
|
|
|
|
|
|
|
|
// We send a community link to alice
|
2021-07-22 17:41:49 +00:00
|
|
|
response, err = s.bob.SendChatMessage(ctx, message)
|
2021-01-11 10:32:51 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
|
|
|
|
|
|
|
// Retrieve community link & community
|
|
|
|
err = tt.RetryWithBackOff(func() error {
|
|
|
|
response, err = s.alice.RetrieveAll()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(response.Communities()) == 0 {
|
|
|
|
return errors.New("message not received")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
request := &requests.RequestToJoinCommunity{CommunityID: community.ID()}
|
|
|
|
// We try to join the org
|
|
|
|
response, err = s.alice.RequestToJoinCommunity(request)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
|
|
|
s.Require().Len(response.RequestsToJoinCommunity, 1)
|
|
|
|
|
2022-10-25 22:06:20 +00:00
|
|
|
s.Require().Len(response.ActivityCenterNotifications(), 1)
|
|
|
|
|
|
|
|
notification := response.ActivityCenterNotifications()[0]
|
|
|
|
s.Require().NotNil(notification)
|
|
|
|
s.Require().Equal(notification.Type, ActivityCenterNotificationTypeCommunityRequest)
|
|
|
|
s.Require().Equal(notification.MembershipStatus, ActivityCenterMembershipStatusPending)
|
2023-01-28 09:52:53 +00:00
|
|
|
s.Require().Equal(notification.Read, true)
|
|
|
|
s.Require().Equal(notification.Accepted, false)
|
|
|
|
s.Require().Equal(notification.Dismissed, false)
|
2022-10-25 22:06:20 +00:00
|
|
|
|
2021-01-11 10:32:51 +00:00
|
|
|
requestToJoin1 := response.RequestsToJoinCommunity[0]
|
|
|
|
s.Require().NotNil(requestToJoin1)
|
|
|
|
s.Require().Equal(community.ID(), requestToJoin1.CommunityID)
|
|
|
|
s.Require().True(requestToJoin1.Our)
|
|
|
|
s.Require().NotEmpty(requestToJoin1.ID)
|
|
|
|
s.Require().NotEmpty(requestToJoin1.Clock)
|
|
|
|
s.Require().Equal(requestToJoin1.PublicKey, common.PubkeyToHex(&s.alice.identity.PublicKey))
|
|
|
|
s.Require().Equal(communities.RequestToJoinStatePending, requestToJoin1.State)
|
|
|
|
|
|
|
|
// Make sure clock is not empty
|
|
|
|
s.Require().NotEmpty(requestToJoin1.Clock)
|
|
|
|
|
|
|
|
s.Require().Len(response.Communities(), 1)
|
|
|
|
s.Require().Equal(response.Communities()[0].RequestedToJoinAt(), requestToJoin1.Clock)
|
|
|
|
|
|
|
|
// pull all communities to make sure we set RequestedToJoinAt
|
|
|
|
|
|
|
|
allCommunities, err := s.alice.Communities()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(allCommunities, 2)
|
|
|
|
|
|
|
|
if bytes.Equal(allCommunities[0].ID(), community.ID()) {
|
|
|
|
s.Require().Equal(allCommunities[0].RequestedToJoinAt(), requestToJoin1.Clock)
|
|
|
|
} else {
|
|
|
|
s.Require().Equal(allCommunities[1].RequestedToJoinAt(), requestToJoin1.Clock)
|
|
|
|
}
|
|
|
|
|
|
|
|
// pull to make sure it has been saved
|
|
|
|
requestsToJoin, err := s.alice.MyPendingRequestsToJoin()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(requestsToJoin, 1)
|
|
|
|
|
|
|
|
// Make sure the requests are fetched also by community
|
|
|
|
requestsToJoin, err = s.alice.PendingRequestsToJoinForCommunity(community.ID())
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(requestsToJoin, 1)
|
|
|
|
|
|
|
|
// Retrieve request to join
|
|
|
|
err = tt.RetryWithBackOff(func() error {
|
|
|
|
response, err = s.bob.RetrieveAll()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(response.RequestsToJoinCommunity) == 0 {
|
|
|
|
return errors.New("request to join community not received")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(response.RequestsToJoinCommunity, 1)
|
|
|
|
|
|
|
|
requestToJoin2 := response.RequestsToJoinCommunity[0]
|
|
|
|
|
|
|
|
s.Require().NotNil(requestToJoin2)
|
|
|
|
s.Require().Equal(community.ID(), requestToJoin2.CommunityID)
|
|
|
|
s.Require().False(requestToJoin2.Our)
|
|
|
|
s.Require().NotEmpty(requestToJoin2.ID)
|
|
|
|
s.Require().NotEmpty(requestToJoin2.Clock)
|
|
|
|
s.Require().Equal(requestToJoin2.PublicKey, common.PubkeyToHex(&s.alice.identity.PublicKey))
|
|
|
|
s.Require().Equal(communities.RequestToJoinStatePending, requestToJoin2.State)
|
|
|
|
|
|
|
|
s.Require().Equal(requestToJoin1.ID, requestToJoin2.ID)
|
|
|
|
|
|
|
|
// Accept request
|
|
|
|
|
|
|
|
acceptRequestToJoin := &requests.AcceptRequestToJoinCommunity{ID: requestToJoin1.ID}
|
|
|
|
|
|
|
|
response, err = s.bob.AcceptRequestToJoinCommunity(acceptRequestToJoin)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
|
|
|
|
|
|
|
s.Require().Len(response.Communities(), 1)
|
|
|
|
|
|
|
|
updatedCommunity := response.Communities()[0]
|
|
|
|
|
|
|
|
s.Require().NotNil(updatedCommunity)
|
|
|
|
s.Require().True(updatedCommunity.HasMember(&s.alice.identity.PublicKey))
|
|
|
|
|
2022-10-25 22:06:20 +00:00
|
|
|
s.Require().Len(response.ActivityCenterNotifications(), 1)
|
|
|
|
|
|
|
|
notification = response.ActivityCenterNotifications()[0]
|
|
|
|
s.Require().NotNil(notification)
|
|
|
|
s.Require().Equal(notification.Type, ActivityCenterNotificationTypeCommunityMembershipRequest)
|
|
|
|
s.Require().Equal(notification.MembershipStatus, ActivityCenterMembershipStatusAccepted)
|
2023-01-28 09:52:53 +00:00
|
|
|
s.Require().Equal(notification.Read, true)
|
|
|
|
s.Require().Equal(notification.Accepted, true)
|
|
|
|
s.Require().Equal(notification.Dismissed, false)
|
2022-10-25 22:06:20 +00:00
|
|
|
|
2021-01-11 10:32:51 +00:00
|
|
|
// Pull message and make sure org is received
|
|
|
|
err = tt.RetryWithBackOff(func() error {
|
|
|
|
response, err = s.alice.RetrieveAll()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(response.Communities()) == 0 {
|
|
|
|
return errors.New("community not received")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
|
|
|
|
2023-02-03 16:33:16 +00:00
|
|
|
s.Require().Len(response.RequestsToJoinCommunity, 1)
|
|
|
|
s.Require().Equal(communities.RequestToJoinStateAccepted, response.RequestsToJoinCommunity[0].State)
|
2021-01-11 10:32:51 +00:00
|
|
|
|
2023-02-03 16:33:16 +00:00
|
|
|
s.Require().Len(response.Communities(), 1)
|
2021-01-11 10:32:51 +00:00
|
|
|
aliceCommunity := response.Communities()[0]
|
|
|
|
|
|
|
|
s.Require().Equal(community.ID(), aliceCommunity.ID())
|
|
|
|
s.Require().True(aliceCommunity.HasMember(&s.alice.identity.PublicKey))
|
|
|
|
|
|
|
|
// Community should be joined at this point
|
|
|
|
s.Require().True(aliceCommunity.Joined())
|
|
|
|
|
|
|
|
// Make sure the requests are not pending on either sides
|
|
|
|
requestsToJoin, err = s.bob.PendingRequestsToJoinForCommunity(community.ID())
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(requestsToJoin, 0)
|
|
|
|
|
|
|
|
requestsToJoin, err = s.alice.MyPendingRequestsToJoin()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(requestsToJoin, 0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-10-28 08:41:20 +00:00
|
|
|
func (s *MessengerCommunitiesSuite) TestCancelRequestAccess() {
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
description := &requests.CreateCommunity{
|
|
|
|
Membership: protobuf.CommunityPermissions_ON_REQUEST,
|
|
|
|
Name: "status",
|
|
|
|
Color: "#ffffff",
|
|
|
|
Description: "status community description",
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create an community chat
|
|
|
|
response, err := s.bob.CreateCommunity(description, true)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
|
|
|
s.Require().Len(response.Communities(), 1)
|
|
|
|
|
|
|
|
community := response.Communities()[0]
|
|
|
|
|
|
|
|
chat := CreateOneToOneChat(common.PubkeyToHex(&s.alice.identity.PublicKey), &s.alice.identity.PublicKey, s.alice.transport)
|
|
|
|
|
|
|
|
s.Require().NoError(s.bob.SaveChat(chat))
|
|
|
|
|
|
|
|
message := buildTestMessage(*chat)
|
|
|
|
message.CommunityID = community.IDString()
|
|
|
|
|
|
|
|
// We send a community link to alice
|
|
|
|
response, err = s.bob.SendChatMessage(ctx, message)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
|
|
|
|
|
|
|
// Retrieve community link & community
|
|
|
|
err = tt.RetryWithBackOff(func() error {
|
|
|
|
response, err = s.alice.RetrieveAll()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(response.Communities()) == 0 {
|
|
|
|
return errors.New("message not received")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
request := &requests.RequestToJoinCommunity{CommunityID: community.ID()}
|
|
|
|
// We try to join the org
|
|
|
|
response, err = s.alice.RequestToJoinCommunity(request)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
|
|
|
s.Require().Len(response.RequestsToJoinCommunity, 1)
|
|
|
|
|
|
|
|
requestToJoin1 := response.RequestsToJoinCommunity[0]
|
|
|
|
s.Require().NotNil(requestToJoin1)
|
|
|
|
s.Require().Equal(community.ID(), requestToJoin1.CommunityID)
|
|
|
|
s.Require().True(requestToJoin1.Our)
|
|
|
|
s.Require().NotEmpty(requestToJoin1.ID)
|
|
|
|
s.Require().NotEmpty(requestToJoin1.Clock)
|
|
|
|
s.Require().Equal(requestToJoin1.PublicKey, common.PubkeyToHex(&s.alice.identity.PublicKey))
|
|
|
|
s.Require().Equal(communities.RequestToJoinStatePending, requestToJoin1.State)
|
|
|
|
|
|
|
|
// Make sure clock is not empty
|
|
|
|
s.Require().NotEmpty(requestToJoin1.Clock)
|
|
|
|
|
|
|
|
s.Require().Len(response.Communities(), 1)
|
|
|
|
s.Require().Equal(response.Communities()[0].RequestedToJoinAt(), requestToJoin1.Clock)
|
|
|
|
|
|
|
|
// pull all communities to make sure we set RequestedToJoinAt
|
|
|
|
|
|
|
|
allCommunities, err := s.alice.Communities()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(allCommunities, 2)
|
|
|
|
|
|
|
|
if bytes.Equal(allCommunities[0].ID(), community.ID()) {
|
|
|
|
s.Require().Equal(allCommunities[0].RequestedToJoinAt(), requestToJoin1.Clock)
|
|
|
|
} else {
|
|
|
|
s.Require().Equal(allCommunities[1].RequestedToJoinAt(), requestToJoin1.Clock)
|
|
|
|
}
|
|
|
|
|
|
|
|
// pull to make sure it has been saved
|
|
|
|
requestsToJoin, err := s.alice.MyPendingRequestsToJoin()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(requestsToJoin, 1)
|
|
|
|
|
|
|
|
// Make sure the requests are fetched also by community
|
|
|
|
requestsToJoin, err = s.alice.PendingRequestsToJoinForCommunity(community.ID())
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(requestsToJoin, 1)
|
|
|
|
|
|
|
|
// Retrieve request to join
|
|
|
|
err = tt.RetryWithBackOff(func() error {
|
|
|
|
response, err = s.bob.RetrieveAll()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(response.RequestsToJoinCommunity) == 0 {
|
|
|
|
return errors.New("request to join community not received")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(response.RequestsToJoinCommunity, 1)
|
|
|
|
|
|
|
|
requestToJoin2 := response.RequestsToJoinCommunity[0]
|
|
|
|
|
|
|
|
s.Require().NotNil(requestToJoin2)
|
|
|
|
s.Require().Equal(community.ID(), requestToJoin2.CommunityID)
|
|
|
|
s.Require().False(requestToJoin2.Our)
|
|
|
|
s.Require().NotEmpty(requestToJoin2.ID)
|
|
|
|
s.Require().NotEmpty(requestToJoin2.Clock)
|
|
|
|
s.Require().Equal(requestToJoin2.PublicKey, common.PubkeyToHex(&s.alice.identity.PublicKey))
|
|
|
|
s.Require().Equal(communities.RequestToJoinStatePending, requestToJoin2.State)
|
|
|
|
|
|
|
|
s.Require().Equal(requestToJoin1.ID, requestToJoin2.ID)
|
|
|
|
|
|
|
|
// Cancel request to join community
|
|
|
|
requestsToJoin, err = s.alice.MyPendingRequestsToJoin()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(requestsToJoin, 1)
|
|
|
|
|
|
|
|
requestToJoin := requestsToJoin[0]
|
|
|
|
|
|
|
|
requestToCancel := &requests.CancelRequestToJoinCommunity{ID: requestToJoin.ID}
|
|
|
|
response, err = s.alice.CancelRequestToJoinCommunity(requestToCancel)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
2023-02-07 18:22:49 +00:00
|
|
|
s.Require().Len(response.RequestsToJoinCommunity, 1)
|
|
|
|
s.Require().Equal(communities.RequestToJoinStateCanceled, response.RequestsToJoinCommunity[0].State)
|
2022-10-28 08:41:20 +00:00
|
|
|
|
|
|
|
// pull to make sure it has been saved
|
|
|
|
cancelRequestsToJoin, err := s.alice.MyCanceledRequestsToJoin()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(cancelRequestsToJoin, 1)
|
|
|
|
s.Require().Equal(cancelRequestsToJoin[0].State, communities.RequestToJoinStateCanceled)
|
|
|
|
|
|
|
|
// Retrieve cancel request to join
|
|
|
|
err = tt.RetryWithBackOff(func() error {
|
|
|
|
response, err = s.bob.RetrieveAll()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(response.RequestsToJoinCommunity) == 0 {
|
|
|
|
return errors.New("request to join community not received")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(response.RequestsToJoinCommunity, 1)
|
|
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(response.RequestsToJoinCommunity, 1)
|
|
|
|
|
|
|
|
cancelRequestToJoin2 := response.RequestsToJoinCommunity[0]
|
|
|
|
|
|
|
|
s.Require().NotNil(cancelRequestToJoin2)
|
|
|
|
s.Require().Equal(community.ID(), cancelRequestToJoin2.CommunityID)
|
|
|
|
s.Require().False(cancelRequestToJoin2.Our)
|
|
|
|
s.Require().NotEmpty(cancelRequestToJoin2.ID)
|
|
|
|
s.Require().NotEmpty(cancelRequestToJoin2.Clock)
|
|
|
|
s.Require().Equal(cancelRequestToJoin2.PublicKey, common.PubkeyToHex(&s.alice.identity.PublicKey))
|
|
|
|
s.Require().Equal(communities.RequestToJoinStateCanceled, cancelRequestToJoin2.State)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-01-11 10:32:51 +00:00
|
|
|
func (s *MessengerCommunitiesSuite) TestRequestAccessAgain() {
|
|
|
|
description := &requests.CreateCommunity{
|
|
|
|
Membership: protobuf.CommunityPermissions_ON_REQUEST,
|
|
|
|
Name: "status",
|
|
|
|
Color: "#ffffff",
|
|
|
|
Description: "status community description",
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create an community chat
|
2022-07-19 09:31:52 +00:00
|
|
|
response, err := s.bob.CreateCommunity(description, true)
|
2021-01-11 10:32:51 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
|
|
|
s.Require().Len(response.Communities(), 1)
|
|
|
|
|
|
|
|
community := response.Communities()[0]
|
|
|
|
|
|
|
|
chat := CreateOneToOneChat(common.PubkeyToHex(&s.alice.identity.PublicKey), &s.alice.identity.PublicKey, s.alice.transport)
|
|
|
|
|
|
|
|
s.Require().NoError(s.bob.SaveChat(chat))
|
|
|
|
|
|
|
|
message := buildTestMessage(*chat)
|
|
|
|
message.CommunityID = community.IDString()
|
|
|
|
|
|
|
|
// We send a community link to alice
|
|
|
|
response, err = s.bob.SendChatMessage(context.Background(), message)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
|
|
|
|
|
|
|
// Retrieve community link & community
|
|
|
|
err = tt.RetryWithBackOff(func() error {
|
|
|
|
response, err = s.alice.RetrieveAll()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(response.Communities()) == 0 {
|
|
|
|
return errors.New("message not received")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
request := &requests.RequestToJoinCommunity{CommunityID: community.ID()}
|
|
|
|
// We try to join the org
|
|
|
|
response, err = s.alice.RequestToJoinCommunity(request)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
|
|
|
s.Require().Len(response.RequestsToJoinCommunity, 1)
|
|
|
|
|
2022-10-25 22:06:20 +00:00
|
|
|
s.Require().Len(response.ActivityCenterNotifications(), 1)
|
|
|
|
|
|
|
|
notification := response.ActivityCenterNotifications()[0]
|
|
|
|
s.Require().NotNil(notification)
|
|
|
|
s.Require().Equal(notification.Type, ActivityCenterNotificationTypeCommunityRequest)
|
|
|
|
s.Require().Equal(notification.MembershipStatus, ActivityCenterMembershipStatusPending)
|
2023-01-28 09:52:53 +00:00
|
|
|
s.Require().Equal(notification.Read, true)
|
|
|
|
s.Require().Equal(notification.Accepted, false)
|
|
|
|
s.Require().Equal(notification.Dismissed, false)
|
2022-10-25 22:06:20 +00:00
|
|
|
|
2021-01-11 10:32:51 +00:00
|
|
|
requestToJoin1 := response.RequestsToJoinCommunity[0]
|
|
|
|
s.Require().NotNil(requestToJoin1)
|
|
|
|
s.Require().Equal(community.ID(), requestToJoin1.CommunityID)
|
|
|
|
s.Require().True(requestToJoin1.Our)
|
|
|
|
s.Require().NotEmpty(requestToJoin1.ID)
|
|
|
|
s.Require().NotEmpty(requestToJoin1.Clock)
|
|
|
|
s.Require().Equal(requestToJoin1.PublicKey, common.PubkeyToHex(&s.alice.identity.PublicKey))
|
|
|
|
s.Require().Equal(communities.RequestToJoinStatePending, requestToJoin1.State)
|
|
|
|
|
|
|
|
// Make sure clock is not empty
|
|
|
|
s.Require().NotEmpty(requestToJoin1.Clock)
|
|
|
|
|
|
|
|
s.Require().Len(response.Communities(), 1)
|
|
|
|
s.Require().Equal(response.Communities()[0].RequestedToJoinAt(), requestToJoin1.Clock)
|
|
|
|
|
|
|
|
// pull all communities to make sure we set RequestedToJoinAt
|
|
|
|
|
|
|
|
allCommunities, err := s.alice.Communities()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(allCommunities, 2)
|
|
|
|
|
|
|
|
if bytes.Equal(allCommunities[0].ID(), community.ID()) {
|
|
|
|
s.Require().Equal(allCommunities[0].RequestedToJoinAt(), requestToJoin1.Clock)
|
|
|
|
} else {
|
|
|
|
s.Require().Equal(allCommunities[1].RequestedToJoinAt(), requestToJoin1.Clock)
|
|
|
|
}
|
|
|
|
|
|
|
|
// pull to make sure it has been saved
|
|
|
|
requestsToJoin, err := s.alice.MyPendingRequestsToJoin()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(requestsToJoin, 1)
|
|
|
|
|
|
|
|
// Make sure the requests are fetched also by community
|
|
|
|
requestsToJoin, err = s.alice.PendingRequestsToJoinForCommunity(community.ID())
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(requestsToJoin, 1)
|
|
|
|
|
|
|
|
// Retrieve request to join
|
|
|
|
err = tt.RetryWithBackOff(func() error {
|
|
|
|
response, err = s.bob.RetrieveAll()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(response.RequestsToJoinCommunity) == 0 {
|
|
|
|
return errors.New("request to join community not received")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(response.RequestsToJoinCommunity, 1)
|
|
|
|
|
|
|
|
requestToJoin2 := response.RequestsToJoinCommunity[0]
|
|
|
|
|
|
|
|
s.Require().NotNil(requestToJoin2)
|
|
|
|
s.Require().Equal(community.ID(), requestToJoin2.CommunityID)
|
|
|
|
s.Require().False(requestToJoin2.Our)
|
|
|
|
s.Require().NotEmpty(requestToJoin2.ID)
|
|
|
|
s.Require().NotEmpty(requestToJoin2.Clock)
|
|
|
|
s.Require().Equal(requestToJoin2.PublicKey, common.PubkeyToHex(&s.alice.identity.PublicKey))
|
|
|
|
s.Require().Equal(communities.RequestToJoinStatePending, requestToJoin2.State)
|
|
|
|
|
|
|
|
s.Require().Equal(requestToJoin1.ID, requestToJoin2.ID)
|
|
|
|
|
2021-03-31 16:23:45 +00:00
|
|
|
// Check that a notification is been added to messenger
|
|
|
|
|
|
|
|
notifications := response.Notifications()
|
|
|
|
s.Require().Len(notifications, 1)
|
|
|
|
s.Require().NotEqual(notifications[0].ID.Hex(), "0x0000000000000000000000000000000000000000000000000000000000000000")
|
|
|
|
|
2021-01-11 10:32:51 +00:00
|
|
|
// Accept request
|
|
|
|
|
|
|
|
acceptRequestToJoin := &requests.AcceptRequestToJoinCommunity{ID: requestToJoin1.ID}
|
|
|
|
|
|
|
|
response, err = s.bob.AcceptRequestToJoinCommunity(acceptRequestToJoin)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
|
|
|
|
2022-10-25 22:06:20 +00:00
|
|
|
s.Require().Len(response.ActivityCenterNotifications(), 1)
|
|
|
|
|
|
|
|
notification = response.ActivityCenterNotifications()[0]
|
|
|
|
s.Require().NotNil(notification)
|
|
|
|
s.Require().Equal(notification.Type, ActivityCenterNotificationTypeCommunityMembershipRequest)
|
|
|
|
s.Require().Equal(notification.MembershipStatus, ActivityCenterMembershipStatusAccepted)
|
2023-01-28 09:52:53 +00:00
|
|
|
s.Require().Equal(notification.Read, true)
|
|
|
|
s.Require().Equal(notification.Accepted, true)
|
|
|
|
s.Require().Equal(notification.Dismissed, false)
|
2022-10-25 22:06:20 +00:00
|
|
|
|
2021-01-11 10:32:51 +00:00
|
|
|
s.Require().Len(response.Communities(), 1)
|
|
|
|
|
|
|
|
updatedCommunity := response.Communities()[0]
|
|
|
|
|
|
|
|
s.Require().NotNil(updatedCommunity)
|
|
|
|
s.Require().True(updatedCommunity.HasMember(&s.alice.identity.PublicKey))
|
|
|
|
|
|
|
|
// Pull message and make sure org is received
|
|
|
|
err = tt.RetryWithBackOff(func() error {
|
|
|
|
response, err = s.alice.RetrieveAll()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(response.Communities()) == 0 {
|
|
|
|
return errors.New("community not received")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
|
|
|
|
|
|
|
s.Require().Len(response.Communities(), 1)
|
|
|
|
|
|
|
|
aliceCommunity := response.Communities()[0]
|
|
|
|
|
|
|
|
s.Require().Equal(community.ID(), aliceCommunity.ID())
|
|
|
|
s.Require().True(aliceCommunity.HasMember(&s.alice.identity.PublicKey))
|
|
|
|
|
|
|
|
// Community should be joined at this point
|
|
|
|
s.Require().True(aliceCommunity.Joined())
|
|
|
|
|
|
|
|
// Make sure the requests are not pending on either sides
|
|
|
|
requestsToJoin, err = s.bob.PendingRequestsToJoinForCommunity(community.ID())
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(requestsToJoin, 0)
|
|
|
|
|
|
|
|
requestsToJoin, err = s.alice.MyPendingRequestsToJoin()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(requestsToJoin, 0)
|
|
|
|
|
|
|
|
// We request again
|
|
|
|
request2 := &requests.RequestToJoinCommunity{CommunityID: community.ID()}
|
|
|
|
// We try to join the org, it should error as we are already a member
|
|
|
|
response, err = s.alice.RequestToJoinCommunity(request2)
|
|
|
|
s.Require().Error(err)
|
|
|
|
|
|
|
|
// We kick the member
|
|
|
|
response, err = s.bob.RemoveUserFromCommunity(
|
|
|
|
community.ID(),
|
|
|
|
common.PubkeyToHex(&s.alice.identity.PublicKey),
|
|
|
|
)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
|
|
|
s.Require().Len(response.Communities(), 1)
|
|
|
|
|
|
|
|
community = response.Communities()[0]
|
|
|
|
s.Require().False(community.HasMember(&s.alice.identity.PublicKey))
|
|
|
|
|
|
|
|
// Alice should then be removed
|
|
|
|
err = tt.RetryWithBackOff(func() error {
|
|
|
|
response, err = s.alice.RetrieveAll()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(response.Communities()) == 0 {
|
|
|
|
return errors.New("community not received")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
|
|
|
|
|
|
|
s.Require().Len(response.Communities(), 1)
|
|
|
|
|
|
|
|
aliceCommunity = response.Communities()[0]
|
|
|
|
|
|
|
|
s.Require().Equal(community.ID(), aliceCommunity.ID())
|
|
|
|
s.Require().False(aliceCommunity.HasMember(&s.alice.identity.PublicKey))
|
|
|
|
|
|
|
|
// Alice can request access again
|
|
|
|
request3 := &requests.RequestToJoinCommunity{CommunityID: community.ID()}
|
|
|
|
response, err = s.alice.RequestToJoinCommunity(request3)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
|
|
|
s.Require().Len(response.RequestsToJoinCommunity, 1)
|
|
|
|
|
|
|
|
requestToJoin3 := response.RequestsToJoinCommunity[0]
|
|
|
|
s.Require().NotNil(requestToJoin3)
|
|
|
|
s.Require().Equal(community.ID(), requestToJoin3.CommunityID)
|
|
|
|
s.Require().True(requestToJoin3.Our)
|
|
|
|
s.Require().NotEmpty(requestToJoin3.ID)
|
|
|
|
s.Require().NotEmpty(requestToJoin3.Clock)
|
|
|
|
s.Require().Equal(requestToJoin3.PublicKey, common.PubkeyToHex(&s.alice.identity.PublicKey))
|
|
|
|
s.Require().Equal(communities.RequestToJoinStatePending, requestToJoin3.State)
|
|
|
|
|
|
|
|
s.Require().Len(response.Communities(), 1)
|
|
|
|
s.Require().Equal(response.Communities()[0].RequestedToJoinAt(), requestToJoin3.Clock)
|
|
|
|
|
2022-10-25 22:06:20 +00:00
|
|
|
s.Require().Len(response.ActivityCenterNotifications(), 1)
|
|
|
|
|
|
|
|
notification = response.ActivityCenterNotifications()[0]
|
|
|
|
s.Require().NotNil(notification)
|
|
|
|
s.Require().Equal(notification.Type, ActivityCenterNotificationTypeCommunityRequest)
|
|
|
|
s.Require().Equal(notification.MembershipStatus, ActivityCenterMembershipStatusPending)
|
|
|
|
|
2021-01-11 10:32:51 +00:00
|
|
|
// Retrieve request to join
|
|
|
|
err = tt.RetryWithBackOff(func() error {
|
|
|
|
response, err = s.bob.RetrieveAll()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(response.RequestsToJoinCommunity) == 0 {
|
|
|
|
return errors.New("request to join community not received")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(response.RequestsToJoinCommunity, 1)
|
|
|
|
|
|
|
|
requestToJoin4 := response.RequestsToJoinCommunity[0]
|
|
|
|
|
|
|
|
s.Require().NotNil(requestToJoin4)
|
|
|
|
s.Require().Equal(community.ID(), requestToJoin4.CommunityID)
|
|
|
|
s.Require().False(requestToJoin4.Our)
|
|
|
|
s.Require().NotEmpty(requestToJoin4.ID)
|
|
|
|
s.Require().NotEmpty(requestToJoin4.Clock)
|
|
|
|
s.Require().Equal(requestToJoin4.PublicKey, common.PubkeyToHex(&s.alice.identity.PublicKey))
|
|
|
|
s.Require().Equal(communities.RequestToJoinStatePending, requestToJoin4.State)
|
|
|
|
|
|
|
|
s.Require().Equal(requestToJoin3.ID, requestToJoin4.ID)
|
|
|
|
}
|
|
|
|
|
2022-08-04 07:44:35 +00:00
|
|
|
func (s *MessengerCommunitiesSuite) TestDeclineAccess() {
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
description := &requests.CreateCommunity{
|
|
|
|
Membership: protobuf.CommunityPermissions_ON_REQUEST,
|
|
|
|
Name: "status",
|
|
|
|
Color: "#ffffff",
|
|
|
|
Description: "status community description",
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create an community chat
|
|
|
|
response, err := s.bob.CreateCommunity(description, true)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
|
|
|
s.Require().Len(response.Communities(), 1)
|
|
|
|
|
|
|
|
community := response.Communities()[0]
|
|
|
|
|
|
|
|
chat := CreateOneToOneChat(common.PubkeyToHex(&s.alice.identity.PublicKey), &s.alice.identity.PublicKey, s.alice.transport)
|
|
|
|
|
|
|
|
s.Require().NoError(s.bob.SaveChat(chat))
|
|
|
|
|
|
|
|
message := buildTestMessage(*chat)
|
|
|
|
message.CommunityID = community.IDString()
|
|
|
|
|
|
|
|
// We send a community link to alice
|
|
|
|
response, err = s.bob.SendChatMessage(ctx, message)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
|
|
|
|
|
|
|
// Retrieve community link & community
|
|
|
|
err = tt.RetryWithBackOff(func() error {
|
|
|
|
response, err = s.alice.RetrieveAll()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(response.Communities()) == 0 {
|
|
|
|
return errors.New("message not received")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
request := &requests.RequestToJoinCommunity{CommunityID: community.ID()}
|
|
|
|
// We try to join the org
|
|
|
|
response, err = s.alice.RequestToJoinCommunity(request)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
|
|
|
s.Require().Len(response.RequestsToJoinCommunity, 1)
|
|
|
|
|
|
|
|
requestToJoin1 := response.RequestsToJoinCommunity[0]
|
|
|
|
s.Require().NotNil(requestToJoin1)
|
|
|
|
s.Require().Equal(community.ID(), requestToJoin1.CommunityID)
|
|
|
|
s.Require().True(requestToJoin1.Our)
|
|
|
|
s.Require().NotEmpty(requestToJoin1.ID)
|
|
|
|
s.Require().NotEmpty(requestToJoin1.Clock)
|
|
|
|
s.Require().Equal(requestToJoin1.PublicKey, common.PubkeyToHex(&s.alice.identity.PublicKey))
|
|
|
|
s.Require().Equal(communities.RequestToJoinStatePending, requestToJoin1.State)
|
|
|
|
|
2022-10-25 22:06:20 +00:00
|
|
|
s.Require().Len(response.ActivityCenterNotifications(), 1)
|
|
|
|
|
|
|
|
notification := response.ActivityCenterNotifications()[0]
|
|
|
|
s.Require().NotNil(notification)
|
|
|
|
s.Require().Equal(notification.Type, ActivityCenterNotificationTypeCommunityRequest)
|
|
|
|
s.Require().Equal(notification.MembershipStatus, ActivityCenterMembershipStatusPending)
|
2023-01-28 09:52:53 +00:00
|
|
|
s.Require().Equal(notification.Read, true)
|
|
|
|
s.Require().Equal(notification.Dismissed, false)
|
|
|
|
s.Require().Equal(notification.Accepted, false)
|
2022-10-25 22:06:20 +00:00
|
|
|
|
2022-08-04 07:44:35 +00:00
|
|
|
// Make sure clock is not empty
|
|
|
|
s.Require().NotEmpty(requestToJoin1.Clock)
|
|
|
|
|
|
|
|
s.Require().Len(response.Communities(), 1)
|
|
|
|
s.Require().Equal(response.Communities()[0].RequestedToJoinAt(), requestToJoin1.Clock)
|
|
|
|
|
|
|
|
// pull all communities to make sure we set RequestedToJoinAt
|
|
|
|
|
|
|
|
allCommunities, err := s.alice.Communities()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(allCommunities, 2)
|
|
|
|
|
|
|
|
if bytes.Equal(allCommunities[0].ID(), community.ID()) {
|
|
|
|
s.Require().Equal(allCommunities[0].RequestedToJoinAt(), requestToJoin1.Clock)
|
|
|
|
} else {
|
|
|
|
s.Require().Equal(allCommunities[1].RequestedToJoinAt(), requestToJoin1.Clock)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Retrieve request to join
|
|
|
|
err = tt.RetryWithBackOff(func() error {
|
|
|
|
response, err = s.bob.RetrieveAll()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(response.RequestsToJoinCommunity) == 0 {
|
|
|
|
return errors.New("request to join community not received")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(response.RequestsToJoinCommunity, 1)
|
|
|
|
|
|
|
|
// Check if admin sees requests correctly
|
|
|
|
requestsToJoin, err := s.bob.PendingRequestsToJoinForCommunity(community.ID())
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(requestsToJoin, 1)
|
|
|
|
|
|
|
|
requestsToJoin, err = s.bob.DeclinedRequestsToJoinForCommunity(community.ID())
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(requestsToJoin, 0)
|
|
|
|
|
|
|
|
requestToJoin2 := response.RequestsToJoinCommunity[0]
|
|
|
|
|
|
|
|
s.Require().NotNil(requestToJoin2)
|
|
|
|
s.Require().Equal(community.ID(), requestToJoin2.CommunityID)
|
|
|
|
s.Require().False(requestToJoin2.Our)
|
|
|
|
s.Require().NotEmpty(requestToJoin2.ID)
|
|
|
|
s.Require().NotEmpty(requestToJoin2.Clock)
|
|
|
|
s.Require().Equal(requestToJoin2.PublicKey, common.PubkeyToHex(&s.alice.identity.PublicKey))
|
|
|
|
s.Require().Equal(communities.RequestToJoinStatePending, requestToJoin2.State)
|
|
|
|
|
|
|
|
s.Require().Equal(requestToJoin1.ID, requestToJoin2.ID)
|
|
|
|
|
|
|
|
// Decline request
|
|
|
|
declinedRequestToJoin := &requests.DeclineRequestToJoinCommunity{ID: requestToJoin1.ID}
|
2022-10-25 22:06:20 +00:00
|
|
|
response, err = s.bob.DeclineRequestToJoinCommunity(declinedRequestToJoin)
|
2022-08-04 07:44:35 +00:00
|
|
|
s.Require().NoError(err)
|
2022-10-25 22:06:20 +00:00
|
|
|
s.Require().NotNil(response)
|
|
|
|
|
|
|
|
s.Require().Len(response.ActivityCenterNotifications(), 1)
|
|
|
|
|
|
|
|
notification = response.ActivityCenterNotifications()[0]
|
|
|
|
s.Require().NotNil(notification)
|
|
|
|
s.Require().Equal(notification.Type, ActivityCenterNotificationTypeCommunityMembershipRequest)
|
|
|
|
s.Require().Equal(notification.MembershipStatus, ActivityCenterMembershipStatusDeclined)
|
2023-01-28 09:52:53 +00:00
|
|
|
s.Require().Equal(notification.Read, true)
|
|
|
|
s.Require().Equal(notification.Accepted, false)
|
|
|
|
s.Require().Equal(notification.Dismissed, true)
|
2022-08-04 07:44:35 +00:00
|
|
|
|
|
|
|
// Check if admin sees requests correctly
|
|
|
|
requestsToJoin, err = s.bob.PendingRequestsToJoinForCommunity(community.ID())
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(requestsToJoin, 0)
|
|
|
|
|
|
|
|
requestsToJoin, err = s.bob.DeclinedRequestsToJoinForCommunity(community.ID())
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(requestsToJoin, 1)
|
|
|
|
|
|
|
|
// Accept declined request
|
|
|
|
acceptRequestToJoin := &requests.AcceptRequestToJoinCommunity{ID: requestToJoin1.ID}
|
|
|
|
response, err = s.bob.AcceptRequestToJoinCommunity(acceptRequestToJoin)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
|
|
|
|
|
|
|
s.Require().Len(response.Communities(), 1)
|
|
|
|
|
|
|
|
updatedCommunity := response.Communities()[0]
|
|
|
|
|
|
|
|
s.Require().NotNil(updatedCommunity)
|
|
|
|
s.Require().True(updatedCommunity.HasMember(&s.alice.identity.PublicKey))
|
|
|
|
|
2022-10-25 22:06:20 +00:00
|
|
|
s.Require().Len(response.ActivityCenterNotifications(), 1)
|
|
|
|
|
|
|
|
notification = response.ActivityCenterNotifications()[0]
|
|
|
|
s.Require().NotNil(notification)
|
|
|
|
s.Require().Equal(notification.Type, ActivityCenterNotificationTypeCommunityMembershipRequest)
|
|
|
|
s.Require().Equal(notification.MembershipStatus, ActivityCenterMembershipStatusAccepted)
|
|
|
|
|
2022-08-04 07:44:35 +00:00
|
|
|
// Pull message and make sure org is received
|
|
|
|
err = tt.RetryWithBackOff(func() error {
|
|
|
|
response, err = s.alice.RetrieveAll()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(response.Communities()) == 0 {
|
|
|
|
return errors.New("community not received")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
|
|
|
|
|
|
|
s.Require().Len(response.Communities(), 1)
|
|
|
|
|
|
|
|
aliceCommunity := response.Communities()[0]
|
|
|
|
|
|
|
|
s.Require().Equal(community.ID(), aliceCommunity.ID())
|
|
|
|
s.Require().True(aliceCommunity.HasMember(&s.alice.identity.PublicKey))
|
|
|
|
|
|
|
|
// Community should be joined at this point
|
|
|
|
s.Require().True(aliceCommunity.Joined())
|
|
|
|
|
|
|
|
// Make sure the requests are not pending on either sides
|
|
|
|
requestsToJoin, err = s.bob.PendingRequestsToJoinForCommunity(community.ID())
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(requestsToJoin, 0)
|
|
|
|
|
|
|
|
requestsToJoin, err = s.bob.DeclinedRequestsToJoinForCommunity(community.ID())
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(requestsToJoin, 0)
|
|
|
|
|
|
|
|
requestsToJoin, err = s.alice.MyPendingRequestsToJoin()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(requestsToJoin, 0)
|
|
|
|
}
|
|
|
|
|
2022-08-23 16:30:19 +00:00
|
|
|
func (s *MessengerCommunitiesSuite) TestLeaveAndRejoinCommunity() {
|
|
|
|
community := s.createCommunity()
|
|
|
|
s.advertiseCommunityTo(community, s.alice)
|
|
|
|
s.advertiseCommunityTo(community, s.bob)
|
|
|
|
|
|
|
|
s.joinCommunity(community, s.alice)
|
|
|
|
s.joinCommunity(community, s.bob)
|
|
|
|
|
|
|
|
joinedCommunities, err := s.admin.communitiesManager.Joined()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Equal(3, joinedCommunities[0].MembersCount())
|
|
|
|
|
|
|
|
response, err := s.alice.LeaveCommunity(community.ID())
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
|
|
|
s.Require().Len(response.Communities(), 1)
|
|
|
|
s.Require().False(response.Communities()[0].Joined())
|
|
|
|
|
|
|
|
// admin should receive alice's request to leave
|
|
|
|
// and then update and advertise community members list accordingly
|
|
|
|
|
|
|
|
verifyCommunityMembers := func(user *Messenger) error {
|
|
|
|
response, err := user.RetrieveAll()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(response.Communities()) == 0 {
|
|
|
|
return errors.New("no communities in response")
|
|
|
|
}
|
|
|
|
|
|
|
|
var communityMembersError error = nil
|
|
|
|
|
|
|
|
if response.Communities()[0].MembersCount() != 2 {
|
|
|
|
communityMembersError = fmt.Errorf("invalid number of members: %d", response.Communities()[0].MembersCount())
|
|
|
|
} else if !response.Communities()[0].HasMember(&s.admin.identity.PublicKey) {
|
|
|
|
communityMembersError = errors.New("admin removed from community")
|
|
|
|
} else if !response.Communities()[0].HasMember(&s.bob.identity.PublicKey) {
|
|
|
|
communityMembersError = errors.New("bob removed from community")
|
|
|
|
} else if response.Communities()[0].HasMember(&s.alice.identity.PublicKey) {
|
|
|
|
communityMembersError = errors.New("alice not removed from community")
|
|
|
|
}
|
|
|
|
|
|
|
|
s.Require().NoError(communityMembersError)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
err = tt.RetryWithBackOff(func() error {
|
|
|
|
return verifyCommunityMembers(s.admin)
|
|
|
|
})
|
|
|
|
s.Require().NoError(err)
|
|
|
|
err = tt.RetryWithBackOff(func() error {
|
|
|
|
return verifyCommunityMembers(s.bob)
|
|
|
|
})
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
joinedCommunities, err = s.admin.communitiesManager.Joined()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Equal(2, joinedCommunities[0].MembersCount())
|
|
|
|
|
2022-12-07 19:34:48 +00:00
|
|
|
chats, err := s.alice.persistence.Chats()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
var numberInactiveChats = 0
|
|
|
|
for i := 0; i < len(chats); i++ {
|
|
|
|
if !chats[i].Active {
|
|
|
|
numberInactiveChats++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s.Require().Equal(3, numberInactiveChats)
|
|
|
|
|
2022-08-23 16:30:19 +00:00
|
|
|
// alice can rejoin
|
|
|
|
s.joinCommunity(community, s.alice)
|
|
|
|
|
|
|
|
joinedCommunities, err = s.admin.communitiesManager.Joined()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Equal(3, joinedCommunities[0].MembersCount())
|
2022-12-07 19:34:48 +00:00
|
|
|
|
|
|
|
chats, err = s.alice.persistence.Chats()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
numberInactiveChats = 0
|
|
|
|
for i := 0; i < len(chats); i++ {
|
|
|
|
if !chats[i].Active {
|
|
|
|
numberInactiveChats++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s.Require().Equal(1, numberInactiveChats)
|
2022-08-23 16:30:19 +00:00
|
|
|
}
|
|
|
|
|
2021-01-11 10:32:51 +00:00
|
|
|
func (s *MessengerCommunitiesSuite) TestShareCommunity() {
|
|
|
|
description := &requests.CreateCommunity{
|
|
|
|
Membership: protobuf.CommunityPermissions_NO_MEMBERSHIP,
|
|
|
|
Name: "status",
|
|
|
|
Color: "#ffffff",
|
|
|
|
Description: "status community description",
|
|
|
|
}
|
|
|
|
|
2022-08-08 10:49:39 +00:00
|
|
|
inviteMessage := "invite to community testing message"
|
|
|
|
|
2021-01-11 10:32:51 +00:00
|
|
|
// Create an community chat
|
2022-07-19 09:31:52 +00:00
|
|
|
response, err := s.bob.CreateCommunity(description, true)
|
2021-01-11 10:32:51 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
|
|
|
s.Require().Len(response.Communities(), 1)
|
|
|
|
|
|
|
|
community := response.Communities()[0]
|
|
|
|
|
|
|
|
response, err = s.bob.ShareCommunity(
|
|
|
|
&requests.ShareCommunity{
|
2022-08-08 10:49:39 +00:00
|
|
|
CommunityID: community.ID(),
|
|
|
|
Users: []types.HexBytes{common.PubkeyToHexBytes(&s.alice.identity.PublicKey)},
|
|
|
|
InviteMessage: inviteMessage,
|
2021-01-11 10:32:51 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
2021-06-03 13:11:55 +00:00
|
|
|
s.Require().Len(response.Messages(), 1)
|
2021-01-11 10:32:51 +00:00
|
|
|
|
2021-04-07 12:57:14 +00:00
|
|
|
// Add bob to contacts so it does not go on activity center
|
|
|
|
bobPk := common.PubkeyToHex(&s.alice.identity.PublicKey)
|
2022-10-14 08:50:36 +00:00
|
|
|
request := &requests.AddContact{ID: bobPk}
|
2021-10-26 10:48:02 +00:00
|
|
|
_, err = s.alice.AddContact(context.Background(), request)
|
2021-04-07 12:57:14 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2021-01-11 10:32:51 +00:00
|
|
|
// Pull message and make sure org is received
|
|
|
|
err = tt.RetryWithBackOff(func() error {
|
|
|
|
response, err = s.alice.RetrieveAll()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-06-03 13:11:55 +00:00
|
|
|
if len(response.messages) == 0 {
|
2021-01-11 10:32:51 +00:00
|
|
|
return errors.New("community link not received")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
s.Require().NoError(err)
|
2021-06-03 13:11:55 +00:00
|
|
|
s.Require().Len(response.Messages(), 1)
|
2022-08-08 10:49:39 +00:00
|
|
|
|
|
|
|
message := response.Messages()[0]
|
|
|
|
s.Require().Equal(community.IDString(), message.CommunityID)
|
|
|
|
s.Require().Equal(inviteMessage, message.Text)
|
2021-01-11 10:32:51 +00:00
|
|
|
}
|
2021-03-19 09:15:45 +00:00
|
|
|
|
|
|
|
func (s *MessengerCommunitiesSuite) TestBanUser() {
|
|
|
|
description := &requests.CreateCommunity{
|
|
|
|
Membership: protobuf.CommunityPermissions_NO_MEMBERSHIP,
|
|
|
|
Name: "status",
|
|
|
|
Color: "#ffffff",
|
|
|
|
Description: "status community description",
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create an community chat
|
2022-07-19 09:31:52 +00:00
|
|
|
response, err := s.bob.CreateCommunity(description, true)
|
2021-03-19 09:15:45 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
|
|
|
s.Require().Len(response.Communities(), 1)
|
|
|
|
|
|
|
|
community := response.Communities()[0]
|
|
|
|
|
|
|
|
response, err = s.bob.InviteUsersToCommunity(
|
|
|
|
&requests.InviteUsersToCommunity{
|
|
|
|
CommunityID: community.ID(),
|
|
|
|
Users: []types.HexBytes{common.PubkeyToHexBytes(&s.alice.identity.PublicKey)},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
|
|
|
s.Require().Len(response.Communities(), 1)
|
|
|
|
|
|
|
|
community = response.Communities()[0]
|
|
|
|
s.Require().True(community.HasMember(&s.alice.identity.PublicKey))
|
|
|
|
|
|
|
|
response, err = s.bob.BanUserFromCommunity(
|
|
|
|
&requests.BanUserFromCommunity{
|
|
|
|
CommunityID: community.ID(),
|
|
|
|
User: common.PubkeyToHexBytes(&s.alice.identity.PublicKey),
|
|
|
|
},
|
|
|
|
)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
|
|
|
s.Require().Len(response.Communities(), 1)
|
|
|
|
|
|
|
|
community = response.Communities()[0]
|
|
|
|
s.Require().False(community.HasMember(&s.alice.identity.PublicKey))
|
|
|
|
s.Require().True(community.IsBanned(&s.alice.identity.PublicKey))
|
|
|
|
|
2022-06-23 07:12:15 +00:00
|
|
|
response, err = s.bob.UnbanUserFromCommunity(
|
|
|
|
&requests.UnbanUserFromCommunity{
|
|
|
|
CommunityID: community.ID(),
|
|
|
|
User: common.PubkeyToHexBytes(&s.alice.identity.PublicKey),
|
|
|
|
},
|
|
|
|
)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
|
|
|
s.Require().Len(response.Communities(), 1)
|
|
|
|
|
|
|
|
community = response.Communities()[0]
|
|
|
|
s.Require().False(community.IsBanned(&s.alice.identity.PublicKey))
|
2021-03-19 09:15:45 +00:00
|
|
|
}
|
2021-08-06 15:40:23 +00:00
|
|
|
|
2022-06-01 07:55:48 +00:00
|
|
|
func (s *MessengerCommunitiesSuite) TestSyncCommunitySettings() {
|
|
|
|
// Create new device
|
|
|
|
alicesOtherDevice, err := newMessengerWithKey(s.shh, s.alice.identity, s.logger, nil)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
// Pair devices
|
|
|
|
err = alicesOtherDevice.SetInstallationMetadata(alicesOtherDevice.installationID, &multidevice.InstallationMetadata{
|
|
|
|
Name: "their-name",
|
|
|
|
DeviceType: "their-device-type",
|
|
|
|
})
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
s.pairTwoDevices(alicesOtherDevice, s.alice, "their-name", "their-device-type")
|
|
|
|
|
|
|
|
// Create a community
|
|
|
|
createCommunityReq := &requests.CreateCommunity{
|
|
|
|
Membership: protobuf.CommunityPermissions_ON_REQUEST,
|
|
|
|
Name: "new community",
|
|
|
|
Color: "#000000",
|
|
|
|
Description: "new community description",
|
|
|
|
}
|
|
|
|
|
2022-07-19 09:31:52 +00:00
|
|
|
mr, err := s.alice.CreateCommunity(createCommunityReq, true)
|
2022-06-01 07:55:48 +00:00
|
|
|
s.Require().NoError(err, "s.alice.CreateCommunity")
|
|
|
|
var newCommunity *communities.Community
|
|
|
|
for _, com := range mr.Communities() {
|
|
|
|
if com.Name() == createCommunityReq.Name {
|
|
|
|
newCommunity = com
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s.Require().NotNil(newCommunity)
|
|
|
|
|
|
|
|
// Check that Alice has community settings
|
|
|
|
cs, err := s.alice.communitiesManager.GetCommunitySettingsByID(newCommunity.ID())
|
|
|
|
s.Require().NoError(err, "communitiesManager.GetCommunitySettingsByID")
|
|
|
|
s.NotNil(cs, "Must have community settings")
|
|
|
|
|
|
|
|
// Wait for the message to reach its destination
|
|
|
|
err = tt.RetryWithBackOff(func() error {
|
|
|
|
_, err = alicesOtherDevice.RetrieveAll()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do we have new synced community settings?
|
|
|
|
syncedSettings, err := alicesOtherDevice.communitiesManager.GetCommunitySettingsByID(newCommunity.ID())
|
|
|
|
if err != nil || syncedSettings == nil {
|
|
|
|
return fmt.Errorf("community with sync not received %w", err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
tcs, err := alicesOtherDevice.communitiesManager.GetCommunitySettingsByID(newCommunity.ID())
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
// Check the community settings on their device matched the community settings on Alice's device
|
|
|
|
s.Equal(cs.CommunityID, tcs.CommunityID)
|
|
|
|
s.Equal(cs.HistoryArchiveSupportEnabled, tcs.HistoryArchiveSupportEnabled)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerCommunitiesSuite) TestSyncCommunitySettings_EditCommunity() {
|
|
|
|
// Create new device
|
|
|
|
alicesOtherDevice, err := newMessengerWithKey(s.shh, s.alice.identity, s.logger, nil)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
// Pair devices
|
|
|
|
err = alicesOtherDevice.SetInstallationMetadata(alicesOtherDevice.installationID, &multidevice.InstallationMetadata{
|
|
|
|
Name: "their-name",
|
|
|
|
DeviceType: "their-device-type",
|
|
|
|
})
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
s.pairTwoDevices(alicesOtherDevice, s.alice, "their-name", "their-device-type")
|
|
|
|
|
|
|
|
// Create a community
|
|
|
|
createCommunityReq := &requests.CreateCommunity{
|
|
|
|
Membership: protobuf.CommunityPermissions_ON_REQUEST,
|
|
|
|
Name: "new community",
|
|
|
|
Color: "#000000",
|
|
|
|
Description: "new community description",
|
|
|
|
}
|
|
|
|
|
2022-07-19 09:31:52 +00:00
|
|
|
mr, err := s.alice.CreateCommunity(createCommunityReq, true)
|
2022-06-01 07:55:48 +00:00
|
|
|
s.Require().NoError(err, "s.alice.CreateCommunity")
|
|
|
|
var newCommunity *communities.Community
|
|
|
|
for _, com := range mr.Communities() {
|
|
|
|
if com.Name() == createCommunityReq.Name {
|
|
|
|
newCommunity = com
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s.Require().NotNil(newCommunity)
|
|
|
|
|
|
|
|
// Check that Alice has community settings
|
|
|
|
cs, err := s.alice.communitiesManager.GetCommunitySettingsByID(newCommunity.ID())
|
|
|
|
s.Require().NoError(err, "communitiesManager.GetCommunitySettingsByID")
|
|
|
|
s.NotNil(cs, "Must have community settings")
|
|
|
|
|
|
|
|
// Wait for the message to reach its destination
|
|
|
|
err = tt.RetryWithBackOff(func() error {
|
|
|
|
_, err = alicesOtherDevice.RetrieveAll()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do we have new synced community settings?
|
|
|
|
syncedSettings, err := alicesOtherDevice.communitiesManager.GetCommunitySettingsByID(newCommunity.ID())
|
|
|
|
if err != nil || syncedSettings == nil {
|
|
|
|
return fmt.Errorf("community settings with sync not received %w", err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
tcs, err := alicesOtherDevice.communitiesManager.GetCommunitySettingsByID(newCommunity.ID())
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
// Check the community settings on their device matched the community settings on Alice's device
|
|
|
|
s.Equal(cs.CommunityID, tcs.CommunityID)
|
|
|
|
s.Equal(cs.HistoryArchiveSupportEnabled, tcs.HistoryArchiveSupportEnabled)
|
|
|
|
|
|
|
|
req := createCommunityReq
|
|
|
|
req.HistoryArchiveSupportEnabled = true
|
|
|
|
editCommunityReq := &requests.EditCommunity{
|
|
|
|
CommunityID: newCommunity.ID(),
|
|
|
|
CreateCommunity: *req,
|
|
|
|
}
|
|
|
|
|
|
|
|
mr, err = s.alice.EditCommunity(editCommunityReq)
|
|
|
|
s.Require().NoError(err, "s.alice.EditCommunity")
|
|
|
|
var editedCommunity *communities.Community
|
|
|
|
for _, com := range mr.Communities() {
|
|
|
|
if com.Name() == createCommunityReq.Name {
|
|
|
|
editedCommunity = com
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s.Require().NotNil(editedCommunity)
|
|
|
|
|
|
|
|
// Wait a bit for sync messages to reach destination
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
err = tt.RetryWithBackOff(func() error {
|
|
|
|
_, err = alicesOtherDevice.RetrieveAll()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
tcs, err = alicesOtherDevice.communitiesManager.GetCommunitySettingsByID(newCommunity.ID())
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
// Check the community settings on their device matched the community settings on Alice's device
|
|
|
|
s.Equal(cs.CommunityID, tcs.CommunityID)
|
|
|
|
s.Equal(req.HistoryArchiveSupportEnabled, tcs.HistoryArchiveSupportEnabled)
|
|
|
|
}
|
|
|
|
|
2021-08-06 15:40:23 +00:00
|
|
|
// TestSyncCommunity tests basic sync functionality between 2 Messengers
|
|
|
|
func (s *MessengerCommunitiesSuite) TestSyncCommunity() {
|
|
|
|
// Create new device
|
|
|
|
alicesOtherDevice, err := newMessengerWithKey(s.shh, s.alice.identity, s.logger, nil)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
tcs, err := alicesOtherDevice.communitiesManager.All()
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err, "alicesOtherDevice.communitiesManager.All")
|
2021-08-06 15:40:23 +00:00
|
|
|
s.Len(tcs, 1, "Must have 1 communities")
|
|
|
|
|
|
|
|
// Pair devices
|
|
|
|
err = alicesOtherDevice.SetInstallationMetadata(alicesOtherDevice.installationID, &multidevice.InstallationMetadata{
|
|
|
|
Name: "their-name",
|
|
|
|
DeviceType: "their-device-type",
|
|
|
|
})
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
s.pairTwoDevices(alicesOtherDevice, s.alice, "their-name", "their-device-type")
|
|
|
|
|
|
|
|
// Create a community
|
|
|
|
createCommunityReq := &requests.CreateCommunity{
|
|
|
|
Membership: protobuf.CommunityPermissions_ON_REQUEST,
|
|
|
|
Name: "new community",
|
2022-11-07 17:30:00 +00:00
|
|
|
Encrypted: true,
|
2021-08-06 15:40:23 +00:00
|
|
|
Color: "#000000",
|
|
|
|
Description: "new community description",
|
|
|
|
}
|
|
|
|
|
2022-07-19 09:31:52 +00:00
|
|
|
mr, err := s.alice.CreateCommunity(createCommunityReq, true)
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err, "s.alice.CreateCommunity")
|
2021-08-06 15:40:23 +00:00
|
|
|
var newCommunity *communities.Community
|
|
|
|
for _, com := range mr.Communities() {
|
|
|
|
if com.Name() == createCommunityReq.Name {
|
|
|
|
newCommunity = com
|
|
|
|
}
|
|
|
|
}
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NotNil(newCommunity)
|
2021-08-06 15:40:23 +00:00
|
|
|
|
2022-11-07 17:30:00 +00:00
|
|
|
// Check HR keys are created
|
|
|
|
encodedKeys, err := s.alice.encryptor.GetAllHREncodedKeys(newCommunity.ID())
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(encodedKeys)
|
|
|
|
|
|
|
|
keys := &encryption.HRKeys{}
|
|
|
|
s.Require().NoError(proto.Unmarshal(encodedKeys, keys))
|
|
|
|
s.Require().Len(keys.Keys, 1)
|
|
|
|
|
2021-08-06 15:40:23 +00:00
|
|
|
// Check that Alice has 2 communities
|
|
|
|
cs, err := s.alice.communitiesManager.All()
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err, "communitiesManager.All")
|
2021-08-06 15:40:23 +00:00
|
|
|
s.Len(cs, 2, "Must have 2 communities")
|
|
|
|
|
|
|
|
// Wait for the message to reach its destination
|
|
|
|
err = tt.RetryWithBackOff(func() error {
|
|
|
|
_, err = alicesOtherDevice.RetrieveAll()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do we have a new synced community?
|
|
|
|
_, err = alicesOtherDevice.communitiesManager.GetSyncedRawCommunity(newCommunity.ID())
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("community with sync not received %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err)
|
2021-08-06 15:40:23 +00:00
|
|
|
|
|
|
|
// Count the number of communities in their device
|
|
|
|
tcs, err = alicesOtherDevice.communitiesManager.All()
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err)
|
2021-08-06 15:40:23 +00:00
|
|
|
s.Len(tcs, 2, "There must be 2 communities")
|
2022-11-07 17:30:00 +00:00
|
|
|
|
|
|
|
// Check HR keys are synced
|
|
|
|
encodedKeys, err = alicesOtherDevice.encryptor.GetAllHREncodedKeys(newCommunity.ID())
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(encodedKeys)
|
|
|
|
|
|
|
|
keys = &encryption.HRKeys{}
|
|
|
|
s.Require().NoError(proto.Unmarshal(encodedKeys, keys))
|
|
|
|
s.Require().Len(keys.Keys, 1)
|
2021-08-06 15:40:23 +00:00
|
|
|
|
|
|
|
s.logger.Debug("", zap.Any("tcs", tcs))
|
|
|
|
|
|
|
|
// Get the new community from their db
|
|
|
|
tnc, err := alicesOtherDevice.communitiesManager.GetByID(newCommunity.ID())
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err)
|
2021-08-06 15:40:23 +00:00
|
|
|
|
|
|
|
// Check the community on their device matched the new community on Alice's device
|
|
|
|
s.Equal(newCommunity.ID(), tnc.ID())
|
|
|
|
s.Equal(newCommunity.Name(), tnc.Name())
|
|
|
|
s.Equal(newCommunity.DescriptionText(), tnc.DescriptionText())
|
|
|
|
s.Equal(newCommunity.IDString(), tnc.IDString())
|
|
|
|
s.Equal(newCommunity.PrivateKey(), tnc.PrivateKey())
|
|
|
|
s.Equal(newCommunity.PublicKey(), tnc.PublicKey())
|
|
|
|
s.Equal(newCommunity.Verified(), tnc.Verified())
|
|
|
|
s.Equal(newCommunity.Muted(), tnc.Muted())
|
|
|
|
s.Equal(newCommunity.Joined(), tnc.Joined())
|
2022-09-20 19:57:39 +00:00
|
|
|
s.Equal(newCommunity.Spectated(), tnc.Spectated())
|
2021-08-06 15:40:23 +00:00
|
|
|
s.Equal(newCommunity.IsAdmin(), tnc.IsAdmin())
|
|
|
|
s.Equal(newCommunity.InvitationOnly(), tnc.InvitationOnly())
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestSyncCommunity_RequestToJoin tests more complex pairing and syncing scenario where one paired device
|
|
|
|
// makes a request to join a community
|
|
|
|
func (s *MessengerCommunitiesSuite) TestSyncCommunity_RequestToJoin() {
|
|
|
|
// Set Alice's installation metadata
|
|
|
|
aim := &multidevice.InstallationMetadata{
|
|
|
|
Name: "alice's-device",
|
|
|
|
DeviceType: "alice's-device-type",
|
|
|
|
}
|
|
|
|
err := s.alice.SetInstallationMetadata(s.alice.installationID, aim)
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err)
|
2021-08-06 15:40:23 +00:00
|
|
|
|
|
|
|
// Create Alice's other device
|
|
|
|
alicesOtherDevice, err := newMessengerWithKey(s.shh, s.alice.identity, s.logger, nil)
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err)
|
2021-08-06 15:40:23 +00:00
|
|
|
|
|
|
|
im1 := &multidevice.InstallationMetadata{
|
|
|
|
Name: "alice's-other-device",
|
|
|
|
DeviceType: "alice's-other-device-type",
|
|
|
|
}
|
|
|
|
err = alicesOtherDevice.SetInstallationMetadata(alicesOtherDevice.installationID, im1)
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err)
|
2021-08-06 15:40:23 +00:00
|
|
|
|
|
|
|
// Pair alice's two devices
|
|
|
|
s.pairTwoDevices(alicesOtherDevice, s.alice, im1.Name, im1.DeviceType)
|
|
|
|
s.pairTwoDevices(s.alice, alicesOtherDevice, aim.Name, aim.DeviceType)
|
|
|
|
|
|
|
|
// Check bob the admin has only one community
|
|
|
|
tcs2, err := s.bob.communitiesManager.All()
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err, "admin.communitiesManager.All")
|
2021-08-06 15:40:23 +00:00
|
|
|
s.Len(tcs2, 1, "Must have 1 communities")
|
|
|
|
|
|
|
|
// Bob the admin creates a community
|
|
|
|
createCommunityReq := &requests.CreateCommunity{
|
|
|
|
Membership: protobuf.CommunityPermissions_ON_REQUEST,
|
|
|
|
Name: "new community",
|
|
|
|
Color: "#000000",
|
|
|
|
Description: "new community description",
|
|
|
|
}
|
2022-07-19 09:31:52 +00:00
|
|
|
mr, err := s.bob.CreateCommunity(createCommunityReq, true)
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err, "CreateCommunity")
|
|
|
|
s.Require().NotNil(mr)
|
2021-08-06 15:40:23 +00:00
|
|
|
s.Len(mr.Communities(), 1)
|
|
|
|
|
|
|
|
community := mr.Communities()[0]
|
|
|
|
|
|
|
|
// Check that admin has 2 communities
|
|
|
|
acs, err := s.bob.communitiesManager.All()
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err, "communitiesManager.All")
|
2021-08-06 15:40:23 +00:00
|
|
|
s.Len(acs, 2, "Must have 2 communities")
|
|
|
|
|
|
|
|
// Check that Alice has only 1 community on either device
|
|
|
|
cs, err := s.alice.communitiesManager.All()
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err, "communitiesManager.All")
|
2021-08-06 15:40:23 +00:00
|
|
|
s.Len(cs, 1, "Must have 1 communities")
|
|
|
|
|
|
|
|
tcs1, err := alicesOtherDevice.communitiesManager.All()
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err, "alicesOtherDevice.communitiesManager.All")
|
2021-08-06 15:40:23 +00:00
|
|
|
s.Len(tcs1, 1, "Must have 1 communities")
|
|
|
|
|
|
|
|
// Bob the admin opens up a 1-1 chat with alice
|
|
|
|
chat := CreateOneToOneChat(common.PubkeyToHex(&s.alice.identity.PublicKey), &s.alice.identity.PublicKey, s.alice.transport)
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(s.bob.SaveChat(chat))
|
2021-08-06 15:40:23 +00:00
|
|
|
|
|
|
|
// Bob the admin shares with Alice, via public chat, an invite link to the new community
|
|
|
|
message := buildTestMessage(*chat)
|
|
|
|
message.CommunityID = community.IDString()
|
|
|
|
response, err := s.bob.SendChatMessage(context.Background(), message)
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
2021-08-06 15:40:23 +00:00
|
|
|
|
|
|
|
// Retrieve community link & community
|
|
|
|
err = tt.RetryWithBackOff(func() error {
|
|
|
|
response, err = s.alice.RetrieveAll()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(response.Communities()) == 0 {
|
|
|
|
return errors.New("no communities received from 1-1")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err)
|
2021-08-06 15:40:23 +00:00
|
|
|
|
|
|
|
// Check that alice now has 2 communities
|
|
|
|
cs, err = s.alice.communitiesManager.All()
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err, "communitiesManager.All")
|
2021-08-06 15:40:23 +00:00
|
|
|
s.Len(cs, 2, "Must have 2 communities")
|
|
|
|
for _, c := range cs {
|
|
|
|
s.False(c.Joined(), "Must not have joined the community")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Alice requests to join the new community
|
|
|
|
response, err = s.alice.RequestToJoinCommunity(&requests.RequestToJoinCommunity{CommunityID: community.ID()})
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
2021-08-06 15:40:23 +00:00
|
|
|
s.Len(response.RequestsToJoinCommunity, 1)
|
|
|
|
|
2022-10-25 22:06:20 +00:00
|
|
|
s.Require().Len(response.ActivityCenterNotifications(), 1)
|
|
|
|
|
|
|
|
notification := response.ActivityCenterNotifications()[0]
|
|
|
|
s.Require().NotNil(notification)
|
|
|
|
s.Require().Equal(notification.Type, ActivityCenterNotificationTypeCommunityRequest)
|
|
|
|
s.Require().Equal(notification.MembershipStatus, ActivityCenterMembershipStatusPending)
|
|
|
|
|
2021-08-06 15:40:23 +00:00
|
|
|
aRtj := response.RequestsToJoinCommunity[0]
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NotNil(aRtj)
|
2021-08-06 15:40:23 +00:00
|
|
|
s.Equal(community.ID(), aRtj.CommunityID)
|
|
|
|
s.True(aRtj.Our)
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NotEmpty(aRtj.ID)
|
|
|
|
s.Require().NotEmpty(aRtj.Clock)
|
2021-08-06 15:40:23 +00:00
|
|
|
s.Equal(aRtj.PublicKey, common.PubkeyToHex(&s.alice.identity.PublicKey))
|
|
|
|
s.Equal(communities.RequestToJoinStatePending, aRtj.State)
|
|
|
|
|
|
|
|
// Make sure clock is not empty
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NotEmpty(aRtj.Clock)
|
2021-08-06 15:40:23 +00:00
|
|
|
|
|
|
|
s.Len(response.Communities(), 1)
|
|
|
|
s.Equal(response.Communities()[0].RequestedToJoinAt(), aRtj.Clock)
|
|
|
|
|
|
|
|
// pull all communities to make sure we set RequestedToJoinAt
|
|
|
|
allCommunities, err := s.alice.Communities()
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err)
|
2021-08-06 15:40:23 +00:00
|
|
|
s.Len(allCommunities, 2)
|
|
|
|
|
|
|
|
if bytes.Equal(allCommunities[0].ID(), community.ID()) {
|
|
|
|
s.Equal(allCommunities[0].RequestedToJoinAt(), aRtj.Clock)
|
|
|
|
} else {
|
|
|
|
s.Equal(allCommunities[1].RequestedToJoinAt(), aRtj.Clock)
|
|
|
|
}
|
|
|
|
|
|
|
|
// pull to make sure it has been saved
|
|
|
|
requestsToJoin, err := s.alice.MyPendingRequestsToJoin()
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err)
|
2021-08-06 15:40:23 +00:00
|
|
|
s.Len(requestsToJoin, 1)
|
|
|
|
|
|
|
|
// Make sure the requests are fetched also by community
|
|
|
|
requestsToJoin, err = s.alice.PendingRequestsToJoinForCommunity(community.ID())
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err)
|
2021-08-06 15:40:23 +00:00
|
|
|
s.Len(requestsToJoin, 1)
|
|
|
|
|
|
|
|
// Alice's other device retrieves sync message from the join
|
|
|
|
err = tt.RetryWithBackOff(func() error {
|
|
|
|
response, err = alicesOtherDevice.RetrieveAll()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do we have a new synced community?
|
|
|
|
_, err = alicesOtherDevice.communitiesManager.GetSyncedRawCommunity(community.ID())
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("community with sync not received %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do we have a new pending request to join for the new community
|
|
|
|
requestsToJoin, err = alicesOtherDevice.PendingRequestsToJoinForCommunity(community.ID())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(requestsToJoin) == 0 {
|
|
|
|
return errors.New("no requests to join")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err)
|
2021-08-06 15:40:23 +00:00
|
|
|
s.Len(response.Communities(), 1)
|
|
|
|
|
|
|
|
// Get the pending requests to join for the new community on alicesOtherDevice
|
|
|
|
requestsToJoin, err = alicesOtherDevice.PendingRequestsToJoinForCommunity(community.ID())
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err)
|
2021-08-06 15:40:23 +00:00
|
|
|
s.Len(requestsToJoin, 1)
|
|
|
|
|
|
|
|
// Check request to join on alicesOtherDevice matches the RTJ on alice
|
|
|
|
aodRtj := requestsToJoin[0]
|
|
|
|
s.Equal(aRtj.PublicKey, aodRtj.PublicKey)
|
|
|
|
s.Equal(aRtj.ID, aodRtj.ID)
|
|
|
|
s.Equal(aRtj.CommunityID, aodRtj.CommunityID)
|
|
|
|
s.Equal(aRtj.Clock, aodRtj.Clock)
|
|
|
|
s.Equal(aRtj.ENSName, aodRtj.ENSName)
|
|
|
|
s.Equal(aRtj.ChatID, aodRtj.ChatID)
|
|
|
|
s.Equal(aRtj.State, aodRtj.State)
|
|
|
|
|
|
|
|
// Bob the admin retrieves request to join
|
|
|
|
err = tt.RetryWithBackOff(func() error {
|
|
|
|
response, err = s.bob.RetrieveAll()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(response.RequestsToJoinCommunity) == 0 {
|
|
|
|
return errors.New("request to join community not received")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err)
|
2021-08-06 15:40:23 +00:00
|
|
|
s.Len(response.RequestsToJoinCommunity, 1)
|
|
|
|
|
|
|
|
// Check that bob the admin's newly received request to join matches what we expect
|
|
|
|
bobRtj := response.RequestsToJoinCommunity[0]
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NotNil(bobRtj)
|
2021-08-06 15:40:23 +00:00
|
|
|
s.Equal(community.ID(), bobRtj.CommunityID)
|
|
|
|
s.False(bobRtj.Our)
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NotEmpty(bobRtj.ID)
|
|
|
|
s.Require().NotEmpty(bobRtj.Clock)
|
2021-08-06 15:40:23 +00:00
|
|
|
s.Equal(bobRtj.PublicKey, common.PubkeyToHex(&s.alice.identity.PublicKey))
|
|
|
|
s.Equal(communities.RequestToJoinStatePending, bobRtj.State)
|
|
|
|
|
|
|
|
s.Equal(aRtj.PublicKey, bobRtj.PublicKey)
|
|
|
|
s.Equal(aRtj.ID, bobRtj.ID)
|
|
|
|
s.Equal(aRtj.CommunityID, bobRtj.CommunityID)
|
|
|
|
s.Equal(aRtj.Clock, bobRtj.Clock)
|
|
|
|
s.Equal(aRtj.ENSName, bobRtj.ENSName)
|
|
|
|
s.Equal(aRtj.ChatID, bobRtj.ChatID)
|
|
|
|
s.Equal(aRtj.State, bobRtj.State)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerCommunitiesSuite) pairTwoDevices(device1, device2 *Messenger, deviceName, deviceType string) {
|
|
|
|
// Send pairing data
|
2023-02-28 12:32:45 +00:00
|
|
|
response, err := device1.SendPairInstallation(context.Background(), nil)
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
2021-08-06 15:40:23 +00:00
|
|
|
s.Len(response.Chats(), 1)
|
|
|
|
s.False(response.Chats()[0].Active)
|
|
|
|
|
|
|
|
// Wait for the message to reach its destination
|
|
|
|
response, err = WaitOnMessengerResponse(
|
|
|
|
device2,
|
2021-10-06 11:44:24 +00:00
|
|
|
func(r *MessengerResponse) bool {
|
|
|
|
for _, installation := range r.Installations {
|
|
|
|
if installation.ID == device1.installationID {
|
|
|
|
return installation.InstallationMetadata != nil && deviceName == installation.InstallationMetadata.Name && deviceType == installation.InstallationMetadata.DeviceType
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
|
|
|
|
},
|
2021-08-06 15:40:23 +00:00
|
|
|
"installation not received",
|
|
|
|
)
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
2021-08-06 15:40:23 +00:00
|
|
|
|
|
|
|
// Ensure installation is enabled
|
|
|
|
err = device2.EnableInstallation(device1.installationID)
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err)
|
2021-08-06 15:40:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerCommunitiesSuite) TestSyncCommunity_Leave() {
|
|
|
|
// Set Alice's installation metadata
|
|
|
|
aim := &multidevice.InstallationMetadata{
|
|
|
|
Name: "alice's-device",
|
|
|
|
DeviceType: "alice's-device-type",
|
|
|
|
}
|
|
|
|
err := s.alice.SetInstallationMetadata(s.alice.installationID, aim)
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err)
|
2021-08-06 15:40:23 +00:00
|
|
|
|
|
|
|
// Create Alice's other device
|
|
|
|
alicesOtherDevice, err := newMessengerWithKey(s.shh, s.alice.identity, s.logger, nil)
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err)
|
2021-08-06 15:40:23 +00:00
|
|
|
|
|
|
|
im1 := &multidevice.InstallationMetadata{
|
|
|
|
Name: "alice's-other-device",
|
|
|
|
DeviceType: "alice's-other-device-type",
|
|
|
|
}
|
|
|
|
err = alicesOtherDevice.SetInstallationMetadata(alicesOtherDevice.installationID, im1)
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err)
|
2021-08-06 15:40:23 +00:00
|
|
|
|
|
|
|
// Pair alice's two devices
|
|
|
|
s.pairTwoDevices(alicesOtherDevice, s.alice, im1.Name, im1.DeviceType)
|
|
|
|
s.pairTwoDevices(s.alice, alicesOtherDevice, aim.Name, aim.DeviceType)
|
|
|
|
|
|
|
|
// Check bob the admin has only one community
|
|
|
|
tcs2, err := s.bob.communitiesManager.All()
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err, "admin.communitiesManager.All")
|
2021-08-06 15:40:23 +00:00
|
|
|
s.Len(tcs2, 1, "Must have 1 communities")
|
|
|
|
|
|
|
|
// Bob the admin creates a community
|
|
|
|
createCommunityReq := &requests.CreateCommunity{
|
|
|
|
Membership: protobuf.CommunityPermissions_NO_MEMBERSHIP,
|
|
|
|
Name: "new community",
|
|
|
|
Color: "#000000",
|
|
|
|
Description: "new community description",
|
|
|
|
}
|
2022-07-19 09:31:52 +00:00
|
|
|
mr, err := s.bob.CreateCommunity(createCommunityReq, true)
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err, "CreateCommunity")
|
|
|
|
s.Require().NotNil(mr)
|
2021-08-06 15:40:23 +00:00
|
|
|
s.Len(mr.Communities(), 1)
|
|
|
|
|
|
|
|
community := mr.Communities()[0]
|
|
|
|
|
|
|
|
// Check that admin has 2 communities
|
|
|
|
acs, err := s.bob.communitiesManager.All()
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err, "communitiesManager.All")
|
2021-08-06 15:40:23 +00:00
|
|
|
s.Len(acs, 2, "Must have 2 communities")
|
|
|
|
|
|
|
|
// Check that Alice has only 1 community on either device
|
|
|
|
cs, err := s.alice.communitiesManager.All()
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err, "communitiesManager.All")
|
2021-08-06 15:40:23 +00:00
|
|
|
s.Len(cs, 1, "Must have 1 communities")
|
|
|
|
|
|
|
|
tcs1, err := alicesOtherDevice.communitiesManager.All()
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err, "alicesOtherDevice.communitiesManager.All")
|
2021-08-06 15:40:23 +00:00
|
|
|
s.Len(tcs1, 1, "Must have 1 communities")
|
|
|
|
|
|
|
|
// Bob the admin opens up a 1-1 chat with alice
|
|
|
|
chat := CreateOneToOneChat(common.PubkeyToHex(&s.alice.identity.PublicKey), &s.alice.identity.PublicKey, s.alice.transport)
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(s.bob.SaveChat(chat))
|
2021-08-06 15:40:23 +00:00
|
|
|
|
|
|
|
// Bob the admin shares with Alice, via public chat, an invite link to the new community
|
|
|
|
message := buildTestMessage(*chat)
|
|
|
|
message.CommunityID = community.IDString()
|
|
|
|
response, err := s.bob.SendChatMessage(context.Background(), message)
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
2021-08-06 15:40:23 +00:00
|
|
|
|
|
|
|
// Retrieve community link & community
|
|
|
|
err = tt.RetryWithBackOff(func() error {
|
|
|
|
response, err = s.alice.RetrieveAll()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(response.Communities()) == 0 {
|
|
|
|
return errors.New("no communities received from 1-1")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err)
|
2021-08-06 15:40:23 +00:00
|
|
|
|
|
|
|
// Check that alice now has 2 communities
|
|
|
|
cs, err = s.alice.communitiesManager.All()
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err, "communitiesManager.All")
|
2021-08-06 15:40:23 +00:00
|
|
|
s.Len(cs, 2, "Must have 2 communities")
|
|
|
|
for _, c := range cs {
|
|
|
|
s.False(c.Joined(), "Must not have joined the community")
|
|
|
|
}
|
|
|
|
|
|
|
|
// alice joins the community
|
|
|
|
mr, err = s.alice.JoinCommunity(context.Background(), community.ID())
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err, "s.alice.JoinCommunity")
|
|
|
|
s.Require().NotNil(mr)
|
2021-08-06 15:40:23 +00:00
|
|
|
s.Len(mr.Communities(), 1)
|
|
|
|
aCom := mr.Communities()[0]
|
|
|
|
|
|
|
|
// Check that the joined community has the correct values
|
|
|
|
s.Equal(community.ID(), aCom.ID())
|
2022-05-10 13:25:08 +00:00
|
|
|
s.Equal(uint64(0x2), aCom.Clock())
|
2021-08-06 15:40:23 +00:00
|
|
|
s.Equal(community.PublicKey(), aCom.PublicKey())
|
|
|
|
|
|
|
|
// Check alicesOtherDevice receives the sync join message
|
|
|
|
err = tt.RetryWithBackOff(func() error {
|
|
|
|
response, err = alicesOtherDevice.RetrieveAll()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do we have a new synced community?
|
|
|
|
_, err = alicesOtherDevice.communitiesManager.GetSyncedRawCommunity(community.ID())
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("community with sync not received %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
2021-10-06 11:44:24 +00:00
|
|
|
s.Require().NoError(err)
|
2021-08-06 15:40:23 +00:00
|
|
|
s.Len(response.Communities(), 1, "")
|
|
|
|
|
|
|
|
aoCom := mr.Communities()[0]
|
|
|
|
s.Equal(aCom, aoCom)
|
|
|
|
}
|
2022-07-06 16:16:19 +00:00
|
|
|
|
|
|
|
func (s *MessengerCommunitiesSuite) TestSetMutePropertyOnChatsByCategory() {
|
|
|
|
// Create a community
|
|
|
|
createCommunityReq := &requests.CreateCommunity{
|
|
|
|
Membership: protobuf.CommunityPermissions_ON_REQUEST,
|
|
|
|
Name: "new community",
|
|
|
|
Color: "#000000",
|
|
|
|
Description: "new community description",
|
|
|
|
}
|
|
|
|
|
2022-07-19 09:31:52 +00:00
|
|
|
mr, err := s.alice.CreateCommunity(createCommunityReq, true)
|
2022-07-06 16:16:19 +00:00
|
|
|
s.Require().NoError(err, "s.alice.CreateCommunity")
|
|
|
|
var newCommunity *communities.Community
|
|
|
|
for _, com := range mr.Communities() {
|
|
|
|
if com.Name() == createCommunityReq.Name {
|
|
|
|
newCommunity = com
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s.Require().NotNil(newCommunity)
|
|
|
|
|
|
|
|
orgChat1 := &protobuf.CommunityChat{
|
|
|
|
Permissions: &protobuf.CommunityPermissions{
|
|
|
|
Access: protobuf.CommunityPermissions_NO_MEMBERSHIP,
|
|
|
|
},
|
|
|
|
Identity: &protobuf.ChatIdentity{
|
|
|
|
DisplayName: "status-core",
|
|
|
|
Emoji: "😎",
|
|
|
|
Description: "status-core community chat",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
orgChat2 := &protobuf.CommunityChat{
|
|
|
|
Permissions: &protobuf.CommunityPermissions{
|
|
|
|
Access: protobuf.CommunityPermissions_NO_MEMBERSHIP,
|
|
|
|
},
|
|
|
|
Identity: &protobuf.ChatIdentity{
|
|
|
|
DisplayName: "status-core2",
|
|
|
|
Emoji: "😎",
|
|
|
|
Description: "status-core community chat2",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
mr, err = s.alice.CreateCommunityChat(newCommunity.ID(), orgChat1)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(mr)
|
|
|
|
s.Require().Len(mr.Communities(), 1)
|
|
|
|
s.Require().Len(mr.Chats(), 1)
|
|
|
|
|
|
|
|
mr, err = s.alice.CreateCommunityChat(newCommunity.ID(), orgChat2)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(mr)
|
|
|
|
s.Require().Len(mr.Communities(), 1)
|
|
|
|
s.Require().Len(mr.Chats(), 1)
|
|
|
|
|
|
|
|
var chatIds []string
|
|
|
|
for k := range newCommunity.Chats() {
|
|
|
|
chatIds = append(chatIds, k)
|
|
|
|
}
|
|
|
|
category := &requests.CreateCommunityCategory{
|
|
|
|
CommunityID: newCommunity.ID(),
|
|
|
|
CategoryName: "category-name",
|
|
|
|
ChatIDs: chatIds,
|
|
|
|
}
|
|
|
|
|
|
|
|
mr, err = s.alice.CreateCommunityCategory(category)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(mr)
|
|
|
|
s.Require().Len(mr.Communities(), 1)
|
|
|
|
s.Require().Len(mr.Communities()[0].Categories(), 1)
|
|
|
|
|
|
|
|
var categoryID string
|
|
|
|
for k := range mr.Communities()[0].Categories() {
|
|
|
|
categoryID = k
|
|
|
|
}
|
|
|
|
|
|
|
|
err = s.alice.SetMutePropertyOnChatsByCategory(newCommunity.IDString(), categoryID, true)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
for _, chat := range s.alice.Chats() {
|
|
|
|
if chat.CategoryID == categoryID {
|
|
|
|
s.Require().True(chat.Muted)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
err = s.alice.SetMutePropertyOnChatsByCategory(newCommunity.IDString(), categoryID, false)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
for _, chat := range s.alice.Chats() {
|
|
|
|
s.Require().False(chat.Muted)
|
|
|
|
}
|
|
|
|
}
|
feat: introduce messenger APIs to extract discord channels
As part of the new Discord <-> Status Community Import functionality,
we're adding an API that extracts all discord categories and channels
from a previously exported discord export file.
These APIs can be used in clients to show the user what categories and
channels will be imported later on.
There are two APIs:
1. `Messenger.ExtractDiscordCategoriesAndChannels(filesToimport
[]string) (*MessengerResponse, map[string]*discord.ImportError)`
This takes a list of exported discord export (JSON) files (typically one per
channel), reads them, and extracts the categories and channels into
dedicated data structures (`[]DiscordChannel` and `[]DiscordCategory`)
It also returns the oldest message timestamp found in all extracted
channels.
The API is synchronous and returns the extracted data as
a `*MessengerResponse`. This allows to make the API available
status-go's RPC interface.
The error case is a `map[string]*discord.ImportError` where each key
is a file path of a JSON file that we tried to extract data from, and
the value a `discord.ImportError` which holds an error message and an
error code, allowing for distinguishing between "critical" errors and
"non-critical" errors.
2. `Messenger.RequestExtractDiscordCategoriesAndChannels(filesToImport
[]string)`
This is the asynchronous counterpart to
`ExtractDiscordCategoriesAndChannels`. The reason this API has been
added is because discord servers can have a lot of message and
channel data, which causes `ExtractDiscordCategoriesAndChannels` to
block the thread for too long, making apps potentially feel like they
are stuck.
This API runs inside a go routine, eventually calls
`ExtractDiscordCategoriesAndChannels`, and then emits a newly
introduced `DiscordCategoriesAndChannelsExtractedSignal` that clients
can react to.
Failure of extraction has to be determined by the
`discord.ImportErrors` emitted by the signal.
**A note about exported discord history files**
We expect users to export their discord histories via the
[DiscordChatExporter](https://github.com/Tyrrrz/DiscordChatExporter/wiki/GUI%2C-CLI-and-Formats-explained#exportguild)
tool. The tool allows to export the data in different formats, such as
JSON, HTML and CSV.
We expect users to have their data exported as JSON.
Closes: https://github.com/status-im/status-desktop/issues/6690
2022-07-13 09:33:53 +00:00
|
|
|
|
|
|
|
func (s *MessengerCommunitiesSuite) TestExtractDiscordChannelsAndCategories() {
|
|
|
|
|
|
|
|
tmpFile, err := ioutil.TempFile(os.TempDir(), "discord-channel-")
|
|
|
|
s.Require().NoError(err)
|
|
|
|
defer os.Remove(tmpFile.Name())
|
|
|
|
|
|
|
|
discordMessage := &protobuf.DiscordMessage{
|
|
|
|
Id: "1234",
|
|
|
|
Type: "Default",
|
|
|
|
Timestamp: "2022-07-26T14:20:17.305+00:00",
|
|
|
|
TimestampEdited: "",
|
|
|
|
Content: "Some discord message",
|
|
|
|
Author: &protobuf.DiscordMessageAuthor{
|
|
|
|
Id: "123",
|
|
|
|
Name: "TestAuthor",
|
|
|
|
Discriminator: "456",
|
|
|
|
Nickname: "",
|
|
|
|
AvatarUrl: "",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
messages := make([]*protobuf.DiscordMessage, 0)
|
|
|
|
messages = append(messages, discordMessage)
|
|
|
|
|
|
|
|
exportedDiscordData := &discord.ExportedData{
|
|
|
|
Channel: discord.Channel{
|
|
|
|
ID: "12345",
|
|
|
|
CategoryName: "test-category",
|
|
|
|
CategoryID: "6789",
|
|
|
|
Name: "test-channel",
|
|
|
|
Description: "This is a channel topic",
|
|
|
|
FilePath: tmpFile.Name(),
|
|
|
|
},
|
|
|
|
Messages: messages,
|
|
|
|
}
|
|
|
|
|
|
|
|
data, err := json.Marshal(exportedDiscordData)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
err = os.WriteFile(tmpFile.Name(), data, 0666) // nolint: gosec
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
files := make([]string, 0)
|
|
|
|
files = append(files, tmpFile.Name())
|
|
|
|
mr, errs := s.bob.ExtractDiscordChannelsAndCategories(files)
|
|
|
|
s.Require().Len(errs, 0)
|
|
|
|
|
|
|
|
s.Require().Len(mr.DiscordCategories, 1)
|
|
|
|
s.Require().Len(mr.DiscordChannels, 1)
|
|
|
|
s.Require().Equal(mr.DiscordOldestMessageTimestamp, int(1658845217))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *MessengerCommunitiesSuite) TestExtractDiscordChannelsAndCategories_WithErrors() {
|
|
|
|
|
|
|
|
tmpFile, err := ioutil.TempFile(os.TempDir(), "discord-channel-2")
|
|
|
|
s.Require().NoError(err)
|
|
|
|
defer os.Remove(tmpFile.Name())
|
|
|
|
|
|
|
|
exportedDiscordData := &discord.ExportedData{
|
|
|
|
Channel: discord.Channel{
|
|
|
|
ID: "12345",
|
|
|
|
CategoryName: "test-category",
|
|
|
|
CategoryID: "6789",
|
|
|
|
Name: "test-channel",
|
|
|
|
Description: "This is a channel topic",
|
|
|
|
FilePath: tmpFile.Name(),
|
|
|
|
},
|
|
|
|
Messages: make([]*protobuf.DiscordMessage, 0),
|
|
|
|
}
|
|
|
|
|
|
|
|
data, err := json.Marshal(exportedDiscordData)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
err = os.WriteFile(tmpFile.Name(), data, 0666) // nolint: gosec
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
files := make([]string, 0)
|
|
|
|
files = append(files, tmpFile.Name())
|
|
|
|
_, errs := s.bob.ExtractDiscordChannelsAndCategories(files)
|
|
|
|
// Expecting 1 errors since there are no messages to be extracted
|
|
|
|
s.Require().Len(errs, 1)
|
|
|
|
}
|
2023-02-20 11:57:33 +00:00
|
|
|
|
|
|
|
func (s *MessengerCommunitiesSuite) TestCommunityTokensMetadata() {
|
|
|
|
|
|
|
|
description := &requests.CreateCommunity{
|
|
|
|
Membership: protobuf.CommunityPermissions_NO_MEMBERSHIP,
|
|
|
|
Name: "status",
|
|
|
|
Color: "#ffffff",
|
|
|
|
Description: "status community description",
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create an community chat
|
|
|
|
response, err := s.bob.CreateCommunity(description, true)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().NotNil(response)
|
|
|
|
s.Require().Len(response.Communities(), 1)
|
|
|
|
s.Require().Len(response.CommunitiesSettings(), 1)
|
|
|
|
|
|
|
|
community := response.Communities()[0]
|
|
|
|
|
|
|
|
tokensMetadata := community.CommunityTokensMetadata()
|
|
|
|
s.Require().Len(tokensMetadata, 0)
|
|
|
|
|
|
|
|
newToken := &protobuf.CommunityTokenMetadata{
|
|
|
|
ContractAddresses: map[uint64]string{3: "0xasd"},
|
|
|
|
Description: "desc1",
|
|
|
|
Image: "IMG1",
|
|
|
|
TokenType: protobuf.CommunityTokenType_ERC721,
|
|
|
|
Symbol: "SMB",
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = community.AddCommunityTokensMetadata(newToken)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
tokensMetadata = community.CommunityTokensMetadata()
|
|
|
|
s.Require().Len(tokensMetadata, 1)
|
|
|
|
|
|
|
|
s.Require().Equal(tokensMetadata[0].ContractAddresses, newToken.ContractAddresses)
|
|
|
|
s.Require().Equal(tokensMetadata[0].Description, newToken.Description)
|
|
|
|
s.Require().Equal(tokensMetadata[0].Image, newToken.Image)
|
|
|
|
s.Require().Equal(tokensMetadata[0].TokenType, newToken.TokenType)
|
|
|
|
s.Require().Equal(tokensMetadata[0].Symbol, newToken.Symbol)
|
2023-03-07 14:29:16 +00:00
|
|
|
s.Require().Equal(tokensMetadata[0].Name, newToken.Name)
|
2023-02-20 11:57:33 +00:00
|
|
|
}
|