Browse Source

Reenable chat rooms on certain conditions related to peer connectivity.

pull/186/head
Simon Eisenmann 10 years ago
parent
commit
369d53fef9
  1. 36
      static/js/directives/chat.js

36
static/js/directives/chat.js

@ -78,7 +78,7 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
if (!with_message) { if (!with_message) {
return; return;
} }
// No room with this id, get one with the from id // No room with this id, get one with the from id.
$scope.$emit("startchat", from, { $scope.$emit("startchat", from, {
restore: with_message restore: with_message
}); });
@ -90,14 +90,19 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
room.peerIsTyping = "no"; room.peerIsTyping = "no";
room.p2p( !! p2p); room.p2p( !! p2p);
if (room.firstmessage) { if (room.firstmessage) {
// Auto show when this is the first message.
$scope.showRoom(room.id, null, { $scope.showRoom(room.id, null, {
restore: with_message restore: with_message
}); });
} }
if (!room.enabled) {
// Reenable chat room when receiving messages again.
room.enabled = true;
}
} }
room.$broadcast("received", from, data);
safeApply(room); safeApply(room);
room.$broadcast("received", from, data);
}); });
@ -108,10 +113,6 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
case "Left": case "Left":
if (data.Status !== "soft") { if (data.Status !== "soft") {
room.enabled = false; room.enabled = false;
room.$broadcast("received", data.Id, {
Type: "LeftOrJoined",
"LeftOrJoined": "left"
});
safeApply(room); safeApply(room);
} }
break; break;
@ -119,10 +120,6 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
if (!room.enabled) { if (!room.enabled) {
room.enabled = true; room.enabled = true;
_.delay(function() { _.delay(function() {
room.$broadcast("received", data.Id, {
Type: "LeftOrJoined",
"LeftOrJoined": "joined"
});
safeApply(room); safeApply(room);
}, 1000); }, 1000);
} }
@ -397,6 +394,22 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
} }
} }
}); });
subscope.$watch("enabled", function(enabled, old) {
if (enabled === old) {
return;
}
//console.log("enabled", enabled, old);
var value;
if (enabled) {
value = "resumed";
} else {
value = "left";
}
subscope.$broadcast("received", subscope.id, {
Type: "LeftOrJoined",
"LeftOrJoined": value
});
});
chat(subscope, function(clonedElement, $scope) { chat(subscope, function(clonedElement, $scope) {
pane.append(clonedElement); pane.append(clonedElement);
@ -444,6 +457,9 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
subscope.index = index; subscope.index = index;
subscope.visible = true; subscope.visible = true;
} }
if (!subscope.enabled) {
subscope.enabled = true;
}
} }
if (options.autofocus && subscope.visible) { if (options.autofocus && subscope.visible) {
subscope.$broadcast("focus"); subscope.$broadcast("focus");

Loading…
Cancel
Save