|
|
@ -716,7 +716,7 @@ angular.module('myApp.controllers', []) |
|
|
|
IdleManager.start(); |
|
|
|
IdleManager.start(); |
|
|
|
StatusManager.start(); |
|
|
|
StatusManager.start(); |
|
|
|
|
|
|
|
|
|
|
|
$scope.history = []; |
|
|
|
$scope.peerHistories = []; |
|
|
|
$scope.skippedHistory = false; |
|
|
|
$scope.skippedHistory = false; |
|
|
|
$scope.selectedMsgs = {}; |
|
|
|
$scope.selectedMsgs = {}; |
|
|
|
$scope.selectedCount = 0; |
|
|
|
$scope.selectedCount = 0; |
|
|
@ -744,6 +744,7 @@ angular.module('myApp.controllers', []) |
|
|
|
$scope.$on('history_return_recent', returnToRecent); |
|
|
|
$scope.$on('history_return_recent', returnToRecent); |
|
|
|
|
|
|
|
|
|
|
|
var peerID, |
|
|
|
var peerID, |
|
|
|
|
|
|
|
peerHistory = false, |
|
|
|
hasMore = false, |
|
|
|
hasMore = false, |
|
|
|
hasLess = false, |
|
|
|
hasLess = false, |
|
|
|
maxID = 0, |
|
|
|
maxID = 0, |
|
|
@ -786,6 +787,47 @@ angular.module('myApp.controllers', []) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function historiesQueuePush (peerID) { |
|
|
|
|
|
|
|
var pos = -1, |
|
|
|
|
|
|
|
maxLen = 10, |
|
|
|
|
|
|
|
i, |
|
|
|
|
|
|
|
history, |
|
|
|
|
|
|
|
diff; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < $scope.peerHistories.length; i++) { |
|
|
|
|
|
|
|
if ($scope.peerHistories[i].peerID == peerID) { |
|
|
|
|
|
|
|
pos = i; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (pos > -1) { |
|
|
|
|
|
|
|
history = $scope.peerHistories[pos]; |
|
|
|
|
|
|
|
if (pos) { |
|
|
|
|
|
|
|
$scope.peerHistories.splice(pos, 1); |
|
|
|
|
|
|
|
$scope.peerHistories.unshift(history); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return history; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
history = {peerID: peerID, messages: []}; |
|
|
|
|
|
|
|
$scope.peerHistories.unshift(history); |
|
|
|
|
|
|
|
diff = $scope.peerHistories.length - maxLen; |
|
|
|
|
|
|
|
if (diff > 0) { |
|
|
|
|
|
|
|
$scope.peerHistories.splice(maxLen - 1, diff); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return history; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function historiesQueueFind (peerID) { |
|
|
|
|
|
|
|
var i; |
|
|
|
|
|
|
|
for (i = 0; i < $scope.peerHistories.length; i++) { |
|
|
|
|
|
|
|
if ($scope.peerHistories[i].peerID == peerID) { |
|
|
|
|
|
|
|
return $scope.peerHistories[i]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function updateHistoryPeer(preload) { |
|
|
|
function updateHistoryPeer(preload) { |
|
|
|
var peerData = AppPeersManager.getPeer(peerID); |
|
|
|
var peerData = AppPeersManager.getPeer(peerID); |
|
|
|
// console.log('update', preload, peerData);
|
|
|
|
// console.log('update', preload, peerData);
|
|
|
@ -794,7 +836,7 @@ angular.module('myApp.controllers', []) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$scope.history = []; |
|
|
|
peerHistory = historiesQueuePush(peerID); |
|
|
|
|
|
|
|
|
|
|
|
safeReplaceObject($scope.historyPeer, { |
|
|
|
safeReplaceObject($scope.historyPeer, { |
|
|
|
id: peerID, |
|
|
|
id: peerID, |
|
|
@ -810,14 +852,17 @@ angular.module('myApp.controllers', []) |
|
|
|
$scope.historyState.typing.splice(0, $scope.historyState.typing.length); |
|
|
|
$scope.historyState.typing.splice(0, $scope.historyState.typing.length); |
|
|
|
$scope.$broadcast('ui_peer_change'); |
|
|
|
$scope.$broadcast('ui_peer_change'); |
|
|
|
$scope.$broadcast('ui_history_change'); |
|
|
|
$scope.$broadcast('ui_history_change'); |
|
|
|
safeReplaceObject($scope.state, {loaded: true}); |
|
|
|
safeReplaceObject($scope.state, {loaded: true, empty: !peerHistory.messages.length}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function messageFocusHistory () { |
|
|
|
function messageFocusHistory () { |
|
|
|
var i, found = false; |
|
|
|
var i, |
|
|
|
for (i = 0; i < $scope.history.length; i++) { |
|
|
|
found = false, |
|
|
|
if ($scope.curDialog.messageID == $scope.history[i].id) { |
|
|
|
history = historiesQueueFind(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < history.messages.length; i++) { |
|
|
|
|
|
|
|
if ($scope.curDialog.messageID == history.messages[i].id) { |
|
|
|
found = true; |
|
|
|
found = true; |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
@ -848,7 +893,7 @@ angular.module('myApp.controllers', []) |
|
|
|
for (i = historyResult.history.length - 1; i >= 0; i--) { |
|
|
|
for (i = historyResult.history.length - 1; i >= 0; i--) { |
|
|
|
id = historyResult.history[i]; |
|
|
|
id = historyResult.history[i]; |
|
|
|
if (id > minID) { |
|
|
|
if (id > minID) { |
|
|
|
$scope.history.push(AppMessagesManager.wrapForHistory(id)); |
|
|
|
peerHistory.messages.push(AppMessagesManager.wrapForHistory(id)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -856,7 +901,8 @@ angular.module('myApp.controllers', []) |
|
|
|
minID = historyResult.history.length >= backLimit |
|
|
|
minID = historyResult.history.length >= backLimit |
|
|
|
? historyResult.history[0] |
|
|
|
? historyResult.history[0] |
|
|
|
: 0; |
|
|
|
: 0; |
|
|
|
AppMessagesManager.regroupWrappedHistory($scope.history, -backLimit); |
|
|
|
AppMessagesManager.regroupWrappedHistory(peerHistory.messages, -backLimit); |
|
|
|
|
|
|
|
delete $scope.state.empty; |
|
|
|
$scope.$broadcast('ui_history_append'); |
|
|
|
$scope.$broadcast('ui_history_append'); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
minID = 0; |
|
|
|
minID = 0; |
|
|
@ -882,15 +928,16 @@ angular.module('myApp.controllers', []) |
|
|
|
if (curJump != jump || curMoreJump != moreJump) return; |
|
|
|
if (curJump != jump || curMoreJump != moreJump) return; |
|
|
|
|
|
|
|
|
|
|
|
angular.forEach(historyResult.history, function (id) { |
|
|
|
angular.forEach(historyResult.history, function (id) { |
|
|
|
$scope.history.unshift(AppMessagesManager.wrapForHistory(id)); |
|
|
|
peerHistory.messages.unshift(AppMessagesManager.wrapForHistory(id)); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
hasMore = historyResult.count === null || |
|
|
|
hasMore = historyResult.count === null || |
|
|
|
historyResult.history.length && $scope.history.length < historyResult.count; |
|
|
|
historyResult.history.length && peerHistory.messages.length < historyResult.count; |
|
|
|
|
|
|
|
|
|
|
|
if (historyResult.history.length) { |
|
|
|
if (historyResult.history.length) { |
|
|
|
maxID = historyResult.history[historyResult.history.length - 1]; |
|
|
|
maxID = historyResult.history[historyResult.history.length - 1]; |
|
|
|
AppMessagesManager.regroupWrappedHistory($scope.history, historyResult.history.length + 1); |
|
|
|
AppMessagesManager.regroupWrappedHistory(peerHistory.messages, historyResult.history.length + 1); |
|
|
|
|
|
|
|
delete $scope.state.empty; |
|
|
|
$scope.$broadcast('ui_history_prepend'); |
|
|
|
$scope.$broadcast('ui_history_prepend'); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
@ -903,6 +950,8 @@ angular.module('myApp.controllers', []) |
|
|
|
$scope.skippedHistory = hasLess = false; |
|
|
|
$scope.skippedHistory = hasLess = false; |
|
|
|
maxID = 0; |
|
|
|
maxID = 0; |
|
|
|
minID = 0; |
|
|
|
minID = 0; |
|
|
|
|
|
|
|
peerHistory = historiesQueuePush(peerID); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var limit = 0, backLimit = 0; |
|
|
|
var limit = 0, backLimit = 0; |
|
|
|
|
|
|
|
|
|
|
@ -917,6 +966,9 @@ angular.module('myApp.controllers', []) |
|
|
|
else if (Config.Mobile) { |
|
|
|
else if (Config.Mobile) { |
|
|
|
limit = 20; |
|
|
|
limit = 20; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else if (peerHistory.messages.length > 0) { |
|
|
|
|
|
|
|
limit = Math.min(20, peerHistory.messages.length); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var curJump = ++jump, |
|
|
|
var curJump = ++jump, |
|
|
|
inputMediaFilter = $scope.historyFilter.mediaType && {_: inputMediaFilters[$scope.historyFilter.mediaType]}, |
|
|
|
inputMediaFilter = $scope.historyFilter.mediaType && {_: inputMediaFilters[$scope.historyFilter.mediaType]}, |
|
|
@ -929,6 +981,8 @@ angular.module('myApp.controllers', []) |
|
|
|
getMessagesPromise.then(function (historyResult) { |
|
|
|
getMessagesPromise.then(function (historyResult) { |
|
|
|
if (curJump != jump) return; |
|
|
|
if (curJump != jump) return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var fetchedLength = historyResult.history.length; |
|
|
|
|
|
|
|
|
|
|
|
minID = (historyResult.unreadSkip || maxID && historyResult.history.indexOf(maxID) >= backLimit - 1) |
|
|
|
minID = (historyResult.unreadSkip || maxID && historyResult.history.indexOf(maxID) >= backLimit - 1) |
|
|
|
? historyResult.history[0] |
|
|
|
? historyResult.history[0] |
|
|
|
: 0; |
|
|
|
: 0; |
|
|
@ -936,22 +990,22 @@ angular.module('myApp.controllers', []) |
|
|
|
|
|
|
|
|
|
|
|
$scope.skippedHistory = hasLess = minID > 0; |
|
|
|
$scope.skippedHistory = hasLess = minID > 0; |
|
|
|
hasMore = historyResult.count === null || |
|
|
|
hasMore = historyResult.count === null || |
|
|
|
historyResult.history.length && historyResult.history.length < historyResult.count; |
|
|
|
fetchedLength && fetchedLength < historyResult.count; |
|
|
|
|
|
|
|
|
|
|
|
updateHistoryPeer(); |
|
|
|
updateHistoryPeer(); |
|
|
|
safeReplaceObject($scope.state, {loaded: true}); |
|
|
|
safeReplaceObject($scope.state, {loaded: true, empty: !fetchedLength}); |
|
|
|
|
|
|
|
|
|
|
|
$scope.history = []; |
|
|
|
peerHistory.messages = []; |
|
|
|
angular.forEach(historyResult.history, function (id) { |
|
|
|
angular.forEach(historyResult.history, function (id) { |
|
|
|
var message = AppMessagesManager.wrapForHistory(id); |
|
|
|
var message = AppMessagesManager.wrapForHistory(id); |
|
|
|
if ($scope.skippedHistory) { |
|
|
|
if ($scope.skippedHistory) { |
|
|
|
delete message.unread; |
|
|
|
delete message.unread; |
|
|
|
} |
|
|
|
} |
|
|
|
$scope.history.push(message); |
|
|
|
peerHistory.messages.push(message); |
|
|
|
}); |
|
|
|
}); |
|
|
|
$scope.history.reverse(); |
|
|
|
peerHistory.messages.reverse(); |
|
|
|
|
|
|
|
|
|
|
|
AppMessagesManager.regroupWrappedHistory($scope.history); |
|
|
|
AppMessagesManager.regroupWrappedHistory(peerHistory.messages); |
|
|
|
|
|
|
|
|
|
|
|
if (historyResult.unreadOffset) { |
|
|
|
if (historyResult.unreadOffset) { |
|
|
|
$scope.historyUnreadAfter = historyResult.history[historyResult.unreadOffset - 1]; |
|
|
|
$scope.historyUnreadAfter = historyResult.history[historyResult.unreadOffset - 1]; |
|
|
@ -972,7 +1026,7 @@ angular.module('myApp.controllers', []) |
|
|
|
|
|
|
|
|
|
|
|
function showEmptyHistory () { |
|
|
|
function showEmptyHistory () { |
|
|
|
safeReplaceObject($scope.state, {notSelected: true}); |
|
|
|
safeReplaceObject($scope.state, {notSelected: true}); |
|
|
|
$scope.history = []; |
|
|
|
peerHistory = false; |
|
|
|
hasMore = false; |
|
|
|
hasMore = false; |
|
|
|
|
|
|
|
|
|
|
|
$scope.$broadcast('ui_history_change'); |
|
|
|
$scope.$broadcast('ui_history_change'); |
|
|
@ -1006,16 +1060,16 @@ angular.module('myApp.controllers', []) |
|
|
|
var dir = lastSelectID > messageID, |
|
|
|
var dir = lastSelectID > messageID, |
|
|
|
i, startPos, curMessageID; |
|
|
|
i, startPos, curMessageID; |
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < $scope.history.length; i++) { |
|
|
|
for (i = 0; i < peerHistory.messages.length; i++) { |
|
|
|
if ($scope.history[i].id == lastSelectID) { |
|
|
|
if (peerHistory.messages[i].id == lastSelectID) { |
|
|
|
startPos = i; |
|
|
|
startPos = i; |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
i = startPos; |
|
|
|
i = startPos; |
|
|
|
while ($scope.history[i] && |
|
|
|
while (peerHistory.messages[i] && |
|
|
|
(curMessageID = $scope.history[i].id) != messageID) { |
|
|
|
(curMessageID = peerHistory.messages[i].id) != messageID) { |
|
|
|
if (!$scope.selectedMsgs[curMessageID]) { |
|
|
|
if (!$scope.selectedMsgs[curMessageID]) { |
|
|
|
$scope.selectedMsgs[curMessageID] = true; |
|
|
|
$scope.selectedMsgs[curMessageID] = true; |
|
|
|
$scope.selectedCount++; |
|
|
|
$scope.selectedCount++; |
|
|
@ -1093,7 +1147,8 @@ angular.module('myApp.controllers', []) |
|
|
|
|
|
|
|
|
|
|
|
function toggleMedia (mediaType) { |
|
|
|
function toggleMedia (mediaType) { |
|
|
|
$scope.historyFilter.mediaType = mediaType || false; |
|
|
|
$scope.historyFilter.mediaType = mediaType || false; |
|
|
|
$scope.history = []; |
|
|
|
peerHistory.messages = []; |
|
|
|
|
|
|
|
$scope.state.empty = true; |
|
|
|
loadHistory(); |
|
|
|
loadHistory(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1113,7 +1168,12 @@ angular.module('myApp.controllers', []) |
|
|
|
|
|
|
|
|
|
|
|
var typingTimeouts = {}; |
|
|
|
var typingTimeouts = {}; |
|
|
|
$scope.$on('history_append', function (e, addedMessage) { |
|
|
|
$scope.$on('history_append', function (e, addedMessage) { |
|
|
|
if (addedMessage.peerID == $scope.curDialog.peerID) { |
|
|
|
var history = historiesQueueFind(addedMessage.peerID); |
|
|
|
|
|
|
|
if (!history) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var curPeer = addedMessage.peerID == $scope.curDialog.peerID; |
|
|
|
|
|
|
|
if (curPeer) { |
|
|
|
if ($scope.historyFilter.mediaType || $scope.skippedHistory) { |
|
|
|
if ($scope.historyFilter.mediaType || $scope.skippedHistory) { |
|
|
|
if (addedMessage.my) { |
|
|
|
if (addedMessage.my) { |
|
|
|
returnToRecent(); |
|
|
|
returnToRecent(); |
|
|
@ -1122,10 +1182,14 @@ angular.module('myApp.controllers', []) |
|
|
|
} |
|
|
|
} |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
// console.log('append', addedMessage);
|
|
|
|
delete $scope.state.empty; |
|
|
|
// console.trace();
|
|
|
|
} |
|
|
|
$scope.history.push(AppMessagesManager.wrapForHistory(addedMessage.messageID)); |
|
|
|
// console.log('append', addedMessage);
|
|
|
|
AppMessagesManager.regroupWrappedHistory($scope.history, -3); |
|
|
|
// console.trace();
|
|
|
|
|
|
|
|
history.messages.push(AppMessagesManager.wrapForHistory(addedMessage.messageID)); |
|
|
|
|
|
|
|
AppMessagesManager.regroupWrappedHistory(history.messages, -3); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (curPeer) { |
|
|
|
$scope.historyState.typing.splice(0, $scope.historyState.typing.length); |
|
|
|
$scope.historyState.typing.splice(0, $scope.historyState.typing.length); |
|
|
|
$scope.$broadcast('ui_history_append_new', {my: addedMessage.my}); |
|
|
|
$scope.$broadcast('ui_history_append_new', {my: addedMessage.my}); |
|
|
|
if (addedMessage.my) { |
|
|
|
if (addedMessage.my) { |
|
|
@ -1142,22 +1206,32 @@ angular.module('myApp.controllers', []) |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
$scope.$on('history_delete', function (e, historyUpdate) { |
|
|
|
$scope.$on('history_delete', function (e, historyUpdate) { |
|
|
|
if (historyUpdate.peerID == $scope.curDialog.peerID) { |
|
|
|
var history = historiesQueueFind(historyUpdate.peerID); |
|
|
|
var newHistory = []; |
|
|
|
if (!history) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var newMessages = [], |
|
|
|
|
|
|
|
i; |
|
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < $scope.history.length; i++) { |
|
|
|
for (i = 0; i < history.messages.length; i++) { |
|
|
|
if (!historyUpdate.msgs[$scope.history[i].id]) { |
|
|
|
if (!historyUpdate.msgs[history.messages[i].id]) { |
|
|
|
newHistory.push($scope.history[i]); |
|
|
|
newMessages.push(history.messages[i]); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
$scope.history = newHistory; |
|
|
|
history.messages = newMessages; |
|
|
|
AppMessagesManager.regroupWrappedHistory($scope.history); |
|
|
|
AppMessagesManager.regroupWrappedHistory(history.messages); |
|
|
|
|
|
|
|
if (historyUpdate.peerID == $scope.curDialog.peerID) { |
|
|
|
|
|
|
|
$scope.state.empty = !newMessages.length; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
$scope.$on('dialog_flush', function (e, dialog) { |
|
|
|
$scope.$on('dialog_flush', function (e, dialog) { |
|
|
|
if (dialog.peerID == $scope.curDialog.peerID) { |
|
|
|
var history = historiesQueueFind(dialog.peerID); |
|
|
|
$scope.history = []; |
|
|
|
if (history) { |
|
|
|
|
|
|
|
history.messages = []; |
|
|
|
|
|
|
|
if (dialog.peerID == $scope.curDialog.peerID) { |
|
|
|
|
|
|
|
$scope.state.empty = true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|