Skip to content

Commit

Permalink
fix(matchmake-extension): Fix incorrect SQL query for notifications
Browse files Browse the repository at this point in the history
Also improve and fix the NotificationData methods.
  • Loading branch information
DaniElectra committed Jan 30, 2025
1 parent 21b019a commit 569a569
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
7 changes: 7 additions & 0 deletions matchmake-extension/database/get_notification_datas.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ func GetNotificationDatas(manager *common_globals.MatchmakingManager, sourcePID
var friendList []uint32
if manager.GetUserFriendPIDs != nil {
friendList = manager.GetUserFriendPIDs(uint32(sourcePID))
} else {
common_globals.Logger.Warning("GetNotificationDatas missing manager.GetUserFriendPIDs!")
}

// * No friends to check
if len(friendList) == 0 {
return dataList, nil
}

rows, err := manager.Database.Query(`SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
func InactivateNotificationDatas(manager *common_globals.MatchmakingManager, sourcePID types.PID) *nex.Error {
_, err := manager.Database.Exec(`UPDATE matchmaking.notifications SET active=false WHERE source_pid=$1`, sourcePID)
if err != nil {
common_globals.Logger.Error(err.Error())
return nex.NewError(nex.ResultCodes.Core.Unknown, err.Error())
}

Expand Down
4 changes: 2 additions & 2 deletions matchmake-extension/database/update_notification_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

// UpdateNotificationData updates the notification data of the specified user and type
func UpdateNotificationData(manager *common_globals.MatchmakingManager, notificationData notifications_types.NotificationEvent) *nex.Error {
_, err := manager.Database.Exec(`INSERT INTO matchmaking.notifications (
_, err := manager.Database.Exec(`INSERT INTO matchmaking.notifications AS n (
source_pid,
type,
param_1,
Expand All @@ -21,7 +21,7 @@ func UpdateNotificationData(manager *common_globals.MatchmakingManager, notifica
$4,
$5
) ON CONFLICT (source_pid, type) DO UPDATE SET
param_1=$3, param_2=$4, param_str=$5, active=true WHERE source_pid=$1 AND type=$2`,
param_1=$3, param_2=$4, param_str=$5, active=true WHERE n.source_pid=$1 AND n.type=$2`,
notificationData.PIDSource,
notificationData.Type,
notificationData.Param1,
Expand Down
3 changes: 2 additions & 1 deletion matchmake-extension/get_friend_notification_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
"github.com/PretendoNetwork/nex-protocols-common-go/v2/matchmake-extension/database"
matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension"
notifications "github.com/PretendoNetwork/nex-protocols-go/v2/notifications"
notifications_types "github.com/PretendoNetwork/nex-protocols-go/v2/notifications/types"
)

Expand All @@ -25,7 +26,7 @@ func (commonProtocol *CommonProtocol) getFriendNotificationData(err error, packe

commonProtocol.manager.Mutex.RLock()

notificationDatas, nexError := database.GetNotificationDatas(commonProtocol.manager, connection.PID(), []uint32{uint32(uiType)})
notificationDatas, nexError := database.GetNotificationDatas(commonProtocol.manager, connection.PID(), []uint32{notifications.BuildNotificationType(uint32(uiType), 0)})
if nexError != nil {
commonProtocol.manager.Mutex.RUnlock()
return nil, nexError
Expand Down
3 changes: 2 additions & 1 deletion matchmake-extension/get_lst_friend_notification_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/PretendoNetwork/nex-go/v2"
"github.com/PretendoNetwork/nex-go/v2/types"
matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension"
notifications "github.com/PretendoNetwork/nex-protocols-go/v2/notifications"
notifications_types "github.com/PretendoNetwork/nex-protocols-go/v2/notifications/types"
common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals"
"github.com/PretendoNetwork/nex-protocols-common-go/v2/matchmake-extension/database"
Expand All @@ -25,7 +26,7 @@ func (commonProtocol *CommonProtocol) getlstFriendNotificationData(err error, pa
return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error")
}

notificationTypes[i] = uint32(notificationType)
notificationTypes[i] = notifications.BuildNotificationType(uint32(notificationType), 0)
}

commonProtocol.manager.Mutex.RLock()
Expand Down

0 comments on commit 569a569

Please sign in to comment.