disable broken event dup suppression, and fix echo for /me

This commit is contained in:
Matthew Hodgson 2014-09-06 10:13:38 -07:00
parent 9be1b2cb23
commit 44bd5e04dd
2 changed files with 25 additions and 16 deletions

View File

@ -79,7 +79,8 @@ angular.module('eventHandlerService', [])
initRoom(event.room_id); initRoom(event.room_id);
if (isLiveEvent) { if (isLiveEvent) {
if (event.user_id === matrixService.config().user_id) { if (event.user_id === matrixService.config().user_id &&
(event.content.msgtype === "m.text" || event.content.msgtype === "m.emote") ) {
// assume we've already echoed it // assume we've already echoed it
// FIXME: track events by ID and ungrey the right message to show it's been delivered // FIXME: track events by ID and ungrey the right message to show it's been delivered
} }
@ -162,11 +163,17 @@ angular.module('eventHandlerService', [])
NAME_EVENT: NAME_EVENT, NAME_EVENT: NAME_EVENT,
handleEvent: function(event, isLiveEvent) { handleEvent: function(event, isLiveEvent) {
// FIXME: event duplication suppression is all broken as the code currently expect to handles
// events multiple times to get their side-effects...
/*
if (eventMap[event.event_id]) { if (eventMap[event.event_id]) {
console.log("discarding duplicate event: " + JSON.stringify(event)); console.log("discarding duplicate event: " + JSON.stringify(event));
return; return;
} }
else {
eventMap[event.event_id] = 1;
}
*/
if (event.type.indexOf('m.call.') === 0) { if (event.type.indexOf('m.call.') === 0) {
handleCallEvent(event, isLiveEvent); handleCallEvent(event, isLiveEvent);
} }

View File

@ -302,7 +302,9 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
scrollToBottom(true); scrollToBottom(true);
var promise; var promise;
var isCmd = false; var cmd;
var args;
var echo = false;
// Check for IRC style commands first // Check for IRC style commands first
var line = $scope.textInput; var line = $scope.textInput;
@ -311,17 +313,16 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
line = line.replace(/\s+$/, ""); line = line.replace(/\s+$/, "");
if (line[0] === "/" && line[1] !== "/") { if (line[0] === "/" && line[1] !== "/") {
isCmd = true;
var bits = line.match(/^(\S+?)( +(.*))?$/); var bits = line.match(/^(\S+?)( +(.*))?$/);
var cmd = bits[1]; cmd = bits[1];
var args = bits[3]; args = bits[3];
console.log("cmd: " + cmd + ", args: " + args); console.log("cmd: " + cmd + ", args: " + args);
switch (cmd) { switch (cmd) {
case "/me": case "/me":
promise = matrixService.sendEmoteMessage($scope.room_id, args); promise = matrixService.sendEmoteMessage($scope.room_id, args);
echo = true;
break; break;
case "/nick": case "/nick":
@ -453,17 +454,20 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
} }
// By default send this as a message unless it's an IRC-style command // By default send this as a message unless it's an IRC-style command
if (!promise && !isCmd) { if (!promise && !cmd) {
var message = $scope.textInput; // Make the request
$scope.textInput = ""; promise = matrixService.sendTextMessage($scope.room_id, line);
echo = true;
}
if (echo) {
// Echo the message to the room // Echo the message to the room
// To do so, create a minimalist fake text message event and add it to the in-memory list of room messages // To do so, create a minimalist fake text message event and add it to the in-memory list of room messages
var echoMessage = { var echoMessage = {
content: { content: {
body: message, body: (cmd === "/me" ? args : line),
hsob_ts: new Date().getTime(), // fake a timestamp hsob_ts: new Date().getTime(), // fake a timestamp
msgtype: "m.text" msgtype: (cmd === "/me" ? "m.emote" : "m.text"),
}, },
room_id: $scope.room_id, room_id: $scope.room_id,
type: "m.room.message", type: "m.room.message",
@ -472,11 +476,9 @@ angular.module('RoomController', ['ngSanitize', 'matrixFilter', 'mFileInput'])
// 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 = "";
$rootScope.events.rooms[$scope.room_id].messages.push(echoMessage); $rootScope.events.rooms[$scope.room_id].messages.push(echoMessage);
scrollToBottom(); scrollToBottom();
// Make the request
promise = matrixService.sendTextMessage($scope.room_id, message);
} }
if (promise) { if (promise) {