From 066cd7e04899714ae55ecca49e0b044085cb689e Mon Sep 17 00:00:00 2001 From: Andrei Mihu Date: Wed, 1 Aug 2018 13:53:02 +0100 Subject: [PATCH] Improve handling of blocked user list when importing friends from Facebook. --- CHANGELOG.md | 1 + server/core_authenticate.go | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 072c4938bd..a0f10155c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr ### Fixed - Runtime module loading now correctly handles paths on non-UNIX environments. +- Correctly handle blocked user list when importing friends from Facebook. ## [2.0.2] - 2018-07-09 ### Added diff --git a/server/core_authenticate.go b/server/core_authenticate.go index 8ee43b12de..f375f97b91 100644 --- a/server/core_authenticate.go +++ b/server/core_authenticate.go @@ -626,17 +626,25 @@ func importFacebookFriends(logger *zap.Logger, db *sql.DB, messageRouter Message } return err } - defer rows.Close() var id string + possibleFriendIDs := make([]uuid.UUID, 0) for rows.Next() { - position := time.Now().UTC().UnixNano() err = rows.Scan(&id) if err != nil { // Error scanning the ID, try to skip this user and move on. continue } - friendID := uuid.FromStringOrNil(id) + friendID, err := uuid.FromString(id) + if err != nil { + continue + } + possibleFriendIDs = append(possibleFriendIDs, friendID) + } + rows.Close() + + for _, friendID := range possibleFriendIDs { + position := time.Now().UTC().UnixNano() var r *sql.Rows r, err = tx.Query("SELECT state FROM user_edge WHERE source_id = $1 AND destination_id = $2 AND state = 3", userID, friendID)