Skip to content

Commit ca4898d

Browse files
authored
feat: Add mark unread and update mark read params (#305)
1 parent 24a72d7 commit ca4898d

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

channel.go

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,10 +609,10 @@ func (ch *Channel) demoteModerators(ctx context.Context, userIDs []string, msg *
609609

610610
type markReadOption struct {
611611
MessageID string `json:"message_id"`
612+
ThreadID string `json:"thread_id"`
612613

613614
UserID string `json:"user_id"`
614615
}
615-
616616
type MarkReadOption func(*markReadOption)
617617

618618
func MarkReadUntilMessage(id string) func(*markReadOption) {
@@ -621,6 +621,12 @@ func MarkReadUntilMessage(id string) func(*markReadOption) {
621621
}
622622
}
623623

624+
func MarkReadThread(id string) func(*markReadOption) {
625+
return func(opt *markReadOption) {
626+
opt.ThreadID = id
627+
}
628+
}
629+
624630
// MarkRead sends the mark read event for user with given ID,
625631
// only works if the `read_events` setting is enabled.
626632
func (ch *Channel) MarkRead(ctx context.Context, userID string, options ...MarkReadOption) (*Response, error) {
@@ -643,6 +649,49 @@ func (ch *Channel) MarkRead(ctx context.Context, userID string, options ...MarkR
643649
return &resp, err
644650
}
645651

652+
type markUnreadOption struct {
653+
MessageID string `json:"message_id"`
654+
ThreadID string `json:"thread_id"`
655+
656+
UserID string `json:"user_id"`
657+
}
658+
659+
type MarkUnreadOption func(option *markUnreadOption)
660+
661+
// Specify ID of the message from where the channel is marked unread
662+
func MarkUnreadFromMessage(id string) func(*markUnreadOption) {
663+
return func(opt *markUnreadOption) {
664+
opt.MessageID = id
665+
}
666+
}
667+
668+
func MarkUnreadThread(id string) func(*markUnreadOption) {
669+
return func(opt *markUnreadOption) {
670+
opt.ThreadID = id
671+
}
672+
}
673+
674+
// MarkUnread message or thread (not both) for specified user.
675+
func (ch *Channel) MarkUnread(ctx context.Context, userID string, options ...MarkUnreadOption) (*Response, error) {
676+
if userID == "" {
677+
return nil, errors.New("user ID must be not empty")
678+
}
679+
680+
p := path.Join("channels", url.PathEscape(ch.Type), url.PathEscape(ch.ID), "unread")
681+
682+
opts := &markUnreadOption{
683+
UserID: userID,
684+
}
685+
686+
for _, fn := range options {
687+
fn(opts)
688+
}
689+
690+
var resp Response
691+
err := ch.client.makeRequest(ctx, http.MethodPost, p, nil, opts, &resp)
692+
return &resp, err
693+
}
694+
646695
// RefreshState makes request to channel api and updates channel internal state.
647696
func (ch *Channel) RefreshState(ctx context.Context) (*QueryResponse, error) {
648697
q := &QueryRequest{State: true}

0 commit comments

Comments
 (0)