Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add MessageNew with ClientInfo object and callback handler for it #224

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

import com.vk.api.sdk.callback.CallbackApi;
import com.vk.api.sdk.objects.messages.Message;
import com.vk.api.sdk.objects.messages.MessageNew;

/**
* Created by tsivarev on 07.09.16.
*/
public class CallbackApiHandler extends CallbackApi {

@Override
public void messageNew(Integer groupId, Message message) {
MessagesHandler.parseMessage(groupId, message);
public void messageNew(Integer groupId, MessageNew message) {
MessagesHandler.parseMessage(groupId, message.getMessage());
}
}
9 changes: 5 additions & 4 deletions sdk/src/main/java/com/vk/api/sdk/callback/CallbackApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.vk.api.sdk.objects.board.TopicComment;
import com.vk.api.sdk.objects.callback.*;
import com.vk.api.sdk.objects.messages.Message;
import com.vk.api.sdk.objects.messages.MessageNew;
import com.vk.api.sdk.objects.photos.Photo;
import com.vk.api.sdk.objects.video.Video;
import com.vk.api.sdk.objects.wall.WallComment;
Expand Down Expand Up @@ -71,7 +72,7 @@ public class CallbackApi {

static {
Map<String, Type> types = new HashMap<>();
types.put(CALLBACK_EVENT_MESSAGE_NEW, new TypeToken<CallbackMessage<Message>>() {
types.put(CALLBACK_EVENT_MESSAGE_NEW, new TypeToken<CallbackMessage<MessageNew>>() {
}.getType());
types.put(CALLBACK_EVENT_MESSAGE_REPLY, new TypeToken<CallbackMessage<Message>>() {
}.getType());
Expand Down Expand Up @@ -166,10 +167,10 @@ public CallbackApi() {
gson = new Gson();
}

public void messageNew(Integer groupId, Message message) {
public void messageNew(Integer groupId, MessageNew message) {
}

public void messageNew(Integer groupId, String secret, Message message) {
public void messageNew(Integer groupId, String secret, MessageNew message) {
messageNew(groupId, message);
}

Expand Down Expand Up @@ -463,7 +464,7 @@ public boolean parse(JsonObject json) {

switch (type) {
case CALLBACK_EVENT_MESSAGE_NEW:
messageNew(message.getGroupId(), message.getSecret(), (Message) message.getObject());
messageNew(message.getGroupId(), message.getSecret(), (MessageNew) message.getObject());
break;

case CALLBACK_EVENT_MESSAGE_REPLY:
Expand Down
84 changes: 84 additions & 0 deletions sdk/src/main/java/com/vk/api/sdk/objects/messages/ClientInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package com.vk.api.sdk.objects.messages;

import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName;
import com.vk.api.sdk.objects.Validable;
import com.vk.api.sdk.objects.annotations.Required;
import com.vk.api.sdk.objects.base.BoolInt;
import com.vk.api.sdk.objects.base.Geo;
import java.util.List;
import java.util.Objects;

/**
* ClientInfo object
*/
public class ClientInfo implements Validable {
@SerializedName("button_actions")
private List<KeyboardButtonActionType> buttonActions;

@SerializedName("keyboard")
private Boolean keyboard;

@SerializedName("inline_keyboard")
private Boolean inlineKeyboard;

@SerializedName("carousel")
private Boolean carousel;

@SerializedName("lang_id")
private Integer lang_id;

public List<KeyboardButtonActionType> getButtonActions() {
return buttonActions;
}

public Boolean getKeyboard() {
return keyboard;
}

public Boolean getInlineKeyboard() {
return inlineKeyboard;
}

public Boolean getCarousel() {
return carousel;
}

public Integer getLang_id() {
return lang_id;
}

@Override
public int hashCode() {
return Objects.hash(buttonActions, keyboard, inlineKeyboard, carousel, lang_id);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ClientInfo clientInfo = (ClientInfo) o;
return Objects.equals(buttonActions, clientInfo.buttonActions) &&
Objects.equals(keyboard, clientInfo.keyboard) &&
Objects.equals(inlineKeyboard, clientInfo.inlineKeyboard) &&
Objects.equals(carousel, clientInfo.carousel) &&
Objects.equals(lang_id, clientInfo.lang_id);
}

@Override
public String toString() {
final Gson gson = new Gson();
return gson.toJson(this);
}

public String toPrettyString() {
final StringBuilder sb = new StringBuilder("ClientInfo{");
sb.append("buttonActions=").append(buttonActions);
sb.append(", keyboard=").append(keyboard);
sb.append(", inlineKeyboard=").append(inlineKeyboard);
sb.append(", carousel=").append(carousel);
sb.append(", lang_id=").append(lang_id);
sb.append('}');
return sb.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,22 @@ public enum KeyboardButtonActionType implements EnumParam {
VKPAY("vkpay"),

@SerializedName("open_app")
OPEN_APP("open_app");
OPEN_APP("open_app"),

@SerializedName("callback")
CALLBACK("callback"),

@SerializedName("open_link")
OPEN_LINK("open_link"),

@SerializedName("open_photo")
OPEN_PHOTO("open_photo"),

@SerializedName("intent_subscribe")
INTENT_SUBSCRIBE("intent_subscribe"),

@SerializedName("intent_unsubscribe")
INTENT_UNSUBSCRIBE("intent_unsubscribe");

private final String value;

Expand Down
51 changes: 51 additions & 0 deletions sdk/src/main/java/com/vk/api/sdk/objects/messages/MessageNew.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.vk.api.sdk.objects.messages;

import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName;
import com.vk.api.sdk.objects.Validable;

import java.util.Objects;

public class MessageNew implements Validable {
@SerializedName("message")
private Message message;

@SerializedName("client_info")
private ClientInfo clientInfo;

public Message getMessage() {
return message;
}

public ClientInfo getClientInfo() {
return clientInfo;
}

@Override
public int hashCode() {
return Objects.hash(message, clientInfo);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MessageNew messageNew = (MessageNew) o;
return Objects.equals(message, messageNew.message) &&
Objects.equals(clientInfo, messageNew.clientInfo);
}

@Override
public String toString() {
final Gson gson = new Gson();
return gson.toJson(this);
}

public String toPrettyString() {
final StringBuilder sb = new StringBuilder("MessageNew{");
sb.append("message=").append(message);
sb.append(", clientInfo=").append(clientInfo);
sb.append('}');
return sb.toString();
}
}