Skip to content
Merged
Prev Previous commit
Next Next commit
Always use the updated color depending on the guest name
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr committed Jan 13, 2021
commit 12b42d11f977f4895cb782dd0bcdfc756e9e6187
3 changes: 3 additions & 0 deletions lib/Service/SessionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ public function updateSession(int $documentId, int $sessionId, string $sessionTo
}
$session = $this->sessionMapper->find($documentId, $sessionId, $sessionToken);
$session->setGuestName($guestName);
$color = $this->avatarManager->getGuestAvatar($guestName)->avatarBackgroundColor($guestName);
$color = sprintf("#%02x%02x%02x", $color->r, $color->g, $color->b);
$session->setColor($color);
return $this->sessionMapper->update($session);
}
}
7 changes: 6 additions & 1 deletion src/components/EditorWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,6 @@ export default {

this.syncError = null
this.tiptap.setOptions({ editable: !this.readOnly })

})
.on('loaded', ({ documentSource }) => {
this.hasConnectionIssue = false
Expand Down Expand Up @@ -483,6 +482,12 @@ export default {

updateSessions(sessions) {
this.sessions = sessions.sort((a, b) => b.lastContact - a.lastContact)

// Make sure we get our own session updated
// This should ideally be part of a global store where we can have that updated on the actual name change for guests
const currentUpdatedSession = this.sessions.find(session => session.id === this.currentSession.id)
Vue.set(this, 'currentSession', currentUpdatedSession)

const currentSessionIds = this.sessions.map((session) => session.userId)
const currentGuestIds = this.sessions.map((session) => session.guestId)

Expand Down
5 changes: 3 additions & 2 deletions src/extensions/UserColor.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ export default class UserColor extends Extension {
.filter(span => typeof tState.commits[span.commit]?.author?.color !== 'undefined')
.map(span => {
const commit = tState.commits[span.commit]
const clientID = commit.author.clientID
return Decoration.inline(span.from, span.to, {
class: 'author-annotation',
style: 'background-color: ' + commit.author.color + 'ee;',
title: commit.author.name,
style: 'background-color: ' + this.spec.color(clientID) + 'ee;',
title: this.spec.name(clientID),
})
}).filter(dec => dec !== null)
return { tracked, deco: DecorationSet.create(state.doc, decos) }
Expand Down
9 changes: 7 additions & 2 deletions tests/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,18 @@
</UndefinedThisPropertyFetch>
</file>
<file src="lib/Service/SessionService.php">
<UndefinedDocblockClass occurrences="4">
<UndefinedDocblockClass occurrences="8">
<code>$color-&gt;b</code>
<code>$color-&gt;b</code>
<code>$color-&gt;g</code>
<code>$color-&gt;g</code>
<code>$color-&gt;r</code>
<code>$color-&gt;r</code>
<code>$this-&gt;avatarManager-&gt;getGuestAvatar($guestName)-&gt;avatarBackgroundColor($guestName)</code>
<code>$this-&gt;avatarManager-&gt;getGuestAvatar($userName)-&gt;avatarBackgroundColor($userName)</code>
</UndefinedDocblockClass>
<UndefinedMagicMethod occurrences="6">
<UndefinedMagicMethod occurrences="7">
<code>setColor</code>
<code>setColor</code>
<code>setDocumentId</code>
<code>setGuestName</code>
Expand Down