Skip to content

Commit 2823d64

Browse files
Unread message count (#267)
* feat: add unread messages to struct * chore: add @JimmyPettersson85 to CODEOWNERS * fix: test limits
1 parent 4fe7441 commit 2823d64

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
* @yaziine @totalimmersion @akupila
1+
* @yaziine @totalimmersion @akupila @JimmyPettersson85

channel.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ import (
1313
)
1414

1515
type ChannelRead struct {
16-
User *User `json:"user"`
17-
LastRead time.Time `json:"last_read"`
16+
User *User `json:"user"`
17+
LastRead time.Time `json:"last_read"`
18+
UnreadMessages int `json:"unread_messages"`
1819
}
1920

2021
type ChannelMember struct {

channel_test.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func (ch *Channel) refresh(ctx context.Context) error {
1818

1919
func TestClient_TestQuery(t *testing.T) {
2020
c := initClient(t)
21-
membersID := randomUsersID(t, c, 1)
21+
membersID := randomUsersID(t, c, 3)
2222
ch := initChannel(t, c, membersID...)
2323
ctx := context.Background()
2424
msg, err := ch.SendMessage(ctx, &Message{Text: "test message", Pinned: true}, ch.CreatedBy.ID)
@@ -27,12 +27,21 @@ func TestClient_TestQuery(t *testing.T) {
2727
q := &QueryRequest{
2828
State: true,
2929
Messages: &MessagePaginationParamsRequest{PaginationParamsRequest: PaginationParamsRequest{Limit: 1, IDLT: msg.Message.ID}},
30-
Members: &PaginationParamsRequest{Limit: 1, Offset: 0},
31-
Watchers: &PaginationParamsRequest{Limit: 1, Offset: 0},
30+
Members: &PaginationParamsRequest{Limit: 3, Offset: 0},
31+
Watchers: &PaginationParamsRequest{Limit: 3, Offset: 0},
3232
}
3333
resp, err := ch.Query(ctx, q)
3434
require.NoError(t, err)
35-
require.Equal(t, 1, len(resp.Members))
35+
require.Equal(t, 3, len(resp.Members))
36+
37+
for _, read := range resp.Read {
38+
if ch.CreatedBy.ID == read.User.ID {
39+
require.Equal(t, 0, read.UnreadMessages)
40+
continue
41+
}
42+
43+
require.Equal(t, 1, read.UnreadMessages)
44+
}
3645
}
3746

3847
func TestClient_CreateChannel(t *testing.T) {

0 commit comments

Comments
 (0)