0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-11-20 12:24:59 +01:00

Merge remote-tracking branch 'origin/develop' into merge_pdu_event_objects

This commit is contained in:
Mark Haines 2014-11-17 10:21:51 +00:00
commit 1d3ef8734c
18 changed files with 481 additions and 249 deletions

1
synctl Symbolic link
View file

@ -0,0 +1 @@
./synapse/app/synctl.py

View file

@ -699,7 +699,7 @@ textarea, input {
vertical-align: middle;
*/
display: inline-block;
max-width: 90%;
max-width: 80%;
padding-left: 1em;
padding-right: 1em;
padding-top: 2px;
@ -721,6 +721,7 @@ textarea, input {
text-align: right;
}
/*
.text.emote .bubble,
.text.membership .bubble,
.mine .text.emote .bubble,
@ -729,6 +730,7 @@ textarea, input {
background-color: transparent ! important;
border: 0px ! important;
}
*/
.mine .text .bubble {
/*

View file

@ -25,7 +25,8 @@ angular.module('mFileInput', [])
return {
restrict: 'A',
transclude: 'true',
template: '<div ng-transclude></div><input ng-hide="true" type="file" accept="image/*"/>',
// FIXME: add back in accept="image/*" when needed - e.g. for avatars
template: '<div ng-transclude></div><input ng-hide="true" type="file"/>',
scope: {
selectedFile: '=mFileInput'
},

View file

@ -47,28 +47,29 @@ angular.module('mFileUpload', ['matrixService', 'mUtilities'])
};
/*
* Upload an image file plus generate a thumbnail of it and upload it so that
* we will have all information to fulfill an image message request data.
* @param {File} imageFile the imageFile to send
* Upload an file plus generate a thumbnail of it (if possible) and upload it so that
* we will have all information to fulfill an file/image message request
* @param {File} file the file to send
* @param {Integer} thumbnailSize the max side size of the thumbnail to create
* @returns {promise} A promise that will be resolved by a image message object
* @returns {promise} A promise that will be resolved by a message object
* ready to be send with the Matrix API
*/
this.uploadImageAndThumbnail = function(imageFile, thumbnailSize) {
this.uploadFileAndThumbnail = function(file, thumbnailSize) {
var self = this;
var deferred = $q.defer();
console.log("uploadImageAndThumbnail " + imageFile.name + " - thumbnailSize: " + thumbnailSize);
console.log("uploadFileAndThumbnail " + file.name + " - thumbnailSize: " + thumbnailSize);
// The message structure that will be returned in the promise
var imageMessage = {
// The message structure that will be returned in the promise will look something like:
var message = {
/*
msgtype: "m.image",
url: undefined,
body: "Image",
info: {
size: undefined,
w: undefined,
h: undefined,
w: undefined,
h: undefined,
mimetype: undefined
},
thumbnail_url: undefined,
@ -78,101 +79,128 @@ angular.module('mFileUpload', ['matrixService', 'mUtilities'])
h: undefined,
mimetype: undefined
}
*/
};
// First, get the image size
mUtilities.getImageSize(imageFile).then(
function(size) {
console.log("image size: " + JSON.stringify(size));
if (file.type.indexOf("image/") === 0) {
// it's an image - try to do clientside thumbnailing.
mUtilities.getImageSize(file).then(
function(size) {
console.log("image size: " + JSON.stringify(size));
// The final operation: send imageFile
var uploadImage = function() {
self.uploadFile(imageFile).then(
function(url) {
// Update message metadata
imageMessage.url = url;
imageMessage.info = {
size: imageFile.size,
w: size.width,
h: size.height,
mimetype: imageFile.type
};
// The final operation: send file
var uploadImage = function() {
self.uploadFile(file).then(
function(url) {
// Update message metadata
message.url = url;
message.msgtype = "m.image";
message.body = file.name;
message.info = {
size: file.size,
w: size.width,
h: size.height,
mimetype: file.type
};
// If there is no thumbnail (because the original image is smaller than thumbnailSize),
// reuse the original image info for thumbnail data
if (!imageMessage.thumbnail_url) {
imageMessage.thumbnail_url = imageMessage.url;
imageMessage.thumbnail_info = imageMessage.info;
}
// We are done
deferred.resolve(imageMessage);
},
function(error) {
console.log(" -> Can't upload image");
deferred.reject(error);
}
);
};
// Create a thumbnail if the image size exceeds thumbnailSize
if (Math.max(size.width, size.height) > thumbnailSize) {
console.log(" Creating thumbnail...");
mUtilities.resizeImage(imageFile, thumbnailSize).then(
function(thumbnailBlob) {
// Get its size
mUtilities.getImageSize(thumbnailBlob).then(
function(thumbnailSize) {
console.log(" -> Thumbnail size: " + JSON.stringify(thumbnailSize));
// Upload it to the server
self.uploadFile(thumbnailBlob).then(
function(thumbnailUrl) {
// Update image message data
imageMessage.thumbnail_url = thumbnailUrl;
imageMessage.thumbnail_info = {
size: thumbnailBlob.size,
w: thumbnailSize.width,
h: thumbnailSize.height,
mimetype: thumbnailBlob.type
};
// Then, upload the original image
uploadImage();
},
function(error) {
console.log(" -> Can't upload thumbnail");
deferred.reject(error);
}
);
},
function(error) {
console.log(" -> Failed to get thumbnail size");
deferred.reject(error);
// If there is no thumbnail (because the original image is smaller than thumbnailSize),
// reuse the original image info for thumbnail data
if (!message.thumbnail_url) {
message.thumbnail_url = message.url;
message.thumbnail_info = message.info;
}
);
},
function(error) {
console.log(" -> Failed to create thumbnail: " + error);
deferred.reject(error);
}
);
}
else {
// No need of thumbnail
console.log(" Thumbnail is not required");
uploadImage();
}
// We are done
deferred.resolve(message);
},
function(error) {
console.log(" -> Can't upload image");
deferred.reject(error);
}
);
};
},
function(error) {
console.log(" -> Failed to get image size");
deferred.reject(error);
}
);
// Create a thumbnail if the image size exceeds thumbnailSize
if (Math.max(size.width, size.height) > thumbnailSize) {
console.log(" Creating thumbnail...");
mUtilities.resizeImage(file, thumbnailSize).then(
function(thumbnailBlob) {
// Get its size
mUtilities.getImageSize(thumbnailBlob).then(
function(thumbnailSize) {
console.log(" -> Thumbnail size: " + JSON.stringify(thumbnailSize));
// Upload it to the server
self.uploadFile(thumbnailBlob).then(
function(thumbnailUrl) {
// Update image message data
message.thumbnail_url = thumbnailUrl;
message.thumbnail_info = {
size: thumbnailBlob.size,
w: thumbnailSize.width,
h: thumbnailSize.height,
mimetype: thumbnailBlob.type
};
// Then, upload the original image
uploadImage();
},
function(error) {
console.log(" -> Can't upload thumbnail");
deferred.reject(error);
}
);
},
function(error) {
console.log(" -> Failed to get thumbnail size");
deferred.reject(error);
}
);
},
function(error) {
console.log(" -> Failed to create thumbnail: " + error);
deferred.reject(error);
}
);
}
else {
// No need of thumbnail
console.log(" Thumbnail is not required");
uploadImage();
}
},
function(error) {
console.log(" -> Failed to get image size");
deferred.reject(error);
}
);
}
else {
// it's a random file - just upload it.
self.uploadFile(file).then(
function(url) {
// Update message metadata
message.url = url;
message.msgtype = "m.file";
message.body = file.name;
message.info = {
size: file.size,
mimetype: file.type
};
// We are done
deferred.resolve(message);
},
function(error) {
console.log(" -> Can't upload file");
deferred.reject(error);
}
);
}
return deferred.promise;
};

View file

@ -501,51 +501,7 @@ function(matrixService, $rootScope, $q, $timeout, $filter, mPresence, notificati
eventContainsBingWord: function(event) {
return containsBingWord(event);
},
/**
* Return the last message event of a room
* @param {String} room_id the room id
* @param {Boolean} filterFake true to not take into account fake messages
* @returns {undefined | Event} the last message event if available
*/
getLastMessage: function(room_id, filterEcho) {
var lastMessage;
var events = modelService.getRoom(room_id).events;
for (var i = events.length - 1; i >= 0; i--) {
var message = events[i];
if (!filterEcho || undefined === message.echo_msg_state) {
lastMessage = message;
break;
}
}
return lastMessage;
},
/**
* Compute the room users number, ie the number of members who has joined the room.
* @param {String} room_id the room id
* @returns {undefined | Number} the room users number if available
*/
getUsersCountInRoom: function(room_id) {
var memberCount;
var room = modelService.getRoom(room_id);
memberCount = 0;
for (var i in room.current_room_state.members) {
if (!room.current_room_state.members.hasOwnProperty(i)) continue;
var member = room.current_room_state.members[i].event;
if ("join" === member.content.membership) {
memberCount = memberCount + 1;
}
}
return memberCount;
}
};
}]);

View file

@ -284,6 +284,52 @@ angular.module('modelService', [])
}
}
return powerLevel;
},
/**
* Compute the room users number, ie the number of members who has joined the room.
* @param {String} room_id the room id
* @returns {undefined | Number} the room users number if available
*/
getUserCountInRoom: function(room_id) {
var memberCount;
var room = this.getRoom(room_id);
memberCount = 0;
for (var i in room.current_room_state.members) {
if (!room.current_room_state.members.hasOwnProperty(i)) continue;
var member = room.current_room_state.members[i].event;
if ("join" === member.content.membership) {
memberCount = memberCount + 1;
}
}
return memberCount;
},
/**
* Return the last message event of a room
* @param {String} room_id the room id
* @param {Boolean} filterFake true to not take into account fake messages
* @returns {undefined | Event} the last message event if available
*/
getLastMessage: function(room_id, filterEcho) {
var lastMessage;
var events = this.getRoom(room_id).events;
for (var i = events.length - 1; i >= 0; i--) {
var message = events[i];
// TODO: define a better marker than echo_msg_state
if (!filterEcho || undefined === message.echo_msg_state) {
lastMessage = message;
break;
}
}
return lastMessage;
}
};

