Skip to content

Commit

Permalink
Unread message count (#267)
Browse files Browse the repository at this point in the history
* feat: add unread messages to struct

* chore: add @JimmyPettersson85 to CODEOWNERS

* fix: test limits
  • Loading branch information
JimmyPettersson85 authored Feb 27, 2024
1 parent 4fe7441 commit 2823d64
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @yaziine @totalimmersion @akupila
* @yaziine @totalimmersion @akupila @JimmyPettersson85
5 changes: 3 additions & 2 deletions channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import (
)

type ChannelRead struct {
User *User `json:"user"`
LastRead time.Time `json:"last_read"`
User *User `json:"user"`
LastRead time.Time `json:"last_read"`
UnreadMessages int `json:"unread_messages"`
}

type ChannelMember struct {
Expand Down
17 changes: 13 additions & 4 deletions channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (ch *Channel) refresh(ctx context.Context) error {

func TestClient_TestQuery(t *testing.T) {
c := initClient(t)
membersID := randomUsersID(t, c, 1)
membersID := randomUsersID(t, c, 3)
ch := initChannel(t, c, membersID...)
ctx := context.Background()
msg, err := ch.SendMessage(ctx, &Message{Text: "test message", Pinned: true}, ch.CreatedBy.ID)
Expand All @@ -27,12 +27,21 @@ func TestClient_TestQuery(t *testing.T) {
q := &QueryRequest{
State: true,
Messages: &MessagePaginationParamsRequest{PaginationParamsRequest: PaginationParamsRequest{Limit: 1, IDLT: msg.Message.ID}},
Members: &PaginationParamsRequest{Limit: 1, Offset: 0},
Watchers: &PaginationParamsRequest{Limit: 1, Offset: 0},
Members: &PaginationParamsRequest{Limit: 3, Offset: 0},
Watchers: &PaginationParamsRequest{Limit: 3, Offset: 0},
}
resp, err := ch.Query(ctx, q)
require.NoError(t, err)
require.Equal(t, 1, len(resp.Members))
require.Equal(t, 3, len(resp.Members))

for _, read := range resp.Read {
if ch.CreatedBy.ID == read.User.ID {
require.Equal(t, 0, read.UnreadMessages)
continue
}

require.Equal(t, 1, read.UnreadMessages)
}
}

func TestClient_CreateChannel(t *testing.T) {
Expand Down

0 comments on commit 2823d64

Please sign in to comment.