Skip to content

Commit

Permalink
Fix calculation if there are more results
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Mar 7, 2018
1 parent 7642449 commit db8d664
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 20 deletions.
6 changes: 5 additions & 1 deletion lib/private/Collaboration/Collaborators/MailPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,14 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
}
}

$reachedEnd = true;
if (!$this->shareeEnumeration) {
$result['wide'] = [];
$userResults['wide'] = [];
} else {
$reachedEnd = (count($result['wide']) < $offset + $limit) ||
(count($userResults['wide']) < $offset + $limit);

$result['wide'] = array_slice($result['wide'], $offset, $limit);
$userResults['wide'] = array_slice($userResults['wide'], $offset, $limit);
}
Expand All @@ -196,7 +200,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
}
$searchResult->addResultSet($emailType, $result['wide'], $result['exact']);

return true;
return !$reachedEnd;
}

public function isCurrentUser(ICloudId $cloud): bool {
Expand Down
71 changes: 52 additions & 19 deletions tests/lib/Collaboration/Collaborators/MailPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,31 +120,31 @@ function($appName, $key, $default)

public function dataGetEmail() {
return [
['test', [], true, ['emails' => [], 'exact' => ['emails' => []]], false, true],
['test', [], false, ['emails' => [], 'exact' => ['emails' => []]], false, true],
['test', [], true, ['emails' => [], 'exact' => ['emails' => []]], false, false],
['test', [], false, ['emails' => [], 'exact' => ['emails' => []]], false, false],
[
'test@remote.com',
[],
true,
['emails' => [], 'exact' => ['emails' => [['label' => 'test@remote.com', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'test@remote.com']]]]],
false,
true,
false,
],
[ // no valid email address
'test@remote',
[],
true,
['emails' => [], 'exact' => ['emails' => []]],
false,
true,
false,
],
[
'test@remote.com',
[],
false,
['emails' => [], 'exact' => ['emails' => [['label' => 'test@remote.com', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'test@remote.com']]]]],
false,
true,
false,
],
[
'test',
Expand All @@ -167,7 +167,7 @@ public function dataGetEmail() {
true,
['emails' => [['label' => 'User @ Localhost (username@localhost)', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'username@localhost']]], 'exact' => ['emails' => []]],
false,
true,
false,
],
[
'test',
Expand All @@ -190,7 +190,7 @@ public function dataGetEmail() {
false,
['emails' => [], 'exact' => ['emails' => []]],
false,
true,
false,
],
[
'test@remote.com',
Expand All @@ -213,7 +213,7 @@ public function dataGetEmail() {
true,
['emails' => [['label' => 'User @ Localhost (username@localhost)', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'username@localhost']]], 'exact' => ['emails' => [['label' => 'test@remote.com', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'test@remote.com']]]]],
false,
true,
false,
],
[
'test@remote.com',
Expand All @@ -236,7 +236,7 @@ public function dataGetEmail() {
false,
['emails' => [], 'exact' => ['emails' => [['label' => 'test@remote.com', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'test@remote.com']]]]],
false,
true,
false,
],
[
'username@localhost',
Expand All @@ -259,7 +259,7 @@ public function dataGetEmail() {
true,
['emails' => [], 'exact' => ['emails' => [['label' => 'User @ Localhost (username@localhost)', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'username@localhost']]]]],
true,
true,
false,
],
[
'username@localhost',
Expand All @@ -282,7 +282,7 @@ public function dataGetEmail() {
false,
['emails' => [], 'exact' => ['emails' => [['label' => 'User @ Localhost (username@localhost)', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'username@localhost']]]]],
true,
true,
false,
],
// contact with space
[
Expand All @@ -306,7 +306,7 @@ public function dataGetEmail() {
false,
['emails' => [], 'exact' => ['emails' => [['label' => 'User Name @ Localhost (user name@localhost)', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'user name@localhost']]]]],
true,
true,
false,
],
// remote with space, no contact
[
Expand All @@ -330,7 +330,7 @@ public function dataGetEmail() {
false,
['emails' => [], 'exact' => ['emails' => []]],
false,
true,
false,
],
// Local user found by email
[
Expand All @@ -344,7 +344,7 @@ public function dataGetEmail() {
]
],
false,
['users' => [], 'exact' => ['users' => [['label' => 'User (test@example.com)','value' => ['shareType' => 0, 'shareWith' => 'test'],]]]],
['users' => [], 'exact' => ['users' => [['label' => 'User (test@example.com)','value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test'],]]]],
true,
false,
],
Expand Down Expand Up @@ -394,12 +394,45 @@ public function dataGetEmail() {
],
true,
['users' => [
['label' => 'User1 (test@example.com)','value' => ['shareType' => 0, 'shareWith' => 'test1']],
['label' => 'User2 (test@example.de)','value' => ['shareType' => 0, 'shareWith' => 'test2']],
['label' => 'User1 (test@example.com)', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test1']],
['label' => 'User2 (test@example.de)', 'value' => ['shareType' => Share::SHARE_TYPE_USER, 'shareWith' => 'test2']],
], 'emails' => [], 'exact' => ['users' => [], 'emails' => []]],
false,
false,
],
// Pagination and "more results" for normal emails
[
'test@example',
[
[
'FN' => 'User1',
'EMAIL' => ['test@example.com'],
'CLOUD' => ['test1@localhost'],
],
[
'FN' => 'User2',
'EMAIL' => ['test@example.de'],
'CLOUD' => ['test2@localhost'],
],
[
'FN' => 'User3',
'EMAIL' => ['test@example.org'],
'CLOUD' => ['test3@localhost'],
],
[
'FN' => 'User4',
'EMAIL' => ['test@example.net'],
'CLOUD' => ['test4@localhost'],
],
],
true,
['emails' => [
['label' => 'User1 (test@example.com)', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'test@example.com']],
['label' => 'User2 (test@example.de)', 'value' => ['shareType' => Share::SHARE_TYPE_EMAIL, 'shareWith' => 'test@example.de']],
], 'exact' => ['emails' => []]],
false,
false,
],
];
}

Expand Down Expand Up @@ -481,7 +514,7 @@ public function dataGetEmailGroupsOnly() {
],
['users' => [['label' => 'User (test@example.com)','value' => ['shareType' => 0, 'shareWith' => 'test'],]], 'emails' => [], 'exact' => ['emails' => [], 'users' => []]],
false,
true,
false,
[
"currentUser" => ["group1"],
"User" => ["group1"]
Expand All @@ -501,7 +534,7 @@ public function dataGetEmailGroupsOnly() {
],
['emails'=> [], 'exact' => ['emails' => []]],
false,
true,
false,
[
"currentUser" => ["group1"],
"User" => ["group2"]
Expand All @@ -521,7 +554,7 @@ public function dataGetEmailGroupsOnly() {
],
['emails' => [], 'exact' => ['emails' => [['label' => 'test@example.com', 'value' => ['shareType' => 4,'shareWith' => 'test@example.com']]]]],
false,
true,
false,
[
"currentUser" => ["group1"],
"User" => ["group2"]
Expand Down

0 comments on commit db8d664

Please sign in to comment.