@Override public final String getContent() { JSONObject json = new JSONObject(); json.put("_lctype", this.getMessageType()); if (!fieldCache.contains(this.getClass())) { computeFieldAttribute(this.getClass()); } Map<String, FieldAttribute> classFieldAttributesMap = fieldCache.get(this.getClass()); for (FieldAttribute fieldAttribute : classFieldAttributesMap.values()) { Object fieldValue = fieldAttribute.get(this); json.put(fieldAttribute.getAliaName(), fieldValue); } return json.toJSONString(); }
private void sendNotification(AVIMTypedMessage message, AVIMConversation conversation) { String notificationContent = message instanceof AVIMTextMessage ? ((AVIMTextMessage) message).getText() : context.getString(R.string.unspport_message_type); Intent intent = new Intent(context, NotificationBroadcastReceiver.class); intent.putExtra(AppConstant.CONVERSATION_ID, conversation.getConversationId()); intent.putExtra(AppConstant.ACTIVITY_TITLE, conversation.getName()); intent.putExtra(AppConstant.MEMBER_ID, message.getFrom()); // NotificationUtils.showNotification(context, "新信息", notificationContent, null, intent); } }
public AVIMTypedMessage() { super(); initMessageType(); }
/** * 判断是什么消息类型 */ @Override public int getItemViewType(int position) { AVIMMessage message = messageList.get(position); if (null != message && message instanceof AVIMTypedMessage) { AVIMTypedMessage typedMessage = (AVIMTypedMessage) message; boolean isMe = fromMe(typedMessage); if (typedMessage.getMessageType() == LCIMRedPacketMessage.RED_PACKET_MESSAGE_TYPE) { return isMe ? ITEM_RIGHT_TEXT_RED_PACKET : ITEM_LEFT_TEXT_RED_PACKET; } else if (typedMessage.getMessageType() == LCIMRedPacketAckMessage.RED_PACKET_ACK_MESSAGE_TYPE) { // return RedPacketUtils.getInstance().receiveRedPacketAckMsg((LCIMRedPacketAckMessage) typedMessage,ITEM_TEXT_RED_PACKET_NOTIFY,ITEM_TEXT_RED_PACKET_NOTIFY_MEMBER); } else if (typedMessage.getMessageType() == LCIMTransferMessage.TRANSFER_MESSAGE_TYPE) { return isMe ? ITEM_RIGHT_TEXT_TRANSFER : ITEM_LEFT_TEXT_TRANSFER; } } return super.getItemViewType(position); } }
@Override public final void setContent(String content) { Map<String, Object> contentMap = JSONObject.parseObject(content, Map.class); if (!fieldCache.contains(this.getClass())) { computeFieldAttribute(this.getClass()); } Map<String, FieldAttribute> classFieldAttributesMap = fieldCache.get(this.getClass()); for (FieldAttribute fieldAttribute : classFieldAttributesMap.values()) { Object value = contentMap.get(fieldAttribute.getAliaName()); if (value instanceof Map && fieldAttribute.getFieldType() != null) { value = JSON.parseObject(JSON.toJSONString(value), fieldAttribute.getFieldType()); } fieldAttribute.set(this, value); } }
field = getField(currentClazz, propertyName); if (field == null && (isBooleanGetterMethod || isSetterMethod)) { String isFieldName = "is" + Character.toUpperCase(propertyName.charAt(0)) + propertyName.substring(1); field = getField(currentClazz, isFieldName); if (field != null) { propertyName = isFieldName;
AVIMMessage message = AVIMTypedMessage.parseMessage(conversationId, jsonObj); conversation.setLastMessage(message);
@Override public void onMessagePatchCommand(boolean isModify, Integer requestKey, Messages.PatchCommand patchCommand) { updateLocalPatchTime(isModify, patchCommand); if (isModify) { if (patchCommand.getPatchesCount() > 0) { for (Messages.PatchItem patchItem : patchCommand.getPatchesList()) { AVIMMessage message = AVIMTypedMessage.getMessage(patchItem.getCid(), patchItem.getMid(), patchItem.getData(), patchItem.getFrom(), patchItem.getTimestamp(), 0, 0); message.setUpdateAt(patchItem.getPatchTimestamp()); AVConversationHolder conversation = session.getConversationHolder(patchItem.getCid(), Conversation.CONV_TYPE_NORMAL); conversation.onMessageUpdateEvent(message, patchItem.getRecall()); } } } else { Operation op = session.conversationOperationCache.poll(requestKey); AVIMOperation operation = AVIMOperation.getAVIMOperation(op.operation); Bundle bundle = new Bundle(); bundle.putLong(Conversation.PARAM_MESSAGE_PATCH_TIME, patchCommand.getLastPatchTime()); BroadcastUtil.sendIMLocalBroadcast(session.getSelfPeerId(), null, requestKey, bundle, operation); } }
@Override public int getItemViewType(int position) { AVIMMessage message = messageList.get(position); if (null != message && message instanceof AVIMTypedMessage) { AVIMTypedMessage typedMessage = (AVIMTypedMessage) message; boolean isMe = message.getFrom().equals(AVImClientManager.getInstance().getClientId()); if (typedMessage.getMessageType() == AVIMReservedMessageType.TextMessageType.getType()) { return isMe ? ITEM_RIGHT_TEXT : ITEM_LEFT_TEXT; } else { return isMe ? ITEM_RIGHT : ITEM_LEFT; } } return 8888; }
@Override public void onMessage(AVIMTypedMessage message, AVIMConversation conversation, AVIMClient client) { Log.e("wxl", "MessageHandler onMessage"); String clientID = ""; try { clientID = AVImClientManager.getInstance().getClientId(); if (client.getClientId().equals(clientID)) { Log.e("wxl", "MessageHandler onMessage clientID=" + clientID + ",client.getClientId()=" + client.getClientId() + ",message.getFrom()=" + message.getFrom()); // 过滤掉自己发的消息 if (!message.getFrom().equals(clientID)) { sendEvent(message, conversation); // Log.e("wxl", "MessageHandler=" + NotificationUtils.isShowNotification(conversation.getConversationId())); // if (NotificationUtils.isShowNotification(conversation.getConversationId())) { // sendNotification(message, conversation); // } } } else { client.close(null); } } catch (IllegalStateException e) { client.close(null); } }
@Override public void onMessage(AVIMTypedMessage message, AVIMConversation conversation, AVIMClient client){ String clientID = ""; try{ clientID = AVImClientManager.getInstance().getClientId(); if(client.getClientId().equals(clientID)){ //过滤自己发的消息 if(!message.getFrom().equals(clientID)){ sendEvent(message, conversation); } }else { client.close(null); } }catch(IllegalStateException e){ client.close(null); e.printStackTrace(); } }