use of forpdateam.ru.forpda.api.qms.models.QmsMessage in project ForPDA by RadiationX.
the class QmsRx method generateMess.
public static MiniTemplator generateMess(MiniTemplator t, List<QmsMessage> messages, int start, int end) {
for (int i = start; i < end; i++) {
QmsMessage mess = messages.get(i);
generateMess(t, mess);
}
return t;
}
use of forpdateam.ru.forpda.api.qms.models.QmsMessage in project ForPDA by RadiationX.
the class Qms method sendMessage.
public ArrayList<QmsMessage> sendMessage(int userId, int themeId, String text) throws Exception {
ArrayList<QmsMessage> messages = new ArrayList<>();
NetworkRequest.Builder builder = new NetworkRequest.Builder().url("https://4pda.ru/forum/index.php").formHeader("act", "qms-xhr").formHeader("action", "send-message").formHeader("message", text).formHeader("mid", Integer.toString(userId)).formHeader("t", Integer.toString(themeId));
NetworkResponse response = Api.getWebClient().request(builder.build());
Matcher matcher = chatPattern.matcher(response.getBody());
QmsMessage item = new QmsMessage();
if (matcher.find()) {
if (matcher.group(1) == null && matcher.group(7) != null) {
item.setIsDate(true);
item.setDate(matcher.group(7).trim());
} else {
item.setMyMessage(!matcher.group(1).isEmpty());
item.setId(Integer.parseInt(matcher.group(2)));
if (item.isMyMessage()) {
item.setReadStatus(!matcher.group(3).equals("1"));
} else {
item.setReadStatus(true);
}
item.setTime(matcher.group(4));
item.setAvatar(matcher.group(5));
item.setContent(matcher.group(6).trim());
}
messages.add(item);
} else {
matcher = Pattern.compile("class=\"list-group-item[^\"]*?error\"[\\s\\S]*?<\\/a>([\\s\\S]*?)<\\/div>").matcher(response.getBody());
if (matcher.find()) {
throw new Exception(matcher.group(1).trim());
}
}
return messages;
}
use of forpdateam.ru.forpda.api.qms.models.QmsMessage in project ForPDA by RadiationX.
the class Qms method getMessagesAfter.
public ArrayList<QmsMessage> getMessagesAfter(int userId, int themeId, int afterMessageId) throws Exception {
ArrayList<QmsMessage> messages = new ArrayList<>();
NetworkRequest.Builder threadMessagesBuilder = new NetworkRequest.Builder().url("https://4pda.ru/forum/index.php?act=qms-xhr&").xhrHeader().formHeader("action", "get-thread-messages").formHeader("mid", Integer.toString(userId)).formHeader("t", Integer.toString(themeId)).formHeader("after-message", Integer.toString(afterMessageId));
NetworkResponse threadMessagesResponse = Api.getWebClient().request(threadMessagesBuilder.build());
Matcher matcher = chatPattern.matcher(threadMessagesResponse.getBody());
while (matcher.find()) {
QmsMessage item = new QmsMessage();
if (matcher.group(1) == null && matcher.group(7) != null) {
item.setIsDate(true);
item.setDate(matcher.group(7).trim());
} else {
item.setMyMessage(!matcher.group(1).isEmpty());
item.setId(Integer.parseInt(matcher.group(2)));
if (item.isMyMessage()) {
item.setReadStatus(!matcher.group(3).equals("1"));
} else {
item.setReadStatus(true);
}
item.setTime(matcher.group(4));
item.setAvatar(matcher.group(5));
item.setContent(matcher.group(6).trim());
}
messages.add(item);
}
return messages;
}
use of forpdateam.ru.forpda.api.qms.models.QmsMessage in project ForPDA by RadiationX.
the class Qms method parseChat.
private QmsChatModel parseChat(String response) {
QmsChatModel chat = new QmsChatModel();
Matcher matcher = chatPattern.matcher(response);
QmsMessage item;
while (matcher.find()) {
item = new QmsMessage();
if (matcher.group(1) == null && matcher.group(7) != null) {
item.setIsDate(true);
item.setDate(matcher.group(7).trim());
} else {
item.setMyMessage(!matcher.group(1).isEmpty());
item.setId(Integer.parseInt(matcher.group(2)));
if (item.isMyMessage()) {
item.setReadStatus(!matcher.group(3).equals("1"));
} else {
item.setReadStatus(true);
}
item.setTime(matcher.group(4));
item.setAvatar(matcher.group(5));
item.setContent(matcher.group(6).trim());
}
chat.addMessage(item);
}
matcher = chatInfoPattern.matcher(response);
if (matcher.find()) {
chat.setNick(ApiUtils.fromHtml(matcher.group(1).trim()));
chat.setTitle(ApiUtils.fromHtml(matcher.group(2).trim()));
chat.setUserId(Integer.parseInt(matcher.group(3)));
chat.setThemeId(Integer.parseInt(matcher.group(4)));
chat.setAvatarUrl(matcher.group(5));
}
return chat;
}
use of forpdateam.ru.forpda.api.qms.models.QmsMessage in project ForPDA by RadiationX.
the class QmsChatFragment method onNewMessages.
private void onNewMessages(ArrayList<QmsMessage> qmsMessage) {
Log.d(LOG_TAG, "Returned messages " + qmsMessage.size());
if (!qmsMessage.isEmpty()) {
MiniTemplator t = App.get().getTemplate(App.TEMPLATE_QMS_CHAT_MESS);
App.setTemplateResStrings(t);
for (int i = 0; i < qmsMessage.size(); i++) {
QmsMessage message = qmsMessage.get(i);
for (QmsMessage viewmessage : currentChat.getMessages()) {
if (viewmessage.getId() == message.getId()) {
return;
}
}
currentChat.addMessage(message);
QmsRx.generateMess(t, message);
}
String messagesSrc = t.generateOutput();
t.reset();
messagesSrc = QmsRx.transformMessageSrc(messagesSrc);
webView.evalJs("showNewMess('".concat(messagesSrc).concat("', true)"));
}
}
Aggregations