Update dependencies

This commit is contained in:
Tulir Asokan 2018-05-10 20:56:46 +03:00
parent 706f4c4404
commit 66b17967eb
7 changed files with 2200 additions and 2156 deletions

8
Gopkg.lock generated
View File

@ -10,8 +10,8 @@
[[projects]] [[projects]]
name = "github.com/disintegration/imaging" name = "github.com/disintegration/imaging"
packages = ["."] packages = ["."]
revision = "fd34ef7671b12cdf1b024d98c6b327b2770d32c4" revision = "bbcee2f5c9d5e94ca42c8b50ec847fec64a6c134"
version = "v1.4.1" version = "v1.4.2"
[[projects]] [[projects]]
branch = "master" branch = "master"
@ -82,7 +82,7 @@
"html", "html",
"html/atom" "html/atom"
] ]
revision = "640f4622ab692b87c2f3a94265e6f579fe38263d" revision = "f73e4c9ed3b7ebdd5f699a16a880c2b1994e50dd"
[[projects]] [[projects]]
name = "golang.org/x/text" name = "golang.org/x/text"
@ -118,7 +118,7 @@
branch = "master" branch = "master"
name = "maunium.net/go/gomatrix" name = "maunium.net/go/gomatrix"
packages = ["."] packages = ["."]
revision = "618319f327acbd401426c711f54e1a634e2243e4" revision = "4ddf8d780ff6a0434a52c256015f7fcd2ca67dc9"
[[projects]] [[projects]]
branch = "master" branch = "master"

View File

