foreveralone

foreveralone Commit Details


Date:2016-02-27 14:34:06 (8 years 9 months ago)
Author:Natalie Adams
Branch:master
Commit:92b3b492d36233b339b0472bd6e8bd5b1b108869
Parents: c3ae3a73b629e1dc889ef2fae84624d25c1c91a0
Message:Issue 121: Break out session data into separate fields

Changes:

File differences

web/application/controllers/main.php
2121
2222
2323
24
25
24
25
26
2627
2728
2829
2930
3031
31
32
32
33
3334
3435
36
37
3538
36
37
39
3840
3941
4042
......
4749
4850
4951
52
5053
5154
5255
5356
5457
5558
56
59
5760
5861
5962
......
6669
6770
6871
69
72
7073
7174
7275
7376
74
77
7578
76
79
7780
7881
7982
80
83
8184
8285
8386
......
8891
8992
9093
91
94
9295
9396
9497
9598
96
99
97100
98
99
101
102
103
100104
101105
102
106
103107
104108
105109
......
111115
112116
113117
114
115
116
117
118
119
120
121
118122
119123
120124
......
124128
125129
126130
127
128
129
130
131
132
133
134
131135
132136
133137
}
public function chat() {
$this->session->setData("waiting", true);
$toUser = $this->session->getData("toUser");
$this->session->waiting = 1;
$this->session->save();
$toUser = $this->session->to_user;
if ($toUser) {
/** @var \application\models\Sessions $otherUserSession */
$otherUserSession = \application\models\Sessions::getByField("id", $toUser);
if ($otherUserSession) {
$otherUserSession = $otherUserSession[0];
$otherUserSession->setData("waiting", "true");
$otherUserSession->setData("toUser", null);
$otherUserSession->waiting = true;
$otherUserSession->to_user = null;
$otherUserSession->save();
}
$this->session->to_user = null;
$this->session->save();
}
$this->session->setData("toUser", null);
$this->session->save();
echo $this->loadRender("chat.html");
}
public function sessionset($key) {
if (in_array($key, ["interests", "gender", "looking"])) {
$this->session->setData($key, $_POST[$key]);
$this->session->save();
}
}
public function send() {
$message = new application\models\Messages();
$message->user_from = $this->session->id;
$message->user_to = $this->session->getData("toUser");
$message->user_to = $this->session->to_user;
$message->message = $_POST["message"];
$message->save();
}
$lock = \application\models\Settings::getSetting("readLock");
while($lock) {
$lock = false;
$lock = \application\models\Settings::getSetting("readLock");
}
\application\models\Settings::setSetting("readLock", (int)true);
// Check if the current user is talking to someone
$toUser = $this->session->getData("toUser");
$toUser = $this->session->to_user;
/** @var \application\models\Sessions $session */
$otherSession = \application\models\Sessions::getByField("id", $this->session->getData("toUser"));
$otherSession = \application\models\Sessions::getByField("id", $toUser);
if ($otherSession) {
$otherSession = $otherSession[0];
// If they aren't waiting and the current toUser is this user..
if ($otherSession->getData("waiting") && $otherSession->getData("toUser") != $this->session->id) {
if ($otherSession->waiting && $toUser != $this->session->id) {
$search = true;
}
} else {
/** @var \application\models\Sessions $firstResult */
$firstResult = null;
if ($search) {
$allSessions = \application\models\Sessions::all();
$allSessions = \application\models\Sessions::getByField("waiting", 1);
shuffle($allSessions);
shuffle($allSessions);
/** @var \application\models\Sessions $session */
foreach ($allSessions as $session) {
if ($session->getData("toUser") == $this->session->id && $this->session->getData("toUser") == null) {
if ($session->getData("toUser") == $this->session->id && $toUser == null) {
// "kick the other user"
$session->setData("toUser", null);
$session->setData("waiting", false);
$session->to_user = null;
$session->waiting = 0;
$session->save();
continue;
}
if ($session->getData("waiting") && $session->id != $this->session->id) {
if ($session->waiting && $session->id != $this->session->id) {
$firstResult = $session;
$interestWeight = [];
$gender1Weight = true;
} catch (\Exception $e) { }
if ($gender1Weight && $gender2Weight && count($interestWeight) > 0) {
$result = true;
$session->setData("waiting", false);
$session->setData("toUser", $this->session->id);
$this->session->setData("toUser", $session->id);
$this->session->setData("waiting", false);
$session->waiting = 0;
$session->to_user = $this->session->id;
$this->session->to_user = $session->id;
$this->session->waiting = 0;
$session->save();
$this->session->save();
break;
// If no match was made - match with first session
if ($firstResult && !$result) {
$firstResult->setData("waiting", false);
$firstResult->setData("toUser", $this->session->id);
$this->session->setData("toUser", $firstResult->id);
$this->session->setData("waiting", false);
$firstResult->waiting = 0;
$firstResult->to_user = $this->session->id;
$this->session->to_user = $firstResult->id;
$this->session->waiting = 0;
$firstResult->save();
$this->session->save();
$result = true;
web/application/migrations/1.php
1010
1111
1212
13
13
14
15
16
1417
sessionid VARCHAR(255),
ip VARCHAR(255),
userAgent VARCHAR(255),
data TEXT
data TEXT,
waiting TINYINT(1),
to_user INTEGER,
lastPing INTEGER
)");
web/application/models/sessions.php
77
88
99
10
11
12
1013
1114
1215
public $ip;
public $userAgent;
public $data;
public $waiting;
public $to_user;
public $lastPing;
public function setData($key, $val) {
$raw = json_decode($this->data, true);

Archive Download the corresponding diff file

Branches

Tags

Number of commits:
Page rendered in 0.06901s using 20 queries.