diff --git a/ServiceAPI/Groups.php b/ServiceAPI/Groups.php new file mode 100644 index 00000000..2b429eee --- /dev/null +++ b/ServiceAPI/Groups.php @@ -0,0 +1,38 @@ +user = $user; + $this->groups = new Clubs; + } + + function getWriteableClubs(callable $resolve, callable $reject) + { + $clubs = []; + $wclubs = $this->groups->getWriteableClubs($this->user->getId()); + + if(count(iterator_to_array($this->groups->getWriteableClubs($this->user->getId()))) == 0) { + $reject("You did not created any groups"); + + return; + } + + foreach($wclubs as $club) { + $clubs[] = [ + "name" => $club->getName(), + "id" => $club->getId(), + "avatar" => $club->getAvatarUrl() # если в овк когда-нибудь появится крутой список с аватарками, то можно использовать это поле + ]; + } + + $resolve($clubs); + } +} diff --git a/Web/Presenters/UserPresenter.php b/Web/Presenters/UserPresenter.php index d1a56547..3cf68757 100644 --- a/Web/Presenters/UserPresenter.php +++ b/Web/Presenters/UserPresenter.php @@ -707,26 +707,4 @@ final class UserPresenter extends OpenVKPresenter $this->redirect("/settings"); } } - - function renderGetWriteableClubs(int $id) - { - $this->assertUserLoggedIn(); - - if($this->user->id == $id) { - $clubs = iterator_to_array((new Clubs)->getWriteableClubs($id)); - $json = []; - - foreach($clubs as $club) - $json[] = [ - "name" => $club->getName(), - "id" => $club->getId() - ]; - - $this->returnJson($json); - } else { - - $this->returnJson(["You are not allowed to see user-created groups"]); - } - } - } diff --git a/Web/Presenters/WallPresenter.php b/Web/Presenters/WallPresenter.php index d9ba06b0..9d59ab59 100644 --- a/Web/Presenters/WallPresenter.php +++ b/Web/Presenters/WallPresenter.php @@ -301,7 +301,7 @@ final class WallPresenter extends OpenVKPresenter if(!is_null($poll)) $post->attach($poll); - + if($wall > 0 && $wall !== $this->user->identity->getId()) (new WallPostNotification($wallOwner, $post, $this->user->identity))->emit(); @@ -402,11 +402,9 @@ final class WallPresenter extends OpenVKPresenter (new RepostNotification($post->getOwner(false), $post, $this->user->identity))->emit(); }; - if($where == "wall") - $this->returnJson(["wall_owner" => $this->user->identity->getId()]); - - else - $this->returnJson(["wall_owner" => $groupId*-1]); + $this->returnJson([ + "wall_owner" => $where == "wall" ? $this->user->identity->getId() : $groupId*-1 + ]); } function renderDelete(int $wall, int $post_id): void diff --git a/Web/Presenters/templates/components/post/microblogpost.xml b/Web/Presenters/templates/components/post/microblogpost.xml index 5fbf07e7..2f2fc2f1 100644 --- a/Web/Presenters/templates/components/post/microblogpost.xml +++ b/Web/Presenters/templates/components/post/microblogpost.xml @@ -96,7 +96,7 @@ {_comment}
- +
{if $post->getRepostCount() > 0}{$post->getRepostCount()}{/if}
diff --git a/Web/Presenters/templates/components/post/oldpost.xml b/Web/Presenters/templates/components/post/oldpost.xml index 2a4dc252..dcbee4f6 100644 --- a/Web/Presenters/templates/components/post/oldpost.xml +++ b/Web/Presenters/templates/components/post/oldpost.xml @@ -107,7 +107,7 @@  |  {/if} - + {_share} {if $post->getRepostCount() > 0} ({$post->getRepostCount()}) diff --git a/Web/routes.yml b/Web/routes.yml index 4df3ec42..0dffb7bf 100644 --- a/Web/routes.yml +++ b/Web/routes.yml @@ -93,8 +93,6 @@ routes: handler: "User->increaseRating" - url: "/id{num}" handler: "User->view" - - url: "/id{num}/getWriteableClubs" - handler: "User->getWriteableClubs" - url: "/friends{num}" handler: "User->friends" - url: "/edit" diff --git a/Web/static/js/openvk.cls.js b/Web/static/js/openvk.cls.js index 737902b7..49760b7f 100644 --- a/Web/static/js/openvk.cls.js +++ b/Web/static/js/openvk.cls.js @@ -168,18 +168,18 @@ document.addEventListener("DOMContentLoaded", function() { //BEGIN }); //END ONREADY DECLS -function repostPost(id, hash, owner) { +async function repostPost(id, hash) { uRepostMsgTxt = ` ${tr('auditory')}:
${tr("in_wall")}
- ${tr("in_group")}
+ ${tr("in_group")}

${tr('your_comment')}:

`; let clubs = []; @@ -197,8 +197,8 @@ function repostPost(id, hash, owner) { } } groupId = document.querySelector("#groupId").value; - asGroup = asgroup.value; - signed = signed.value; + asGroup = asgroup.checked == true ? 1 : 0; + signed = signed.checked == true ? 1 : 0; hash = encodeURIComponent(hash); xhr = new XMLHttpRequest(); xhr.open("POST", "/wall"+id+"/repost?hash="+hash, true); @@ -215,16 +215,15 @@ function repostPost(id, hash, owner) { }), Function.noop ]); - let xhrj = new XMLHttpRequest(); - xhrj.open("GET", "id"+owner+"/getWriteableClubs?hash="+hash) - xhrj.send() - xhrj.onload = () => + try { - clubs = JSON.parse(xhrj.responseText); - for(const el of clubs) - { + clubs = await API.Groups.getWriteableClubs(); + for(const el of clubs) { document.getElementById("groupId").insertAdjacentHTML("beforeend", ``) } + } catch(rejection) { + console.error("You did not created any groups") + document.getElementById("group").setAttribute("disabled", "disabled") } } @@ -484,4 +483,4 @@ $(document).on("scroll", () => { $(".floating_sidebar")[0].classList.remove("hide_anim"); }, 250); } -}) +}) \ No newline at end of file