Skip to content

Commit

Permalink
cmt history
Browse files Browse the repository at this point in the history
  • Loading branch information
Xavrax committed Dec 10, 2024
1 parent 8f4c160 commit 73adbd6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
14 changes: 14 additions & 0 deletions history_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,17 @@ func (b *historyBuilder) QueryParam(queryParam map[string]string) *historyBuilde
// Transport sets the Transport for the History request.
func (b *historyBuilder) Transport(tr http.RoundTripper) *historyBuilder {
b.opts.Transport = tr

return b
}

// includeCustomMessageType tells server to send the custom message type with each history item
func (b *historyBuilder) includeCustomMessageType(i bool) *historyBuilder {
b.opts.includeCustomMessageType = i

return b
}

// Execute runs the History request.
func (b *historyBuilder) Execute() (*HistoryResponse, StatusResponse, error) {
rawJSON, status, err := executeRequest(b.opts)
Expand Down Expand Up @@ -127,6 +135,8 @@ type historyOpts struct {
setStart bool
setEnd bool

includeCustomMessageType bool

Transport http.RoundTripper
}

Expand Down Expand Up @@ -165,6 +175,10 @@ func (o *historyOpts) buildQuery() (*url.Values, error) {
q.Set("count", "100")
}

if o.includeCustomMessageType {
q.Set("include_custom_message_type", "true")
}

q.Set("reverse", strconv.FormatBool(o.Reverse))
q.Set("include_token", strconv.FormatBool(o.IncludeTimetoken))
q.Set("include_meta", strconv.FormatBool(o.WithMeta))
Expand Down
3 changes: 3 additions & 0 deletions history_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func (pn *PubNub) initHistoryOpts() *historyOpts {
opts.Count = 3
opts.IncludeTimetoken = true
opts.pubnub = pn
opts.includeCustomMessageType = false
return opts
}

Expand Down Expand Up @@ -132,6 +133,7 @@ func TestHistoryRequestAllParams(t *testing.T) {
opts.Reverse = false
opts.Count = 3
opts.IncludeTimetoken = true
opts.includeCustomMessageType = true

path, err := opts.buildPath()
assert.Nil(err)
Expand All @@ -151,6 +153,7 @@ func TestHistoryRequestAllParams(t *testing.T) {
expected.Set("reverse", "false")
expected.Set("count", "3")
expected.Set("include_token", "true")
expected.Set("include_custom_message_type", "true")
h.AssertQueriesEqual(t, expected, query, []string{"pnsdk", "uuid", "include_meta"}, []string{})
}

Expand Down

0 comments on commit 73adbd6

Please sign in to comment.