grommunio /
grommunio-web
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * NewMailNotifier. |
||
| 5 | * |
||
| 6 | * Generates notifications for hierarchy folder updates (content unread). |
||
| 7 | */ |
||
| 8 | class NewMailNotifier extends Notifier { |
||
| 9 | /** |
||
| 10 | * @return Number the event which this module handles |
||
| 11 | */ |
||
| 12 | #[Override] |
||
| 13 | public function getEvents() { |
||
| 14 | return HIERARCHY_UPDATE; |
||
| 15 | } |
||
| 16 | |||
| 17 | /** |
||
| 18 | * If an event elsewhere has occurred, it enters in this method. This method |
||
| 19 | * executes one or more actions, depends on the event. |
||
| 20 | * |
||
| 21 | * @param int $event event |
||
| 22 | * @param string $entryid entryid |
||
| 23 | * @param mixed $props |
||
| 24 | */ |
||
| 25 | #[Override] |
||
| 26 | public function update($event, $entryid, $props) { |
||
| 27 | switch ($event) { |
||
| 28 | case HIERARCHY_UPDATE: |
||
| 29 | $this->updateFolderHierachy($props[0], $props[1]); |
||
| 30 | break; |
||
| 31 | } |
||
| 32 | } |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Fetch the folder hierarchy from the IPM.Subtree with the properties required for the newmail notification |
||
| 36 | * for grommunio Web client. |
||
| 37 | * |
||
| 38 | * The returned hierarchy is cached in the session state and compared when the function is called, when |
||
| 39 | * the data differs newmail notifications for the changed folder(s) are created and send to the client. |
||
| 40 | * |
||
| 41 | * @param string $username The user for whom the store is checked for mail updates. If not set, it will be |
||
| 42 | * current user's own store. |
||
| 43 | * @param string $folderType the type of shared folder (all, inbox or calendar) |
||
| 44 | */ |
||
| 45 | private function updateFolderHierachy($username = '', $folderType = '') { |
||
| 46 | $counterState = new State('counters_sessiondata'); |
||
| 47 | $counterState->open(); |
||
| 48 | $cacheKey = 'sessionData'; |
||
| 49 | if ($username) { |
||
| 50 | $cacheKey = $username; |
||
| 51 | } |
||
| 52 | |||
| 53 | $sessionData = $counterState->read($cacheKey); |
||
| 54 | if (!is_array($sessionData)) { |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 55 | $sessionData = []; |
||
| 56 | } |
||
| 57 | |||
| 58 | $folderStatCache = updateHierarchyCounters($username, $folderType); |
||
| 59 | |||
| 60 | if ($folderStatCache !== $sessionData) { |
||
| 61 | $data = ["item" => []]; |
||
| 62 | |||
| 63 | foreach ($folderStatCache as $display_name => $props) { |
||
| 64 | if (isset($sessionData[$display_name]) && |
||
| 65 | $sessionData[$display_name]['commit_time'] !== $props['commit_time']) { |
||
| 66 | if ($username) { |
||
| 67 | $name = $GLOBALS["mapisession"]->getDisplayNameofUser($username); |
||
| 68 | } |
||
| 69 | else { |
||
| 70 | $name = null; |
||
| 71 | } |
||
| 72 | $data['item'][] = [ |
||
| 73 | 'entryid' => $props['entryid'], |
||
| 74 | 'store_entryid' => $props['store_entryid'], |
||
| 75 | 'content_count' => $props['content_count'], |
||
| 76 | 'content_unread' => $props['content_unread'], |
||
| 77 | 'display_name' => $display_name, |
||
| 78 | 'user_display_name' => $name, |
||
| 79 | ]; |
||
| 80 | } |
||
| 81 | } |
||
| 82 | |||
| 83 | $this->addNotificationActionData("newmail", $data); |
||
| 84 | $GLOBALS["bus"]->addData($this->createNotificationResponseData()); |
||
| 85 | |||
| 86 | $counterState->write($cacheKey, $folderStatCache); |
||
| 87 | } |
||
| 88 | |||
| 89 | $counterState->close(); |
||
| 90 | } |
||
| 91 | } |
||
| 92 |