Fixed send messages to channels
This commit is contained in:
parent
923250bc41
commit
f3051aa443
@ -1332,7 +1332,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
|
|||||||
// console.log(dT(), 'start load history', $scope.curDialog);
|
// console.log(dT(), 'start load history', $scope.curDialog);
|
||||||
getMessagesPromise.then(function (historyResult) {
|
getMessagesPromise.then(function (historyResult) {
|
||||||
if (curJump != jump) return;
|
if (curJump != jump) return;
|
||||||
// console.log(dT(), 'history loaded', historyResult);
|
// console.log(dT(), 'history loaded', angular.copy(historyResult));
|
||||||
|
|
||||||
var fetchedLength = historyResult.history.length;
|
var fetchedLength = historyResult.history.length;
|
||||||
|
|
||||||
@ -1724,7 +1724,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
|
|||||||
});
|
});
|
||||||
|
|
||||||
$scope.$on('history_multiappend', function (e, historyMultiAdded) {
|
$scope.$on('history_multiappend', function (e, historyMultiAdded) {
|
||||||
// console.log(dT(), 'multiappend', historyMultiAdded);
|
// console.log(dT(), 'multiappend', angular.copy(historyMultiAdded));
|
||||||
var regroupped = false;
|
var regroupped = false;
|
||||||
var unreadAfterChanged = false;
|
var unreadAfterChanged = false;
|
||||||
var isIDLE = $rootScope.idle.isIDLE;
|
var isIDLE = $rootScope.idle.isIDLE;
|
||||||
@ -1769,7 +1769,8 @@ angular.module('myApp.controllers', ['myApp.i18n'])
|
|||||||
var lastIsRead = !historyMessage || !historyMessage.unread;
|
var lastIsRead = !historyMessage || !historyMessage.unread;
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
messageID = msgs[i];
|
messageID = msgs[i];
|
||||||
if (history.ids.indexOf(messageID) !== -1) {
|
if (messageID < maxID ||
|
||||||
|
history.ids.indexOf(messageID) !== -1) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
historyMessage = AppMessagesManager.wrapForHistory(messageID);
|
historyMessage = AppMessagesManager.wrapForHistory(messageID);
|
||||||
@ -1788,6 +1789,7 @@ angular.module('myApp.controllers', ['myApp.i18n'])
|
|||||||
hasOut = true;
|
hasOut = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// console.log('after append', angular.copy(history.messages), angular.copy(history.ids));
|
||||||
|
|
||||||
if (AppMessagesManager.regroupWrappedHistory(history.messages, -len - 2)) {
|
if (AppMessagesManager.regroupWrappedHistory(history.messages, -len - 2)) {
|
||||||
regroupped = true;
|
regroupped = true;
|
||||||
|
@ -374,7 +374,7 @@ angular.module('myApp.services')
|
|||||||
var fullMsgIDModulus = 4294967296;
|
var fullMsgIDModulus = 4294967296;
|
||||||
|
|
||||||
function getFullMessageID (msgID, channelID) {
|
function getFullMessageID (msgID, channelID) {
|
||||||
if (!channelID) {
|
if (!channelID || msgID < 0) {
|
||||||
return msgID;
|
return msgID;
|
||||||
}
|
}
|
||||||
msgID = getMessageLocalID(msgID);
|
msgID = getMessageLocalID(msgID);
|
||||||
@ -1020,6 +1020,8 @@ angular.module('myApp.services')
|
|||||||
inputPeer = AppPeersManager.getInputPeerByID(peerID),
|
inputPeer = AppPeersManager.getInputPeerByID(peerID),
|
||||||
flags = 0,
|
flags = 0,
|
||||||
replyToMsgID = options.replyToMsgID,
|
replyToMsgID = options.replyToMsgID,
|
||||||
|
isChannel = AppPeersManager.isChannel(peerID),
|
||||||
|
asChannel = isChannel ? true : false,
|
||||||
entities = [],
|
entities = [],
|
||||||
message;
|
message;
|
||||||
|
|
||||||
@ -1032,13 +1034,18 @@ angular.module('myApp.services')
|
|||||||
MtpApiManager.getUserID().then(function (fromID) {
|
MtpApiManager.getUserID().then(function (fromID) {
|
||||||
if (peerID != fromID) {
|
if (peerID != fromID) {
|
||||||
flags |= 2;
|
flags |= 2;
|
||||||
if (!AppUsersManager.isBot(peerID)) {
|
if (!isChannel && !AppUsersManager.isBot(peerID)) {
|
||||||
flags |= 1;
|
flags |= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (replyToMsgID) {
|
if (replyToMsgID) {
|
||||||
flags |= 8;
|
flags |= 8;
|
||||||
}
|
}
|
||||||
|
if (asChannel) {
|
||||||
|
fromID = 0;
|
||||||
|
} else {
|
||||||
|
flags |= 256;
|
||||||
|
}
|
||||||
message = {
|
message = {
|
||||||
_: 'message',
|
_: 'message',
|
||||||
id: messageID,
|
id: messageID,
|
||||||
@ -1082,6 +1089,9 @@ angular.module('myApp.services')
|
|||||||
if (entities.length) {
|
if (entities.length) {
|
||||||
flags |= 8;
|
flags |= 8;
|
||||||
}
|
}
|
||||||
|
if (asChannel) {
|
||||||
|
flags |= 16;
|
||||||
|
}
|
||||||
// console.log(flags, entities);
|
// console.log(flags, entities);
|
||||||
MtpApiManager.invokeApi('messages.sendMessage', {
|
MtpApiManager.invokeApi('messages.sendMessage', {
|
||||||
flags: flags,
|
flags: flags,
|
||||||
@ -1107,7 +1117,7 @@ angular.module('myApp.services')
|
|||||||
random_id: randomIDS,
|
random_id: randomIDS,
|
||||||
id: updates.id
|
id: updates.id
|
||||||
}, {
|
}, {
|
||||||
_: 'updateNewMessage',
|
_: isChannel ? 'updateNewChannelMessage' : 'updateNewMessage',
|
||||||
message: message,
|
message: message,
|
||||||
pts: updates.pts,
|
pts: updates.pts,
|
||||||
pts_count: updates.pts_count
|
pts_count: updates.pts_count
|
||||||
@ -1147,6 +1157,8 @@ angular.module('myApp.services')
|
|||||||
inputPeer = AppPeersManager.getInputPeerByID(peerID),
|
inputPeer = AppPeersManager.getInputPeerByID(peerID),
|
||||||
flags = 0,
|
flags = 0,
|
||||||
replyToMsgID = options.replyToMsgID,
|
replyToMsgID = options.replyToMsgID,
|
||||||
|
isChannel = AppPeersManager.isChannel(peerID),
|
||||||
|
asChannel = isChannel ? true : false,
|
||||||
attachType, apiFileName, realFileName;
|
attachType, apiFileName, realFileName;
|
||||||
|
|
||||||
if (!options.isMedia) {
|
if (!options.isMedia) {
|
||||||
@ -1173,13 +1185,18 @@ angular.module('myApp.services')
|
|||||||
MtpApiManager.getUserID().then(function (fromID) {
|
MtpApiManager.getUserID().then(function (fromID) {
|
||||||
if (peerID != fromID) {
|
if (peerID != fromID) {
|
||||||
flags |= 2;
|
flags |= 2;
|
||||||
if (!AppUsersManager.isBot(peerID)) {
|
if (!isChannel && !AppUsersManager.isBot(peerID)) {
|
||||||
flags |= 1;
|
flags |= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (replyToMsgID) {
|
if (replyToMsgID) {
|
||||||
flags |= 8;
|
flags |= 8;
|
||||||
}
|
}
|
||||||
|
if (asChannel) {
|
||||||
|
fromID = 0;
|
||||||
|
} else {
|
||||||
|
flags |= 256;
|
||||||
|
}
|
||||||
var media = {
|
var media = {
|
||||||
_: 'messageMediaPending',
|
_: 'messageMediaPending',
|
||||||
type: attachType,
|
type: attachType,
|
||||||
@ -1319,7 +1336,9 @@ angular.module('myApp.services')
|
|||||||
randomIDS = bigint(randomID[0]).shiftLeft(32).add(bigint(randomID[1])).toString(),
|
randomIDS = bigint(randomID[0]).shiftLeft(32).add(bigint(randomID[1])).toString(),
|
||||||
historyStorage = historiesStorage[peerID],
|
historyStorage = historiesStorage[peerID],
|
||||||
inputPeer = AppPeersManager.getInputPeerByID(peerID),
|
inputPeer = AppPeersManager.getInputPeerByID(peerID),
|
||||||
replyToMsgID = options.replyToMsgID;
|
replyToMsgID = options.replyToMsgID,
|
||||||
|
isChannel = AppPeersManager.isChannel(peerID),
|
||||||
|
asChannel = isChannel ? true : false;
|
||||||
|
|
||||||
if (historyStorage === undefined) {
|
if (historyStorage === undefined) {
|
||||||
historyStorage = historiesStorage[peerID] = {count: null, history: [], pending: []};
|
historyStorage = historiesStorage[peerID] = {count: null, history: [], pending: []};
|
||||||
@ -1354,6 +1373,14 @@ angular.module('myApp.services')
|
|||||||
flags |= 1;
|
flags |= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (replyToMsgID) {
|
||||||
|
flags |= 8;
|
||||||
|
}
|
||||||
|
if (asChannel) {
|
||||||
|
fromID = 0;
|
||||||
|
} else {
|
||||||
|
flags |= 256;
|
||||||
|
}
|
||||||
|
|
||||||
var message = {
|
var message = {
|
||||||
_: 'message',
|
_: 'message',
|
||||||
@ -1365,6 +1392,7 @@ angular.module('myApp.services')
|
|||||||
message: '',
|
message: '',
|
||||||
media: media,
|
media: media,
|
||||||
random_id: randomIDS,
|
random_id: randomIDS,
|
||||||
|
reply_to_msg_id: replyToMsgID,
|
||||||
pending: true
|
pending: true
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1425,14 +1453,17 @@ angular.module('myApp.services')
|
|||||||
msgIDs.push(getMessageLocalID(mids[i]));
|
msgIDs.push(getMessageLocalID(mids[i]));
|
||||||
randomIDs.push([nextRandomInt(0xFFFFFFFF), nextRandomInt(0xFFFFFFFF)]);
|
randomIDs.push([nextRandomInt(0xFFFFFFFF), nextRandomInt(0xFFFFFFFF)]);
|
||||||
}
|
}
|
||||||
|
var sentRequestOptions = {};
|
||||||
|
if (pendingAfterMsgs[peerID]) {
|
||||||
|
sentRequestOptions.afterMessageID = pendingAfterMsgs[peerID].messageID;
|
||||||
|
}
|
||||||
return MtpApiManager.invokeApi('messages.forwardMessages', {
|
return MtpApiManager.invokeApi('messages.forwardMessages', {
|
||||||
flags: flags,
|
flags: flags,
|
||||||
from_peer: AppPeersManager.getInputPeerByID(-fromChannel),
|
from_peer: AppPeersManager.getInputPeerByID(-fromChannel),
|
||||||
id: msgIDs,
|
id: msgIDs,
|
||||||
random_id: randomIDs,
|
random_id: randomIDs,
|
||||||
to_peer: AppPeersManager.getInputPeerByID(peerID),
|
to_peer: AppPeersManager.getInputPeerByID(peerID),
|
||||||
}).then(function (updates) {
|
}, sentRequestOptions).then(function (updates) {
|
||||||
ApiUpdatesManager.processUpdateMessage(updates);
|
ApiUpdatesManager.processUpdateMessage(updates);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -2015,6 +2046,7 @@ angular.module('myApp.services')
|
|||||||
notification.title = AppChatsManager.getChat(-peerID).title || _('conversation_unknown_chat_raw');
|
notification.title = AppChatsManager.getChat(-peerID).title || _('conversation_unknown_chat_raw');
|
||||||
|
|
||||||
if (message.from_id > 0) {
|
if (message.from_id > 0) {
|
||||||
|
var fromUser = AppUsersManager.getUser(message.from_id);
|
||||||
notification.title = (fromUser.first_name || fromUser.last_name || _('conversation_unknown_user_raw')) +
|
notification.title = (fromUser.first_name || fromUser.last_name || _('conversation_unknown_user_raw')) +
|
||||||
' @ ' +
|
' @ ' +
|
||||||
notification.title;
|
notification.title;
|
||||||
@ -2123,12 +2155,18 @@ angular.module('myApp.services')
|
|||||||
}
|
}
|
||||||
|
|
||||||
$rootScope.$on('apiUpdate', function (e, update) {
|
$rootScope.$on('apiUpdate', function (e, update) {
|
||||||
if (update._ != 'updateUserStatus') {
|
// if (update._ != 'updateUserStatus') {
|
||||||
console.log('on apiUpdate', update);
|
// console.log('on apiUpdate', update);
|
||||||
}
|
// }
|
||||||
switch (update._) {
|
switch (update._) {
|
||||||
case 'updateMessageID':
|
case 'updateMessageID':
|
||||||
pendingByMessageID[update.id] = update.random_id;
|
var randomID = update.random_id;
|
||||||
|
var pendingData = pendingByRandomID[randomID];
|
||||||
|
if (pendingData) {
|
||||||
|
var peerID = pendingData[0];
|
||||||
|
var channelID = AppPeersManager.isChannel(peerID) ? -peerID : 0;
|
||||||
|
pendingByMessageID[getFullMessageID(update.id, channelID)] = randomID;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'updateNewMessage':
|
case 'updateNewMessage':
|
||||||
|
@ -2572,7 +2572,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
|
|||||||
}
|
}
|
||||||
var curState = channelID ? getChannelState(channelID, update.pts) : updatesState;
|
var curState = channelID ? getChannelState(channelID, update.pts) : updatesState;
|
||||||
|
|
||||||
console.log('process', channelID, curState, update);
|
// console.log('process', channelID, curState, update);
|
||||||
|
|
||||||
if (curState.syncLoading) {
|
if (curState.syncLoading) {
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user