Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions css/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ input[type="password"] {
@include icon-color('text', 'filetypes', $color-white, 1, true);
}

.icon-changelog {
background-image: url('../img/changelog.svg');
}

#app-navigation .favorite-mark {
position: absolute;
/* 44px is the padding of the main entry link, and 16px the size (size, not
Expand Down
53 changes: 53 additions & 0 deletions img/changelog.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
ROOM_TYPE_ONE_TO_ONE: 1,
ROOM_TYPE_GROUP: 2,
ROOM_TYPE_PUBLIC: 3,
ROOM_TYPE_CHANGELOG: 4,

/** @property {OCA.SpreedMe.Models.Room} activeRoom */
activeRoom: null,
Expand Down Expand Up @@ -405,7 +406,9 @@
// happens it will overlap with the content area (the narrower the
// window the larger the overlap). Due to this the sidebar is opened
// automatically only if it will not overlap with the content area.
if ($(window).width() > 1111) {
if (this.activeRoom.get('type') === this.ROOM_TYPE_CHANGELOG) {
this._sidebarView.close();
} else if (this.activeRoom.get('type') !== this.ROOM_TYPE_CHANGELOG && $(window).width() > 1111) {
this._sidebarView.open();
}

Expand Down
8 changes: 4 additions & 4 deletions js/collections.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/collections.js.map

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions js/views/callinfoview.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@

initialize: function() {
var nameAttribute = 'name';
if (this.model.get('objectType') === 'share:password') {
if (this.model.get('objectType') === 'share:password' ||
this.model.get('type') === OCA.SpreedMe.app.ROOM_TYPE_CHANGELOG) {
nameAttribute = 'displayName';
}

Expand Down Expand Up @@ -271,9 +272,12 @@
// This has to be added below the "enable/disableEdition" calls as
// those calls render the view if needed, while the setters expect
// the view to be already rendered.
if (this.model.get('type') === 1) {
if (this.model.get('type') === OCA.SpreedMe.app.ROOM_TYPE_ONE_TO_ONE) {
this._nameEditableTextLabel.setModelAttribute(undefined);
this._nameEditableTextLabel.setLabelPlaceholder(t('spreed', 'Conversation with {name}', {name: this.model.get('displayName')}));
} else if (this.model.get('type') === OCA.SpreedMe.app.ROOM_TYPE_CHANGELOG) {
this._nameEditableTextLabel.setModelAttribute(undefined);
this._nameEditableTextLabel.setLabelPlaceholder(this.model.get('displayName'));
} else {
this._nameEditableTextLabel.setModelAttribute('name');
this._nameEditableTextLabel.setLabelPlaceholder(t('spreed', 'Conversation name'));
Expand Down
8 changes: 6 additions & 2 deletions js/views/chatview.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,12 @@
};
$el.find('.authorRow .avatar').each(function() {
if (model && model.get('actorType') === 'bots') {
$(this).imageplaceholder('>_', $(this).data('displayname'), 32);
$(this).css('background-color', '#363636');
if (model.get('actorId') === 'changelog') {
$(this).addClass('icon icon-changelog');
} else {
$(this).imageplaceholder('>_', $(this).data('displayname'), 32);
$(this).css('background-color', '#363636');
}
} else {
setAvatar($(this), 32);
}
Expand Down
2 changes: 2 additions & 0 deletions js/views/roomlistview.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@
icon = 'icon icon-file';
} else if (this.model.get('objectType') === 'share:password') {
icon = 'icon icon-password';
} else if (this.model.get('type') === OCA.SpreedMe.app.ROOM_TYPE_CHANGELOG) {
icon = 'icon icon-changelog';
} else if (this.model.get('type') === OCA.SpreedMe.app.ROOM_TYPE_GROUP) {
icon = 'icon icon-contacts';
} else if (this.model.get('type') === OCA.SpreedMe.app.ROOM_TYPE_PUBLIC) {
Expand Down
2 changes: 2 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

use OCA\Spreed\Activity\Listener as ActivityListener;
use OCA\Spreed\Capabilities;
use OCA\Spreed\Chat\Changelog\Listener as ChangelogListener;
use OCA\Spreed\Chat\ChatManager;
use OCA\Spreed\Chat\Command\Listener as CommandListener;
use OCA\Spreed\Chat\Parser\Listener as ParserListener;
Expand Down Expand Up @@ -113,6 +114,7 @@ public function register(): void {
SignalingListener::register($dispatcher);
CommandListener::register($dispatcher);
ResourceListener::register($dispatcher);
ChangelogListener::register($dispatcher);

$this->registerNavigationLink($server);
$this->registerRoomActivityHooks($dispatcher);
Expand Down
9 changes: 5 additions & 4 deletions lib/BackgroundJob/RemoveEmptyRooms.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ protected function run($argument): void {
}

public function callback(Room $room): void {
if ($room->getType() === Room::ONE_TO_ONE_CALL && $room->getNumberOfParticipants(false) <= 1) {
$room->deleteRoom();
$this->numDeletedRooms++;
} else if ($room->getNumberOfParticipants(false) === 0 && $room->getObjectType() !== 'file') {
if ($room->getType() === Room::CHANGELOG_CONVERSATION) {
return;
}

if ($room->getNumberOfParticipants(false) === 0 && $room->getObjectType() !== 'file') {
$room->deleteRoom();
$this->numDeletedRooms++;
}
Expand Down
55 changes: 55 additions & 0 deletions lib/Chat/Changelog/Listener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2019 Joas Schilling <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\Spreed\Chat\Changelog;

use OCA\Spreed\Controller\RoomController;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;

class Listener {

public static function register(EventDispatcherInterface $dispatcher): void {
$dispatcher->addListener(RoomController::class . '::preGetRooms', function(GenericEvent $event) {
$userId = $event->getArgument('userId');

/** @var Listener $listener */
$listener = \OC::$server->query(self::class);
$listener->preGetRooms($userId);
}, -100);
}

/** @var Manager */
protected $manager;

public function __construct(Manager $manager) {
$this->manager = $manager;
}

public function preGetRooms(string $userId): void {
if (!$this->manager->userHasNewChangelog($userId)) {
return;
}

$this->manager->updateChangelog($userId);
}
}
86 changes: 86 additions & 0 deletions lib/Chat/Changelog/Manager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2019 Joas Schilling <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\Spreed\Chat\Changelog;


use OCA\Spreed\Chat\ChatManager;
use OCA\Spreed\Manager as RoomManager;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IConfig;
use OCP\IL10N;

class Manager {

/** @var IConfig */
protected $config;
/** @var RoomManager */
protected $roomManager;
/** @var ChatManager */
protected $chatManager;
/** @var ITimeFactory */
protected $timeFactory;
/** @var IL10N */
protected $l;

public function __construct(IConfig $config,
RoomManager $roomManager,
ChatManager $chatManager,
ITimeFactory $timeFactory,
IL10N $l) {
$this->config = $config;
$this->roomManager = $roomManager;
$this->chatManager = $chatManager;
$this->timeFactory = $timeFactory;
$this->l = $l;
}

public function getChangelogForUser(string $userId): int {
return (int) $this->config->getUserValue($userId, 'spreed', 'changelog', 0);
}

public function userHasNewChangelog(string $userId): bool {
return $this->getChangelogForUser($userId) < count($this->getChangelogs());
}

public function updateChangelog(string $userId): void {
$room = $this->roomManager->getChangelogRoom($userId);

$logs = $this->getChangelogs();
$hasReceivedLog = $this->getChangelogForUser($userId);

foreach ($logs as $key => $changelog) {
if ($key < $hasReceivedLog) {
continue;
}
$this->chatManager->addChangelogMessage($room, $changelog);
}

$this->config->setUserValue($userId, 'spreed', 'changelog', count($this->getChangelogs()));
}

public function getChangelogs(): array {
return [
$this->l->t("Welcome to Nextcloud Talk!\nIn this conversation you will be informed about new features available in Nextcloud Talk."),
];
}
}
28 changes: 28 additions & 0 deletions lib/Chat/ChatManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,34 @@ public function addSystemMessage(Room $chat, string $actorType, string $actorId,
return $comment;
}

/**
* Sends a new message to the given chat.
*
* @param Room $chat
* @param string $message
* @return IComment
*/
public function addChangelogMessage(Room $chat, string $message): IComment {
$comment = $this->commentsManager->create('guests', 'changelog', 'chat', (string) $chat->getId());
$comment->setMessage($message);
$comment->setCreationDateTime($this->timeFactory->getDateTime());
$comment->setVerb('comment'); // Has to be comment, so it counts as unread message

try {
$this->commentsManager->save($comment);

// Update last_message
$chat->setLastMessage($comment);

$this->dispatcher->dispatch(self::class . '::sendSystemMessage', new GenericEvent($chat, [
'comment' => $comment,
]));
} catch (NotFoundException $e) {
}

return $comment;
}

/**
* Sends a new message to the given chat.
*
Expand Down
43 changes: 43 additions & 0 deletions lib/Chat/Parser/Changelog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2018 Joas Schilling <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\Spreed\Chat\Parser;

use OCA\Spreed\Model\Message;

class Changelog {

/**
* @param Message $chatMessage
* @throws \OutOfBoundsException
*/
public function parseMessage(Message $chatMessage): void {

if ($chatMessage->getActorType() !== 'guests' ||
$chatMessage->getActorId() !== 'changelog') {
throw new \OutOfBoundsException('Not a changelog');
}

$l = $chatMessage->getL10n();
$chatMessage->setActor('bots', 'changelog', $l->t('Talk updates ✅'));
}
}
Loading