mirror of
https://github.com/PretendoNetwork/friends.git
synced 2026-04-25 23:37:46 -05:00
Now database getters do error handling aswell, and in case of any error, the NEX or GRPC method throws a proper error about it. There are still some doubts on how to handle errors when a list of data is processed, so for now skip that element on the list and continue. Also add some constant errors to do better error handling.
58 lines
1.9 KiB
Go
58 lines
1.9 KiB
Go
package database_3ds
|
|
|
|
import (
|
|
"database/sql"
|
|
"time"
|
|
|
|
"github.com/PretendoNetwork/friends/database"
|
|
"github.com/PretendoNetwork/friends/globals"
|
|
"github.com/PretendoNetwork/nex-go"
|
|
friends_3ds_types "github.com/PretendoNetwork/nex-protocols-go/friends-3ds/types"
|
|
)
|
|
|
|
// GetFriendPersistentInfos returns the persistent information of all friends
|
|
func GetFriendPersistentInfos(user1_pid uint32, pids []uint32) ([]*friends_3ds_types.FriendPersistentInfo, error) {
|
|
persistentInfos := make([]*friends_3ds_types.FriendPersistentInfo, 0)
|
|
|
|
rows, err := database.Postgres.Query(`
|
|
SELECT pid, region, area, language, favorite_title, favorite_title_version, comment, comment_changed, last_online FROM "3ds".user_data WHERE pid IN ($1)`, database.PIDArrayToString(pids))
|
|
if err != nil {
|
|
return persistentInfos, err
|
|
}
|
|
|
|
for rows.Next() {
|
|
persistentInfo := friends_3ds_types.NewFriendPersistentInfo()
|
|
|
|
gameKey := friends_3ds_types.NewGameKey()
|
|
|
|
var lastOnlineTime uint64
|
|
var msgUpdateTime uint64
|
|
var friendedAtTime uint64
|
|
|
|
rows.Scan(
|
|
&persistentInfo.PID, &persistentInfo.Region, &persistentInfo.Area, &persistentInfo.Language,
|
|
&gameKey.TitleID, &gameKey.TitleVersion, &persistentInfo.Message, &msgUpdateTime, &lastOnlineTime)
|
|
|
|
err = database.Postgres.QueryRow(`
|
|
SELECT date FROM "3ds".friendships WHERE user1_pid=$1 AND user2_pid=$2 AND type=0 LIMIT 1`, user1_pid, persistentInfo.PID).Scan(&friendedAtTime)
|
|
if err != nil {
|
|
if err == sql.ErrNoRows {
|
|
friendedAtTime = uint64(time.Now().Unix())
|
|
} else {
|
|
globals.Logger.Critical(err.Error())
|
|
continue
|
|
}
|
|
}
|
|
|
|
persistentInfo.MessageUpdatedAt = nex.NewDateTime(msgUpdateTime)
|
|
persistentInfo.FriendedAt = nex.NewDateTime(friendedAtTime)
|
|
persistentInfo.LastOnline = nex.NewDateTime(lastOnlineTime)
|
|
persistentInfo.GameKey = gameKey
|
|
persistentInfo.Platform = 2 // Always 3DS
|
|
|
|
persistentInfos = append(persistentInfos, persistentInfo)
|
|
}
|
|
|
|
return persistentInfos, nil
|
|
}
|