Commit b9443862 authored by Ivanq's avatar Ivanq

Merge branch 'feed'

parents 2d7e3741 8b6ce17c
......@@ -96,5 +96,11 @@
"indexes": ["CREATE INDEX repo_index_address ON repo_index(address)"],
"schema_changed": 3
}
},
"feeds": {
"Issues": "SELECT 'issue' AS type, issues.date_added / 1000 AS date_added, issues.title AS title, issues.body AS body, 'repo/issues/view/?' || json.site || '/' || issues.id || '@' || REPLACE(json.directory, 'data/users/', '') AS url FROM issues, json WHERE issues.json_id = json.json_id",
"Pull requests": "SELECT 'pull_request' AS type, pull_requests.date_added / 1000 AS date_added, pull_requests.title AS title, pull_requests.body AS body, 'repo/pull-requests/view/?' || json.site || '/' || pull_requests.id || '@' || REPLACE(json.directory, 'data/users/', '') AS url FROM pull_requests, json WHERE pull_requests.json_id = json.json_id",
"Issue comments": "SELECT 'comment' AS type, issue_comments.date_added / 1000 AS date_added, issues.title AS title, issue_comments.body AS body, 'repo/issues/view/?' || json.site || '/' || issues.id || '@' || REPLACE(json.directory, 'data/users/', '') AS url FROM issues, issue_comments, json, json AS json2 WHERE issues.json_id = json.json_id AND issue_comments.issue_id = issues.id AND issue_comments.json_id = json2.json_id AND issue_comments.issue_json = json2.directory AND json.site = json2.site",
"Pull request comments": "SELECT 'comment' AS type, pull_request_comments.date_added / 1000 AS date_added, pull_requests.title AS title, pull_request_comments.body AS body, 'repo/pull-requests/view/?' || json.site || '/' || pull_requests.id || '@' || REPLACE(json.directory, 'data/users/', '') AS url FROM pull_requests, pull_request_comments, json, json AS json2 WHERE pull_requests.json_id = json.json_id AND pull_request_comments.pull_request_id = pull_requests.id AND pull_request_comments.json_id = json2.json_id AND pull_request_comments.pull_request_json = json2.directory AND json.site = json2.site"
}
}
\ No newline at end of file
FOLLOW_QUERIES = {
issues: "SELECT 'issue' AS type, issues.date_added AS date_added, issues.title AS title, issues.body AS body, 'repo/issues/view/?' || json.site || '/' || issues.id || '@' || REPLACE(json.directory, 'data/users/', '') AS url FROM issues, json WHERE issues.json_id = json.json_id AND json.site IN (:params)",
pullRequests: "SELECT 'pull_request' AS type, pull_requests.date_added AS date_added, pull_requests.title AS title, pull_requests.body AS body, 'repo/pull-requests/view/?' || json.site || '/' || pull_requests.id || '@' || REPLACE(json.directory, 'data/users/', '') AS url FROM pull_requests, json WHERE pull_requests.json_id = json.json_id AND json.site IN (:params)",
issueComments: "SELECT 'comment' AS type, issue_comments.date_added AS date_added, issues.title AS title, issue_comments.body AS body, 'repo/issues/view/?' || json.site || '/' || issues.id || '@' || REPLACE(json.directory, 'data/users/', '') AS url FROM issues, issue_comments, json, json AS json2 WHERE issues.json_id = json.json_id AND issue_comments.issue_id = issues.id AND issue_comments.json_id = json2.json_id AND issue_comments.issue_json = json2.directory AND json.site = json2.site AND json.site IN (:params)",
pullRequestComments: "SELECT 'comment' AS type, pull_request_comments.date_added AS date_added, pull_requests.title AS title, pull_request_comments.body AS body, 'repo/pull-requests/view/?' || json.site || '/' || pull_requests.id || '@' || REPLACE(json.directory, 'data/users/', '') AS url FROM pull_requests, pull_request_comments, json, json AS json2 WHERE pull_requests.json_id = json.json_id AND pull_request_comments.pull_request_id = pull_requests.id AND pull_request_comments.json_id = json2.json_id AND pull_request_comments.pull_request_json = json2.directory AND json.site = json2.site AND json.site IN (:params)"
};
class Repository {
constructor(address, zeroPage) {
this.address = address;
......@@ -745,6 +752,51 @@ class Repository {
});
}
// Follow
follow() {
return this.zeroPage.cmd("feedListFollow")
.then(feedList => {
if(!feedList["Issues"]) {
feedList["Issues"] = [FOLLOW_QUERIES.issues, []];
}
if(!feedList["Pull requests"]) {
feedList["Pull requests"] = [FOLLOW_QUERIES.pullRequests, []];
}
if(!feedList["Issue comments"]) {
feedList["Issue comments"] = [FOLLOW_QUERIES.issueComments, []];
}
if(!feedList["Pull request comments"]) {
feedList["Pull request comments"] = [FOLLOW_QUERIES.pullRequestComments, []];
}
Object.values(feedList).forEach(feed => feed[1].push(this.address));
return this.zeroPage.cmd("feedFollow", [feedList]);
});
}
unfollow() {
return this.zeroPage.cmd("feedListFollow")
.then(feedList => {
Object.values(feedList).forEach(feed => {
let index = feed[1].indexOf(this.address);
if(index > -1) {
feed[1].splice(index, 1);
}
});
return this.zeroPage.cmd("feedFollow", [feedList]);
});
}
isFollowing() {
return this.zeroPage.cmd("feedListFollow")
.then(feedList => {
return (
Object.values(feedList).length > 0 &&
Object.values(feedList).every(feed => feed[1].indexOf(this.address) > -1)
);
});
}
// Index
addToIndex() {
let content, auth;
......
......@@ -70,6 +70,7 @@
<div class="info">
<a class="button button-blue" id="new_issue">New issue</a>
<a class="button info-link" id="follow"></a>
</div>
<table id="issues" class="issues"></table>
......
......@@ -4,6 +4,10 @@ if(address == "1RepoXU8bQE9m7ssNwL4nnxBnZVejHCc6") {
let currentPage = Number.isSafeInteger(+additional) ? +additional : 0;
function showFollowing(isFollowing) {
document.getElementById("follow").innerHTML = isFollowing ? "Stop following" : "Follow issues and pull requests in newsfeed";
}
repo.addMerger()
.then(() => {
return repo.getContent();
......@@ -69,4 +73,25 @@ repo.addMerger()
button.classList.remove("button-disabled");
button.href = "?" + address + "/" + (currentPage + 1);
}
return repo.isFollowing();
})
.then(isFollowing => {
let followButton = document.getElementById("follow");
showFollowing(isFollowing);
followButton.onclick = () => {
if(isFollowing) {
repo.unfollow()
.then(() => {
isFollowing = false;
showFollowing(isFollowing);
});
} else {
repo.follow()
.then(() => {
isFollowing = true;
showFollowing(isFollowing);
});
}
};
});
\ No newline at end of file
......@@ -70,6 +70,7 @@
<div class="info">
<a class="button button-blue" id="new_pull_request">New pull request</a>
<a class="button info-link" id="follow"></a>
</div>
<table id="pull_requests" class="pull-requests"></table>
......
......@@ -4,6 +4,10 @@ if(address == "1RepoXU8bQE9m7ssNwL4nnxBnZVejHCc6") {
let currentPage = Number.isSafeInteger(+additional) ? +additional : 0;
function showFollowing(isFollowing) {
document.getElementById("follow").innerHTML = isFollowing ? "Stop following" : "Follow issues and pull requests in newsfeed";
}
repo.addMerger()
.then(() => {
return repo.getContent();
......@@ -69,4 +73,25 @@ repo.addMerger()
button.classList.remove("button-disabled");
button.href = "?" + address + "/" + (currentPage + 1);
}
return repo.isFollowing();
})
.then(isFollowing => {
let followButton = document.getElementById("follow");
showFollowing(isFollowing);
followButton.onclick = () => {
if(isFollowing) {
repo.unfollow()
.then(() => {
isFollowing = false;
showFollowing(isFollowing);
});
} else {
repo.follow()
.then(() => {
isFollowing = true;
showFollowing(isFollowing);
});
}
};
});
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment