Open olala2288 opened 6 years ago
I use this and it's work for me
TLRequestMessagesGetAllChats getAllChats = new TLRequestMessagesGetAllChats();
getAllChats.setExceptIds(new TLIntVector());
try {
TLAbsMessagesChats messagesChats = kernel.getKernelComm().getApi().doRpcCall(getAllChats);
TLVector<TLAbsChat> absChats = messagesChats.getChats();
absChats.forEach((absChat) -> {
if (absChat instanceof TLChannel) {
int channelId = absChat.getId();
Long channelHash = ((TLChannel) absChat).getAccessHash();
String channelUsername = ((TLChannel) absChat).getUsername();
TLRequestMessagesGetHistory getHistory = new TLRequestMessagesGetHistory();
TLInputPeerChannel channel = new TLInputPeerChannel();
channel.setChannelId(absChat.getId());
channel.setAccessHash(((TLChannel) absChat).getAccessHash());
try {
ResultSet result = db.select("SELECT max(messageId) as maxId FROM messages WHERE channelId=" + channelId + ";");
if (result.next()) {
if (result.getInt("maxId") > 0) {
getHistory.setMinId(result.getInt("maxId"));
} else {
getHistory.setLimit(1);
}
} else {
getHistory.setLimit(1);
}
} catch (SQLException ex) {
Logger.getLogger(MainClass.class.getName()).log(Level.SEVERE, null, ex);
return;
}
getHistory.setPeer(channel);
try {
TLAbsMessages t = kernel.getKernelComm().getApi().doRpcCall(getHistory);
TLVector<TLAbsMessage> absMessages = t.getMessages();
absMessages.forEach((absMessage) -> {
if (absMessage instanceof TLMessage) {
TLMessage message = (TLMessage) absMessage;
}
}
}
I don't test your code but I think you must use kernelComm.doRpcCall(tlreqHistory);
not kernelComm.doRpcCallSyncNoAuth(tlreqHistory);
the second thing you must test is your phone join the channel you want to get his history
Hi, How do you intercept messages from channels?
I tried to add these codes in MessageHandler class but it's not functioning.
Pls. maybe you can help me. Thank you.
i want to get history of a channel and i keep requesting and it returns null here is my Code is there anybody can help me ? ` public void handleChannelMessage(@NotNull IUser user, @NotNull TLMessage message){ TLMessageFwdHeader tlMessageFwdHeader = message.getFwdFrom();
}`