View file

@ -11,17 +11,17 @@
<meta name="viewport" content="width=device-width">
<script type='text/javascript' src='js/jquery-1.8.3.min.js'></script>
<script type="text/javascript" src="https://www.google.com/recaptcha/api/js/recaptcha_ajax.js"></script>
<script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="js/recaptcha_ajax.js"></script>
<script src="js/angular.js"></script>
<script src="js/angular-route.min.js"></script>
<script src="js/angular-sanitize.min.js"></script>
<script src="js/jquery.peity.min.js"></script>
<script src="js/angular-peity.js"></script>
<script type='text/javascript' src="js/ui-bootstrap-tpls-0.11.2.js"></script>
<script type='text/javascript' src='js/ng-infinite-scroll-matrix.js'></script>
<script type='text/javascript' src='js/autofill-event.js'></script>
<script type='text/javascript' src='js/elastic.js'></script>
<script type="text/javascript" src="js/ui-bootstrap-tpls-0.11.2.js"></script>
<script type="text/javascript" src="js/ng-infinite-scroll-matrix.js"></script>
<script type="text/javascript" src="js/autofill-event.js"></script>
<script type="text/javascript" src="js/elastic.js"></script>
<script src="app.js"></script>
<script src="config.js"></script>
<script src="app-controller.js"></script>