@ -148,32 +148,36 @@ func (s *GomuksSyncer) OnFailedSync(res *gomatrix.RespSync, err error) (time.Dur
// GetFilterJSON returns a filter with a timeline limit of 50. // GetFilterJSON returns a filter with a timeline limit of 50.
func (s *GomuksSyncer) GetFilterJSON(userID string) json.RawMessage { func (s *GomuksSyncer) GetFilterJSON(userID string) json.RawMessage {
return json.RawMessage(`{ filter := &gomatrix.Filter{
"room": { Room: gomatrix.RoomFilter{
"include_leave": false, IncludeLeave: false,
"state": { State: gomatrix.FilterPart{
"types": [ Types: []string{
"m.room.member", "m.room.member",
"m.room.name", "m.room.name",
"m.room.topic", "m.room.topic",
"m.room.canonical_alias", "m.room.canonical_alias",
"m.room.aliases" "m.room.aliases",
]
}, },
"timeline": {
"types": ["m.room.message"],
"limit": 50
}, },
"ephemeral": { Timeline: gomatrix.FilterPart{
"types": ["m.typing"] Types: []string{"m.room.message"},
Limit: 50,
},
Ephemeral: gomatrix.FilterPart{
Types: []string{"m.typing"},
},
AccountData: gomatrix.FilterPart{
Types: []string{"m.tag"},
},
},
AccountData: gomatrix.FilterPart{
Types: []string{"m.push_rules"},
},
Presence: gomatrix.FilterPart{
Types: []string{},
}, },
"account_data": {
"types": ["m.tag"]
} }
}, rawFilter, _ := json.Marshal(&filter)
"account_data": { return rawFilter
"types": ["m.push_rules"]
},
"presence": {"types": []}
}`)
} }

View File

@ -56,6 +56,7 @@ func TestGomuksSyncer_ProcessResponse(t *testing.T) {
syncer := matrix.NewGomuksSyncer(mss) syncer := matrix.NewGomuksSyncer(mss)
syncer.OnEventType("m.room.member", ml.receive) syncer.OnEventType("m.room.member", ml.receive)
syncer.OnEventType("m.room.message", ml.receive) syncer.OnEventType("m.room.message", ml.receive)
syncer.GetFilterJSON("@tulir:maunium.net")
joinEvt := &gomatrix.Event{ joinEvt := &gomatrix.Event{
ID: "!join:maunium.net", ID: "!join:maunium.net",

View File

@ -1,6 +1,7 @@
package imaging package imaging
import ( import (
"bytes"
"errors" "errors"
"image" "image"
"image/color" "image/color"
@ -46,6 +47,26 @@ func (f Format) String() string {
} }
} }
var formatFromExt = map[string]Format{
".jpg": JPEG,
".jpeg": JPEG,
".png": PNG,
".tif": TIFF,
".tiff": TIFF,
".bmp": BMP,
".gif": GIF,
}
// FormatFromFilename parses image format from filename extension:
// "jpg" (or "jpeg"), "png", "gif", "tif" (or "tiff") and "bmp" are supported.
func FormatFromFilename(filename string) (Format, error) {
ext := strings.ToLower(filepath.Ext(filename))
if f, ok := formatFromExt[ext]; ok {
return f, nil
}
return -1, ErrUnsupportedFormat
}
var ( var (
// ErrUnsupportedFormat means the given image format (or file extension) is unsupported. // ErrUnsupportedFormat means the given image format (or file extension) is unsupported.
ErrUnsupportedFormat = errors.New("imaging: unsupported image format") ErrUnsupportedFormat = errors.New("imaging: unsupported image format")
@ -199,22 +220,10 @@ func Encode(w io.Writer, img image.Image, format Format, opts ...EncodeOption) e
// err := imaging.Save(img, "out.jpg", imaging.JPEGQuality(80)) // err := imaging.Save(img, "out.jpg", imaging.JPEGQuality(80))
// //
func Save(img image.Image, filename string, opts ...EncodeOption) (err error) { func Save(img image.Image, filename string, opts ...EncodeOption) (err error) {
formats := map[string]Format{ f, err := FormatFromFilename(filename)
".jpg": JPEG, if err != nil {
".jpeg": JPEG, return err
".png": PNG,
".tif": TIFF,
".tiff": TIFF,
".bmp": BMP,
".gif": GIF,
} }
ext := strings.ToLower(filepath.Ext(filename))
f, ok := formats[ext]
if !ok {
return ErrUnsupportedFormat
}
file, err := fs.Create(filename) file, err := fs.Create(filename)
if err != nil { if err != nil {
return err return err
@ -236,33 +245,16 @@ func New(width, height int, fillColor color.Color) *image.NRGBA {
return &image.NRGBA{} return &image.NRGBA{}
} }
dst := image.NewNRGBA(image.Rect(0, 0, width, height))
c := color.NRGBAModel.Convert(fillColor).(color.NRGBA) c := color.NRGBAModel.Convert(fillColor).(color.NRGBA)
if (c == color.NRGBA{0, 0, 0, 0}) {
if c.R == 0 && c.G == 0 && c.B == 0 && c.A == 0 { return image.NewNRGBA(image.Rect(0, 0, width, height))
return dst
} }
// Fill the first row. return &image.NRGBA{
i := 0 Pix: bytes.Repeat([]byte{c.R, c.G, c.B, c.A}, width*height),
for x := 0; x < width; x++ { Stride: 4 * width,
dst.Pix[i+0] = c.R Rect: image.Rect(0, 0, width, height),
dst.Pix[i+1] = c.G
dst.Pix[i+2] = c.B
dst.Pix[i+3] = c.A
i += 4
} }
// Copy the first row to other rows.
size := width * 4
parallel(1, height, func(ys <-chan int) {
for y := range ys {
i = y * dst.Stride
copy(dst.Pix[i:i+size], dst.Pix[0:size])
}
})
return dst
} }
// Clone returns a copy of the given image. // Clone returns a copy of the given image.

View File

@ -529,7 +529,7 @@ func (cli *Client) ForgetRoom(roomID string) (resp *RespForgetRoom, err error) {
// InviteUser invites a user to a room. See http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-invite // InviteUser invites a user to a room. See http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-invite
func (cli *Client) InviteUser(roomID string, req *ReqInviteUser) (resp *RespInviteUser, err error) { func (cli *Client) InviteUser(roomID string, req *ReqInviteUser) (resp *RespInviteUser, err error) {
u := cli.BuildURL("rooms", roomID, "invite") u := cli.BuildURL("rooms", roomID, "invite")
_, err = cli.MakeRequest("POST", u, struct{}{}, &resp) _, err = cli.MakeRequest("POST", u, req, &resp)
return return
} }

View File

@ -14,6 +14,8 @@
package gomatrix package gomatrix
import "errors"
//Filter is used by clients to specify how the server should filter responses to e.g. sync requests //Filter is used by clients to specify how the server should filter responses to e.g. sync requests
//Specified by: https://matrix.org/docs/spec/client_server/r0.2.0.html#filtering //Specified by: https://matrix.org/docs/spec/client_server/r0.2.0.html#filtering
type Filter struct { type Filter struct {
@ -21,7 +23,11 @@ type Filter struct {
EventFields []string `json:"event_fields,omitempty"` EventFields []string `json:"event_fields,omitempty"`
EventFormat string `json:"event_format,omitempty"` EventFormat string `json:"event_format,omitempty"`
Presence FilterPart `json:"presence,omitempty"` Presence FilterPart `json:"presence,omitempty"`
Room struct { Room RoomFilter `json:"room,omitempty"`
}
// RoomFilter is used to define filtering rules for room events
type RoomFilter struct {
AccountData FilterPart `json:"account_data,omitempty"` AccountData FilterPart `json:"account_data,omitempty"`
Ephemeral FilterPart `json:"ephemeral,omitempty"` Ephemeral FilterPart `json:"ephemeral,omitempty"`
IncludeLeave bool `json:"include_leave,omitempty"` IncludeLeave bool `json:"include_leave,omitempty"`
@ -29,15 +35,56 @@ type Filter struct {
Rooms []string `json:"rooms,omitempty"` Rooms []string `json:"rooms,omitempty"`
State FilterPart `json:"state,omitempty"` State FilterPart `json:"state,omitempty"`
Timeline FilterPart `json:"timeline,omitempty"` Timeline FilterPart `json:"timeline,omitempty"`
} `json:"room,omitempty"`
} }
// FilterPart is used to define filtering rules for specific categories of events
type FilterPart struct { type FilterPart struct {
NotRooms []string `json:"not_rooms,omitempty"` NotRooms []string `json:"not_rooms,omitempty"`
Rooms []string `json:"rooms,omitempty"` Rooms []string `json:"rooms,omitempty"`
Limit *int `json:"limit,omitempty"` Limit int `json:"limit,omitempty"`
NotSenders []string `json:"not_senders,omitempty"` NotSenders []string `json:"not_senders,omitempty"`
NotTypes []string `json:"not_types,omitempty"` NotTypes []string `json:"not_types,omitempty"`
Senders []string `json:"senders,omitempty"` Senders []string `json:"senders,omitempty"`
Types []string `json:"types,omitempty"` Types []string `json:"types,omitempty"`
ContainsURL *bool `json:"contains_url,omitempty"`
}
// Validate checks if the filter contains valid property values
func (filter *Filter) Validate() error {
if filter.EventFormat != "client" && filter.EventFormat != "federation" {
return errors.New("Bad event_format value. Must be one of [\"client\", \"federation\"]")
}
return nil
}
// DefaultFilter returns the default filter used by the Matrix server if no filter is provided in the request
func DefaultFilter() Filter {
return Filter{
AccountData: DefaultFilterPart(),
EventFields: nil,
EventFormat: "client",
Presence: DefaultFilterPart(),
Room: RoomFilter{
AccountData: DefaultFilterPart(),
Ephemeral: DefaultFilterPart(),
IncludeLeave: false,
NotRooms: nil,
Rooms: nil,
State: DefaultFilterPart(),
Timeline: DefaultFilterPart(),
},
}
}
// DefaultFilterPart returns the default filter part used by the Matrix server if no filter is provided in the request
func DefaultFilterPart() FilterPart {
return FilterPart{
NotRooms: nil,
Rooms: nil,
Limit: 20,
NotSenders: nil,
NotTypes: nil,
Senders: nil,
Types: nil,
}
} }