Skip to content

Commit 7e9c8a6

Browse files
committed
History for room conversations
1 parent 97e61b2 commit 7e9c8a6

17 files changed

Lines changed: 120 additions & 35 deletions

File tree

appserver

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/META-INF/classes/EmberChat/Services/AbstractProcessor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class AbstractProcessor
3333
/**
3434
* The application instance that provides the entity manager.
3535
*
36-
* @var Application
36+
* @var ApplicationInterface
3737
*/
3838
protected $application;
3939

@@ -43,14 +43,14 @@ class AbstractProcessor
4343
* Checks on every start if the database already exists, if not
4444
* the database will be created immediately.
4545
*
46-
* @param Application $application
46+
* @param ApplicationInterface $application
4747
* The application instance
4848
*
4949
* @return void
5050
*/
5151
public function __construct(ApplicationInterface $application)
5252
{
53-
error_log(date("H:i:s") .' ' .__METHOD__);
53+
5454
try {
5555

5656
// set the application instance and initialize the connection parameters

src/META-INF/classes/EmberChat/Services/RoomProcessor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class RoomProcessor extends AbstractProcessor
1717

1818
public function findAll()
1919
{
20-
error_log(date("H:i:s") .' ' .__METHOD__);
20+
2121
// load the entity manager and the user repository
2222
$entityManager = $this->getEntityManager();
2323
$repository = $entityManager->getRepository('EmberChat\Entities\Room');
@@ -27,15 +27,15 @@ public function findAll()
2727
}
2828

2929
public function createNew(Room $room){
30-
error_log(date("H:i:s") .' ' .__METHOD__);
30+
3131
$entityManager = $this->getEntityManager();
3232
$entityManager->persist($room);
3333
$entityManager->flush();
3434
return $room;
3535
}
3636

3737
public function remove(Room $room){
38-
error_log(date("H:i:s") .' ' .__METHOD__);
38+
3939
$entityManager = $this->getEntityManager();
4040
// @TODO why it the $room the same object like in websocket handler?
4141
// @TODO why are there more properties that defined in __sleep()?

src/META-INF/classes/EmberChat/Services/UserProcessor.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class UserProcessor extends AbstractProcessor
2424
*/
2525
public function findByName($name)
2626
{
27-
error_log(date("H:i:s") .' ' .__METHOD__);
27+
2828
// load the entity manager and the user repository
2929
$entityManager = $this->getEntityManager();
3030
$repository = $entityManager->getRepository('EmberChat\Entities\User');
@@ -35,7 +35,7 @@ public function findByName($name)
3535

3636
public function findAll()
3737
{
38-
error_log(date("H:i:s") .' ' .__METHOD__);
38+
3939
// load the entity manager and the user repository
4040
$entityManager = $this->getEntityManager();
4141
$repository = $entityManager->getRepository('EmberChat\Entities\User');
@@ -53,7 +53,7 @@ public function findAll()
5353
*/
5454
public function findById($id)
5555
{
56-
error_log(date("H:i:s") .' ' .__METHOD__);
56+
5757
// load the entity manager and the user repository
5858
$entityManager = $this->getEntityManager();
5959
$repository = $entityManager->getRepository('EmberChat\Entities\User');
@@ -68,23 +68,23 @@ public function findById($id)
6868
* @param $user
6969
*/
7070
public function updateEntity(User $user){
71-
error_log(date("H:i:s") .' ' .__METHOD__);
71+
7272
$entityManager = $this->getEntityManager();
7373
$entityManager->merge($user);
7474
$entityManager->flush();
7575
return $user;
7676
}
7777

7878
public function createNew(User $user){
79-
error_log(date("H:i:s") .' ' .__METHOD__);
79+
8080
$entityManager = $this->getEntityManager();
8181
$entityManager->persist($user);
8282
$entityManager->flush();
8383
return $user;
8484
}
8585

8686
public function remove(User $user){
87-
error_log(date("H:i:s") .' ' .__METHOD__);
87+
8888
$entityManager = $this->getEntityManager();
8989
// @TODO why it the $room the same object like in websocket handler?
9090
// @TODO why are there more properties that defined in __sleep()?

src/WEB-INF/classes/EmberChat/Entities/Room.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ class Room extends \EmberChat\Entities\Original\Room
4141
*/
4242
public function __construct()
4343
{
44-
error_log(date("H:i:s") .' ' .__METHOD__);
44+
4545
$this->conversation = new \EmberChat\Model\Conversation();
4646
}
4747

4848
public function destruct(){
49-
error_log(date("H:i:s") .' ' .__METHOD__);
49+
5050
/** @var $user User */
5151
foreach($this->users as $user){
5252
$user->leaveRoom($this);
@@ -78,7 +78,7 @@ public function getUsers()
7878
*/
7979
public function addUser(User $user)
8080
{
81-
error_log(date("H:i:s") .' ' .__METHOD__);
81+
8282
if ($this->getIndexForUser($user) === null) {
8383
$this->users[] = $user;
8484
// notify all users
@@ -95,7 +95,7 @@ public function addUser(User $user)
9595
*/
9696
public function removeUser(User $user)
9797
{
98-
error_log(date("H:i:s") .' ' .__METHOD__);
98+
9999
$index = $this->getIndexForUser($user);
100100
if ($index === null) {
101101
return false;

src/WEB-INF/classes/EmberChat/Entities/User.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function isOnline()
5757
*/
5858
public function addClient(Client $client)
5959
{
60-
error_log(date("H:i:s") .' ' .__METHOD__);
60+
6161
$this->clients[] = $client;
6262
$this->online = true;
6363
}
@@ -79,7 +79,7 @@ public function getClients()
7979
*/
8080
public function joinRoom(Room $room)
8181
{
82-
error_log(date("H:i:s") .' ' .__METHOD__);
82+
8383
if ($this->getIndexForRoom($room) === null) {
8484
$this->rooms[] = $room;
8585
return true;
@@ -96,7 +96,7 @@ public function joinRoom(Room $room)
9696
*/
9797
public function leaveRoom(Room $room)
9898
{
99-
error_log(date("H:i:s") .' ' .__METHOD__);
99+
100100
$index = $this->getIndexForRoom($room);
101101
if ($index === null) {
102102
return false;
@@ -112,7 +112,7 @@ public function leaveRoom(Room $room)
112112
*/
113113
public function removeClient(Client $client)
114114
{
115-
error_log(date("H:i:s") .' ' .__METHOD__);
115+
116116
foreach ($this->clients as $index => $cmpClient) {
117117
if ($client == $cmpClient) {
118118
unset($this->clients[$index]);
@@ -177,7 +177,7 @@ public function getToken()
177177
* Removes all relations to this user
178178
*/
179179
public function destruct(){
180-
error_log(date("H:i:s") .' ' .__METHOD__);
180+
181181
/** @var Client $client */
182182
foreach($this->clients as $client){
183183
$client->getConnection()->close();

src/WEB-INF/classes/EmberChat/Handler/SocketHandler.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct()
3434
*/
3535
public function init(HandlerConfig $config)
3636
{
37-
error_log(date("H:i:s") .' ' .__METHOD__);
37+
3838
parent::init($config);
3939
$this->serviceLocator = new ServiceLocator($this->getApplication());
4040
$this->clientHandler = new ClientHandler($this->serviceLocator);
@@ -45,7 +45,7 @@ public function init(HandlerConfig $config)
4545
*/
4646
public function onOpen(ConnectionInterface $connection)
4747
{
48-
error_log(date("H:i:s") .' ' .__METHOD__);
48+
4949
$this->clientHandler->createNewClient($connection);
5050
}
5151

@@ -54,7 +54,7 @@ public function onOpen(ConnectionInterface $connection)
5454
*/
5555
public function onMessage(ConnectionInterface $connection, $message)
5656
{
57-
error_log(date("H:i:s") .' ' .__METHOD__);
57+
5858
$this->clientHandler->messageFromClient($connection, $message);
5959
}
6060

@@ -63,7 +63,7 @@ public function onMessage(ConnectionInterface $connection, $message)
6363
*/
6464
public function onClose(ConnectionInterface $connection)
6565
{
66-
error_log(date("H:i:s") .' ' .__METHOD__);
66+
6767
$this->clientHandler->unsetClient($connection);
6868
}
6969

@@ -72,7 +72,7 @@ public function onClose(ConnectionInterface $connection)
7272
*/
7373
public function onError(ConnectionInterface $connection, \Exception $e)
7474
{
75-
error_log(date("H:i:s") .' ' .__METHOD__);
75+
7676
$this->clientHandler->unsetClient($connection);
7777
error_log($e->__toString());
7878
$connection->close();

src/WEB-INF/classes/EmberChat/Model/Client.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function __construct(
4444
ConnectionInterface $connection,
4545
ServiceLocator $serviceLocator
4646
) {
47-
error_log(date("H:i:s") .' ' .__METHOD__);
47+
4848
$this->serviceLocator = $serviceLocator;
4949
$this->userRepository = $this->serviceLocator->getUserRepository();
5050
$this->connection = $connection;
@@ -57,7 +57,7 @@ public function __construct(
5757
*/
5858
public function destruct()
5959
{
60-
error_log(date("H:i:s") .' ' .__METHOD__);
60+
6161
// only client has a user
6262
if ($this->user) {
6363
$this->user->removeClient($this);
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
namespace EmberChat\Model\Message;
4+
5+
6+
use EmberChat\Entities\Room;
7+
use EmberChat\Sender\StandardSender;
8+
use EmberChat\Model\Client;
9+
use EmberChat\Model\SendMessage;
10+
use EmberChat\Service\ServiceLocator;
11+
12+
/**
13+
* @package EmberChatAppServer
14+
* @author Matthias Witte <wittematze@gmail.com>
15+
*/
16+
class RoomHistory extends SendMessage
17+
{
18+
19+
/**
20+
* Overwrite type to get on client side same purpose like regular conversation
21+
*
22+
* @var string
23+
*/
24+
protected $type = 'RoomConversation';
25+
26+
/**
27+
* @var Room
28+
*/
29+
protected $room;
30+
31+
/**
32+
* @var array
33+
*/
34+
protected $content;
35+
36+
/**
37+
* @var bool
38+
*/
39+
protected $history = true;
40+
41+
/**
42+
* @param Client $client
43+
* @param Room $room
44+
* @param ServiceLocator $serviceLocator
45+
*/
46+
public function __construct(Client $client, Room $room, ServiceLocator $serviceLocator)
47+
{
48+
//parent::__construct();
49+
$this->room = $room;
50+
// get corresponding conversation
51+
$conversation = $serviceLocator->getConversationRepository()->findConversationByRoom(
52+
$room
53+
);
54+
55+
// @TODO send not the hole content! only the last ~50 entries or something
56+
$this->content = $conversation->getContent();
57+
$standardSender = new StandardSender();
58+
$standardSender->sendMessageForClient($this, $client);
59+
unset($this);
60+
}
61+
}

src/WEB-INF/classes/EmberChat/Model/Message/UserHistory.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ class UserHistory extends SendMessage
3333
*/
3434
protected $content;
3535

36+
/**
37+
* @var bool
38+
*/
39+
protected $history = true;
40+
3641
/**
3742
* @param Client $client
3843
* @param User $receiver

0 commit comments

Comments
 (0)