PageRenderTime 1265ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/QingTingFanBianYi/src/fm/qingting/qtradio/pushmessage/IMHandler.java

https://gitlab.com/qt-prometheus/qt-prometheus
Java | 366 lines | 346 code | 16 blank | 4 comment | 98 complexity | 17568479df3b826167a5405e3212e313 MD5 | raw file
  1. package fm.qingting.qtradio.pushmessage;
  2. import android.content.Context;
  3. import com.alibaba.fastjson.JSON;
  4. import com.alibaba.fastjson.JSONArray;
  5. import com.alibaba.fastjson.JSONObject;
  6. import fm.qingting.qtradio.data.IMDatabaseDS;
  7. import fm.qingting.qtradio.im.IMContacts;
  8. import fm.qingting.qtradio.im.info.GroupInfo;
  9. import fm.qingting.qtradio.im.message.IMMessage;
  10. import fm.qingting.qtradio.model.GlobalCfg;
  11. import fm.qingting.utils.ProcessDetect;
  12. import java.util.ArrayList;
  13. import java.util.HashMap;
  14. import java.util.Iterator;
  15. import java.util.List;
  16. import java.util.Map;
  17. import java.util.Map.Entry;
  18. import java.util.Set;
  19. public class IMHandler
  20. implements MessagePump.IRecvPushMsgListener
  21. {
  22. private static final String IM = "qingting:im";
  23. private static IMHandler _instance;
  24. private long SEND_NOTIFICATION_INTERVAL = 2000L;
  25. private boolean loginSuccess = true;
  26. private String mAlias;
  27. private Context mContext;
  28. private String mLastFromId = null;
  29. private String mMsgType = "pullmsg";
  30. private int mRecvMsgCnt = 0;
  31. private long mRecvMsgTime = 0L;
  32. private Map<String, Integer> mapUnReadCnt = new HashMap();
  33. private long msgSeq = -1L;
  34. private boolean canHandle(String paramString)
  35. {
  36. if (paramString == null);
  37. while (!paramString.equalsIgnoreCase("qingting:im"))
  38. return false;
  39. return ProcessDetect.processExists(this.mContext.getPackageName() + ":local", null);
  40. }
  41. private boolean canHandle(String paramString, int paramInt)
  42. {
  43. if (paramString == null);
  44. do
  45. {
  46. return false;
  47. if (paramInt == 0)
  48. return true;
  49. }
  50. while ((paramInt != 1) || (!IMContacts.getInstance().hasWatchedGroup(paramString)));
  51. return true;
  52. }
  53. public static IMHandler getInstance()
  54. {
  55. if (_instance == null)
  56. _instance = new IMHandler();
  57. return _instance;
  58. }
  59. private void handleIM(String paramString)
  60. {
  61. if ((paramString == null) || (paramString.equalsIgnoreCase("")));
  62. while (true)
  63. {
  64. return;
  65. try
  66. {
  67. paramString = (JSONObject)JSON.parse(paramString);
  68. String str = paramString.getString("event");
  69. if (str != null)
  70. {
  71. if (this.msgSeq == -1L)
  72. this.msgSeq = GlobalCfg.getInstance(this.mContext).getMsgSeq();
  73. if (str.equalsIgnoreCase("peer"))
  74. {
  75. if ((this.loginSuccess) && (canHandle(paramString.getString("from"), 0)))
  76. recvMsg(0, null, paramString.getJSONArray("body"));
  77. }
  78. else if ((str.equalsIgnoreCase("group")) && (this.loginSuccess))
  79. {
  80. str = paramString.getString("to");
  81. if (canHandle(str, 1))
  82. {
  83. recvMsg(1, str, paramString.getJSONArray("body"));
  84. return;
  85. }
  86. }
  87. }
  88. }
  89. catch (Exception paramString)
  90. {
  91. }
  92. }
  93. }
  94. private boolean handleMsg(String paramString)
  95. {
  96. if ((paramString == null) || (paramString.equalsIgnoreCase("")))
  97. return false;
  98. try
  99. {
  100. paramString = (JSONObject)JSON.parse(paramString);
  101. if (paramString != null)
  102. {
  103. paramString = paramString.getString("msg");
  104. if (paramString != null)
  105. {
  106. handleIM(paramString);
  107. return true;
  108. }
  109. }
  110. }
  111. catch (Exception paramString)
  112. {
  113. }
  114. return false;
  115. }
  116. private void recvMsg(int paramInt, String paramString, JSONArray paramJSONArray)
  117. {
  118. int i = 0;
  119. if (paramJSONArray != null);
  120. while (true)
  121. {
  122. try
  123. {
  124. IMMessage localIMMessage;
  125. if (paramJSONArray.size() == 1)
  126. {
  127. localIMMessage = new IMMessage();
  128. IMMessage.parseData(paramJSONArray.getJSONObject(0), localIMMessage);
  129. localIMMessage.chatType = paramInt;
  130. if (localIMMessage != null)
  131. {
  132. this.msgSeq += 1L;
  133. localIMMessage.msgSeq = this.msgSeq;
  134. this.mRecvMsgCnt += 1;
  135. if (localIMMessage.isGroupMsg())
  136. {
  137. if ((localIMMessage.mFromGroupId == null) || (localIMMessage.mFromGroupId.equalsIgnoreCase("")))
  138. localIMMessage.mFromGroupId = paramString;
  139. if (localIMMessage.mGroupName == null)
  140. {
  141. paramString = IMContacts.getInstance().getWatchedGroup(localIMMessage.mFromGroupId);
  142. if (paramString != null)
  143. localIMMessage.mGroupName = paramString.groupName;
  144. }
  145. else
  146. {
  147. IMDatabaseDS.getInstance().appendGroupMessage(localIMMessage, true);
  148. paramString = (Integer)this.mapUnReadCnt.get(localIMMessage.mFromGroupId);
  149. if (paramString == null)
  150. {
  151. this.mapUnReadCnt.put(localIMMessage.mFromGroupId, Integer.valueOf(1));
  152. storeUnReadMsgCnt();
  153. sendNotification(localIMMessage);
  154. return;
  155. }
  156. paramInt = paramString.intValue();
  157. this.mapUnReadCnt.put(localIMMessage.mFromGroupId, Integer.valueOf(paramInt + 1));
  158. continue;
  159. }
  160. }
  161. else
  162. {
  163. IMDatabaseDS.getInstance().appendPrivateMessage(localIMMessage, true);
  164. paramString = (Integer)this.mapUnReadCnt.get(localIMMessage.mFromID);
  165. if (paramString == null)
  166. {
  167. this.mapUnReadCnt.put(localIMMessage.mFromID, Integer.valueOf(1));
  168. storeUnReadMsgCnt();
  169. continue;
  170. }
  171. paramInt = paramString.intValue();
  172. this.mapUnReadCnt.put(localIMMessage.mFromID, Integer.valueOf(paramInt + 1));
  173. continue;
  174. }
  175. }
  176. }
  177. else if (paramJSONArray.size() > 1)
  178. {
  179. paramString = new ArrayList();
  180. if (i < paramJSONArray.size())
  181. {
  182. localIMMessage = new IMMessage();
  183. IMMessage.parseData(paramJSONArray.getJSONObject(i), localIMMessage);
  184. localIMMessage.chatType = paramInt;
  185. this.msgSeq += 1L;
  186. localIMMessage.msgSeq = this.msgSeq;
  187. if (localIMMessage == null)
  188. break label470;
  189. paramString.add(localIMMessage);
  190. break label470;
  191. }
  192. if (paramString.size() > 0)
  193. {
  194. if (!((IMMessage)paramString.get(0)).isGroupMsg())
  195. {
  196. IMDatabaseDS.getInstance().appendListPrivateMessage(paramString, true);
  197. this.mRecvMsgCnt += paramString.size();
  198. return;
  199. }
  200. IMDatabaseDS.getInstance().appendListGroupMessage(paramString, true);
  201. continue;
  202. }
  203. }
  204. return;
  205. }
  206. catch (Exception paramString)
  207. {
  208. return;
  209. }
  210. label470: i += 1;
  211. }
  212. }
  213. private void sendNotification(IMMessage paramIMMessage)
  214. {
  215. if (paramIMMessage == null)
  216. return;
  217. long l = System.currentTimeMillis();
  218. if (l - this.mRecvMsgTime < this.SEND_NOTIFICATION_INTERVAL)
  219. {
  220. this.mRecvMsgTime = l;
  221. return;
  222. }
  223. this.mRecvMsgTime = l;
  224. String str1 = "";
  225. String str2;
  226. if (paramIMMessage.isGroupMsg())
  227. {
  228. str2 = paramIMMessage.mFromGroupId;
  229. if (str2 != null)
  230. {
  231. if ((this.mLastFromId != null) && (!str2.equalsIgnoreCase(this.mLastFromId)))
  232. break label176;
  233. if (paramIMMessage.mGroupName == null)
  234. paramIMMessage.mGroupName = "蜻蜓fm";
  235. str1 = paramIMMessage.mGroupName;
  236. str1 = str1 + "发来";
  237. str1 = str1 + String.valueOf(this.mRecvMsgCnt);
  238. str1 = str1 + "消息";
  239. this.mLastFromId = str2;
  240. }
  241. }
  242. while (true)
  243. {
  244. MessageNotification.sendIMNotification(paramIMMessage, this.mContext, str1);
  245. return;
  246. label176: str1 = "您收到" + String.valueOf(this.mRecvMsgCnt);
  247. str1 = str1 + "消息";
  248. this.mLastFromId = "#";
  249. continue;
  250. str2 = paramIMMessage.mFromID;
  251. if (str2 != null)
  252. if ((this.mLastFromId == null) || (str2.equalsIgnoreCase(this.mLastFromId)))
  253. {
  254. str1 = paramIMMessage.mFromName;
  255. str1 = str1 + "发来";
  256. str1 = str1 + String.valueOf(this.mRecvMsgCnt);
  257. str1 = str1 + "消息";
  258. this.mLastFromId = str2;
  259. }
  260. else
  261. {
  262. str1 = "蜻蜓fm收到" + String.valueOf(this.mRecvMsgCnt);
  263. str1 = str1 + "消息";
  264. this.mLastFromId = "#";
  265. }
  266. }
  267. }
  268. private void storeUnReadMsgCnt()
  269. {
  270. if (this.mapUnReadCnt.size() > 0)
  271. {
  272. Iterator localIterator = this.mapUnReadCnt.entrySet().iterator();
  273. Object localObject1 = "";
  274. Object localObject2 = "";
  275. int i = 0;
  276. while (localIterator.hasNext())
  277. {
  278. Object localObject3 = (Map.Entry)localIterator.next();
  279. int j = ((Integer)((Map.Entry)localObject3).getValue()).intValue();
  280. localObject3 = (String)localObject2 + (String)((Map.Entry)localObject3).getKey();
  281. String str = (String)localObject1 + String.valueOf(j);
  282. localObject2 = str;
  283. localObject1 = localObject3;
  284. if (i != this.mapUnReadCnt.size() - 1)
  285. {
  286. localObject1 = (String)localObject3 + "_";
  287. localObject2 = str + "_";
  288. }
  289. i += 1;
  290. localObject3 = localObject1;
  291. localObject1 = localObject2;
  292. localObject2 = localObject3;
  293. }
  294. GlobalCfg.getInstance(this.mContext).setUnReadCnt((String)localObject1);
  295. GlobalCfg.getInstance(this.mContext).setUnReadID((String)localObject2);
  296. }
  297. }
  298. public void clearMsgCnt()
  299. {
  300. this.mLastFromId = null;
  301. this.mRecvMsgCnt = 0;
  302. this.mRecvMsgTime = 0L;
  303. initUnReadMsg();
  304. }
  305. public void init(Context paramContext)
  306. {
  307. MessagePump.getInstance().registerRecvMsg(this);
  308. this.mContext = paramContext;
  309. }
  310. public void initUnReadMsg()
  311. {
  312. Object localObject2 = GlobalCfg.getInstance(this.mContext).getUnReadID();
  313. Object localObject1 = GlobalCfg.getInstance(this.mContext).getUnReadCnt();
  314. if ((localObject2 != null) && (localObject1 != null))
  315. {
  316. localObject2 = ((String)localObject2).split("_");
  317. if (localObject2 != null)
  318. break label43;
  319. }
  320. while (true)
  321. {
  322. return;
  323. label43: localObject1 = ((String)localObject1).split("_");
  324. if ((localObject1 != null) && (localObject1.length == localObject2.length))
  325. {
  326. int i = 0;
  327. while (i < localObject2.length)
  328. {
  329. this.mapUnReadCnt.put(localObject2[i], Integer.valueOf(localObject1[i]));
  330. i += 1;
  331. }
  332. }
  333. }
  334. }
  335. public boolean onRecvPushMsg(PushMessage paramPushMessage, int paramInt)
  336. {
  337. if (paramPushMessage == null);
  338. while ((paramInt != 0) || (!canHandle(paramPushMessage.mTopic)))
  339. return false;
  340. return handleMsg(paramPushMessage.mMessage);
  341. }
  342. public void setAlias(String paramString)
  343. {
  344. this.mAlias = paramString;
  345. }
  346. }
  347. /* Location: C:\Users\User\dex2jar-2.0\dex\qting\classes-dex2jar.jar
  348. * Qualified Name: fm.qingting.qtradio.pushmessage.IMHandler
  349. * JD-Core Version: 0.6.2
  350. */