Skip to content

Commit

Permalink
🌟 Update notifications, messages and more
Browse files Browse the repository at this point in the history
--- summary:
* 🌟 Add offline indicator and fix ws notif refresh
* 🛠 Do not return deleted workspace
* 🌟 Improve applications and connectors management (#201)
* 📚 Translations fixes
* 🌟 Chat improvements (Fix Twacode, hightlight mentions)
* 🌟 Channels improvement (New mute options, fix notifications and unwanted direct messages channels)

--- commits history

* 🛠 Do not return deleted workspace

* 🛠  Update workspace permission in frontend

* 🌟 Add offline indicator and fix ws notif refresh

* 🌟 Chat improvements

* Add offline indicator and fix ws notif refresh

* Implement more mute options

* Update backend for new mute options

* Fix notifications not visible or too visible

* Fix messages list moving up / down when send

* Remove direct messages channel when empty

* Fix notifications and Twacode parser

* 🌟 Improve applications and connectors management (#201)

* #193 Remove simplified name application and application group inputs

* #193 Fix missing icons and remove open/close system for Applications developed by the company

* #193 Add new section that allow manager to easily access necessary data for Twake applications

* #193 Change app settings background color and improve application privileges

* 📚 Translations fixes

* Translation fixes

* Translation fixes 2

* Translation fixes 2

* Correcting general._ language keys

* Correcting general._ language keys 2

Co-authored-by: Romaric Mourgues <rmourgues@linagora.com>

* Fix twacode typo

Co-authored-by: Stéphane Vieira <36481167+stephanevieira75@users.noreply.github.com>
Co-authored-by: droste89 <68430672+droste89@users.noreply.github.com>

Closes #175
Closes #197
Closes #198
Closes #203
Closes #166
Closes #167
Closes #161
Closes #169
Closes #193
  • Loading branch information
RomaricMourgues committed Sep 1, 2020
1 parent 0dd441a commit 9dda7e1
Show file tree
Hide file tree
Showing 91 changed files with 935 additions and 988 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ class ChannelsNotifications extends BaseController
public function mute(Request $request)
{
$channel_id = $request->request->get("channel_id");
$mute = $request->request->get("mute", true);
$mute = $request->request->get("mute", 1);
if(!is_integer($mute)){
$mute = $mute?2:0;
}
$res = $this->get("app.channels.notifications")->mute($channel_id, $mute, $this->getUser());
if (!$res) {
return new Response(Array("status" => "error"));
Expand Down
25 changes: 23 additions & 2 deletions twake/backend/core/src/Twake/Channels/Entity/ChannelMember.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class ChannelMember
private $last_access = 0;

/**
* @ORM\Column(name="muted", type="twake_boolean")
* @ORM\Column(name="muted", type="tinyint")
*/
private $muted = 0;

Expand All @@ -73,6 +73,11 @@ class ChannelMember
*/
private $last_messages_increment = 0; //Will increment on each new message to count notifications

/**
* @ORM\Column(name="last_quoted_message_id", type="text")
*/
private $last_quoted_message_id = ""; //Will be set when the user is quoted to the quoted message id

/**
* ChannelMember constructor.
* @param $user
Expand Down Expand Up @@ -193,7 +198,7 @@ public function getMuted()
}

/**
* @param mixed $muted
* @param mixed $muted 0: no, 1: mute default (except @all, @[user]), 2: mute all except user mension, 3: mute everything
*/
public function setMuted($muted)
{
Expand All @@ -216,4 +221,20 @@ public function setLastMessagesIncrement($last_messages_increment)
$this->last_messages_increment = $last_messages_increment;
}

/**
* @return mixed
*/
public function getLastQuotedMessageId()
{
return $this->last_quoted_message_id;
}

/**
* @param mixed $last_quoted_message_id
*/
public function setLastQuotedMessageId($last_quoted_message_id)
{
$this->last_quoted_message_id = $last_quoted_message_id;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ public function addTab($channel_id, $application_id, $name)
$this->entity_manager->persist($channel);
$this->entity_manager->flush();

return $tab;

}

public function addAllWorkspaceMember($workspace, $channel)
Expand Down Expand Up @@ -217,16 +219,30 @@ public function updateChannelMembers($channel_entity, $members_ids, $current_use
$members_ids[] = $current_user_id;
}

$members_ids = array_unique($members_ids);
$final_members_ids = [];

$current_members = $channel_entity->getMembers();

$membersRepo = $this->entity_manager->getRepository("Twake\Channels:ChannelMember");
$usersRepo = $this->entity_manager->getRepository("Twake\Users:User");

foreach ($members_ids as $member_id) {
if (!in_array($member_id, $current_members)) {
$member = new \Twake\Channels\Entity\ChannelMember($member_id . "", $channel_entity);
$member->setLastMessagesIncrement($channel_entity->getMessagesIncrement());
$this->entity_manager->persist($member);
//Check if user is in workspace
$canBeAdded = true;
if(!$channel_entity->getDirect()){
$wuRepo = $this->entity_manager->getRepository("Twake\Workspaces:WorkspaceUser");
$canBeAdded = !!$wuRepo->findBy(Array("workspace" => $channel_entity->getOriginalWorkspaceId()."", "user" => $member_id.""));
}
if($canBeAdded){
$member = new \Twake\Channels\Entity\ChannelMember($member_id . "", $channel_entity);
$member->setLastMessagesIncrement($channel_entity->getMessagesIncrement());
$this->entity_manager->persist($member);
$final_members_ids[] = $member_id;
}
}else{
$final_members_ids[] = $member_id;
}
}

Expand All @@ -239,7 +255,7 @@ public function updateChannelMembers($channel_entity, $members_ids, $current_use
}
}

$channel_entity->setMembers($members_ids);
$channel_entity->setMembers($final_members_ids);
$this->entity_manager->persist($channel_entity);
$this->entity_manager->flush();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,43 @@ public function newElement($channel, $sender_application = null, $sender_user =
$workspace_ent = $this->doctrine->getRepository("Twake\Workspaces:Workspace")->find($workspace);

$users_to_notify = [];
$users_to_notify_mention = [];
$mentions_types = [];

foreach ($members as $member) {

$mention = strpos(json_encode($message->getContent()), $member->getUserId()) !== false;
$mention = $mention || strpos(json_encode($message->getContent()), "@here") !== false;
$mention = $mention || strpos(json_encode($message->getContent()), "@all") !== false;

$muted = $member->getMuted();
if ($muted && $mention) {
$user_mention = strpos(json_encode($message->getContent()), $member->getUserId()) !== false;
$here_mention = strpos(json_encode($message->getContent()), "@here") !== false;
$all_mention = strpos(json_encode($message->getContent()), "@all") !== false;
$any_mention = $here_mention || $all_mention || $user_mention;

$muted_options = $member->getMuted();
$mention_level = ($any_mention?1:0) + ($user_mention?1:0); //2 if @user, 1 if only @here

$muted = true;
$mention_text = false;
if($mention_level >= $muted_options){
$muted = false;
}

if (!$muted && (!$sender_user || $member->getUserId() != $sender_user->getId())) {

$user = $userRepo->find($member->getUserId());

$member->setLastActivity(new \DateTime());
if($mention_level === 1){
$mention_text = "@".($all_mention?"all":"here");
}
if($mention_level === 2){
$mention_text = "@".$user->getUsername();
}

$this->pusher->push(Array("type" => "update", "notification" => Array("channel" => $channel->getAsArray())), "notifications/" . $member->getUserId());
$member->setLastActivity(new \DateTime());
if($mention_text){
$member->setLastQuotedMessageId("" . $message->getId());
}

$channel_array = $channel->getAsArray();
$channel_array["_user_last_quoted_message_id"] = $member->getLastQuotedMessageId();
$this->pusher->push(Array("type" => "update", "notification" => Array("channel" => $channel_array)), "notifications/" . $member->getUserId());

//Updating workspace and group notifications
if (!$channel->getDirect()) {
Expand All @@ -62,16 +79,15 @@ public function newElement($channel, $sender_application = null, $sender_user =

}

if($mention){
$users_to_notify_mention[] = $user;
if($mention_text){
$mentions_types[$mention_text] = $mentions_types[$mention_text] ?: [];
$mentions_types[$mention_text][] = $user;
}else{
$users_to_notify[] = $user;
}

} else {
$member->setLastMessagesIncrement($channel->getMessagesIncrement());
$member->setLastAccess(new \DateTime());
}

$this->doctrine->persist($member);
}

Expand All @@ -90,20 +106,23 @@ public function newElement($channel, $sender_application = null, $sender_user =
true
);

$this->notificationSystem->pushNotification(
null,
$sender_application,
$sender_user,
$workspace_ent,
$channel,
$users_to_notify_mention,
"channel_" . $channel->getId(),
"@mentionned: ".$message_as_text,
$message ? $message->getId() : "",
Array(),
Array("push"),
true
);
foreach($mentions_types as $mention_text => $users){
error_log($mention_text);
$this->notificationSystem->pushNotification(
null,
$sender_application,
$sender_user,
$workspace_ent,
$channel,
$users,
"channel_" . $channel->getId(),
"@".ltrim($mention_text, "@").": ".$message_as_text,
$message ? $message->getId() : "",
Array(),
Array("push"),
true
);
}

$this->doctrine->persist($channel);

Expand Down Expand Up @@ -168,9 +187,11 @@ public function unread($channel, $user)
$member = $membersRepo->findOneBy(Array("direct" => $channel->getDirect(), "channel_id" => $channel->getId(), "user_id" => $user->getId()));

$member->setLastMessagesIncrement($channel->getMessagesIncrement() - 1);
$member->setLastQuotedMessageId("force_unread");

$array = $channel->getAsArray();
$array["_user_last_message_increment"] = $member->getLastMessagesIncrement();
$array["_user_last_quoted_message_id"] = $member->getLastQuotedMessageId();
$array["_user_last_access"] = $member->getLastAccess() ? $member->getLastAccess()->getTimestamp() : 0;
$this->pusher->push(Array("type" => "update", "notification" => Array("channel" => $array)), "notifications/" . $user->getId());

Expand Down Expand Up @@ -210,9 +231,11 @@ public function read($channel, $user)

$member->setLastMessagesIncrement($channel->getMessagesIncrement());
$member->setLastAccess(new \DateTime());
$member->setLastQuotedMessageId("");

$array = $channel->getAsArray();
$array["_user_last_message_increment"] = $member->getLastMessagesIncrement();
$array["_user_last_quoted_message_id"] = $member->getLastQuotedMessageId();
$array["_user_last_access"] = $member->getLastAccess() ? $member->getLastAccess()->getTimestamp() : 0;
$this->pusher->push(Array("type" => "update", "notification" => Array("channel" => $array)), "notifications/" . $user->getId());

Expand Down
33 changes: 19 additions & 14 deletions twake/backend/core/src/Twake/Channels/Services/ChannelsSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public function get($options, $current_user)
if ($res) {
$tmp = $channel->getAsArray();
$tmp["_user_last_message_increment"] = $res->getLastMessagesIncrement();
$tmp["_user_last_quoted_message_id"] = $res->getLastQuotedMessageId();
$tmp["_user_last_access"] = $res->getLastAccess() ? $res->getLastAccess()->getTimestamp() : null;
$tmp["_user_muted"] = $res->getMuted();
$result[] = $tmp;
Expand Down Expand Up @@ -158,18 +159,6 @@ public function save($object, $options, $current_user)
$this->entity_manager->flush($channel);


//Send first message if created channel
if ($did_create) {
//Init channel with a first message
$init_message = Array(
"channel_id" => $channel->getId(),
"hidden_data" => Array("type" => "init_channel"),
"content" => "[]"
);
$this->messages_service->save($init_message, Array());
}


//Private and non private users management
if ($channel->getPrivate()) {
$this->updateChannelMembers($channel, $members, $current_user->getId());
Expand Down Expand Up @@ -197,18 +186,34 @@ public function save($object, $options, $current_user)


//Tabs
$tab = null;
if (isset($object["_once_save_tab"])) {
if (isset($object["_once_save_tab"]["id"]) && $object["_once_save_tab"]["id"]) {
$this->renameTab($channel->getId(), $object["_once_save_tab"]["app_id"], $object["_once_save_tab"]["id"], $object["_once_save_tab"]["name"]);
} else {
$this->addTab($channel->getId(), $object["_once_save_tab"]["app_id"], $object["_once_save_tab"]["name"]);
$tab = $this->addTab($channel->getId(), $object["_once_save_tab"]["app_id"], $object["_once_save_tab"]["name"]);
}
}
if (isset($object["_once_remove_tab"])) {
$this->removeTab($channel->getId(), $object["_once_remove_tab"]["app_id"], $object["_once_remove_tab"]["id"]);
}
if (isset($object["_once_save_tab_config"])) {
$this->updateTabConfiguration($channel->getId(), $object["_once_save_tab_config"]["app_id"], $object["_once_save_tab_config"]["id"], $object["_once_save_tab_config"]["configuration"]);
$tab_id = $object["_once_save_tab_config"]["id"];
if($tab && !$tab_id){
$tab_id = $tab->getId();
}
$this->updateTabConfiguration($channel->getId(), $object["_once_save_tab_config"]["app_id"], $tab_id, $object["_once_save_tab_config"]["configuration"]);
}

//Send first message if created channel
if ($did_create) {
//Init channel with a first message
$init_message = Array(
"channel_id" => $channel->getId(),
"hidden_data" => Array("type" => "init_channel"),
"content" => "[]"
);
$this->messages_service->save($init_message, Array());
}

return $channel->getAsArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public function get($options, $current_user)
if ($channel) {
$tmp = $channel->getAsArray();
$tmp["_user_last_message_increment"] = $link->getLastMessagesIncrement();
$tmp["_user_last_quoted_message_id"] = $link->getLastQuotedMessageId();
$tmp["_user_last_access"] = $link->getLastAccess() ? $link->getLastAccess()->getTimestamp() : null;
$tmp["_user_muted"] = $link->getMuted();
$result[] = $tmp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ private function convertType($type)
"twake_timeuuid" => "timeuuid",
"array" => "text",
"twake_boolean" => "tinyint",
"tinyint" => "tinyint",
"boolean" => "tinyint",
"text" => "text",
"twake_float" => "float",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/


namespace Twake\Core\Services\DoctrineAdapter\DBAL;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/


namespace Twake\Core\Services\DoctrineAdapter\DBAL\Types;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/


namespace Twake\Core\Services\DoctrineAdapter\DBAL\Types;

Expand Down
Loading

0 comments on commit 9dda7e1

Please sign in to comment.