diff --git a/app/js/controllers.js b/app/js/controllers.js index b59143e6..cc9ac45a 100644 --- a/app/js/controllers.js +++ b/app/js/controllers.js @@ -790,7 +790,17 @@ angular.module('myApp.controllers', ['myApp.i18n']) } function sortDialogs () { + var myID = false + if ($scope.forPeerSelect) { + myID = AppUsersManager.getSelf().id + } $scope.dialogs.sort(function (d1, d2) { + if (d1.peerID == myID) { + return -1 + } + else if (d2.peerID == myID) { + return 1 + } return d2.index - d1.index }) } @@ -974,6 +984,13 @@ angular.module('myApp.controllers', ['myApp.i18n']) if (curJump != jump) { return $q.reject() } + if (!query && !offsetIndex && $scope.forPeerSelect) { + var myID = AppUsersManager.getSelf().id + return AppMessagesManager.getConversation(myID).then(function (dialog) { + result.dialogs.unshift(dialog) + return result + }) + } return result }) } @@ -1018,7 +1035,11 @@ angular.module('myApp.controllers', ['myApp.i18n']) if (searchMessages) { wrappedDialog.unreadCount = -1 } else { - peersInDialogs[dialog.peerID] = true + if (peersInDialogs[dialog.peerID]) { + return + } else { + peersInDialogs[dialog.peerID] = true + } } dialogsList.push(wrappedDialog) }) diff --git a/app/js/directives.js b/app/js/directives.js index dc8a14f8..07fd2521 100755 --- a/app/js/directives.js +++ b/app/js/directives.js @@ -3140,7 +3140,7 @@ angular.module('myApp.directives', ['myApp.filters']) } }) - .directive('myUserStatus', function ($filter, $rootScope, AppUsersManager) { + .directive('myUserStatus', function (_, $filter, $rootScope, AppUsersManager) { var statusFilter = $filter('userStatus') var ind = 0 var statuses = {} @@ -3166,12 +3166,18 @@ angular.module('myApp.directives', ['myApp.filters']) function link ($scope, element, attrs) { var userID var curInd = ind++ + var forDialog = attrs.forDialog && $scope.$eval(attrs.forDialog) + var update = function () { var user = AppUsersManager.getUser(userID) - element - .html(statusFilter(user, attrs.botChatPrivacy)) - .toggleClass('status_online', (user.status && user.status._ == 'userStatusOnline') || false) - // console.log(dT(), 'update status', element[0], user.status && user.status, tsNow(true), element.html()) + if (forDialog && user.pFlags.self) { + element.html('') + } else { + element + .html(statusFilter(user, attrs.botChatPrivacy)) + .toggleClass('status_online', (user.status && user.status._ == 'userStatusOnline') || false) + } + // console.log(dT(), 'update status', element[0], user.status && user.status, tsNow(true), element.html()) } $scope.$watch(attrs.myUserStatus, function (newUserID) { @@ -3331,7 +3337,7 @@ angular.module('myApp.directives', ['myApp.filters']) } }) - .directive('myPeerLink', function ($rootScope, AppChatsManager, AppUsersManager, AppMessagesIDsManager) { + .directive('myPeerLink', function (_, $rootScope, AppPeersManager, AppChatsManager, AppUsersManager, AppMessagesIDsManager) { return { link: link } @@ -3340,6 +3346,7 @@ angular.module('myApp.directives', ['myApp.filters']) var override = attrs.userOverride && $scope.$eval(attrs.userOverride) || {} var short = attrs.short && $scope.$eval(attrs.short) var username = attrs.username && $scope.$eval(attrs.username) + var forDialog = attrs.forDialog && $scope.$eval(attrs.forDialog) var peerID var update = function () { @@ -3348,16 +3355,21 @@ angular.module('myApp.directives', ['myApp.filters']) } if (peerID > 0) { var user = AppUsersManager.getUser(peerID) - var prefix = username ? '@' : '' - var key = username ? 'username' : (short ? 'rFirstName' : 'rFullName') + if (forDialog && user.pFlags.self) { + element.text(_('user_name_saved_msgs_raw')) + } else { + var prefix = username ? '@' : '' + var key = username ? 'username' : (short ? 'rFirstName' : 'rFullName') - element.html( - prefix + - (override[key] || user[key] || '').valueOf() + - (attrs.verified && user.pFlags && user.pFlags.verified ? ' ' : '') - ) - if (attrs.color && $scope.$eval(attrs.color)) { - element.addClass('user_color_' + user.num) + element.html( + prefix + + (override[key] || user[key] || '').valueOf() + + (attrs.verified && user.pFlags && user.pFlags.verified ? ' ' : '') + ) + + if (attrs.color && $scope.$eval(attrs.color)) { + element.addClass('user_color_' + user.num) + } } } else { var chat = AppChatsManager.getChat(-peerID) @@ -3375,12 +3387,19 @@ angular.module('myApp.directives', ['myApp.filters']) AppUsersManager.openUser(peerID, override) } else { var chatID = -peerID - var postID = $scope.$eval(attrs.postId) + var postID = attrs.postId && $scope.$eval(attrs.postId) + var savedFrom = attrs.savedFrom && $scope.$eval(attrs.savedFrom) if (postID) { $rootScope.$broadcast('history_focus', { peerString: AppChatsManager.getChatString(chatID), messageID: AppMessagesIDsManager.getFullMessageID(parseInt(postID), chatID) }) + } else if (savedFrom) { + var peerMid = savedFrom.split('_') + $rootScope.$broadcast('history_focus', { + peerString: AppPeersManager.getPeerString(peerMid[0]), + messageID: peerMid[1] + }) } else { AppChatsManager.openChat(chatID) } @@ -3426,6 +3445,7 @@ angular.module('myApp.directives', ['myApp.filters']) var initEl = $('') var jump = 0 var prevClass = false + var forDialog = attrs.forDialog && $scope.$eval(attrs.forDialog) var setPeerID = function (newPeerID) { if (peerID == newPeerID) { @@ -3453,6 +3473,12 @@ angular.module('myApp.directives', ['myApp.filters']) peerPhoto = peer.photo && angular.copy(peer.photo.photo_small) + if (forDialog && peer.pFlags && peer.pFlags.self) { + initEl.remove() + imgEl.prependTo(element).attr('src', 'img/icons/icon120.png') + return + } + var hasPhoto = peerPhoto !== undefined if (hasPhoto) { diff --git a/app/js/locales/en-us.json b/app/js/locales/en-us.json index a961813e..8e5aa62d 100644 --- a/app/js/locales/en-us.json +++ b/app/js/locales/en-us.json @@ -169,6 +169,7 @@ "user_name_deleted": "DELETED", "user_first_name_deleted": "DELETED", + "user_name_saved_msgs": "Saved Messages", "user_status_online": "online", "user_status_last_seen": "last seen {0}", "user_status_recently": "last seen recently", diff --git a/app/js/messages_manager.js b/app/js/messages_manager.js index 389d225e..ea182a19 100644 --- a/app/js/messages_manager.js +++ b/app/js/messages_manager.js @@ -116,6 +116,19 @@ angular.module('myApp.services') }) } + function getConversation(peerID) { + var foundDialog = getDialogByPeerID(peerID) + if (foundDialog.length) { + return $q.when(foundDialog[0]) + } + return $q.when({ + peerID: peerID, + top_message: 0, + index: generateDialogIndex(generateDialogPinnedDate()), + pFlags: {} + }) + } + function getDialogByPeerID (peerID) { for (var i = 0; i < dialogsStorage.dialogs.length; i++) { if (dialogsStorage.dialogs[i].peerID == peerID) { @@ -1376,16 +1389,25 @@ angular.module('myApp.services') apiMessage.date -= ServerTimeManager.serverTimeOffset + apiMessage.peerID = peerID + apiMessage.fromID = apiMessage.pFlags.post ? peerID : apiMessage.from_id + var fwdHeader = apiMessage.fwd_from if (fwdHeader) { - apiMessage.fwdFromID = fwdHeader.channel_id ? -fwdHeader.channel_id : fwdHeader.from_id - apiMessage.fwdPostID = fwdHeader.channel_post + if (peerID == AppUsersManager.getSelf().id) { + if (fwdHeader.saved_from_peer && fwdHeader.saved_from_msg_id) { + var savedFromPeerID = AppPeersManager.getPeerID(fwdHeader.saved_from_peer) + var savedFromMid = AppMessagesIDsManager.getFullMessageID(fwdHeader.saved_from_msg_id, AppPeersManager.isChannel(savedFromPeerID) ? -savedFromPeerID : 0) + apiMessage.savedFrom = savedFromPeerID + '_' + savedFromMid + } + apiMessage.fromID = fwdHeader.channel_id ? -fwdHeader.channel_id : fwdHeader.from_id + } else { + apiMessage.fwdFromID = fwdHeader.channel_id ? -fwdHeader.channel_id : fwdHeader.from_id + apiMessage.fwdPostID = fwdHeader.channel_post + } fwdHeader.date -= ServerTimeManager.serverTimeOffset } - apiMessage.peerID = peerID - apiMessage.fromID = apiMessage.pFlags.post ? peerID : apiMessage.from_id - if (apiMessage.via_bot_id > 0) { apiMessage.viaBotID = apiMessage.via_bot_id } @@ -2362,7 +2384,7 @@ angular.module('myApp.services') to_id: AppPeersManager.getOutputPeer(dialog.peerID), deleted: true, date: tsNow(true), - pFlags: {} + pFlags: {out: true} } } else { return message @@ -3754,6 +3776,7 @@ angular.module('myApp.services') return { getConversations: getConversations, + getConversation: getConversation, getHistory: getHistory, getSearch: getSearch, getMessage: getMessage, diff --git a/app/js/services.js b/app/js/services.js index 1dfdc876..8a9ab79f 100755 --- a/app/js/services.js +++ b/app/js/services.js @@ -52,8 +52,16 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) if (!user) { return false } + var serviceText = '' + if (user.pFlags.self) { + serviceText = _('user_name_saved_msgs_raw') + } - return (user.first_name || '') + ' ' + (user.last_name || '') + ' ' + (user.phone || '') + ' ' + (user.username || '') + return (user.first_name || '') + + ' ' + (user.last_name || '') + + ' ' + (user.phone || '') + + ' ' + (user.username || '') + + ' ' + serviceText } function getContacts (query) { @@ -4385,6 +4393,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) var scope = $rootScope.$new() scope.multiSelect = false scope.noMessages = true + scope.forPeerSelect = true if (options) { angular.extend(scope, options) } @@ -4408,6 +4417,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) var scope = $rootScope.$new() scope.multiSelect = true scope.noMessages = true + scope.forPeerSelect = true if (options) { angular.extend(scope, options) } diff --git a/app/partials/desktop/dialog.html b/app/partials/desktop/dialog.html index 3d97feda..ae644e66 100644 --- a/app/partials/desktop/dialog.html +++ b/app/partials/desktop/dialog.html @@ -18,12 +18,12 @@ > -
+ - +