Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions lib/TalkSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,23 @@ protected function getValues(string $key): array {
}

protected function getValue(string $key, string $token, bool $useTabId = true): ?string {
$token .= $useTabId ? $this->getTabId() : '';
$values = $this->getValues($key);
return $values[$token] ?? null;
$tabId = $useTabId ? $this->getTabId() : '';

if ($tabId !== '') {
return $values[$token . $tabId] ?? null;
}

// Requests without the tab id header (e.g. an <img> tag) can not tell the
// tabs apart, so fall back to any value stored for the token
foreach ($values as $tokenKey => $value) {
$tokenKey = (string)$tokenKey;
if ($tokenKey === $token || str_starts_with($tokenKey, $token . self::TAB_ID_SEPARATOR)) {
return $value;
}
}

return null;
}

protected function setValue(string $key, string $token, string $value, bool $useTabId = true): void {
Expand All @@ -142,7 +156,7 @@ protected function removeValue(string $key, string $token, bool $useTabId = true
// This request does not support tabId, so we need to destroy all related data
foreach ($values as $tokenKey => $value) {
$tokenKey = (string)$tokenKey;
if (str_starts_with($tokenKey, $token)) {
if ($tokenKey === $token || str_starts_with($tokenKey, $token . self::TAB_ID_SEPARATOR)) {
unset($values[$tokenKey]);
}
}
Expand Down
Loading