From 18c59e68cdc2801f36bc4bee2403a2d2483b84fd Mon Sep 17 00:00:00 2001 From: Cnly Date: Wed, 26 Jun 2019 17:46:08 +0800 Subject: [PATCH] Fix more linting issues and docs Signed-off-by: Alex Chen --- syncapi/sync/notifier.go | 8 ++++---- syncapi/sync/request.go | 9 ++++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/syncapi/sync/notifier.go b/syncapi/sync/notifier.go index 0bc90dbae..2f4d2cde7 100644 --- a/syncapi/sync/notifier.go +++ b/syncapi/sync/notifier.go @@ -72,7 +72,7 @@ func (n *Notifier) OnNewEvent(ev *gomatrixserverlib.Event, roomID string, userID if ev != nil { // Map this event's room_id to a list of joined users, and wake them up. - userIDs := n.joinedUsers(ev.RoomID()) + usersToNotify := n.joinedUsers(ev.RoomID()) // If this is an invite, also add in the invitee to this list. if ev.Type() == "m.room.member" && ev.StateKey() != nil { targetUserID := *ev.StateKey() @@ -85,11 +85,11 @@ func (n *Notifier) OnNewEvent(ev *gomatrixserverlib.Event, roomID string, userID // Keep the joined user map up-to-date switch membership { case "invite": - userIDs = append(userIDs, targetUserID) + usersToNotify = append(usersToNotify, targetUserID) case "join": // Manually append the new user's ID so they get notified // along all members in the room - userIDs = append(userIDs, targetUserID) + usersToNotify = append(usersToNotify, targetUserID) n.addJoinedUser(ev.RoomID(), targetUserID) case "leave": fallthrough @@ -99,7 +99,7 @@ func (n *Notifier) OnNewEvent(ev *gomatrixserverlib.Event, roomID string, userID } } - n.wakeupUsers(userIDs, pos) + n.wakeupUsers(usersToNotify, pos) } else if roomID != "" { n.wakeupUsers(n.joinedUsers(roomID), pos) } else if len(userIDs) > 0 { diff --git a/syncapi/sync/request.go b/syncapi/sync/request.go index a2a1b1001..371ecd015 100644 --- a/syncapi/sync/request.go +++ b/syncapi/sync/request.go @@ -76,7 +76,7 @@ func getTimeout(timeoutMS string) time.Duration { // getSyncStreamPosition tries to parse a 'since' token taken from the API to a // stream position. If the string is empty then (nil, nil) is returned. -// There are two types of token: The first is a normal length one containing +// There are two types of token: The first is a full length one containing // all PDU and EDU positions. The second only contains the PDU position; prev_batch // tokens generated by the server will be in this form. func getSyncStreamPosition(since string) (*types.SyncPosition, error) { @@ -86,6 +86,7 @@ func getSyncStreamPosition(since string) (*types.SyncPosition, error) { posStrings := strings.Split(since, "_") if len(posStrings) != 2 && len(posStrings) != 1 { + // A token can either be a full length one or a short (PDU-only) one return nil, errors.New("malformed batch token") } @@ -99,8 +100,10 @@ func getSyncStreamPosition(since string) (*types.SyncPosition, error) { } if len(positions) == 2 { - // Normal length token - return &types.SyncPosition{ + // Full length token; construct SyncPosition with every entry in + // `positions`. These entries must have the same order with the fields + // in struct SyncPosition, so we disable the govet check below. + return &types.SyncPosition{ //nolint:govet positions[0], positions[1], }, nil } else {