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

[federation] Implement get missing events api #516

Merged
merged 4 commits into from
Jun 26, 2018

Conversation

APwhitehat
Copy link
Contributor

@APwhitehat APwhitehat commented Jun 22, 2018

Might be unnecessarily inefficient, suggestions are welcome.
fixes #492

Signed-off-by: Anant Prakash <anantprakashjsr@gmail.com>

Copy link
Member

@erikjohnston erikjohnston left a comment

Choose a reason for hiding this comment

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

Looks good! Just a couple of minor things.


func filterEvents(
events []gomatrixserverlib.Event, minDepth int64, roomID string,
) []gomatrixserverlib.Event {
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a quick docstring explaining what this does, as its not immediately obvious from the name nor return type.

return util.JSONResponse{
Code: http.StatusBadRequest,
JSON: jsonerror.NotJSON("The request body could not be decoded into valid JSON. " + err.Error()),
}
Copy link
Member

Choose a reason for hiding this comment

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

We should probably log an error too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't usually log badJSON errors, should I do it still ?

@@ -154,6 +154,24 @@ type QueryServerAllowedToSeeEventResponse struct {
AllowedToSeeEvent bool `json:"can_see_event"`
}

// QueryMissingEventsRequest is request to QueryMissingEvents
Copy link
Member

Choose a reason for hiding this comment

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

"is a request"

MinDepth int64 `json:"min_depth"`
}

// GetMissingEvents returns missing event between earliest_events & latest_events.
Copy link
Member

Choose a reason for hiding this comment

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

"returns missing events"

@@ -154,6 +154,24 @@ type QueryServerAllowedToSeeEventResponse struct {
AllowedToSeeEvent bool `json:"can_see_event"`
}

// QueryMissingEventsRequest is request to QueryMissingEvents
type QueryMissingEventsRequest struct {
// Events which are known previous to the gap in timeline.
Copy link
Member

Choose a reason for hiding this comment

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

"gap in the timeline"

ServerName gomatrixserverlib.ServerName `json:"server_name"`
}

// QueryMissingEventsResponse is response to QueryMissingEvents
Copy link
Member

Choose a reason for hiding this comment

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

"is a response"


import "github.com/matrix-org/gomatrixserverlib"

// IsServerAllowed checks if a server has a client as member in authEvents
Copy link
Member

Choose a reason for hiding this comment

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

Not quite sure what this means?

}

if domain == serverName {
isInRoom = true
Copy link
Member

Choose a reason for hiding this comment

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

Presumably you could just return true here, and return false after the for loop?

response.AllowedToSeeEvent = false
return nil
var err error
response.Events, err = r.loadEvents(ctx, resultNIDs)
Copy link
Member

Choose a reason for hiding this comment

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

Can remove the var err error line and just change ... err = r.loadEvents to ... err := r.loadEvents.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

response.Events is a declared variable. :/

Copy link
Member

Choose a reason for hiding this comment

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

Oh, turns out you can't := assign to non-identifiers. My bad :p

@APwhitehat APwhitehat merged commit 262fc25 into matrix-org:master Jun 26, 2018
@APwhitehat APwhitehat deleted the getMissingEvents branch June 26, 2018 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[federation] Implement missing events API
3 participants