Skip to content
This repository was archived by the owner on Nov 25, 2024. It is now read-only.

Implement server notices#2180

Merged
S7evinK merged 29 commits intomainfrom
s7evink/server-notices
Feb 18, 2022
Merged

Implement server notices#2180
S7evinK merged 29 commits intomainfrom
s7evink/server-notices

Conversation

@S7evinK
Copy link
Contributor

@S7evinK S7evinK commented Feb 11, 2022

This adds the unspecced server notices.
Synapse Docs:
admin api server_notices.md (for the request)
server_notices (for server side implementation details)

When the user is first sent a server notice, they will get an invitation to a room (typically called 'Server Notices', though this is configurable in homeserver.yaml). They will be unable to reject this invitation - attempts to do so will receive an error.

Once they accept the invitation, they will see the notice message in the room history; it will appear to have come from the 'server notices user' (see below).

The user is prevented from sending any messages in this room by the power levels.

Having joined the room, the user can leave the room if they want. Subsequent server notices will then cause a new room to be created.

Due to not having the history visibility yet, a message is sent, but the user can't see it after joining the room. After joining, subsequent messages show up correctly.

@S7evinK S7evinK mentioned this pull request Feb 15, 2022
Copy link
Member

@kegsay kegsay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly LGTM - how has this been tested?

username: metrics
password: metrics
server_notices:
local_part: "server"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be starting with _? That generally gets reserved by the HS as per AS API docs:

Exclusive user and alias namespaces should begin with an underscore after the sigil to avoid collisions with other users on the homeserver.


func (c *ServerNotices) Defaults(generate bool) {
if generate {
c.LocalPart = "server"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See before: maybe use _server?

}, accData); err != nil {
return nil, fmt.Errorf("unable to query account data")
}
roomData := accData.RoomAccountData[req.RoomID]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there is a guarantee that roomData is always non-nil? Don't you need to ok it?

// create a new room for the user
if len(commonRooms) == 0 {
powerLevelContent := eventutil.InitialPowerLevelsContent(senderUserID)
powerLevelContent.Users[r.UserID] = -10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not 0? Please quote synapse for things like this.

) (*userapi.Device, error) {
var accRes userapi.PerformAccountCreationResponse
// create account if it doesn't exist
err := userAPI.PerformAccountCreation(ctx, &userapi.PerformAccountCreationRequest{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be called every time this endpoint is invoked which surely isn't what's intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, forgot about moving this to routing.go.

Only add routes if sever notices are enabled
Check that we actually got roomData
@S7evinK
Copy link
Contributor Author

S7evinK commented Feb 15, 2022

Mostly LGTM - how has this been tested?

Since there's no spec for this, mostly manually with a local sqlite database and running curl with the required data.

@kegsay
Copy link
Member

kegsay commented Feb 15, 2022

Hmm, we can do better than that I think. I'll see if I can hook up admin user support in Complement and then we can actually test this in CI.

@kegsay
Copy link
Member

kegsay commented Feb 17, 2022

I'll work to add admin support in Complement today so we can test then merge this.

@kegsay
Copy link
Member

kegsay commented Feb 17, 2022

Tests can now be added to Complement.

Enable server notices for CI
Return same values as Synapse
return util.JSONResponse{
Code: leaveRes.Code,
JSON: jsonerror.Forbidden(leaveRes.Message),
JSON: jsonerror.LeaveServerNoticeError(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no guarantee that this is because of server notices though?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PerformLeaveResponse struct just got the Code in 2e1e0c81a19830cbf2055a6d15c5d7424c2d0087, so right now it should be guaranteed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not very extensible or kind to the next person who wants to add an additional code :) it would be nicer to just proxy back the JSON blob to send back so instead of Message string having Message interface{} which is JSON serialisable should work.

Copy link
Member

@kegsay kegsay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking fantastic, and the passing tests gives me much confidence this PR does what we think it should do. Excellent work!

@kegsay kegsay marked this pull request as ready for review February 18, 2022 14:53
@kegsay kegsay requested a review from a team as a code owner February 18, 2022 14:53
@S7evinK S7evinK merged commit 002429c into main Feb 18, 2022
@S7evinK S7evinK deleted the s7evink/server-notices branch February 18, 2022 15:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants