From 1cfdb247e6dd8037c5d8efa2057d6e3be8a3adb2 Mon Sep 17 00:00:00 2001 From: Jonathan Barrow Date: Wed, 28 Sep 2022 20:59:54 -0400 Subject: [PATCH] Reactivate friendships if existed before --- ...accept_friendship_and_return_friend_info.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/database/wiiu/accept_friendship_and_return_friend_info.go b/database/wiiu/accept_friendship_and_return_friend_info.go index 724d4a4..af548c2 100644 --- a/database/wiiu/accept_friendship_and_return_friend_info.go +++ b/database/wiiu/accept_friendship_and_return_friend_info.go @@ -28,13 +28,27 @@ func AcceptFriendshipAndReturnFriendInfo(friendRequestID uint64) *nexproto.Frien // Friendships are two-way relationships, not just one link between 2 entities // "A" has friend "B" and "B" has friend "A", so store both relationships - _, err = database.Postgres.Exec(`INSERT INTO wiiu.friendships (user1_pid, user2_pid, date, active) VALUES ($1, $2, $3, true)`, senderPID, recipientPID, acceptedTime.Value()) + // If were friends before, just activate the status again + + _, err = database.Postgres.Exec(` + INSERT INTO wiiu.friendships (user1_pid, user2_pid, date, active) + VALUES ($1, $2, $3, true) + ON CONFLICT (user1_pid, user2_pid) + DO UPDATE SET + date = $3 + active = true`, senderPID, recipientPID, acceptedTime.Value()) if err != nil { globals.Logger.Critical(err.Error()) return nil } - _, err = database.Postgres.Exec(`INSERT INTO wiiu.friendships (user1_pid, user2_pid, date, active) VALUES ($1, $2, $3, true)`, recipientPID, senderPID, acceptedTime.Value()) + _, err = database.Postgres.Exec(` + INSERT INTO wiiu.friendships (user1_pid, user2_pid, date, active) + VALUES ($1, $2, $3, true) + ON CONFLICT (user1_pid, user2_pid) + DO UPDATE SET + date = $3 + active = true`, recipientPID, senderPID, acceptedTime.Value()) if err != nil { globals.Logger.Critical(err.Error()) return nil