mirror of
https://github.com/hoernschen/dendrite.git
synced 2024-12-27 07:28:27 +00:00
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.
This commit is contained in:
parent
d21a2fb152
commit
d63d2a50cd
8 changed files with 33 additions and 105 deletions
|
@ -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 {
|
||||
|
|
|
@ -144,7 +144,7 @@ func buildMembershipEvent(
|
|||
membership = gomatrixserverlib.Leave
|
||||
}
|
||||
|
||||
content := common.MemberContent{
|
||||
content := gomatrixserverlib.MemberContent{
|
||||
Membership: membership,
|
||||
DisplayName: profile.DisplayName,
|
||||
AvatarURL: profile.AvatarURL,
|
||||
|
|
|
@ -332,7 +332,7 @@ func buildMembershipEvents(
|
|||
StateKey: &userID,
|
||||
}
|
||||
|
||||
content := common.MemberContent{
|
||||
content := gomatrixserverlib.MemberContent{
|
||||
Membership: gomatrixserverlib.Join,
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
2
go.mod
2
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
|
||||
|
|
2
go.sum
2
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=
|
||||
|
|
Loading…
Reference in a new issue