foreveralone

foreveralone Commit Details


Date:2016-02-27 21:54:19 (8 years 9 months ago)
Author:Natalie Adams
Branch:master
Commit:97849d2c2ce231578a84ddc373197dd3b46f21ae
Parents: 233f5a1538da4091de53f6fc30396fff3fedb51b
Message:Issue 126: Allow users to "ban" other users

Changes:

File differences

web/application/controllers/base.php
5959
6060
6161
62
63
62
63
6464
6565
66
67
6668
6769
6870
foreach($expiredSessions as $session) {
if ($session->to_user) {
/** @var \application\models\Sessions $otherSession */
$otherSession = \application\models\Sessions::getByField("id", $session->to_user);
$otherSession->waiting = true;
$otherSession = \application\models\Sessions::getByField("id", $session->to_user)[0];
$otherSession->waiting = 1;
$otherSession->to_user = null;
$otherSession->save();
\vendor\DB\DB::query("DELETE FROM messages WHERE user_from = ? AND user_to = ?", [$session->id, $otherSession->id]);
\vendor\DB\DB::query("DELETE FROM messages WHERE user_from = ? AND user_to = ?", [$otherSession->id, $session->id]);
}
$session->delete();
}
web/application/controllers/main.php
2121
2222
2323
24
25
26
27
2428
2529
2630
......
5357
5458
5559
60
61
62
63
64
65
66
5667
5768
5869
......
7586
7687
7788
78
89
7990
80
91
8192
8293
83
94
8495
8596
8697
......
99110
100111
101112
113
114
102115
103116
117
118
119
120
121
122
123
124
104125
105126
106127
107128
108
129
109130
110131
111132
......
113134
114135
115136
116
137
138
139
117140
118141
119142
......
147170
148171
149172
150
173
151174
152175
153176
......
164187
165188
166189
167
190
168191
169192
}
public function chat() {
if (!$this->session->data) {
header("location: /main/info/");
return;
}
$this->session->waiting = 1;
$this->session->save();
$toUser = $this->session->to_user;
}
}
public function ignoresession() {
$ignore = $this->session->getData("ignore");
$ignore[] = $this->session->to_user;
$this->session->setData("ignore", $ignore);
$this->session->save();
}
public function togglerandom() {
if ($_POST["random"] == "true") {
$this->session->random = 1;
$search = false;
// work around for SQLite
$lock = \application\models\Settings::getSetting("readLock");
//$lock = \application\models\Settings::getSetting("readLock");
while($lock) {
/*while($lock) {
$lock = \application\models\Settings::getSetting("readLock");
}
\application\models\Settings::setSetting("readLock", (int)true);
\application\models\Settings::setSetting("readLock", (int)true);*/
// Check if the current user is talking to someone
$toUser = $this->session->to_user;
// search for someone else in waiting queue
/** @var \application\models\Sessions $firstResult */
$firstResult = null;
$tmpSessions = [];
$ignoreUsers = $this->session->getData("ignore") ?: [];
if ($search) {
$allSessions = \application\models\Sessions::getByField("waiting", 1);
foreach ($allSessions as $session) {
$ignoreUsersOther = $session->getData("ignore") ?: [];
if (!in_array($session->id, $ignoreUsers) && !in_array($this->session->id, $ignoreUsersOther)) {
$tmpSessions[] = $session;
}
$allSessions = $tmpSessions;
}
shuffle($allSessions);
shuffle($allSessions);
/** @var \application\models\Sessions $session */
foreach ($allSessions as $session) {
if ($session->getData("toUser") == $this->session->id && $toUser == null) {
if ($session->to_user == $this->session->id && $toUser == null) {
// "kick the other user"
$session->to_user = null;
$session->waiting = 0;
continue;
}
if ($session->waiting && $session->id != $this->session->id) {
$firstResult = $session;
if ($session->random) {
$firstResult = $session;
}
$interestWeight = [];
$gender1Weight = true;
$gender2Weight = true;
}
if (!$result) {
\application\models\Settings::setSetting("readLock", (int)false);
//\application\models\Settings::setSetting("readLock", (int)false);
echo json_encode(false);
return;
}
}
echo json_encode($return);
\application\models\Settings::setSetting("readLock", (int)false);
//\application\models\Settings::setSetting("readLock", (int)false);
}
}
web/application/views/chat.html
33
44
55
6
7
6
7
8
89
910
1011
1112
1213
14
15
16
17
1318
1419
15
20
21
1622
1723
1824
1925
2026
2127
22
28
29
30
31
32
33
34
35
36
37
38
2339
2440
2541
{% block content %}
<div class="centered">
<div class="checkbox">
<label> <input type="checkbox" id="random"
title="Checking this box will match you with anyone - including those that don't match what you are looking for"
<label> <input type="checkbox" id="random" class="set-tooltip"
title="Checking this box will match you with anyone - including those that don't match what you are looking for.
You and the other party must have this box checked for it to create a match."
{% if session.random %}checked="checked"{% endif %}
>
Match random users</label>
</div>
<div id="container">
<button title="You may or may not be matched with the same person again" type="button" id="newMatch" class="set-tooltip btn btn-primary">Find new match</button>
<button title="This will prevent the person at the current session from talking to you and match you with a new person" id="banAndNewMatch" type="button" class="set-tooltip btn btn-danger">Ignore and find new match</button>
<br>
<br>
<textarea disabled="disabled" autocomplete="off" cols="100" rows="25" id="chat"></textarea>
<br>
<input autocomplete="off" style="width: 725px;" placeholder="Your message here..." type="text" id="input">
<input autocomplete="off" style="width: 725px;" placeholder="Your message here..." type="text" id="input"><br>
</div>
</div>
<script type="text/javascript">
$(function () {
$("#random").tooltip();
$("#newMatch").click(function () {
location.reload();
});
$("#banAndNewMatch").click(function () {
$.get("./main/ignoresession/", function () {
location.reload();
});
});
$(".set-tooltip").tooltip();
$("#random").change(function (e) {
console.log(e);

Archive Download the corresponding diff file

Branches

Tags

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