Change mail options
This commit is contained in:
@@ -1180,6 +1180,51 @@ function microsoft_get_mail_demo_data(?string $folderId = 'inbox'): array {
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Haalt de door de gebruiker uitgeschakelde mailmappen op
|
||||
*/
|
||||
function microsoft_get_disabled_folders(int $userId): array {
|
||||
try {
|
||||
$db = get_db_connection();
|
||||
$stmt = $db->prepare("SELECT settings FROM integrations WHERE user_id = ? AND provider = 'OUTLOOK'");
|
||||
$stmt->execute([$userId]);
|
||||
$row = $stmt->fetch();
|
||||
if (!$row || empty($row['settings'])) return [];
|
||||
$settings = json_decode($row['settings'], true);
|
||||
if (is_array($settings) && !empty($settings['disabled_mail_folders']) && is_array($settings['disabled_mail_folders'])) {
|
||||
return array_values(array_unique(array_filter(array_map('strval', $settings['disabled_mail_folders']))));
|
||||
}
|
||||
return [];
|
||||
} catch (Throwable $e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Slaat de uitgeschakelde mailmappen op voor een gebruiker
|
||||
*/
|
||||
function microsoft_save_disabled_folders(int $userId, array $disabledFolders): bool {
|
||||
try {
|
||||
$db = get_db_connection();
|
||||
$stmt = $db->prepare("SELECT settings FROM integrations WHERE user_id = ? AND provider = 'OUTLOOK'");
|
||||
$stmt->execute([$userId]);
|
||||
$row = $stmt->fetch();
|
||||
$settings = ($row && !empty($row['settings'])) ? (json_decode($row['settings'], true) ?: []) : [];
|
||||
|
||||
$clean = array_values(array_unique(array_filter(array_map('strval', $disabledFolders))));
|
||||
$settings['disabled_mail_folders'] = $clean;
|
||||
|
||||
$update = $db->prepare("UPDATE integrations SET settings = ?, updated_at = NOW() WHERE user_id = ? AND provider = 'OUTLOOK'");
|
||||
$ok = $update->execute([json_encode($settings, JSON_UNESCAPED_UNICODE), $userId]);
|
||||
|
||||
fociz_cache_delete("ms_folders_{$userId}");
|
||||
return $ok;
|
||||
} catch (Throwable $e) {
|
||||
error_log("microsoft_save_disabled_folders error: " . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Haalt alle beschikbare mailmappen op van Microsoft Graph API (exclusief SPAM/Junk, Prullenbak/Deleted, Outbox en Concepten)
|
||||
*/
|
||||
@@ -1237,12 +1282,20 @@ function microsoft_fetch_mail_folders(int $userId, bool $forceRefresh = false):
|
||||
'is_child' => false,
|
||||
],
|
||||
];
|
||||
$totalUnread = array_sum(array_column($demoFolders, 'unread_count'));
|
||||
$disabledFolders = microsoft_get_disabled_folders($userId);
|
||||
$disabledSet = array_flip($disabledFolders);
|
||||
$totalUnread = 0;
|
||||
foreach ($demoFolders as $df) {
|
||||
if (!isset($disabledSet[$df['id']])) {
|
||||
$totalUnread += (int)($df['unread_count'] ?? 0);
|
||||
}
|
||||
}
|
||||
return [
|
||||
'success' => true,
|
||||
'is_demo' => true,
|
||||
'folders' => $demoFolders,
|
||||
'total_unread' => $totalUnread,
|
||||
'success' => true,
|
||||
'is_demo' => true,
|
||||
'folders' => $demoFolders,
|
||||
'total_unread' => $totalUnread,
|
||||
'disabled_folders' => $disabledFolders,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -1427,13 +1480,22 @@ function microsoft_fetch_mail_folders(int $userId, bool $forceRefresh = false):
|
||||
return strcasecmp($a['name'], $b['name']);
|
||||
});
|
||||
|
||||
$totalUnread = array_sum(array_column($folders, 'unread_count'));
|
||||
$disabledFolders = microsoft_get_disabled_folders($userId);
|
||||
$disabledSet = array_flip($disabledFolders);
|
||||
|
||||
$totalUnread = 0;
|
||||
foreach ($folders as $f) {
|
||||
if (!isset($disabledSet[$f['id']])) {
|
||||
$totalUnread += (int)($f['unread_count'] ?? 0);
|
||||
}
|
||||
}
|
||||
|
||||
$result = [
|
||||
'success' => true,
|
||||
'is_demo' => false,
|
||||
'folders' => $folders,
|
||||
'total_unread' => $totalUnread,
|
||||
'success' => true,
|
||||
'is_demo' => false,
|
||||
'folders' => $folders,
|
||||
'total_unread' => $totalUnread,
|
||||
'disabled_folders' => $disabledFolders,
|
||||
];
|
||||
|
||||
fociz_cache_set($cacheKey, $result, 300); // 5 minuten cache
|
||||
|
||||
Reference in New Issue
Block a user