Browse Source

Make sure new users don't start at the end

Signed-off-by: Joas Schilling <coding@schilljs.com>
pull/1214/head
Joas Schilling 6 years ago
parent
commit
c3d90782bc
No known key found for this signature in database GPG Key ID: 7076EA9751AACDDA
  1. 12
      lib/Room.php

12
lib/Room.php

@ -524,6 +524,11 @@ class Room {
'users' => $participants,
]));
$lastMessage = 0;
if ($this->getLastMessage() instanceof IComment) {
$lastMessage = (int) $this->getLastMessage()->getId();
}
$query = $this->db->getQueryBuilder();
$query->insert('talk_participants')
->values(
@ -533,6 +538,7 @@ class Room {
'participant_type' => $query->createParameter('participant_type'),
'room_id' => $query->createNamedParameter($this->getId()),
'last_ping' => $query->createNamedParameter(0, IQueryBuilder::PARAM_INT),
'last_read_message' => $query->createNamedParameter($lastMessage, IQueryBuilder::PARAM_INT),
]
);
@ -779,6 +785,11 @@ class Room {
throw new InvalidPasswordException();
}
$lastMessage = 0;
if ($this->getLastMessage() instanceof IComment) {
$lastMessage = (int) $this->getLastMessage()->getId();
}
$sessionId = $this->secureRandom->generate(255);
while (!$this->db->insertIfNotExist('*PREFIX*talk_participants', [
'user_id' => '',
@ -786,6 +797,7 @@ class Room {
'last_ping' => 0,
'session_id' => $sessionId,
'participant_type' => Participant::GUEST,
'last_read_message' => $lastMessage,
], ['session_id'])) {
$sessionId = $this->secureRandom->generate(255);
}

Loading…
Cancel
Save