Skip to content

Commit cf2d72b

Browse files
authored
Mute and Unmute community
* mute and unmute all community chats when community mute status changes * unmute community when atleast one channel is unmuted * fix: save community, extend the function to save muted state and mute duration
1 parent 1f379ae commit cf2d72b

File tree

22 files changed

+699
-348
lines changed

22 files changed

+699
-348
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.162.4
1+
0.162.5

appdatabase/migrations/bindata.go

Lines changed: 81 additions & 81 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

appdatabase/migrationsprevnodecfg/bindata.go

Lines changed: 54 additions & 54 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mailserver/migrations/bindata.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

multiaccounts/migrations/bindata.go

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protocol/activity_center_persistence_test.go

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package protocol
22

33
import (
4+
"context"
45
"strconv"
56
"testing"
67
"time"
@@ -9,6 +10,8 @@ import (
910

1011
"github.com/status-im/status-go/eth-node/types"
1112
"github.com/status-im/status-go/protocol/common"
13+
"github.com/status-im/status-go/protocol/protobuf"
14+
"github.com/status-im/status-go/protocol/requests"
1215
)
1316

1417
func currentMilliseconds() uint64 {
@@ -210,6 +213,98 @@ func TestDeleteActivityCenterNotificationsForMessage(t *testing.T) {
210213
require.NoError(t, err)
211214
}
212215

216+
func (s *MessengerActivityCenterMessageSuite) TestMuteCommunityActivityCenterNotifications() {
217+
218+
description := &requests.CreateCommunity{
219+
Membership: protobuf.CommunityPermissions_NO_MEMBERSHIP,
220+
Name: "status",
221+
Color: "#ffffff",
222+
Description: "status community description",
223+
}
224+
225+
alice := s.m
226+
bob := s.newMessenger()
227+
_, err := bob.Start()
228+
s.Require().NoError(err)
229+
230+
// Create an community chat
231+
response, err := bob.CreateCommunity(description, true)
232+
s.Require().NoError(err)
233+
s.Require().Len(response.Communities(), 1)
234+
235+
community := response.Communities()[0]
236+
s.Require().NotNil(community)
237+
238+
chat := CreateOneToOneChat(common.PubkeyToHex(&alice.identity.PublicKey), &alice.identity.PublicKey, bob.transport)
239+
240+
// bob sends a community message
241+
inputMessage := &common.Message{}
242+
inputMessage.ChatId = chat.ID
243+
inputMessage.Text = "some text"
244+
inputMessage.CommunityID = community.IDString()
245+
246+
err = bob.SaveChat(chat)
247+
s.Require().NoError(err)
248+
_, err = bob.SendChatMessage(context.Background(), inputMessage)
249+
s.Require().NoError(err)
250+
251+
_, err = WaitOnMessengerResponse(
252+
alice,
253+
func(r *MessengerResponse) bool { return len(r.Communities()) == 1 },
254+
"no messages",
255+
)
256+
257+
s.Require().NoError(err)
258+
259+
// Alice joins the community
260+
response, err = alice.JoinCommunity(context.Background(), community.ID(), true)
261+
s.Require().NoError(err)
262+
s.Require().NotNil(response)
263+
s.Require().Len(response.Communities(), 1)
264+
s.Require().True(response.Communities()[0].Joined())
265+
s.Require().Len(response.Chats(), 1)
266+
267+
defaultCommunityChatID := response.Chats()[0].ID
268+
269+
// Bob mutes the community
270+
time, err := bob.MuteAllCommunityChats(&requests.MuteCommunity{
271+
CommunityID: community.ID(),
272+
MutedType: MuteTillUnmuted,
273+
})
274+
s.Require().NoError(err)
275+
s.Require().NotNil(time)
276+
277+
bobCommunity, err := bob.GetCommunityByID(community.ID())
278+
s.Require().NoError(err)
279+
s.Require().True(bobCommunity.Muted())
280+
281+
// alice sends a community message
282+
inputMessage = &common.Message{}
283+
inputMessage.ChatId = defaultCommunityChatID
284+
inputMessage.Text = "Good news, @" + common.EveryoneMentionTag + " !"
285+
inputMessage.CommunityID = community.IDString()
286+
287+
response, err = alice.SendChatMessage(context.Background(), inputMessage)
288+
s.Require().NoError(err)
289+
290+
s.Require().Len(response.Messages(), 1)
291+
292+
s.Require().True(response.Messages()[0].Mentioned)
293+
294+
response, err = WaitOnMessengerResponse(
295+
bob,
296+
func(r *MessengerResponse) bool { return len(r.Messages()) == 1 },
297+
"no messages",
298+
)
299+
300+
s.Require().NoError(err)
301+
302+
s.Require().Len(response.Messages(), 1)
303+
304+
s.Require().True(response.Messages()[0].Mentioned)
305+
s.Require().Len(response.ActivityCenterNotifications(), 0)
306+
}
307+
213308
func TestAcceptActivityCenterNotificationsForInvitesFromUser(t *testing.T) {
214309
db, err := openTestDB()
215310
require.NoError(t, err)

protocol/anonmetrics/migrations/migrations.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protocol/communities/community_categories.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ func (o *Community) ChatsByCategoryID(categoryID string) []string {
2222
return chatIDs
2323
}
2424

25+
func (o *Community) CommunityChatsIDs() []string {
26+
o.mutex.Lock()
27+
defer o.mutex.Unlock()
28+
var chatIDs []string
29+
if o.config == nil || o.config.CommunityDescription == nil {
30+
return chatIDs
31+
}
32+
33+
for chatID := range o.config.CommunityDescription.Chats {
34+
chatIDs = append(chatIDs, chatID)
35+
}
36+
return chatIDs
37+
}
38+
2539
func (o *Community) CreateCategory(categoryID string, categoryName string, chatIDs []string) (*CommunityChanges, error) {
2640
o.mutex.Lock()
2741
defer o.mutex.Unlock()

protocol/communities/manager.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,10 +1426,13 @@ func (m *Manager) UpdateClockInRequestToJoin(id types.HexBytes, clock uint64) er
14261426
return m.persistence.UpdateClockInRequestToJoin(id, clock)
14271427
}
14281428

1429-
func (m *Manager) SetMuted(id types.HexBytes, muted bool, mutedTill time.Time) error {
1430-
return m.persistence.SetMuted(id, muted, mutedTill)
1429+
func (m *Manager) SetMuted(id types.HexBytes, muted bool) error {
1430+
return m.persistence.SetMuted(id, muted)
14311431
}
14321432

1433+
func (m *Manager) MuteCommunityTill(communityID []byte, muteTill time.Time) error {
1434+
return m.persistence.MuteCommunityTill(communityID, muteTill)
1435+
}
14331436
func (m *Manager) CancelRequestToJoin(request *requests.CancelRequestToJoinCommunity) (*RequestToJoin, *Community, error) {
14341437
dbRequest, err := m.persistence.GetRequestToJoin(request.ID)
14351438
if err != nil {

protocol/communities/persistence.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,8 @@ func (p *Persistence) SaveCommunity(community *Community) error {
4545
}
4646

4747
_, err = p.db.Exec(`
48-
INSERT INTO communities_communities (id, private_key, description, joined, spectated, verified) VALUES (?, ?, ?, ?, ?, ?);`,
49-
id, crypto.FromECDSA(privateKey), description, community.config.Joined, community.config.Spectated, community.config.Verified)
50-
48+
INSERT INTO communities_communities (id, private_key, description, joined, spectated, verified, muted, muted_till) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
49+
id, crypto.FromECDSA(privateKey), description, community.config.Joined, community.config.Spectated, community.config.Verified, community.config.Muted, community.config.MuteTill)
5150
return err
5251
}
5352

@@ -764,9 +763,14 @@ func (p *Persistence) UpdateClockInRequestToJoin(id []byte, clock uint64) error
764763
return err
765764
}
766765

767-
func (p *Persistence) SetMuted(communityID []byte, muted bool, mutedTill time.Time) error {
766+
func (p *Persistence) SetMuted(communityID []byte, muted bool) error {
767+
_, err := p.db.Exec(`UPDATE communities_communities SET muted = ? WHERE id = ?`, muted, communityID)
768+
return err
769+
}
770+
771+
func (p *Persistence) MuteCommunityTill(communityID []byte, mutedTill time.Time) error {
768772
mutedTillFormatted := mutedTill.Format(time.RFC3339)
769-
_, err := p.db.Exec(`UPDATE communities_communities SET muted = ?, muted_till = ? WHERE id = ?`, muted, mutedTillFormatted, communityID)
773+
_, err := p.db.Exec(`UPDATE communities_communities SET muted_till = ? WHERE id = ?`, mutedTillFormatted, communityID)
770774
return err
771775
}
772776

protocol/communities/persistence_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ func (s *PersistenceSuite) TestSaveCommunity() {
6060
Joined: true,
6161
Spectated: true,
6262
Verified: true,
63+
Muted: true,
64+
MuteTill: time.Time{},
6365
CommunityDescription: &protobuf.CommunityDescription{},
6466
},
6567
}
@@ -72,6 +74,8 @@ func (s *PersistenceSuite) TestSaveCommunity() {
7274
s.Equal(true, communities[1].Joined())
7375
s.Equal(true, communities[1].Spectated())
7476
s.Equal(true, communities[1].Verified())
77+
s.Equal(true, communities[1].Muted())
78+
s.Equal(time.Time{}, communities[1].MuteTill())
7579
}
7680

7781
func (s *PersistenceSuite) TestShouldHandleSyncCommunity() {

0 commit comments

Comments
 (0)