Kate Mobile v109.1版本的 MD5 值为:fcd76ded5f363ecbfac46035a4ed2a23
以下内容为反编译后的 MessageSendQueue.java 源代码,内容仅作参考
package com.perm.kate;
import android.app.Activity;
import android.os.Looper;
import android.widget.Toast;
import com.perm.kate.MessageSender;
import com.perm.kate.api.Attachment;
import com.perm.kate.api.Audio;
import com.perm.kate.api.AudioAlbum;
import com.perm.kate.api.Document;
import com.perm.kate.api.Geo;
import com.perm.kate.api.Link;
import com.perm.kate.api.Message;
import com.perm.kate.api.Photo;
import com.perm.kate.api.Sticker;
import com.perm.kate.api.Video;
import com.perm.kate.api.VkPoll;
import com.perm.kate.session.Session;
import com.perm.utils.TimeFix;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
public class MessageSendQueue {
WeakReference activity;
Session session;
final ArrayList messages = new ArrayList();
boolean is_sending = false;
int current_message = 0;
private final MessageSender.MessageSenderCallback senderCallback = new MessageSender.MessageSenderCallback() {
@Override
public void error(Throwable th, String str, ArrayList arrayList, ArrayList arrayList2) {
MessageSendQueue messageSendQueue = MessageSendQueue.this;
if (messageSendQueue.current_message < messageSendQueue.messages.size()) {
MessageSendQueue messageSendQueue2 = MessageSendQueue.this;
((MessageData) messageSendQueue2.messages.get(messageSendQueue2.current_message)).state = MessageData.State.ERROR;
}
MessageSender.sendMessagesBroadcast();
if (th instanceof IOException) {
MessageSendQueue.this.is_sending = false;
return;
}
MessageSendQueue messageSendQueue3 = MessageSendQueue.this;
int i = messageSendQueue3.current_message + 1;
messageSendQueue3.current_message = i;
if (i < messageSendQueue3.messages.size()) {
MessageSendQueue.this.send();
} else {
MessageSendQueue.this.is_sending = false;
}
}
@Override
public void ready() {
}
@Override
public void refreshed() {
MessageSendQueue.this.nextStep();
}
@Override
public void start() {
}
};
public static class MessageData {
ArrayList forward_messages;
public long group_id;
Message message;
public String payload;
public Integer sticker_id;
ArrayList attachments = new ArrayList();
ArrayList attachments_objects = new ArrayList();
State state = State.QUEUE;
public enum State {
QUEUE,
SENDING,
ERROR
}
MessageData() {
}
}
public MessageSendQueue(Session session) {
this.session = session;
}
public static void fillAttachments(ArrayList arrayList, ArrayList arrayList2, Message message, Integer num, ArrayList arrayList3, long j) {
String str;
ArrayList arrayList4 = arrayList;
ArrayList arrayList5 = arrayList2;
String str2 = "photo";
char c = 0;
if (arrayList4 != null) {
int i = 0;
while (i < arrayList.size()) {
try {
String str3 = (String) arrayList4.get(i);
if (str3.startsWith(str2)) {
String[] split = str3.substring(5).split("_");
Photo fetchPhotoFull = KApplication.db.fetchPhotoFull(Long.parseLong(split[1]), Long.parseLong(split[c]));
if (fetchPhotoFull == null) {
fetchPhotoFull = (Photo) arrayList5.get(i);
}
if (fetchPhotoFull != null) {
Attachment attachment = new Attachment();
attachment.type = str2;
attachment.photo = fetchPhotoFull;
message.attachments.add(attachment);
}
str = str2;
} else if (str3.startsWith("audio_playlist")) {
String[] split2 = str3.substring(14).split("_");
long parseLong = Long.parseLong(split2[0]);
long parseLong2 = Long.parseLong(split2[1]);
Link link = new Link();
str = str2;
AudioAlbum fetchAudioAlbum = KApplication.db.fetchAudioAlbum(parseLong, parseLong2);
if (fetchAudioAlbum != null) {
link.title = fetchAudioAlbum.title;
}
link.url = AudioAlbum.getLink(parseLong2, parseLong, null);
Attachment attachment2 = new Attachment();
attachment2.type = "link";
attachment2.link = link;
message.attachments.add(attachment2);
} else {
str = str2;
if (str3.startsWith("audio_message")) {
Attachment attachment3 = new Attachment();
attachment3.type = "audio";
attachment3.audio = (Audio) arrayList5.get(i);
message.attachments.add(attachment3);
} else if (str3.startsWith("audio")) {
String[] split3 = str3.substring(5).split("_");
Audio fetchAudio = KApplication.db.fetchAudio(Long.parseLong(split3[1]), Long.parseLong(split3[0]));
Attachment attachment4 = new Attachment();
attachment4.type = "audio";
attachment4.audio = fetchAudio;
message.attachments.add(attachment4);
} else if (str3.startsWith("video")) {
String[] split4 = str3.substring(5).split("_");
long parseLong3 = Long.parseLong(split4[0]);
long parseLong4 = Long.parseLong(split4[1]);
Video fetchVideo = KApplication.db.fetchVideo(parseLong4, parseLong3);
if (fetchVideo == null) {
Helper.reportError(new Exception("Failed to fetch video"), "video_id=" + parseLong4 + " owner_id=" + parseLong3);
}
Attachment attachment5 = new Attachment();
attachment5.type = "video";
attachment5.video = fetchVideo;
message.attachments.add(attachment5);
} else if (str3.startsWith("doc")) {
String[] split5 = str3.substring(3).split("_");
Document fetchDocFull = KApplication.db.fetchDocFull(Long.parseLong(split5[1]), Long.parseLong(split5[0]));
if (fetchDocFull != null) {
Attachment attachment6 = new Attachment();
attachment6.type = "doc";
attachment6.document = fetchDocFull;
message.attachments.add(attachment6);
}
} else {
if (str3.startsWith("location:")) {
String[] parseLocationString = Helper.parseLocationString(str3);
Attachment attachment7 = new Attachment();
attachment7.type = "geo";
Geo geo = new Geo();
attachment7.geo = geo;
geo.lat = parseLocationString[0];
geo.lon = parseLocationString[1];
message.attachments.add(attachment7);
} else if (str3.startsWith("wall")) {
Attachment attachment8 = new Attachment();
attachment8.type = "wall";
message.attachments.add(attachment8);
} else if (str3.startsWith("poll")) {
VkPoll fetchPoll = KApplication.db.fetchPoll(Long.parseLong(str3.replace("poll", "").split("_")[1]), Long.parseLong(KApplication.session.getMid()));
if (fetchPoll != null) {
Attachment attachment9 = new Attachment();
attachment9.type = "poll";
attachment9.poll = fetchPoll;
message.attachments.add(attachment9);
}
} else if (str3.startsWith("story")) {
Attachment attachment10 = new Attachment();
attachment10.type = "link";
Link link2 = new Link();
attachment10.link = link2;
link2.title = KApplication.current.getString(R.string.stories);
attachment10.link.url = "https://vk.com/" + str3;
message.attachments.add(attachment10);
}
i++;
arrayList4 = arrayList;
arrayList5 = arrayList2;
str2 = str;
c = 0;
}
}
i++;
arrayList4 = arrayList;
arrayList5 = arrayList2;
str2 = str;
c = 0;
} catch (Throwable th) {
th.printStackTrace();
Helper.reportError(th);
return;
}
}
}
if (num != null) {
Attachment attachment11 = new Attachment();
attachment11.type = "sticker";
Sticker sticker = new Sticker();
attachment11.sticker = sticker;
sticker.id = num.intValue();
attachment11.sticker.photo_64 = "https://vk.com/sticker/1-" + num + "-64";
attachment11.sticker.photo_128 = "https://vk.com/sticker/1-" + num + "-128";
attachment11.sticker.photo_256 = "https://vk.com/sticker/1-" + num + "-256";
String str4 = Vmoji.get(num.intValue());
if (str4 != null) {
Sticker sticker2 = attachment11.sticker;
sticker2.photo_64 = str4;
sticker2.photo_128 = str4;
sticker2.photo_256 = str4;
}
message.attachments.add(attachment11);
}
long parseLong5 = Long.parseLong(KApplication.session.getMid());
if (arrayList3 != null) {
Collections.sort(arrayList3);
Iterator it = arrayList3.iterator();
while (it.hasNext()) {
Long l = (Long) it.next();
Message fetchMessage = KApplication.db.fetchMessage(parseLong5, l.longValue() > 0 ? l.longValue() : -l.longValue(), j);
if (fetchMessage == null) {
fetchMessage = new Message();
fetchMessage.body = "[Обновите список сообщний]";
}
if (l.longValue() < 0) {
int i2 = 0;
while (i2 < fetchMessage.attachments.size()) {
if (fetchMessage.attachments.get(i2).type.equals("message")) {
fetchMessage.attachments.remove(i2);
i2--;
}
i2++;
}
}
Attachment attachment12 = new Attachment();
attachment12.type = "message";
attachment12.message = fetchMessage;
message.attachments.add(attachment12);
}
}
}
public void nextStep() {
try {
Thread.sleep(300L);
if (this.current_message < this.messages.size()) {
this.messages.remove(this.current_message);
}
if (this.current_message < this.messages.size()) {
send();
} else {
this.is_sending = false;
}
} catch (Throwable th) {
th.printStackTrace();
Helper.reportError(th);
}
}
private boolean onlyReplyInAttachments(ArrayList arrayList, ArrayList arrayList2) {
return (arrayList2 != null && arrayList2.size() != 0 && (((Long) arrayList2.get(0)).longValue() > 0L ? 1 : (((Long) arrayList2.get(0)).longValue() == 0L ? 0 : -1)) < 0) && (arrayList != null && arrayList.size() == 1);
}
public void send() {
this.is_sending = true;
MessageData messageData = (MessageData) this.messages.get(this.current_message);
messageData.state = MessageData.State.SENDING;
Message message = messageData.message;
WeakReference weakReference = this.activity;
new MessageSender(weakReference != null ? (Activity) weakReference.get() : null, message.body, Long.valueOf(message.uid), message.chat_id.longValue(), null, this.senderCallback, messageData.attachments, messageData.attachments_objects, messageData.forward_messages, messageData.sticker_id, messageData.group_id, messageData.payload).sendMessage(this.session);
}
public void add(String str, long j, long j2, ArrayList arrayList, ArrayList arrayList2, Integer num, long j3) {
add(str, j, j2, arrayList, arrayList2, num, j3, null, null);
}
public void add(String str, long j, long j2, ArrayList arrayList, ArrayList arrayList2, Integer num, long j3, ArrayList arrayList3, String str2) {
if (str.trim().equals("") && ((arrayList == null || arrayList.size() == 0 || onlyReplyInAttachments(arrayList, arrayList3)) && num == null)) {
if (Looper.myLooper() == Looper.getMainLooper()) {
Toast.makeText(KApplication.current, (int) R.string.message_empty, 1).show();
return;
}
return;
}
MessageData messageData = new MessageData();
Message message = new Message();
message.body = str;
message.is_out = true;
message.uid = j;
if (j2 != 0) {
message.uid = Long.parseLong(KApplication.session.getMid());
}
message.chat_id = Long.valueOf(j2);
message.date = TimeFix.unfix(System.currentTimeMillis() / 1000);
message.important = Boolean.FALSE;
messageData.message = message;
fillAttachments(arrayList, arrayList2, message, num, arrayList3, j3);
messageData.attachments = arrayList;
messageData.attachments_objects = arrayList2;
messageData.sticker_id = num;
messageData.group_id = j3;
messageData.forward_messages = arrayList3;
messageData.payload = str2;
this.messages.add(messageData);
if (this.is_sending) {
return;
}
start();
}
public void remove(int i) {
int i2;
if (i >= this.messages.size()) {
return;
}
if (this.is_sending && i < (i2 = this.current_message)) {
this.current_message = i2 - 1;
}
this.messages.remove(i);
}
public void start() {
this.current_message = 0;
if (this.messages.size() == 0) {
return;
}
send();
}
}