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 {
// 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 {

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
// 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 {