From d63d2a50cdce891e6d4159919b304ce0c66ac0c5 Mon Sep 17 00:00:00 2001 From: Alex Chen Date: Fri, 16 Aug 2019 01:45:11 +0800 Subject: [PATCH] Replace event content types with ones in gomatrixserverlib (#785) The types that are not in gomatrixserverlib are not replaced. This also updates the gomatrixserverlib dependency. --- clientapi/routing/createroom.go | 6 +- clientapi/routing/membership.go | 2 +- clientapi/routing/profile.go | 2 +- clientapi/threepid/invites.go | 10 ++-- common/eventcontent.go | 95 ++++--------------------------- federationapi/routing/threepid.go | 19 +++---- go.mod | 2 +- go.sum | 2 + 8 files changed, 33 insertions(+), 105 deletions(-) diff --git a/clientapi/routing/createroom.go b/clientapi/routing/createroom.go index 4a76e1b06..620246d28 100644 --- a/clientapi/routing/createroom.go +++ b/clientapi/routing/createroom.go @@ -106,7 +106,7 @@ func (r createRoomRequest) Validate() *util.JSONResponse { } } - var CreationContent common.CreateContent + var CreationContent gomatrixserverlib.CreateContent err = json.Unmarshal(creationContentBytes, &CreationContent) if err != nil { return &util.JSONResponse{ @@ -196,7 +196,7 @@ func createRoom( return httputil.LogThenError(req, err) } - membershipContent := common.MemberContent{ + membershipContent := gomatrixserverlib.MemberContent{ Membership: gomatrixserverlib.Join, DisplayName: profile.DisplayName, AvatarURL: profile.AvatarURL, @@ -246,7 +246,7 @@ func createRoom( {"m.room.member", userID, membershipContent}, {"m.room.power_levels", "", common.InitialPowerLevelsContent(userID)}, // TODO: m.room.canonical_alias - {"m.room.join_rules", "", common.JoinRulesContent{JoinRule: joinRules}}, + {"m.room.join_rules", "", gomatrixserverlib.JoinRuleContent{JoinRule: joinRules}}, {"m.room.history_visibility", "", common.HistoryVisibilityContent{HistoryVisibility: historyVisibility}}, } if r.GuestCanJoin { diff --git a/clientapi/routing/membership.go b/clientapi/routing/membership.go index 5e183fa0f..c71ac2de2 100644 --- a/clientapi/routing/membership.go +++ b/clientapi/routing/membership.go @@ -144,7 +144,7 @@ func buildMembershipEvent( membership = gomatrixserverlib.Leave } - content := common.MemberContent{ + content := gomatrixserverlib.MemberContent{ Membership: membership, DisplayName: profile.DisplayName, AvatarURL: profile.AvatarURL, diff --git a/clientapi/routing/profile.go b/clientapi/routing/profile.go index e8ea6cf13..a87c6f743 100644 --- a/clientapi/routing/profile.go +++ b/clientapi/routing/profile.go @@ -332,7 +332,7 @@ func buildMembershipEvents( StateKey: &userID, } - content := common.MemberContent{ + content := gomatrixserverlib.MemberContent{ Membership: gomatrixserverlib.Join, } diff --git a/clientapi/threepid/invites.go b/clientapi/threepid/invites.go index 251afb0d3..bfe5060a8 100644 --- a/clientapi/threepid/invites.go +++ b/clientapi/threepid/invites.go @@ -56,10 +56,10 @@ type idServerLookupResponse struct { // idServerLookupResponse represents the response described at https://matrix.org/docs/spec/client_server/r0.2.0.html#invitation-storage type idServerStoreInviteResponse struct { - PublicKey string `json:"public_key"` - Token string `json:"token"` - DisplayName string `json:"display_name"` - PublicKeys []common.PublicKey `json:"public_keys"` + PublicKey string `json:"public_key"` + Token string `json:"token"` + DisplayName string `json:"display_name"` + PublicKeys []gomatrixserverlib.PublicKey `json:"public_keys"` } var ( @@ -342,7 +342,7 @@ func emit3PIDInviteEvent( } validityURL := fmt.Sprintf("https://%s/_matrix/identity/api/v1/pubkey/isvalid", body.IDServer) - content := common.ThirdPartyInviteContent{ + content := gomatrixserverlib.ThirdPartyInviteContent{ DisplayName: res.DisplayName, KeyValidityURL: validityURL, PublicKey: res.PublicKey, diff --git a/common/eventcontent.go b/common/eventcontent.go index c45724fcd..c07c56276 100644 --- a/common/eventcontent.go +++ b/common/eventcontent.go @@ -14,55 +14,7 @@ package common -// CreateContent is the event content for http://matrix.org/docs/spec/client_server/r0.2.0.html#m-room-create -type CreateContent struct { - Creator string `json:"creator"` - Federate *bool `json:"m.federate,omitempty"` - RoomVersion string `json:"room_version,omitempty"` - Predecessor PreviousRoom `json:"predecessor,omitempty"` -} - -// PreviousRoom is the "Previous Room" structure defined at https://matrix.org/docs/spec/client_server/r0.5.0#m-room-create -type PreviousRoom struct { - RoomID string `json:"room_id"` - EventID string `json:"event_id"` -} - -// MemberContent is the event content for http://matrix.org/docs/spec/client_server/r0.2.0.html#m-room-member -type MemberContent struct { - Membership string `json:"membership"` - DisplayName string `json:"displayname,omitempty"` - AvatarURL string `json:"avatar_url,omitempty"` - Reason string `json:"reason,omitempty"` - ThirdPartyInvite *TPInvite `json:"third_party_invite,omitempty"` -} - -// TPInvite is the "Invite" structure defined at http://matrix.org/docs/spec/client_server/r0.2.0.html#m-room-member -type TPInvite struct { - DisplayName string `json:"display_name"` - Signed TPInviteSigned `json:"signed"` -} - -// TPInviteSigned is the "signed" structure defined at http://matrix.org/docs/spec/client_server/r0.2.0.html#m-room-member -type TPInviteSigned struct { - MXID string `json:"mxid"` - Signatures map[string]map[string]string `json:"signatures"` - Token string `json:"token"` -} - -// ThirdPartyInviteContent is the content event for https://matrix.org/docs/spec/client_server/r0.2.0.html#m-room-third-party-invite -type ThirdPartyInviteContent struct { - DisplayName string `json:"display_name"` - KeyValidityURL string `json:"key_validity_url"` - PublicKey string `json:"public_key"` - PublicKeys []PublicKey `json:"public_keys"` -} - -// PublicKey is the PublicKeys structure in https://matrix.org/docs/spec/client_server/r0.2.0.html#m-room-third-party-invite -type PublicKey struct { - KeyValidityURL string `json:"key_validity_url"` - PublicKey string `json:"public_key"` -} +import "github.com/matrix-org/gomatrixserverlib" // NameContent is the event content for https://matrix.org/docs/spec/client_server/r0.2.0.html#m-room-name type NameContent struct { @@ -79,51 +31,26 @@ type GuestAccessContent struct { GuestAccess string `json:"guest_access"` } -// JoinRulesContent is the event content for http://matrix.org/docs/spec/client_server/r0.2.0.html#m-room-join-rules -type JoinRulesContent struct { - JoinRule string `json:"join_rule"` -} - // HistoryVisibilityContent is the event content for http://matrix.org/docs/spec/client_server/r0.2.0.html#m-room-history-visibility type HistoryVisibilityContent struct { HistoryVisibility string `json:"history_visibility"` } -// PowerLevelContent is the event content for http://matrix.org/docs/spec/client_server/r0.2.0.html#m-room-power-levels -type PowerLevelContent struct { - EventsDefault int `json:"events_default"` - Invite int `json:"invite"` - StateDefault int `json:"state_default"` - Redact int `json:"redact"` - Ban int `json:"ban"` - UsersDefault int `json:"users_default"` - Events map[string]int `json:"events"` - Kick int `json:"kick"` - Users map[string]int `json:"users"` -} - // InitialPowerLevelsContent returns the initial values for m.room.power_levels on room creation // if they have not been specified. // http://matrix.org/docs/spec/client_server/r0.2.0.html#m-room-power-levels // https://github.com/matrix-org/synapse/blob/v0.19.2/synapse/handlers/room.py#L294 -func InitialPowerLevelsContent(roomCreator string) PowerLevelContent { - return PowerLevelContent{ - EventsDefault: 0, - Invite: 0, - StateDefault: 50, - Redact: 50, - Ban: 50, - UsersDefault: 0, - Events: map[string]int{ - "m.room.name": 50, - "m.room.power_levels": 100, - "m.room.history_visibility": 100, - "m.room.canonical_alias": 50, - "m.room.avatar": 50, - }, - Kick: 50, - Users: map[string]int{roomCreator: 100}, +func InitialPowerLevelsContent(roomCreator string) (c gomatrixserverlib.PowerLevelContent) { + c.Defaults() + c.Events = map[string]int64{ + "m.room.name": 50, + "m.room.power_levels": 100, + "m.room.history_visibility": 100, + "m.room.canonical_alias": 50, + "m.room.avatar": 50, } + c.Users = map[string]int64{roomCreator: 100} + return c } // AliasesContent is the event content for http://matrix.org/docs/spec/client_server/r0.2.0.html#m-room-aliases diff --git a/federationapi/routing/threepid.go b/federationapi/routing/threepid.go index cff311cc4..7fa02be91 100644 --- a/federationapi/routing/threepid.go +++ b/federationapi/routing/threepid.go @@ -27,7 +27,6 @@ import ( "github.com/matrix-org/dendrite/clientapi/httputil" "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/clientapi/producers" - "github.com/matrix-org/dendrite/common" "github.com/matrix-org/dendrite/common/config" roomserverAPI "github.com/matrix-org/dendrite/roomserver/api" @@ -38,11 +37,11 @@ import ( ) type invite struct { - MXID string `json:"mxid"` - RoomID string `json:"room_id"` - Sender string `json:"sender"` - Token string `json:"token"` - Signed common.TPInviteSigned `json:"signed"` + MXID string `json:"mxid"` + RoomID string `json:"room_id"` + Sender string `json:"sender"` + Token string `json:"token"` + Signed gomatrixserverlib.MemberThirdPartyInviteSigned `json:"signed"` } type invites struct { @@ -199,11 +198,11 @@ func createInviteFrom3PIDInvite( return nil, err } - content := common.MemberContent{ + content := gomatrixserverlib.MemberContent{ AvatarURL: profile.AvatarURL, DisplayName: profile.DisplayName, Membership: gomatrixserverlib.Invite, - ThirdPartyInvite: &common.TPInvite{ + ThirdPartyInvite: &gomatrixserverlib.MemberThirdPartyInvite{ Signed: inv.Signed, }, } @@ -330,7 +329,7 @@ func sendToRemoteServer( func fillDisplayName( builder *gomatrixserverlib.EventBuilder, authEvents gomatrixserverlib.AuthEvents, ) error { - var content common.MemberContent + var content gomatrixserverlib.MemberContent if err := json.Unmarshal(builder.Content, &content); err != nil { return err } @@ -343,7 +342,7 @@ func fillDisplayName( return nil } - var thirdPartyInviteContent common.ThirdPartyInviteContent + var thirdPartyInviteContent gomatrixserverlib.ThirdPartyInviteContent if err := json.Unmarshal(thirdPartyInviteEvent.Content(), &thirdPartyInviteContent); err != nil { return err } diff --git a/go.mod b/go.mod index 8e14253ca..d51f0a33e 100644 --- a/go.mod +++ b/go.mod @@ -24,7 +24,7 @@ require ( github.com/lib/pq v0.0.0-20170918175043-23da1db4f16d github.com/matrix-org/dugong v0.0.0-20171220115018-ea0a4690a0d5 github.com/matrix-org/gomatrix v0.0.0-20190528120928-7df988a63f26 - github.com/matrix-org/gomatrixserverlib v0.0.0-20190805173246-3a2199d5ecd6 + github.com/matrix-org/gomatrixserverlib v0.0.0-20190814163046-d6285a18401f github.com/matrix-org/naffka v0.0.0-20171115094957-662bfd0841d0 github.com/matrix-org/util v0.0.0-20171127121716-2e2df66af2f5 github.com/matttproud/golang_protobuf_extensions v1.0.1 diff --git a/go.sum b/go.sum index 0d59d1dd6..56781c9a6 100644 --- a/go.sum +++ b/go.sum @@ -58,6 +58,8 @@ github.com/matrix-org/gomatrixserverlib v0.0.0-20190724145009-a6df10ef35d6 h1:B8 github.com/matrix-org/gomatrixserverlib v0.0.0-20190724145009-a6df10ef35d6/go.mod h1:sf0RcKOdiwJeTti7A313xsaejNUGYDq02MQZ4JD4w/E= github.com/matrix-org/gomatrixserverlib v0.0.0-20190805173246-3a2199d5ecd6 h1:xr69Hk6QM3RIN6JSvx3RpDowBGpHpDDqhqXCeySwYow= github.com/matrix-org/gomatrixserverlib v0.0.0-20190805173246-3a2199d5ecd6/go.mod h1:sf0RcKOdiwJeTti7A313xsaejNUGYDq02MQZ4JD4w/E= +github.com/matrix-org/gomatrixserverlib v0.0.0-20190814163046-d6285a18401f h1:20CZL7ApB7xgR7sZF9yD/qpsP51Sfx0TTgUJ3vKgnZQ= +github.com/matrix-org/gomatrixserverlib v0.0.0-20190814163046-d6285a18401f/go.mod h1:sf0RcKOdiwJeTti7A313xsaejNUGYDq02MQZ4JD4w/E= github.com/matrix-org/naffka v0.0.0-20171115094957-662bfd0841d0 h1:p7WTwG+aXM86+yVrYAiCMW3ZHSmotVvuRbjtt3jC+4A= github.com/matrix-org/naffka v0.0.0-20171115094957-662bfd0841d0/go.mod h1:cXoYQIENbdWIQHt1SyCo6Bl3C3raHwJ0wgVrXHSqf+A= github.com/matrix-org/util v0.0.0-20171013132526-8b1c8ab81986 h1:TiWl4hLvezAhRPM8tPcPDFTysZ7k4T/1J4GPp/iqlZo=