@@ -700,38 +700,49 @@ static String boolean2String(boolean bool) {
700700
701701
702702 /**
703+ * case text
704+ * case image
705+ * case voice
706+ * case video
707+ * case location
708+ * case notification
709+ * case redpacket
710+ * case transfer
711+ * case url
712+ * case account_notice
713+ * case redpacketOpen
703714 *
704715 * @return
705716 */
706717 static String getMessageType (IMMessage item ) {
707- String type = "" ;
718+ String type = MessageConstant . MsgType . CUSTON ;
708719 switch (item .getMsgType ()) {
709720 case text :
710- type = "text" ;
721+ type = MessageConstant . MsgType . TEXT ;
711722 break ;
712723 case image :
713- type = "image" ;
724+ type = MessageConstant . MsgType . IMAGE ;
714725 break ;
715726 case audio :
716- type = "voice" ;
727+ type = MessageConstant . MsgType . VOICE ;
717728 break ;
718729 case video :
719- type = "video" ;
730+ type = MessageConstant . MsgType . VIDEO ;
720731 break ;
721732 case location :
722- type = "location" ;
733+ type = MessageConstant . MsgType . LOCATION ;
723734 break ;
724735 case file :
725- type = "file" ;
736+ type = MessageConstant . MsgType . FILE ;
726737 break ;
727738 case notification :
728- type = "notification" ;
739+ type = MessageConstant . MsgType . NOTIFICATION ;
729740 break ;
730741 case tip :
731- type = "tip" ;
742+ type = MessageConstant . MsgType . TIP ;
732743 break ;
733744 case robot :
734- type = "robot" ;
745+ type = MessageConstant . MsgType . ROBOT ;
735746 break ;
736747 case custom :
737748 CustomAttachment attachment = null ;
@@ -743,33 +754,39 @@ static String getMessageType(IMMessage item) {
743754 if (attachment != null ) {
744755 switch (attachment .getType ()) {
745756 case CustomAttachmentType .RedPacket :
746- type = "red_packet" ;
757+ type = MessageConstant . MsgType . RED_PACKET ;
747758 break ;
748759
749760 case CustomAttachmentType .BankTransfer :
750- type = "bank_transfer" ;
761+ type = MessageConstant . MsgType . BANK_TRANSFER ;
751762 break ;
752763 case CustomAttachmentType .AccountNotice :
753- type = "account_notice" ;
764+ type = MessageConstant . MsgType . ACCOUNT_NOTICE ;
754765 break ;
755766 case CustomAttachmentType .LinkUrl :
756- type = "link" ;
767+ type = MessageConstant . MsgType . LINK ;
757768 break ;
758769 case CustomAttachmentType .RedPacketOpen :
759- type = "red_packet_open" ;
770+ type = MessageConstant . MsgType . RED_PACKET_OPEN ;
760771 break ;
761772 default :
773+ type = MessageConstant .MsgType .CUSTON ;
774+ break ;
762775 }
776+ }else {
777+ type = MessageConstant .MsgType .CUSTON ;
763778 }
764779 break ;
765780 default :
781+ type = MessageConstant .MsgType .CUSTON ;
766782 break ;
767783 }
768784
769785 return type ;
770786 }
771787
772- final static String MESSAGE_EXTEND = "extend" ;
788+ final static String MESSAGE_EXTEND = MessageConstant .Message .EXTEND ;
789+
773790 /**
774791 * <br/>uuid 消息ID
775792 * <br/>sessionId 会话id
@@ -787,17 +804,17 @@ static String getMessageType(IMMessage item) {
787804 */
788805 public static WritableMap createMessage (IMMessage item ) {
789806 WritableMap itemMap = Arguments .createMap ();
790- itemMap .putString ("_id" , item .getUuid ());
807+ itemMap .putString (MessageConstant . Message . MSG_ID , item .getUuid ());
791808
792- itemMap .putString ("msgType" , getMessageType (item ));
793- itemMap .putString ("createdAt" , Long .toString (item .getTime () / 1000 ));
794- itemMap .putString ("sessionId" , item .getSessionId ());
795- itemMap .putString ("sessionType" , Integer .toString (item .getSessionType ().getValue ()));
809+ itemMap .putString (MessageConstant . Message . MSG_TYPE , getMessageType (item ));
810+ itemMap .putString (MessageConstant . Message . TIME_STRING , Long .toString (item .getTime () / 1000 ));
811+ itemMap .putString (MessageConstant . Message . SESSION_ID , item .getSessionId ());
812+ itemMap .putString (MessageConstant . Message . SESSION_TYPE , Integer .toString (item .getSessionType ().getValue ()));
796813
797- itemMap .putString ("direct" , Integer .toString (item .getDirect ().getValue ()));
798- itemMap .putString ("status" , Integer .toString (item .getStatus ().getValue ()));
799- itemMap .putString ("attachStatus" , Integer .toString (item .getAttachStatus ().getValue ()));
800- itemMap .putString ("isRemoteRead" , boolean2String (receiveReceiptCheck (item )));
814+ itemMap .putString (MessageConstant . Message . IS_OUTGOING , Integer .toString (item .getDirect ().getValue ()));
815+ itemMap .putString (MessageConstant . Message . STATUS , Integer .toString (item .getStatus ().getValue ()));
816+ itemMap .putString (MessageConstant . Message . ATTACH_STATUS , Integer .toString (item .getAttachStatus ().getValue ()));
817+ itemMap .putString (MessageConstant . Message . IS_REMOTE_READ , boolean2String (receiveReceiptCheck (item )));
801818
802819 WritableMap user = Arguments .createMap ();
803820 String fromAccount = item .getFromAccount ();
@@ -807,17 +824,16 @@ public static WritableMap createMessage(IMMessage item) {
807824 } catch (Exception e ) {
808825 e .printStackTrace ();
809826 }
810- user .putString ("_id" , fromAccount );
827+ user .putString (MessageConstant . User . USER_ID , fromAccount );
811828
812829 if (item .getSessionType () == SessionTypeEnum .Team && !TextUtils .equals (LoginService .getInstance ().getAccount (), fromAccount )) {
813- user .putString ("name" , getTeamUserDisplayName (item .getSessionId (), fromAccount ));
830+ user .putString (MessageConstant . User . DISPLAY_NAME , getTeamUserDisplayName (item .getSessionId (), fromAccount ));
814831 } else {
815- user .putString ("name" , !TextUtils .isEmpty (fromNick ) ? fromNick : NimUserInfoCache .getInstance ().getUserDisplayName (fromAccount ));
832+ user .putString (MessageConstant . User . DISPLAY_NAME , !TextUtils .isEmpty (fromNick ) ? fromNick : NimUserInfoCache .getInstance ().getUserDisplayName (fromAccount ));
816833 }
817834 String avatar = NimUserInfoCache .getInstance ().getAvatar (fromAccount );
818- user .putString ("avatar" , avatar );
819- user .putString ("avatarLocal" , ImageLoaderKit .getMemoryCachedAvatar (avatar ));
820- itemMap .putMap ("user" , user );
835+ user .putString (MessageConstant .User .AVATAR_PATH , avatar );
836+ itemMap .putMap (MessageConstant .Message .FROM_USER , user );
821837
822838 MsgAttachment attachment = item .getAttachment ();
823839 String text = "" ;
@@ -828,54 +844,49 @@ public static WritableMap createMessage(IMMessage item) {
828844 if (attachment instanceof ImageAttachment ) {
829845 ImageAttachment imageAttachment = (ImageAttachment ) attachment ;
830846 if (item .getDirect () == MsgDirectionEnum .Out ) {
831- imageObj .putString ("thumbPath2" , imageAttachment .getPathForSave ());
832- imageObj .putString ("thumbPath" , imageAttachment .getPath ());
847+ imageObj .putString (MessageConstant .MediaFile .THUMB_PATH , imageAttachment .getPath ());
833848 } else {
834- imageObj .putString ("thumbPath2" , imageAttachment .getThumbPathForSave ());
835- imageObj .putString ("thumbPath" , imageAttachment .getThumbPath ());
849+ imageObj .putString (MessageConstant .MediaFile .THUMB_PATH , imageAttachment .getThumbPath ());
836850 }
837- imageObj .putString ("path2" , imageAttachment .getPathForSave ());
838- imageObj .putString ("path" , imageAttachment .getPath ());
839- imageObj .putString ("url" , imageAttachment .getUrl ());
840- imageObj .putString ("displayName" , imageAttachment .getDisplayName ());
841- imageObj .putString ("height" , Integer .toString (imageAttachment .getHeight ()));
842- imageObj .putString ("width" , Integer .toString (imageAttachment .getWidth ()));
851+ imageObj .putString (MessageConstant .MediaFile .PATH , imageAttachment .getPath ());
852+ imageObj .putString (MessageConstant .MediaFile .URL , imageAttachment .getUrl ());
853+ imageObj .putString (MessageConstant .MediaFile .DISPLAY_NAME , imageAttachment .getDisplayName ());
854+ imageObj .putString (MessageConstant .MediaFile .HEIGHT , Integer .toString (imageAttachment .getHeight ()));
855+ imageObj .putString (MessageConstant .MediaFile .WIDTH , Integer .toString (imageAttachment .getWidth ()));
843856 }
844857 itemMap .putMap (MESSAGE_EXTEND , imageObj );
845858 } else if (item .getMsgType () == MsgTypeEnum .audio ) {
846859 WritableMap audioObj = Arguments .createMap ();
847860 if (attachment instanceof AudioAttachment ) {
848861 AudioAttachment audioAttachment = (AudioAttachment ) attachment ;
849- audioObj .putString ("path" , audioAttachment .getPath ());
850- audioObj .putString ("thumbPath" , audioAttachment .getThumbPath ());
851- audioObj .putString ("url" , audioAttachment .getUrl ());
852- audioObj .putString ("duration" , Long .toString (audioAttachment .getDuration ()));
862+ audioObj .putString (MessageConstant . MediaFile . PATH , audioAttachment .getPath ());
863+ audioObj .putString (MessageConstant . MediaFile . THUMB_PATH , audioAttachment .getThumbPath ());
864+ audioObj .putString (MessageConstant . MediaFile . URL , audioAttachment .getUrl ());
865+ audioObj .putString (MessageConstant . MediaFile . DURATION , Long .toString (audioAttachment .getDuration ()));
853866 }
854867 itemMap .putMap (MESSAGE_EXTEND , audioObj );
855868 } else if (item .getMsgType () == MsgTypeEnum .video ) {
856869 WritableMap videoDic = Arguments .createMap ();
857870 if (attachment instanceof VideoAttachment ) {
858871 VideoAttachment videoAttachment = (VideoAttachment ) attachment ;
859- videoDic .putString ("url" , videoAttachment .getUrl ());
860- videoDic .putString ("path2" , videoAttachment .getPathForSave ());
861- videoDic .putString ("path" , videoAttachment .getPath ());
862- videoDic .putString ("displayName" , videoAttachment .getDisplayName ());
863- videoDic .putString ("height" , Integer .toString (videoAttachment .getHeight ()));
864- videoDic .putString ("width" , Integer .toString (videoAttachment .getWidth ()));
865- videoDic .putString ("duration" , Long .toString (videoAttachment .getDuration ()));
866- videoDic .putString ("fileLength" , Long .toString (videoAttachment .getSize ()));
867-
868- videoDic .putString ("thumbPath" , videoAttachment .getThumbPath ());
869- videoDic .putString ("coverPath" , videoAttachment .getThumbPathForSave ());
872+ videoDic .putString (MessageConstant .MediaFile .URL , videoAttachment .getUrl ());
873+ videoDic .putString (MessageConstant .MediaFile .PATH , videoAttachment .getPath ());
874+ videoDic .putString (MessageConstant .MediaFile .DISPLAY_NAME , videoAttachment .getDisplayName ());
875+ videoDic .putString (MessageConstant .MediaFile .HEIGHT , Integer .toString (videoAttachment .getHeight ()));
876+ videoDic .putString (MessageConstant .MediaFile .WIDTH , Integer .toString (videoAttachment .getWidth ()));
877+ videoDic .putString (MessageConstant .MediaFile .DURATION , Long .toString (videoAttachment .getDuration ()));
878+ videoDic .putString (MessageConstant .MediaFile .SIZE , Long .toString (videoAttachment .getSize ()));
879+
880+ videoDic .putString (MessageConstant .MediaFile .THUMB_PATH , videoAttachment .getThumbPath ());
870881 }
871882 itemMap .putMap (MESSAGE_EXTEND , videoDic );
872883 } else if (item .getMsgType () == MsgTypeEnum .location ) {
873884 WritableMap locationObj = Arguments .createMap ();
874885 if (attachment instanceof LocationAttachment ) {
875886 LocationAttachment locationAttachment = (LocationAttachment ) attachment ;
876- locationObj .putString ("latitude" , Double .toString (locationAttachment .getLatitude ()));
877- locationObj .putString ("longitude" , Double .toString (locationAttachment .getLongitude ()));
878- locationObj .putString ("address" , locationAttachment .getAddress ());
887+ locationObj .putString (MessageConstant . Location . LATITUDE , Double .toString (locationAttachment .getLatitude ()));
888+ locationObj .putString (MessageConstant . Location . LONGITUDE , Double .toString (locationAttachment .getLongitude ()));
889+ locationObj .putString (MessageConstant . Location . ADDRESS , locationAttachment .getAddress ());
879890 }
880891 itemMap .putMap (MESSAGE_EXTEND , locationObj );
881892 } else if (item .getMsgType () == MsgTypeEnum .notification ) {
@@ -959,7 +970,7 @@ public static WritableMap createMessage(IMMessage item) {
959970 }
960971
961972 }
962- itemMap .putString ("content" , text );
973+ itemMap .putString (MessageConstant . Message . MSG_TEXT , text );
963974
964975 return itemMap ;
965976 }
0 commit comments