File diff suppressed because one or more lines are too long

View file

@ -20,7 +20,7 @@ angular.module('RegisterController', ['matrixService'])
'use strict';
var config = window.webClientConfig;
var useCaptcha = true;
var useCaptcha = false; // default to no captcha to make it easier to get a homeserver up and running...
if (config !== undefined) {
useCaptcha = config.useCaptcha;
}
@ -167,16 +167,10 @@ angular.module('RegisterController', ['matrixService'])
var setupCaptcha = function() {
console.log("Setting up ReCaptcha")
var config = window.webClientConfig;
var public_key = undefined;
if (config === undefined) {
console.error("Couldn't find webClientConfig. Cannot get public key for captcha.");
}
else {
public_key = webClientConfig.recaptcha_public_key;
if (public_key === undefined) {
console.error("No public key defined for captcha!")
}
var public_key = window.webClientConfig.recaptcha_public_key;
if (public_key === undefined) {
console.error("No public key defined for captcha!")
return;
}
Recaptcha.create(public_key,
"regcaptcha",

View file

@ -17,11 +17,11 @@
'use strict';
angular.module('RecentsController', ['matrixService', 'matrixFilter'])
.controller('RecentsController', ['$rootScope', '$scope', 'eventHandlerService', 'modelService', 'recentsService',
function($rootScope, $scope, eventHandlerService, modelService, recentsService) {
.controller('RecentsController', ['$rootScope', '$scope', 'modelService', 'recentsService',
function($rootScope, $scope, modelService, recentsService) {
// Expose the service to the view
$scope.eventHandlerService = eventHandlerService;
$scope.modelService = modelService;
// retrieve all rooms and expose them
$scope.rooms = modelService.getRooms();

View file

@ -17,7 +17,7 @@
'use strict';
angular.module('RecentsController')
.filter('orderRecents', ["matrixService", "eventHandlerService", "modelService", function(matrixService, eventHandlerService, modelService) {
.filter('orderRecents', ["matrixService", "modelService", function(matrixService, modelService) {
return function(rooms) {
var user_id = matrixService.config().user_id;
@ -39,8 +39,8 @@ angular.module('RecentsController')
room.recent.inviter = member.user_id;
}
// Count users here
// TODO: Compute it directly in eventHandlerService
room.recent.numUsersInRoom = eventHandlerService.getUsersCountInRoom(room_id);
// TODO: Compute it directly in modelService
room.recent.numUsersInRoom = modelService.getUserCountInRoom(room_id);
filtered.push(room);
}
@ -54,8 +54,8 @@ angular.module('RecentsController')
// The room with the latest message at first
filtered.sort(function (roomA, roomB) {
var lastMsgRoomA = eventHandlerService.getLastMessage(roomA.room_id, true);
var lastMsgRoomB = eventHandlerService.getLastMessage(roomB.room_id, true);
var lastMsgRoomA = modelService.getLastMessage(roomA.room_id, true);
var lastMsgRoomB = modelService.getLastMessage(roomB.room_id, true);
// Invite message does not have a body message nor ts
// Puth them at the top of the list

View file

@ -16,7 +16,7 @@
<td class="recentsRoomSummaryTS">
<!-- Use a temp var as alias to the last room message.
Declaring it in this way ensures the data-binding -->
{{ lastMsg = eventHandlerService.getLastMessage(room.room_id, true);"" }}
{{ lastMsg = modelService.getLastMessage(room.room_id, true);"" }}
{{ (lastMsg.origin_server_ts) | date:'MMM d HH:mm' }}
@ -84,7 +84,7 @@
</div>
<div ng-switch-default>
{{ lastMsg.content }}
{{ lastMsg.content.body | linky:'_blank' }}
</div>
</div>
</div>

View file

@ -495,6 +495,7 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput', 'a
});
};
// used to send an image based on just a URL, rather than uploading one
$scope.sendImage = function(url, body) {
scrollToBottom(true);
@ -507,23 +508,23 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput', 'a
});
};
$scope.imageFileToSend;
$scope.$watch("imageFileToSend", function(newValue, oldValue) {
if ($scope.imageFileToSend) {
// Upload this image with its thumbnail to Internet
mFileUpload.uploadImageAndThumbnail($scope.imageFileToSend, THUMBNAIL_SIZE).then(
function(imageMessage) {
// imageMessage is complete message structure, send it as is
matrixService.sendMessage($scope.room_id, undefined, imageMessage).then(
$scope.fileToSend;
$scope.$watch("fileToSend", function(newValue, oldValue) {
if ($scope.fileToSend) {
// Upload this file
mFileUpload.uploadFileAndThumbnail($scope.fileToSend, THUMBNAIL_SIZE).then(
function(fileMessage) {
// fileMessage is complete message structure, send it as is
matrixService.sendMessage($scope.room_id, undefined, fileMessage).then(
function() {
console.log("Image message sent");
console.log("File message sent");
},
function(error) {
$scope.feedback = "Failed to send image message: " + error.data.error;
$scope.feedback = "Failed to send file message: " + error.data.error;
});
},
function(error) {
$scope.feedback = "Can't upload image";
$scope.feedback = "Can't upload file";
}
);
}

View file

@ -198,31 +198,45 @@
{{ msg.user_id }} changed their display name from {{ msg.prev_content.displayname }} to {{ msg.content.displayname }}
</span>
<span ng-show='msg.content.msgtype === "m.emote"'
ng-class="msg.echo_msg_state"
ng-bind-html="'* ' + (msg.__room_member.cnt.displayname || msg.user_id) + ' ' + msg.content.body | linky:'_blank'"
/>
<span ng-show='msg.type === "m.room.message"' ng-switch='msg.content.msgtype'>
<span ng-switch-when="m.emote"
ng-class="containsBingWord(msg) && msg.user_id != state.user_id ? msg.echo_msg_state + ' messageBing' : msg.echo_msg_state"
ng-bind-html="'* ' + (msg.__room_member.cnt.displayname || msg.user_id) + ' ' + msg.content.body | linky:'_blank'"
/>
<span ng-show='msg.content.msgtype === "m.text"'
class="message"
ng-class="containsBingWord(msg) && msg.user_id != state.user_id ? msg.echo_msg_state + ' messageBing' : msg.echo_msg_state"
ng-bind-html="(msg.content.msgtype === 'm.text' && msg.type === 'm.room.message' && msg.content.format === 'org.matrix.custom.html') ?
(msg.content.formatted_body | unsanitizedLinky) :
(msg.content.msgtype === 'm.text' && msg.type === 'm.room.message') ? (msg.content.body | linky:'_blank') : '' "/>
<span ng-switch-when="m.text"
class="message"
ng-class="containsBingWord(msg) && msg.user_id != state.user_id ? msg.echo_msg_state + ' messageBing' : msg.echo_msg_state"
ng-bind-html="(msg.content.format === 'org.matrix.custom.html') ? (msg.content.formatted_body | unsanitizedLinky) : (msg.content.body | linky:'_blank') "/>
<div ng-switch-when="m.image">
<div ng-hide='msg.content.thumbnail_url' ng-style="msg.content.body.h && { 'height' : (msg.content.body.h < 320) ? msg.content.body.h : 320}">
<img class="image" ng-src="{{ msg.content.url }}"/>
</div>
<div ng-show='msg.content.thumbnail_url' ng-style="{ 'height' : msg.content.thumbnail_info.h }">
<img class="image mouse-pointer" ng-src="{{ msg.content.thumbnail_url }}"
ng-click="$parent.$parent.fullScreenImageURL = msg.content.url; $event.stopPropagation();"/>
</div>
</div>
<span ng-switch-when="m.file" ng-class="msg.echo_msg_state">
<a href="{{ msg.content.url}}" target="_blank">{{ msg.content.body }}</a>
<div ng-show='msg.content.thumbnail_url' ng-style="{ 'height' : msg.content.thumbnail_info.h }">
<a href="{{ msg.content.url}}" target="_blank">
<img class="image mouse-pointer" ng-src="{{ msg.content.thumbnail_url }}"/>
</a>
</div>
</span>
<span ng-switch-default
ng-class="containsBingWord(msg) && msg.user_id != state.user_id ? msg.echo_msg_state + ' messageBing' : msg.echo_msg_state"
ng-bind-html="msg.content.body | linky:'_blank'"
/>
</span>
<span ng-show='msg.type === "m.call.invite" && msg.user_id == state.user_id'>Outgoing Call{{ isWebRTCSupported() ? '' : ' (But your browser does not support VoIP)' }}</span>
<span ng-show='msg.type === "m.call.invite" && msg.user_id != state.user_id'>Incoming Call{{ isWebRTCSupported() ? '' : ' (But your browser does not support VoIP)' }}</span>
<div ng-show='msg.content.msgtype === "m.image"'>
<div ng-hide='msg.content.thumbnail_url' ng-style="msg.content.body.h && { 'height' : (msg.content.body.h < 320) ? msg.content.body.h : 320}">
<img class="image" ng-src="{{ msg.content.url }}"/>
</div>
<div ng-show='msg.content.thumbnail_url' ng-style="{ 'height' : msg.content.thumbnail_info.h }">
<img class="image mouse-pointer" ng-src="{{ msg.content.thumbnail_url }}"
ng-click="$parent.fullScreenImageURL = msg.content.url; $event.stopPropagation();"/>
</div>
</div>
<span ng-if="'m.room.topic' === msg.type">
{{ msg.__room_member.cnt.displayname || msg.user_id }} changed the topic to: {{ msg.content.topic }}
</span>
@ -250,7 +264,7 @@
<div id="controlPanel">
<div id="controls">
<button id="attachButton" m-file-input="imageFileToSend" class="extraControls" ng-disabled="state.permission_denied"></button>
<button id="attachButton" m-file-input="fileToSend" class="extraControls" ng-disabled="state.permission_denied"></button>
<textarea id="mainInput" rows="1" ng-enter="send()"
ng-disabled="state.permission_denied"
ng-focus="true" autocomplete="off" tab-complete command-history="room_id"/>

View file

@ -54,7 +54,7 @@
Notifications are enabled.
<div class="section">
<h4>Specific words to alert on:</h4>
<p>Leave blank to alert on all messages. Your username & display name always alerts.</p>
<p>If blank, all messages will trigger an alert. Your username & display name always alerts.</p>
<input size=40 name="bingWords" ng-model="settings.bingWords" ng-list placeholder="Enter words separated with , (supports regex)"
ng-blur="saveBingWords()"/>
<ul>

View file

@ -26,45 +26,5 @@ describe('EventHandlerService', function() {
scope = $rootScope;
}));
it('should be able to get the number of joined users in a room', inject(
function(eventHandlerService) {
var roomId = "!foo:matrix.org";
// set mocked data
modelService.getRoom = function(roomId) {
return {
room_id: roomId,
current_room_state: {
members: {
"@adam:matrix.org": {
event: {
content: { membership: "join" },
user_id: "@adam:matrix.org"
}
},
"@beth:matrix.org": {
event: {
content: { membership: "invite" },
user_id: "@beth:matrix.org"
}
},
"@charlie:matrix.org": {
event: {
content: { membership: "join" },
user_id: "@charlie:matrix.org"
}
},
"@danice:matrix.org": {
event: {
content: { membership: "leave" },
user_id: "@danice:matrix.org"
}
}
}
}
};
}
var num = eventHandlerService.getUsersCountInRoom(roomId);
expect(num).toEqual(2);
}));
});

View file

@ -193,4 +193,38 @@ describe('ModelService', function() {
}));
it('should be able to get the number of joined users in a room', inject(
function(modelService) {
var roomId = "!foo:matrix.org";
// set mocked data
var room = modelService.getRoom(roomId);
room.current_room_state.storeStateEvent({
content: { membership: "join" },
user_id: "@adam:matrix.org",
state_key: "@adam:matrix.org",
type: "m.room.member"
});
room.current_room_state.storeStateEvent({
content: { membership: "invite" },
user_id: "@adam:matrix.org",
state_key: "@beth:matrix.org",
type: "m.room.member"
});
room.current_room_state.storeStateEvent({
content: { membership: "join" },
user_id: "@charlie:matrix.org",
state_key: "@charlie:matrix.org",
type: "m.room.member"
});
room.current_room_state.storeStateEvent({
content: { membership: "leave" },
user_id: "@danice:matrix.org",
state_key: "@danice:matrix.org",
type: "m.room.member"
});
var num = modelService.getUserCountInRoom(roomId);
expect(num).toEqual(2);
}));
});

View file

@ -5,7 +5,7 @@ describe("RegisterController ", function() {
var avatarUrl = "avatar.url";
window.webClientConfig = {
useCapatcha: false
useCaptcha: false
};
// test vars