Fix more linting issues and docs

Signed-off-by: Alex Chen <minecnly@gmail.com>
This commit is contained in:
Cnly 2019-06-26 17:46:08 +08:00
parent e6870279ed
commit 18c59e68cd
2 changed files with 10 additions and 7 deletions

View file

@ -72,7 +72,7 @@ func (n *Notifier) OnNewEvent(ev *gomatrixserverlib.Event, roomID string, userID
if ev != nil { if ev != nil {
// Map this event's room_id to a list of joined users, and wake them up. // 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 this is an invite, also add in the invitee to this list.
if ev.Type() == "m.room.member" && ev.StateKey() != nil { if ev.Type() == "m.room.member" && ev.StateKey() != nil {
targetUserID := *ev.StateKey() 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 // Keep the joined user map up-to-date
switch membership { switch membership {
case "invite": case "invite":
userIDs = append(userIDs, targetUserID) usersToNotify = append(usersToNotify, targetUserID)
case "join": case "join":
// Manually append the new user's ID so they get notified // Manually append the new user's ID so they get notified
// along all members in the room // along all members in the room
userIDs = append(userIDs, targetUserID) usersToNotify = append(usersToNotify, targetUserID)
n.addJoinedUser(ev.RoomID(), targetUserID) n.addJoinedUser(ev.RoomID(), targetUserID)
case "leave": case "leave":
fallthrough 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 != "" { } else if roomID != "" {
n.wakeupUsers(n.joinedUsers(roomID), pos) n.wakeupUsers(n.joinedUsers(roomID), pos)
} else if len(userIDs) > 0 { } else if len(userIDs) > 0 {

View file

@ -76,7 +76,7 @@ func getTimeout(timeoutMS string) time.Duration {
// getSyncStreamPosition tries to parse a 'since' token taken from the API to a // 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. // 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 // all PDU and EDU positions. The second only contains the PDU position; prev_batch
// tokens generated by the server will be in this form. // tokens generated by the server will be in this form.
func getSyncStreamPosition(since string) (*types.SyncPosition, error) { func getSyncStreamPosition(since string) (*types.SyncPosition, error) {
@ -86,6 +86,7 @@ func getSyncStreamPosition(since string) (*types.SyncPosition, error) {
posStrings := strings.Split(since, "_") posStrings := strings.Split(since, "_")
if len(posStrings) != 2 && len(posStrings) != 1 { 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") return nil, errors.New("malformed batch token")
} }
@ -99,8 +100,10 @@ func getSyncStreamPosition(since string) (*types.SyncPosition, error) {
} }
if len(positions) == 2 { if len(positions) == 2 {
// Normal length token // Full length token; construct SyncPosition with every entry in
return &types.SyncPosition{ // `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], positions[0], positions[1],
}, nil }, nil
} else { } else {