diff --git a/webclient/room/room-controller.js b/webclient/room/room-controller.js
index 3d75ef5499..3cc127140b 100644
--- a/webclient/room/room-controller.js
+++ b/webclient/room/room-controller.js
@@ -15,8 +15,8 @@ limitations under the License.
*/
angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
-.controller('RoomController', ['$scope', '$timeout', '$routeParams', '$location', '$rootScope', 'matrixService', 'eventHandlerService', 'mFileUpload', 'mPresence', 'matrixPhoneService', 'MatrixCall',
- function($scope, $timeout, $routeParams, $location, $rootScope, matrixService, eventHandlerService, mFileUpload, mPresence, matrixPhoneService, MatrixCall) {
+.controller('RoomController', ['$filter', '$scope', '$timeout', '$routeParams', '$location', '$rootScope', 'matrixService', 'eventHandlerService', 'mFileUpload', 'mPresence', 'matrixPhoneService', 'MatrixCall',
+ function($filter, $scope, $timeout, $routeParams, $location, $rootScope, matrixService, eventHandlerService, mFileUpload, mPresence, matrixPhoneService, MatrixCall) {
'use strict';
var MESSAGES_PER_PAGINATION = 30;
var THUMBNAIL_SIZE = 320;
@@ -27,8 +27,7 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
$scope.state = {
user_id: matrixService.config().user_id,
- events_from: "END", // when to start the event stream from.
- earliest_token: "END", // stores how far back we've paginated.
+ permission_denied: undefined, // If defined, this string contains the reason why the user cannot join the room
first_pagination: true, // this is toggled off when the first pagination is done
can_paginate: false, // this is toggled off when we are not ready yet to paginate or when we run out of items
paginating: false, // used to avoid concurrent pagination requests pulling in dup contents
@@ -43,6 +42,44 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
$scope.imageURLToSend = "";
$scope.userIDToInvite = "";
+
+ // vars and functions for updating the name
+ $scope.name = {
+ isEditing: false,
+ newNameText: "",
+ editName: function() {
+ if ($scope.name.isEditing) {
+ console.log("Warning: Already editing name.");
+ return;
+ };
+
+ // Use the filter applied in html to set the input value
+ $scope.name.newNameText = $filter('mRoomName')($scope.room_id);
+
+ // Force focus to the input
+ $timeout(function() {
+ angular.element('.roomNameInput').focus();
+ }, 0);
+
+ $scope.name.isEditing = true;
+ },
+ updateName: function() {
+ console.log("Updating name to "+$scope.name.newNameText);
+ matrixService.setName($scope.room_id, $scope.name.newNameText).then(
+ function() {
+ },
+ function(error) {
+ $scope.feedback = "Request failed: " + error.data.error;
+ }
+ );
+
+ $scope.name.isEditing = false;
+ },
+ cancelEdit: function() {
+ $scope.name.isEditing = false;
+ }
+ };
+
// vars and functions for updating the topic
$scope.topic = {
isEditing: false,
@@ -60,20 +97,29 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
$scope.topic.newTopicText = "";
}
+ // Force focus to the input
+ $timeout(function() {
+ angular.element('.roomTopicInput').focus();
+ }, 0);
+
$scope.topic.isEditing = true;
},
updateTopic: function() {
console.log("Updating topic to "+$scope.topic.newTopicText);
- matrixService.setTopic($scope.room_id, $scope.topic.newTopicText);
+ matrixService.setTopic($scope.room_id, $scope.topic.newTopicText).then(
+ function() {
+ },
+ function(error) {
+ $scope.feedback = "Request failed: " + error.data.error;
+ }
+ );
+
$scope.topic.isEditing = false;
},
cancelEdit: function() {
$scope.topic.isEditing = false;
}
- };
-
-
-
+ };
var scrollToBottom = function(force) {
console.log("Scrolling to bottom");
@@ -119,6 +165,28 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
$scope.state.waiting_for_joined_event = false;
onInit3();
}
+ else if (event.state_key === $scope.state.user_id && "invite" !== event.membership && "join" !== event.membership) {
+ var user;
+
+ if ($scope.members[event.user_id]) {
+ user = $scope.members[event.user_id].displayname;
+ }
+ if (user) {
+ user = user + " (" + event.user_id + ")";
+ }
+ else {
+ user = event.user_id;
+ }
+
+
+ if ("ban" === event.membership) {
+ $scope.state.permission_denied = "You have been banned by " + user;
+ }
+ else {
+ $scope.state.permission_denied = "You have been kicked by " + user;
+ }
+
+ }
else {
scrollToBottom();
updateMemberList(event);
@@ -159,12 +227,15 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
else {
$scope.state.paginating = true;
}
- // console.log("paginateBackMessages from " + $scope.state.earliest_token + " for " + numItems);
+
+ console.log("paginateBackMessages from " + $rootScope.events.rooms[$scope.room_id].pagination.earliest_token + " for " + numItems);
var originalTopRow = $("#messageTable>tbody>tr:first")[0];
- matrixService.paginateBackMessages($scope.room_id, $scope.state.earliest_token, numItems).then(
+
+ // Paginate events from the point in cache
+ matrixService.paginateBackMessages($scope.room_id, $rootScope.events.rooms[$scope.room_id].pagination.earliest_token, numItems).then(
function(response) {
- eventHandlerService.handleEvents(response.data.chunk, false);
- $scope.state.earliest_token = response.data.end;
+
+ eventHandlerService.handleRoomMessages($scope.room_id, response.data, false);
if (response.data.chunk.length < MESSAGES_PER_PAGINATION) {
// no more messages to paginate. this currently never gets turned true again, as we never
// expire paginated contents in the current implementation.
@@ -459,7 +530,7 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
var powerLevel = 50; // default power level for op
if (matches) {
var user_id = matches[1];
- if (matches.length === 4) {
+ if (matches.length === 4 && undefined !== matches[3]) {
powerLevel = parseInt(matches[3]);
}
if (powerLevel !== NaN) {
@@ -512,8 +583,7 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
room_id: $scope.room_id,
type: "m.room.message",
user_id: $scope.state.user_id,
- // FIXME: re-enable echo_msg_state when we have a nice way to turn the field off again
- // echo_msg_state: "messagePending" // Add custom field to indicate the state of this fake message to HTML
+ echo_msg_state: "messagePending" // Add custom field to indicate the state of this fake message to HTML
};
$scope.textInput = "";
@@ -522,26 +592,21 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
}
if (promise) {
+ // Reset previous feedback
+ $scope.feedback = "";
+
promise.then(
- function() {
+ function(response) {
console.log("Request successfully sent");
- if (!echo) {
- $scope.textInput = "";
- }
-/*
- if (echoMessage) {
- // Remove the fake echo message from the room messages
- // It will be replaced by the one acknowledged by the server
- // ...except this causes a nasty flicker. So don't swap messages for now. --matthew
- // var index = $rootScope.events.rooms[$scope.room_id].messages.indexOf(echoMessage);
- // if (index > -1) {
- // $rootScope.events.rooms[$scope.room_id].messages.splice(index, 1);
- // }
+ if (echo) {
+ // Mark this fake message event with its allocated event_id
+ // When the true message event will come from the events stream (in handleMessage),
+ // we will be able to replace the fake one by the true one
+ echoMessage.event_id = response.data.event_id;
}
else {
$scope.textInput = "";
- }
-*/
+ }
},
function(error) {
$scope.feedback = "Request failed: " + error.data.error;
@@ -647,7 +712,7 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
},
function(reason) {
console.log("Can't join room: " + JSON.stringify(reason));
- $scope.feedback = "You do not have permission to join this room";
+ $scope.state.permission_denied = "You do not have permission to join this room";
});
}
else {
@@ -659,9 +724,6 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
var onInit3 = function() {
console.log("onInit3");
-
- // TODO: We should be able to keep them
- eventHandlerService.resetRoomMessages($scope.room_id);
// Make recents highlight the current room
$scope.recentsSelectedRoomID = $scope.room_id;
@@ -690,12 +752,13 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
);
};
- $scope.inviteUser = function(user_id) {
+ $scope.inviteUser = function() {
- matrixService.invite($scope.room_id, user_id).then(
+ matrixService.invite($scope.room_id, $scope.userIDToInvite).then(
function() {
console.log("Invited.");
- $scope.feedback = "Invite sent successfully";
+ $scope.feedback = "Invite successfully sent to " + $scope.userIDToInvite;
+ $scope.userIDToInvite = "";
},
function(reason) {
$scope.feedback = "Failure: " + reason;
diff --git a/webclient/room/room.html b/webclient/room/room.html
index 5debeaba7c..9d617eadd8 100644
--- a/webclient/room/room.html
+++ b/webclient/room/room.html
@@ -3,9 +3,16 @@
<div id="roomHeader">
<a href ng-click="goToPage('/')"><img src="img/logo-small.png" width="100" height="43" alt="[matrix]"/></a>
<div class="roomHeaderInfo">
- <div id="roomName">
- {{ room_id | mRoomName }}
+
+ <div class="roomNameSection">
+ <div ng-hide="name.isEditing" ng-dblclick="name.editName()" id="roomName">
+ {{ room_id | mRoomName }}
+ </div>
+ <form ng-submit="name.updateName()" ng-show="name.isEditing" class="roomNameForm">
+ <input ng-model="name.newNameText" ng-blur="name.cancelEdit()" class="roomNameInput" />
+ </form>
</div>
+
<div class="roomTopicSection">
<button ng-hide="events.rooms[room_id]['m.room.topic'].content.topic || topic.isEditing"
ng-click="topic.editTopic()" class="roomTopicSetNew">
@@ -16,8 +23,7 @@
{{ events.rooms[room_id]['m.room.topic'].content.topic | limitTo: 200}}
</div>
<form ng-submit="topic.updateTopic()" ng-show="topic.isEditing" class="roomTopicForm">
- <input ng-model="topic.newTopicText" ng-blur="topic.cancelEdit()" class="roomTopicInput"
- autofocus />
+ <input ng-model="topic.newTopicText" ng-blur="topic.cancelEdit()" class="roomTopicInput" />
</form>
</div>
</div>
@@ -31,14 +37,14 @@
<div ng-include="'recents/recents.html'"></div>
</div>
- <div id="usersTableWrapper">
+ <div id="usersTableWrapper" ng-hide="state.permission_denied">
<table id="usersTable">
<tr ng-repeat="member in members | orderMembersList">
<td class="userAvatar mouse-pointer" ng-click="$parent.goToUserPage(member.id)" ng-class="member.membership == 'invite' ? 'invited' : ''">
<img class="userAvatarImage"
ng-src="{{member.avatar_url || 'img/default-profile.png'}}"
alt="{{ member.displayname || member.id.substr(0, member.id.indexOf(':')) }}"
- title="{{ member.id }}"
+ title="{{ member.id }} - power: {{ member.powerLevel }}"
width="80" height="80"/>
<img class="userAvatarGradient" src="img/gradient.png" title="{{ member.id }}" width="80" height="24"/>
<div class="userPowerLevel" ng-style="{'width': member.powerLevelNorm +'%'}"></div>
@@ -50,7 +56,7 @@
</table>
</div>
- <div id="messageTableWrapper" keep-scroll>
+ <div id="messageTableWrapper" ng-hide="state.permission_denied" keep-scroll>
<!-- FIXME: need to have better timestamp semantics than the (msg.content.hsob_ts || msg.ts) hack below -->
<table id="messageTable" infinite-scroll="paginateMore()">
<tr ng-repeat="msg in events.rooms[room_id].messages"
@@ -66,7 +72,7 @@
<img class="avatarImage" ng-src="{{ members[msg.user_id].avatar_url || 'img/default-profile.png' }}" width="32" height="32"
ng-hide="events.rooms[room_id].messages[$index - 1].user_id === msg.user_id || msg.user_id === state.user_id"/>
</td>
- <td ng-class="!msg.content.membership ? (msg.content.msgtype === 'm.emote' ? 'emote text' : 'text') : 'membership text'">
+ <td ng-class="(!msg.content.membership && ('m.room.topic' !== msg.type && 'm.room.name' !== msg.type))? (msg.content.msgtype === 'm.emote' ? 'emote text' : 'text') : 'membership text'">
<div class="bubble">
<span ng-if="'join' === msg.content.membership">
{{ members[msg.state_key].displayname || msg.state_key }} joined
@@ -93,8 +99,12 @@
</span>
</span>
- <span ng-show='msg.content.msgtype === "m.emote"' ng-bind-html="'* ' + (members[msg.user_id].displayname || msg.user_id) + ' ' + msg.content.body | linky:'_blank'"/>
+ <span ng-show='msg.content.msgtype === "m.emote"'
+ ng-class="msg.echo_msg_state"
+ ng-bind-html="'* ' + (members[msg.user_id].displayname || msg.user_id) + ' ' + msg.content.body | linky:'_blank'"/>
+
<span ng-show='msg.content.msgtype === "m.text"'
+ class="message"
ng-class="msg.echo_msg_state"
ng-bind-html="((msg.content.msgtype === 'm.text') ? msg.content.body : '') | linky:'_blank'"/>
@@ -110,6 +120,15 @@
ng-click="$parent.fullScreenImageURL = msg.content.url"/>
</div>
</div>
+
+ <span ng-if="'m.room.topic' === msg.type">
+ {{ members[msg.user_id].displayname || msg.user_id }} changed the topic to: {{ msg.content.topic }}
+ </span>
+
+ <span ng-if="'m.room.name' === msg.type">
+ {{ members[msg.user_id].displayname || msg.user_id }} changed the room name to: {{ msg.content.name }}
+ </span>
+
</div>
</td>
<td class="rightBlock">
@@ -119,6 +138,10 @@
</tr>
</table>
</div>
+
+ <div ng-show="state.permission_denied">
+ {{ state.permission_denied }}
+ </div>
</div>
</div>
@@ -131,11 +154,13 @@
{{ state.user_id }}
</td>
<td width="*">
- <input id="mainInput" ng-model="textInput" ng-enter="send()" ng-focus="true" autocomplete="off" tab-complete/>
+ <textarea id="mainInput" rows="1" ng-model="textInput" ng-enter="send()"
+ ng-disabled="state.permission_denied"
+ ng-focus="true" autocomplete="off" tab-complete/>
</td>
<td id="buttonsCell">
- <button ng-click="send()">Send</button>
- <button m-file-input="imageFileToSend" class="extraControls">Image</button>
+ <button ng-click="send()" ng-disabled="state.permission_denied">Send</button>
+ <button m-file-input="imageFileToSend" class="extraControls" ng-disabled="state.permission_denied">Image</button>
</td>
</tr>
</table>
@@ -143,11 +168,11 @@
<div class="extraControls">
<span>
Invite a user:
- <input ng-model="userIDToInvite" size="32" type="text" placeholder="User ID (ex:@user:homeserver)"/>
- <button ng-click="inviteUser(userIDToInvite)">Invite</button>
+ <input ng-model="userIDToInvite" size="32" type="text" ng-enter="inviteUser()" ng-disabled="state.permission_denied" placeholder="User ID (ex:@user:homeserver)"/>
+ <button ng-click="inviteUser()" ng-disabled="state.permission_denied">Invite</button>
</span>
- <button ng-click="leaveRoom()">Leave</button>
- <button ng-click="startVoiceCall()" ng-show="(currentCall == undefined || currentCall.state == 'ended') && memberCount() == 2">Voice Call</button>
+ <button ng-click="leaveRoom()" ng-disabled="state.permission_denied">Leave</button>
+ <button ng-click="startVoiceCall()" ng-show="(currentCall == undefined || currentCall.state == 'ended') && memberCount() == 2" ng-disabled="state.permission_denied">Voice Call</button>
</div>
{{ feedback }}
|