Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move must and match packages out of internal; add generic must functions #661

Merged
merged 8 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,17 @@ func (c *CSAPI) SendRedaction(t TestLike, roomID string, e b.Event, eventID stri
return GetJSONFieldStr(t, body, "event_id")
}

// SendTyping marks this user as typing until the timeout is reached. If isTyping is false, timeout is ignored.
func (c *CSAPI) SendTyping(t TestLike, roomID string, isTyping bool, timeoutMillis int) {
content := map[string]interface{}{
"typing": isTyping,
}
if isTyping {
content["timeout"] = timeoutMillis
}
c.MustDo(t, "PUT", []string{"_matrix", "client", "v3", "rooms", roomID, "typing", c.UserID}, WithJSONBody(t, content))
}

// GetCapbabilities queries the server's capabilities
func (c *CSAPI) GetCapabilities(t TestLike) []byte {
t.Helper()
Expand Down
28 changes: 28 additions & 0 deletions client/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package client
import (
"fmt"
"net/url"
"reflect"
"sort"
"strings"
"time"

Expand Down Expand Up @@ -365,6 +367,32 @@ func SyncRoomAccountDataHas(roomID string, check func(gjson.Result) bool) SyncCh
}
}

// SyncUsersTyping passes when all users in `userIDs` are typing in the same typing EDU.
// It must see a typing EDU first before returning, even if the list of user IDs is empty.
func SyncUsersTyping(roomID string, userIDs []string) SyncCheckOpt {
// don't sort the input slice the test gave us.
userIDsCopy := make([]string, len(userIDs))
copy(userIDsCopy, userIDs)
sort.Strings(userIDsCopy)
return SyncEphemeralHas(roomID, func(r gjson.Result) bool {
if r.Get("type").Str != "m.typing" {
return false
}

var usersSeenTyping []string
for _, item := range r.Get("content").Get("user_ids").Array() {
usersSeenTyping = append(usersSeenTyping, item.Str)
}
// special case to support nil and 0 length slices
if len(usersSeenTyping) == 0 && len(userIDsCopy) == 0 {
return true
}
sort.Strings(userIDsCopy)
sort.Strings(usersSeenTyping)
return reflect.DeepEqual(userIDsCopy, usersSeenTyping)
})
}

// Check that sync has received a to-device message,
// with optional user filtering.
//
Expand Down
38 changes: 26 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,32 +1,46 @@
module github.com/matrix-org/complement

go 1.16
go 1.18

require (
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/docker/docker v20.10.24+incompatible
github.com/docker/go-connections v0.4.0
github.com/docker/go-units v0.4.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/gorilla/mux v1.8.0
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530
github.com/matrix-org/gomatrixserverlib v0.0.0-20230921171121-0466775328c7
github.com/matrix-org/util v0.0.0-20221111132719-399730281e66
github.com/sirupsen/logrus v1.9.3
github.com/tidwall/gjson v1.16.0
github.com/tidwall/sjson v1.2.5
golang.org/x/exp v0.0.0-20230905200255-921286631fa9
gonum.org/v1/plot v0.11.0
maunium.net/go/mautrix v0.11.0
)

require (
git.sr.ht/~sbinet/gg v0.3.1 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/ajstarks/svgo v0.0.0-20211024235047-1546f124cd8b // indirect
github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/go-fonts/liberation v0.2.0 // indirect
github.com/go-latex/latex v0.0.0-20210823091927-c0d11ff05a81 // indirect
github.com/go-pdf/fpdf v0.6.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/moby/term v0.0.0-20210610120745-9d4ed1856297 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.3-0.20211202183452-c5a74bcca799 // indirect
github.com/sirupsen/logrus v1.9.3
github.com/tidwall/gjson v1.16.0
github.com/pkg/errors v0.9.1 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/tidwall/sjson v1.2.5
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6 // indirect
golang.org/x/image v0.5.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
gonum.org/v1/plot v0.11.0
gotest.tools/v3 v3.0.3 // indirect
maunium.net/go/mautrix v0.11.0
)
Loading
Loading