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

[federation] Implement get missing events api#516

Merged
APwhitehat merged 4 commits intomatrix-org:masterfrom
APwhitehat:getMissingEvents
Jun 26, 2018
Merged

[federation] Implement get missing events api#516
APwhitehat merged 4 commits intomatrix-org:masterfrom
APwhitehat:getMissingEvents

Conversation

@APwhitehat
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 ?

AllowedToSeeEvent bool `json:"can_see_event"`
}

// QueryMissingEventsRequest is request to QueryMissingEvents
Copy link
Copy Markdown
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

"returns missing events"


// QueryMissingEventsRequest is request to QueryMissingEvents
type QueryMissingEventsRequest struct {
// Events which are known previous to the gap in timeline.
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[federation] Implement missing events API

3 participants