|
|
@ -773,45 +773,51 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
var chatFull = angular.copy(fullChat) |
|
|
|
var chatFull = angular.copy(fullChat) |
|
|
|
var chat = getChat(id) |
|
|
|
var chat = getChat(id) |
|
|
|
|
|
|
|
|
|
|
|
console.warn(chat, chatFull) |
|
|
|
|
|
|
|
if (!chatFull.participants_count) { |
|
|
|
if (!chatFull.participants_count) { |
|
|
|
chatFull.participants_count = chat.participants_count |
|
|
|
chatFull.participants_count = chat.participants_count |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (chatFull.participants && chatFull.participants._ == 'chatParticipants') { |
|
|
|
if (chatFull.participants && |
|
|
|
MtpApiManager.getUserID().then(function (myID) { |
|
|
|
chatFull.participants._ == 'chatParticipants') { |
|
|
|
var isAdmin = chat.pFlags.creator || chat.pFlags.admins_enabled && chat.pFlags.admin |
|
|
|
chatFull.participants.participants = wrapParticipants(id, chatFull.participants.participants) |
|
|
|
angular.forEach(chatFull.participants.participants, function (participant) { |
|
|
|
} |
|
|
|
participant.canLeave = myID == participant.user_id |
|
|
|
|
|
|
|
participant.canKick = !participant.canLeave && ( |
|
|
|
|
|
|
|
chat.pFlags.creator || |
|
|
|
|
|
|
|
participant._ == 'chatParticipant' && (isAdmin || myID == participant.inviter_id) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// just for order by last seen
|
|
|
|
if (chatFull.about) { |
|
|
|
participant.user = AppUsersManager.getUser(participant.user_id) |
|
|
|
chatFull.rAbout = RichTextProcessor.wrapRichText(chatFull.about, {noLinebreaks: true}) |
|
|
|
}) |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
chatFull.peerString = getChatString(id) |
|
|
|
|
|
|
|
chatFull.chat = chat |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return chatFull |
|
|
|
} |
|
|
|
} |
|
|
|
if (chatFull.participants && chatFull.participants._ == 'channelParticipants') { |
|
|
|
|
|
|
|
|
|
|
|
function wrapParticipants(id, participants) { |
|
|
|
|
|
|
|
var chat = getChat(id) |
|
|
|
|
|
|
|
if (isChannel(id)) { |
|
|
|
var isAdmin = chat.pFlags.creator || chat.pFlags.editor || chat.pFlags.moderator |
|
|
|
var isAdmin = chat.pFlags.creator || chat.pFlags.editor || chat.pFlags.moderator |
|
|
|
angular.forEach(chatFull.participants.participants, function (participant) { |
|
|
|
angular.forEach(participants, function (participant) { |
|
|
|
participant.canLeave = participant._ == 'channelParticipantSelf' |
|
|
|
participant.canLeave = participant._ == 'channelParticipantSelf' |
|
|
|
participant.canKick = isAdmin && participant._ == 'channelParticipant' |
|
|
|
participant.canKick = isAdmin && participant._ == 'channelParticipant' |
|
|
|
|
|
|
|
|
|
|
|
// just for order by last seen
|
|
|
|
// just for order by last seen
|
|
|
|
participant.user = AppUsersManager.getUser(participant.user_id) |
|
|
|
participant.user = AppUsersManager.getUser(participant.user_id) |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} else { |
|
|
|
|
|
|
|
var myID = AppUsersManager.getSelf().id |
|
|
|
|
|
|
|
var isAdmin = chat.pFlags.creator || chat.pFlags.admins_enabled && chat.pFlags.admin |
|
|
|
|
|
|
|
angular.forEach(participants, function (participant) { |
|
|
|
|
|
|
|
participant.canLeave = myID == participant.user_id |
|
|
|
|
|
|
|
participant.canKick = !participant.canLeave && ( |
|
|
|
|
|
|
|
chat.pFlags.creator || |
|
|
|
|
|
|
|
participant._ == 'chatParticipant' && (isAdmin || myID == participant.inviter_id) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
if (chatFull.about) { |
|
|
|
// just for order by last seen
|
|
|
|
chatFull.rAbout = RichTextProcessor.wrapRichText(chatFull.about, {noLinebreaks: true}) |
|
|
|
participant.user = AppUsersManager.getUser(participant.user_id) |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return participants |
|
|
|
chatFull.peerString = getChatString(id) |
|
|
|
|
|
|
|
chatFull.chat = chat |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return chatFull |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function openChat (chatID, accessHash) { |
|
|
|
function openChat (chatID, accessHash) { |
|
|
@ -862,6 +868,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
resolveUsername: resolveUsername, |
|
|
|
resolveUsername: resolveUsername, |
|
|
|
hasChat: hasChat, |
|
|
|
hasChat: hasChat, |
|
|
|
wrapForFull: wrapForFull, |
|
|
|
wrapForFull: wrapForFull, |
|
|
|
|
|
|
|
wrapParticipants: wrapParticipants, |
|
|
|
openChat: openChat |
|
|
|
openChat: openChat |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
@ -1042,7 +1049,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
.service('AppProfileManager', function ($q, $rootScope, AppUsersManager, AppChatsManager, AppPeersManager, AppPhotosManager, NotificationsManager, MtpApiManager, ApiUpdatesManager, RichTextProcessor) { |
|
|
|
.service('AppProfileManager', function ($q, $rootScope, AppUsersManager, AppChatsManager, AppMessagesIDsManager, AppPeersManager, AppPhotosManager, NotificationsManager, MtpApiManager, ApiUpdatesManager, RichTextProcessor, Storage) { |
|
|
|
var botInfos = {} |
|
|
|
var botInfos = {} |
|
|
|
var chatsFull = {} |
|
|
|
var chatsFull = {} |
|
|
|
var chatFullPromises = {} |
|
|
|
var chatFullPromises = {} |
|
|
@ -1191,6 +1198,14 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
var promiseKey = [id, filter._, offset, limit].join('_') |
|
|
|
var promiseKey = [id, filter._, offset, limit].join('_') |
|
|
|
var promiseData = chatParticipantsPromises[promiseKey] |
|
|
|
var promiseData = chatParticipantsPromises[promiseKey] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (filter._ == 'channelParticipantsRecent') { |
|
|
|
|
|
|
|
var chat = AppChatsManager.getChat(id) |
|
|
|
|
|
|
|
if (chat.pFlags.kicked || |
|
|
|
|
|
|
|
chat.pFlags.broadcast && !chat.pFlags.creator && !chat.admin_rights) { |
|
|
|
|
|
|
|
return $q.reject() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var fetchParticipants = function (cachedParticipants) { |
|
|
|
var fetchParticipants = function (cachedParticipants) { |
|
|
|
var hash = 0 |
|
|
|
var hash = 0 |
|
|
|
if (cachedParticipants) { |
|
|
|
if (cachedParticipants) { |
|
|
@ -1279,32 +1294,21 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
AppChatsManager.saveApiChats(result.chats) |
|
|
|
AppChatsManager.saveApiChats(result.chats) |
|
|
|
AppUsersManager.saveApiUsers(result.users) |
|
|
|
AppUsersManager.saveApiUsers(result.users) |
|
|
|
var fullChannel = result.full_chat |
|
|
|
var fullChannel = result.full_chat |
|
|
|
var chat = AppChatsManager.getChat(id) |
|
|
|
|
|
|
|
if (fullChannel && fullChannel.chat_photo.id) { |
|
|
|
if (fullChannel && fullChannel.chat_photo.id) { |
|
|
|
AppPhotosManager.savePhoto(fullChannel.chat_photo) |
|
|
|
AppPhotosManager.savePhoto(fullChannel.chat_photo) |
|
|
|
} |
|
|
|
} |
|
|
|
NotificationsManager.savePeerSettings(-id, fullChannel.notify_settings) |
|
|
|
NotificationsManager.savePeerSettings(-id, fullChannel.notify_settings) |
|
|
|
var participantsPromise |
|
|
|
|
|
|
|
if (fullChannel.flags & 8) { |
|
|
|
if (fullChannel.pinned_msg_id) { |
|
|
|
participantsPromise = getChannelParticipants(id).then(function (participants) { |
|
|
|
fullChannel.pinned_msg_id = AppMessagesIDsManager.getFullMessageID(fullChannel.pinned_msg_id, id) |
|
|
|
delete chatFullPromises[id] |
|
|
|
|
|
|
|
fullChannel.participants = { |
|
|
|
|
|
|
|
_: 'channelParticipants', |
|
|
|
|
|
|
|
participants: participants |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, function (error) { |
|
|
|
|
|
|
|
error.handled = true |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
participantsPromise = $q.when() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return participantsPromise.then(function () { |
|
|
|
|
|
|
|
delete chatFullPromises[id] |
|
|
|
delete chatFullPromises[id] |
|
|
|
chatsFull[id] = fullChannel |
|
|
|
chatsFull[id] = fullChannel |
|
|
|
$rootScope.$broadcast('chat_full_update', id) |
|
|
|
$rootScope.$broadcast('chat_full_update', id) |
|
|
|
|
|
|
|
|
|
|
|
return fullChannel |
|
|
|
return fullChannel |
|
|
|
}) |
|
|
|
|
|
|
|
}, function (error) { |
|
|
|
}, function (error) { |
|
|
|
switch (error.type) { |
|
|
|
switch (error.type) { |
|
|
|
case 'CHANNEL_PRIVATE': |
|
|
|
case 'CHANNEL_PRIVATE': |
|
|
@ -1325,6 +1329,28 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getChannelPinnedMessage(id) { |
|
|
|
|
|
|
|
return getChannelFull(id).then(function (fullChannel) { |
|
|
|
|
|
|
|
var pinnedMessageID = fullChannel && fullChannel.pinned_msg_id |
|
|
|
|
|
|
|
if (!pinnedMessageID) { |
|
|
|
|
|
|
|
return false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return Storage.get('pinned_hidden' + id).then(function (hiddenMessageID) { |
|
|
|
|
|
|
|
if (AppMessagesIDsManager.getMessageLocalID(pinnedMessageID) == hiddenMessageID) { |
|
|
|
|
|
|
|
return false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return pinnedMessageID |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function hideChannelPinnedMessage(id, pinnedMessageID) { |
|
|
|
|
|
|
|
var setKeys = {} |
|
|
|
|
|
|
|
setKeys['pinned_hidden' + id] = AppMessagesIDsManager.getMessageLocalID(pinnedMessageID) |
|
|
|
|
|
|
|
Storage.set(setKeys) |
|
|
|
|
|
|
|
$rootScope.$broadcast('peer_pinned_message', -id) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$rootScope.$on('apiUpdate', function (e, update) { |
|
|
|
$rootScope.$on('apiUpdate', function (e, update) { |
|
|
|
// console.log('on apiUpdate', update)
|
|
|
|
// console.log('on apiUpdate', update)
|
|
|
|
switch (update._) { |
|
|
|
switch (update._) { |
|
|
@ -1372,6 +1398,15 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
} |
|
|
|
} |
|
|
|
break |
|
|
|
break |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'updateChannelPinnedMessage': |
|
|
|
|
|
|
|
var channelID = update.channel_id |
|
|
|
|
|
|
|
var fullChannel = chatsFull[channelID] |
|
|
|
|
|
|
|
if (fullChannel !== undefined) { |
|
|
|
|
|
|
|
fullChannel.pinned_msg_id = AppMessagesIDsManager.getFullMessageID(update.id, channelID) |
|
|
|
|
|
|
|
$rootScope.$broadcast('peer_pinned_message', -channelID) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
@ -1404,7 +1439,9 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) |
|
|
|
getChatInviteLink: getChatInviteLink, |
|
|
|
getChatInviteLink: getChatInviteLink, |
|
|
|
getChatFull: getChatFull, |
|
|
|
getChatFull: getChatFull, |
|
|
|
getChannelFull: getChannelFull, |
|
|
|
getChannelFull: getChannelFull, |
|
|
|
getChannelParticipants: getChannelParticipants |
|
|
|
getChannelParticipants: getChannelParticipants, |
|
|
|
|
|
|
|
getChannelPinnedMessage: getChannelPinnedMessage, |
|
|
|
|
|
|
|
hideChannelPinnedMessage: hideChannelPinnedMessage |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|