|
|
|
@ -30,33 +30,44 @@ define(['underscore', 'text!partials/chat.html', 'text!partials/chatroom.html'], |
|
|
|
$scope.layout.chat = false; |
|
|
|
$scope.layout.chat = false; |
|
|
|
$scope.layout.chatMaximized = false; |
|
|
|
$scope.layout.chatMaximized = false; |
|
|
|
|
|
|
|
|
|
|
|
var rooms = {}; |
|
|
|
var ctrl = this; |
|
|
|
var visibleRooms = []; |
|
|
|
var rooms = ctrl.rooms = {}; |
|
|
|
|
|
|
|
ctrl.visibleRooms = []; |
|
|
|
|
|
|
|
ctrl.group = group_chat_id; |
|
|
|
|
|
|
|
ctrl.get = function(id) { |
|
|
|
|
|
|
|
return ctrl.rooms[id]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
mediaStream.api.e.on("received.chat", function(event, id, from, data, p2p) { |
|
|
|
mediaStream.api.e.on("received.chat", function(event, id, from, data, p2p) { |
|
|
|
|
|
|
|
|
|
|
|
//console.log("received", data, id, from);
|
|
|
|
//console.log("received", data, id, from);
|
|
|
|
|
|
|
|
|
|
|
|
var with_message = !!data.Message; |
|
|
|
var roomid = id; |
|
|
|
|
|
|
|
if (roomid === mediaStream.api.id) { |
|
|
|
if (!with_message && !rooms[from] && !rooms[id]) { |
|
|
|
roomid = from; |
|
|
|
// Ignore empty messages for non existing rooms.
|
|
|
|
} else { |
|
|
|
return; |
|
|
|
if (roomid !== ctrl.group && from !== mediaStream.api.id) { |
|
|
|
|
|
|
|
console.log("Received chat message for invalid room", roomid, id, from); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var room = rooms[id]; |
|
|
|
var with_message = !!data.Message; |
|
|
|
|
|
|
|
var room = rooms[roomid]; |
|
|
|
if (!room) { |
|
|
|
if (!room) { |
|
|
|
|
|
|
|
if (!with_message) { |
|
|
|
|
|
|
|
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, {restore: with_message}); |
|
|
|
$scope.$emit("startchat", from, {restore: with_message}); |
|
|
|
room = rooms[from]; |
|
|
|
room = rooms[from]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (with_message && from !== $scope.$parent.id) { |
|
|
|
if (with_message && from !== mediaStream.api.id) { |
|
|
|
room.newmessage = true; |
|
|
|
room.newmessage = true; |
|
|
|
room.peerIsTyping = "no"; |
|
|
|
room.peerIsTyping = "no"; |
|
|
|
room.p2p(!!p2p); |
|
|
|
room.p2p(!!p2p); |
|
|
|
} |
|
|
|
} |
|
|
|
//console.log("room", room);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
room.$broadcast("received", from, data); |
|
|
|
room.$broadcast("received", from, data); |
|
|
|
safeApply(room); |
|
|
|
safeApply(room); |
|
|
|
@ -100,17 +111,6 @@ define(['underscore', 'text!partials/chat.html', 'text!partials/chatroom.html'], |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// Shared data;
|
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
rooms: rooms, |
|
|
|
|
|
|
|
visibleRooms: visibleRooms, |
|
|
|
|
|
|
|
group: group_chat_id, |
|
|
|
|
|
|
|
get: function(id) { |
|
|
|
|
|
|
|
return rooms[id]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}]; |
|
|
|
}]; |
|
|
|
|
|
|
|
|
|
|
|
var compile = function(tElement, tAttrs) { |
|
|
|
var compile = function(tElement, tAttrs) { |
|
|
|
@ -127,7 +127,7 @@ define(['underscore', 'text!partials/chat.html', 'text!partials/chatroom.html'], |
|
|
|
var subscope = controller.rooms[id]; |
|
|
|
var subscope = controller.rooms[id]; |
|
|
|
var index = controller.visibleRooms.length; |
|
|
|
var index = controller.visibleRooms.length; |
|
|
|
if (!subscope) { |
|
|
|
if (!subscope) { |
|
|
|
console.log("Create new chatroom", id); |
|
|
|
console.log("Create new chatroom", [id]); |
|
|
|
controller.visibleRooms.push(id); |
|
|
|
controller.visibleRooms.push(id); |
|
|
|
subscope = controller.rooms[id] = scope.$new(); |
|
|
|
subscope = controller.rooms[id] = scope.$new(); |
|
|
|
translation.inject(subscope); |
|
|
|
translation.inject(subscope); |
|
|
|
@ -287,16 +287,16 @@ define(['underscore', 'text!partials/chat.html', 'text!partials/chatroom.html'], |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!options.noactivate) { |
|
|
|
|
|
|
|
scope.activateRoom(subscope.id, true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (options.restore && !options.noenable) { |
|
|
|
if (options.restore && !options.noenable) { |
|
|
|
if (!scope.layout.chat) { |
|
|
|
if (!scope.layout.chat) { |
|
|
|
scope.layout.chat = true; |
|
|
|
scope.layout.chat = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!options.noactivate) { |
|
|
|
|
|
|
|
scope.activateRoom(subscope.id, true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
safeApply(subscope); |
|
|
|
safeApply(subscope); |
|
|
|
return subscope; |
|
|
|
return subscope; |
|
|
|
}; |
|
|
|
}; |
|
|
|
@ -341,21 +341,31 @@ define(['underscore', 'text!partials/chat.html', 'text!partials/chatroom.html'], |
|
|
|
scope.layout.chatMaximized = !scope.layout.chatMaximized; |
|
|
|
scope.layout.chatMaximized = !scope.layout.chatMaximized; |
|
|
|
}; |
|
|
|
}; |
|
|
|
scope.activateRoom = function(id, active) { |
|
|
|
scope.activateRoom = function(id, active) { |
|
|
|
|
|
|
|
var visible = !!scope.layout.chat; |
|
|
|
|
|
|
|
var flip = false; |
|
|
|
var subscope = controller.rooms[id]; |
|
|
|
var subscope = controller.rooms[id]; |
|
|
|
//console.log("toggleActive", active, id, scope.currentRoom, scope.currentRoom == subscope, subscope.active);
|
|
|
|
//console.log("toggleActive", active, id, scope.currentRoom, scope.currentRoom == subscope, subscope.active);
|
|
|
|
if (scope.currentRoom == subscope) { |
|
|
|
if (scope.currentRoom == subscope) { |
|
|
|
subscope.active = active; |
|
|
|
subscope.active = active; |
|
|
|
|
|
|
|
if (visible) { |
|
|
|
|
|
|
|
flip = true; |
|
|
|
|
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if (scope.currentRoom) { |
|
|
|
if (scope.currentRoom) { |
|
|
|
scope.currentRoom.active = false; |
|
|
|
scope.currentRoom.active = false; |
|
|
|
scope.currentRoom.hide(); |
|
|
|
scope.currentRoom.hide(); |
|
|
|
|
|
|
|
if (visible) { |
|
|
|
|
|
|
|
flip = true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (active) { |
|
|
|
if (active) { |
|
|
|
scope.currentRoom = subscope; |
|
|
|
scope.currentRoom = subscope; |
|
|
|
iElement.toggleClass("flip"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
subscope.active = active; |
|
|
|
subscope.active = active; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (flip) { |
|
|
|
|
|
|
|
iElement.toggleClass("flip"); |
|
|
|
|
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
scope.$on("room", function(event, room) { |
|
|
|
scope.$on("room", function(event, room) { |
|
|
|
|