mirror of
https://github.com/PretendoNetwork/friends.git
synced 2024-06-01 11:37:53 -04:00
2f80336681
Replace MongoDB usage with GRPC calls to the account server. Also include documentation on the README and a Makefile.
41 lines
1.3 KiB
Go
41 lines
1.3 KiB
Go
package database_wiiu
|
|
|
|
import (
|
|
"database/sql"
|
|
|
|
"github.com/PretendoNetwork/friends/database"
|
|
)
|
|
|
|
func SaveFriendRequest(senderPID uint32, recipientPID uint32, sentTime uint64, expireTime uint64, message string) (uint64, error) {
|
|
var id uint64
|
|
|
|
friendRequestBlocked := IsFriendRequestBlocked(recipientPID, senderPID)
|
|
|
|
// Make sure we don't already have that friend request! If we do, give them the one we already have.
|
|
err := database.Postgres.QueryRow(`SELECT id FROM wiiu.friend_requests WHERE sender_pid=$1 AND recipient_pid=$2`, senderPID, recipientPID).Scan(&id)
|
|
if err != nil && err != sql.ErrNoRows {
|
|
return 0, err
|
|
} else if id != 0 {
|
|
// If they aren't blocked, we want to unset the denied status on the previous request we have so that it appears again.
|
|
if friendRequestBlocked {
|
|
return id, nil
|
|
} else {
|
|
err = UnsetFriendRequestDenied(id)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
return id, nil
|
|
}
|
|
}
|
|
|
|
err = database.Postgres.QueryRow(`
|
|
INSERT INTO wiiu.friend_requests (sender_pid, recipient_pid, sent_on, expires_on, message, received, accepted, denied)
|
|
VALUES ($1, $2, $3, $4, $5, false, false, $6) RETURNING id`, senderPID, recipientPID, sentTime, expireTime, message, friendRequestBlocked).Scan(&id)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
return id, nil
|
|
}
|