@@ -256,16 +256,8 @@ abstract class NotificationProcessor(context: Context) {
256256 val content = original.extras.getString(Notification .EXTRA_TEXT )
257257 val ticker = original.tickerText?.toString()
258258
259- // 合并消息
260- // title: QQ
261- // ticker: 昵称:内容
262- // text: 有 x 个联系人给你发过来y条新消息
263- val isMulti = content?.let {
264- ! it.contains(" :" ) && ! (ticker?.endsWith(it) ? : false )
265- } ? : false
266-
267- // 单独处理QQ空间
268- val isQzone = title?.let { qzonePattern.matcher(it).matches() } ? : false
259+ val isMulti = isMulti(ticker, content)
260+ val isQzone = isQzone(title)
269261
270262 Timber .tag(TAG ).v(" Title: $title ; Ticker: $ticker ; QZone: $isQzone ; Multi: $isMulti ; Content: $content " )
271263
@@ -274,12 +266,60 @@ abstract class NotificationProcessor(context: Context) {
274266 }
275267
276268 // 隐藏消息详情
277- if (ticker != null && ticker == content && hideMsgPattern.matcher(ticker).matches( )) {
269+ if (isHidden( ticker, content)) {
278270 Timber .tag(TAG ).v(" Hidden message content, skip." )
279271 return null
280272 }
281273
282274 // QQ空间
275+ tryResolveQzone(context, tag, original, isQzone, title, ticker, content)?.also { conversation ->
276+ return renewQzoneNotification(context, tag, conversation, sbn, original)
277+ }
278+
279+ if (ticker == null ) {
280+ Timber .tag(TAG ).i(" Ticker is null, skip." )
281+ return null
282+ }
283+
284+ // 群消息
285+ tryResolveGroupMsg(context, tag, original, isMulti, title, ticker, content)?.also { (channel, conversation) ->
286+ return renewConversionNotification(context, tag, channel, conversation, sbn, original)
287+ }
288+
289+ // 私聊消息
290+ tryResolvePrivateMsg(context, tag, original, isMulti, title, ticker)?.also { (channel, conversation) ->
291+ return renewConversionNotification(context, tag, channel, conversation, sbn, original)
292+ }
293+
294+ // 关联账号消息
295+ tryResolveBindingMsg(context, tag, original, title, ticker, content)?.also { (channel, conversation) ->
296+ return renewConversionNotification(context, tag, channel, conversation, sbn, original)
297+ }
298+
299+ Timber .tag(TAG ).w(" [None] Not match any pattern." )
300+ return null
301+ }
302+
303+ private fun isMulti (ticker : String? , content : String? ): Boolean {
304+ // 合并消息
305+ // title: QQ
306+ // ticker: 昵称:内容
307+ // text: 有 x 个联系人给你发过来y条新消息
308+ return content?.let {
309+ ! it.contains(" :" ) && ! (ticker?.endsWith(it) ? : false )
310+ } ? : false
311+ }
312+
313+ private fun isQzone (title : String? ): Boolean {
314+ return title?.let { qzonePattern.matcher(it).matches() } ? : false
315+ }
316+
317+ private fun isHidden (ticker : String? , content : String? ): Boolean {
318+ return ticker != null && ticker == content && hideMsgPattern.matcher(ticker).matches()
319+ }
320+
321+ private fun tryResolveQzone (context : Context , tag : Tag , original : Notification , isQzone : Boolean , title : String? ,
322+ ticker : String? , content : String? ): Conversation ? {
283323 if (isQzone && ! content.isNullOrEmpty()) {
284324 val num = matchQzoneNum(title)
285325 val conversation: Conversation
@@ -302,15 +342,13 @@ abstract class NotificationProcessor(context: Context) {
302342 deleteOldMessage(conversation, num)
303343 Timber .tag(TAG ).d(" [QZone] Ticker: $ticker " )
304344 }
305- return renewQzoneNotification(context, tag, conversation, sbn, original)
306- }
307-
308- if (ticker == null ) {
309- Timber .tag(TAG ).i(" Ticker is null, skip." )
310- return null
345+ return conversation
311346 }
347+ return null
348+ }
312349
313- // 群消息
350+ private fun tryResolveGroupMsg (context : Context , tag : Tag , original : Notification , isMulti : Boolean , title : String? ,
351+ ticker : String , content : String? ): Pair <NotifyChannel , Conversation >? {
314352 groupMsgPattern.matcher(ticker).also { matcher ->
315353 if (matcher.matches()) {
316354 val name = matcher.group(1 ) ? : return null
@@ -330,11 +368,14 @@ abstract class NotificationProcessor(context: Context) {
330368 NotifyChannel .FRIEND_SPECIAL
331369 else
332370 NotifyChannel .GROUP
333- return renewConversionNotification(context, tag, channel, conversation, sbn, original )
371+ return Pair ( channel, conversation)
334372 }
335373 }
374+ return null
375+ }
336376
337- // 私聊消息
377+ private fun tryResolvePrivateMsg (context : Context , tag : Tag , original : Notification , isMulti : Boolean ,
378+ title : String? , ticker : String ): Pair <NotifyChannel , Conversation >? {
338379 msgPattern.matcher(ticker).also { matcher ->
339380 if (matcher.matches()) {
340381 val titleMatcher = msgTitlePattern.matcher(title ? : " " )
@@ -346,17 +387,20 @@ abstract class NotificationProcessor(context: Context) {
346387 val conversation = addMessage(tag, name, text, null , avatarManager.getAvatar(name.hashCode()),
347388 original.contentIntent, original.deleteIntent, special)
348389 deleteOldMessage(conversation, if (isMulti) 0 else matchMessageNum(titleMatcher))
349- return if (special) {
390+ if (special) {
350391 Timber .tag(TAG ).d(" [FriendS] Name: $name ; Text: $text " )
351- renewConversionNotification(context, tag, NotifyChannel .FRIEND_SPECIAL , conversation, sbn, original )
392+ return Pair ( NotifyChannel .FRIEND_SPECIAL , conversation)
352393 } else {
353394 Timber .tag(TAG ).d(" [Friend] Name: $name ; Text: $text " )
354- renewConversionNotification(context, tag, NotifyChannel .FRIEND , conversation, sbn, original )
395+ return Pair ( NotifyChannel .FRIEND , conversation)
355396 }
356397 }
357398 }
399+ return null
400+ }
358401
359- // 关联账号消息
402+ private fun tryResolveBindingMsg (context : Context , tag : Tag , original : Notification , title : String? ,
403+ ticker : String , content : String? ): Pair <NotifyChannel , Conversation >? {
360404 bindingQQMsgTickerPattern.matcher(ticker).also { matcher ->
361405 if (matcher.matches()) {
362406 val account = matcher.group(1 ) ? : " "
@@ -366,11 +410,9 @@ abstract class NotificationProcessor(context: Context) {
366410 original.deleteIntent, false )
367411 deleteOldMessage(conversation, matchBindingMsgNum(title, content))
368412 Timber .tag(TAG ).d(" [Binding] Account: $account ; Text: $text " )
369- return renewConversionNotification(context, tag, NotifyChannel .FRIEND , conversation, sbn, original )
413+ return Pair ( NotifyChannel .FRIEND , conversation)
370414 }
371415 }
372-
373- Timber .tag(TAG ).w(" [None] Not match any pattern." )
374416 return null
375417 }
376418
0 commit comments