@@ -3049,6 +3049,57 @@ public static function getUsersThatHadConversationWithUser($userId, $startDate =
3049
3049
return $ userList ;
3050
3050
}
3051
3051
3052
+ /**
3053
+ * Retrieves a list of users with whom the specified user has exchanged messages within an optional date range.
3054
+ *
3055
+ * @param int $userId The user ID for whom to retrieve message exchange.
3056
+ * @param string|null $startDate Start date to filter the messages (optional).
3057
+ * @param string|null $endDate End date to filter the messages (optional).
3058
+ *
3059
+ * @return array Array of user information for each user with whom the specified user has exchanged messages.
3060
+ */
3061
+ public static function getMessageExchangeWithUser ($ userId , $ startDate = null , $ endDate = null )
3062
+ {
3063
+ $ messagesTable = Database::get_main_table (TABLE_MESSAGE );
3064
+ $ userId = (int ) $ userId ;
3065
+
3066
+ if ($ startDate !== null ) {
3067
+ $ startDate = Database::escape_string ($ startDate );
3068
+ }
3069
+ if ($ endDate !== null ) {
3070
+ $ endDate = Database::escape_string ($ endDate );
3071
+ }
3072
+
3073
+ $ sql = "SELECT DISTINCT user_sender_id AS user_id
3074
+ FROM $ messagesTable
3075
+ WHERE user_receiver_id = $ userId " .
3076
+ ($ startDate ? " AND send_date >= ' $ startDate' " : "" ) .
3077
+ ($ endDate ? " AND send_date <= ' $ endDate' " : "" ) .
3078
+ " UNION
3079
+ SELECT DISTINCT user_receiver_id
3080
+ FROM $ messagesTable
3081
+ WHERE user_sender_id = $ userId " .
3082
+ ($ startDate ? " AND send_date >= ' $ startDate' " : "" ) .
3083
+ ($ endDate ? " AND send_date <= ' $ endDate' " : "" );
3084
+
3085
+ $ result = Database::query ($ sql );
3086
+ $ users = Database::store_result ($ result );
3087
+
3088
+ $ userList = [];
3089
+ foreach ($ users as $ userData ) {
3090
+ $ userId = $ userData ['user_id ' ];
3091
+ if (empty ($ userId )) {
3092
+ continue ;
3093
+ }
3094
+ $ userInfo = api_get_user_info ($ userId );
3095
+ if ($ userInfo ) {
3096
+ $ userList [$ userId ] = $ userInfo ;
3097
+ }
3098
+ }
3099
+
3100
+ return $ userList ;
3101
+ }
3102
+
3052
3103
/**
3053
3104
* @param int $userId
3054
3105
* @param int $otherUserId
0 commit comments