Expand Plugin and REST APIs to trigger user typing event (#14331)

Этот коммит содержится в:
Attila Molnar
2020-06-16 16:41:05 +07:00
коммит произвёл GitHub
родитель 8c1164d86b
Коммит 66597d0fcb
14 изменённых файлов: 267 добавлений и 8 удалений

Просмотреть файл

@@ -487,6 +487,10 @@ func (c *Client4) GetGroupsRoute() string {
return "/groups"
}
func (c *Client4) GetPublishUserTypingRoute(userId string) string {
return c.GetUserRoute(userId) + "/typing"
}
func (c *Client4) GetGroupRoute(groupID string) string {
return fmt.Sprintf("%s/%s", c.GetGroupsRoute(), groupID)
}
@@ -5094,6 +5098,16 @@ func (c *Client4) GetKnownUsers() ([]string, *Response) {
return userIds, BuildResponse(r)
}
// PublishUserTyping publishes a user is typing websocket event based on the provided TypingRequest.
func (c *Client4) PublishUserTyping(userID string, typingRequest TypingRequest) (bool, *Response) {
r, err := c.DoApiPost(c.GetPublishUserTypingRoute(userID), typingRequest.ToJson())
if err != nil {
return false, BuildErrorResponse(r, err)
}
defer closeBody(r)
return CheckStatusOK(r), BuildResponse(r)
}
func (c *Client4) GetChannelMemberCountsByGroup(channelID string, includeTimezones bool, etag string) ([]*ChannelMemberCountByGroup, *Response) {
r, err := c.DoApiGet(c.GetChannelRoute(channelID)+"/member_counts_by_group?include_timezones="+strconv.FormatBool(includeTimezones), etag)
if err != nil {

25
model/typing_request.go Обычный файл
Просмотреть файл

@@ -0,0 +1,25 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package model
import (
"encoding/json"
"io"
)
type TypingRequest struct {
ChannelId string `json:"channel_id"`
ParentId string `json:"parent_id"`
}
func (o *TypingRequest) ToJson() string {
b, _ := json.Marshal(o)
return string(b)
}
func TypingRequestFromJson(data io.Reader) *TypingRequest {
var o *TypingRequest
json.NewDecoder(data).Decode(&o)
return o
}

20
model/typing_request_test.go Обычный файл
Просмотреть файл

@@ -0,0 +1,20 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package model
import (
"strings"
"testing"
"github.com/stretchr/testify/require"
)
func TestTypingRequestJson(t *testing.T) {
o := TypingRequest{ChannelId: NewId(), ParentId: NewId()}
json := o.ToJson()
ro := TypingRequestFromJson(strings.NewReader(json))
require.Equal(t, o.ChannelId, ro.ChannelId, "ChannelIds do not match")
require.Equal(t, o.ParentId, ro.ParentId, "ParentIds do not match")
}