Commit 555ade9b authored by Alex朱枝文's avatar Alex朱枝文

IM列表追加到消息页以及推送跳转

parent 13f7a1f0
...@@ -72,7 +72,7 @@ extension AppDelegate: JPUSHRegisterDelegate { ...@@ -72,7 +72,7 @@ extension AppDelegate: JPUSHRegisterDelegate {
// 转换到消息tab // 转换到消息tab
YHLoginManager.shared.needJumpToMsgTabFlag = true YHLoginManager.shared.needJumpToMsgTabFlag = true
DispatchQueue.main.asyncAfter(deadline: .now() + 0.25, execute: { DispatchQueue.main.asyncAfter(deadline: .now() + 0.25, execute: {
goToMessagePage() goToMessagePage(userInfo)
}) })
} }
...@@ -113,12 +113,11 @@ extension AppDelegate: JPUSHRegisterDelegate { ...@@ -113,12 +113,11 @@ extension AppDelegate: JPUSHRegisterDelegate {
} }
// 系统要求执行这个方法 // 系统要求执行这个方法
completionHandler() completionHandler()
// 转换到消息tab // 转换到消息tab
YHLoginManager.shared.needJumpToMsgTabFlag = true YHLoginManager.shared.needJumpToMsgTabFlag = true
DispatchQueue.main.asyncAfter(deadline: .now() + 0.25, execute: { DispatchQueue.main.asyncAfter(deadline: .now() + 0.25, execute: {
goToMessagePage()
if let msgType = userInfo["msg_type"] as? Int, msgType == YHMessageType.article.rawValue { if let msgType = userInfo["msg_type"] as? Int, msgType == YHMessageType.article.rawValue {
goToMessagePage()
let model = YHNewsModel() let model = YHNewsModel()
model.id = userInfo["msg_id"] as? String ?? "" model.id = userInfo["msg_id"] as? String ?? ""
model.article_id = userInfo["article_id"] as? Int ?? 0 model.article_id = userInfo["article_id"] as? Int ?? 0
...@@ -129,7 +128,10 @@ extension AppDelegate: JPUSHRegisterDelegate { ...@@ -129,7 +128,10 @@ extension AppDelegate: JPUSHRegisterDelegate {
model.media_transcode_url = userInfo["media_transcode_url"] as? String ?? "" model.media_transcode_url = userInfo["media_transcode_url"] as? String ?? ""
yh_newsList.enterDetail(model) yh_newsList.enterDetail(model)
yh_newsList.markRead(model) yh_newsList.markRead(model)
} else {
goToMessagePage(userInfo)
} }
}) })
} }
......
...@@ -146,7 +146,7 @@ class YHCommunityViewController: YHBaseViewController { ...@@ -146,7 +146,7 @@ class YHCommunityViewController: YHBaseViewController {
make.edges.equalToSuperview() make.edges.equalToSuperview()
} }
NotificationCenter.default.addObserver(self, selector: #selector(goMessageListVC), name: YhConstant.YhNotification.goMessageVCNotifiction, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(goMessageListVC(_:)), name: YhConstant.YhNotification.goMessageVCNotifiction, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(goActivityVC), name: YhConstant.YhNotification.goActivityVCNotifiction, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(goActivityVC), name: YhConstant.YhNotification.goActivityVCNotifiction, object: nil)
...@@ -271,8 +271,17 @@ class YHCommunityViewController: YHBaseViewController { ...@@ -271,8 +271,17 @@ class YHCommunityViewController: YHBaseViewController {
} }
} }
@objc func goMessageListVC() { @objc func goMessageListVC(_ notification: Notification) {
segmentedView.selectItemAt(index: 0) segmentedView.selectItemAt(index: 0)
guard let userInfo = notification.userInfo else {
return
}
DispatchQueue.main.asyncAfter(deadline: .now() + 0.15) {
guard let messageListVC = self.arrItemVCs[0] as? YHMessageListVC else {
return
}
messageListVC.handleRemoteNotification(userInfo)
}
} }
@objc func goActivityVC() { @objc func goActivityVC() {
......
...@@ -23,6 +23,7 @@ enum YHMessageType: Int { ...@@ -23,6 +23,7 @@ enum YHMessageType: Int {
case article = 10 // 资讯 case article = 10 // 资讯
case yinheManager = 9527 // 银河管家 case yinheManager = 9527 // 银河管家
case txIM = 9528 // im聊天
} }
class YHMessageInfoModel: SmartCodable { class YHMessageInfoModel: SmartCodable {
...@@ -30,11 +31,62 @@ class YHMessageInfoModel: SmartCodable { ...@@ -30,11 +31,62 @@ class YHMessageInfoModel: SmartCodable {
var lastMessage: String = "" var lastMessage: String = ""
var lastMessageTime: Int64 = 0 var lastMessageTime: Int64 = 0
var type: Int = 0 var type: Int = 0
var title: String = ""
var avatar: String = ""
var conversationID: String = ""
var userID: String = ""
var groupID: String = ""
var orderKey: Int64 = 0
var isPinned: Bool = false
var isNotDisturb: Bool = false
var isOnline: Bool = false
var draftText: String = ""
var attributedSubtitle: NSAttributedString = NSAttributedString()
var avatarImage: UIImage?
var groupType: String = ""
required init() { required init() {
} }
init(
unreadCount: Int = 0,
lastMessage: String = "",
lastMessageTime: Int64 = 0,
type: Int = 0,
title: String = "",
avatar: String = "",
conversationID: String = "",
userID: String = "",
groupID: String = "",
orderKey: Int64 = 0,
isPinned: Bool = false,
isNotDisturb: Bool = false,
isOnline: Bool = false,
draftText: String = "",
attributedSubtitle: NSAttributedString = NSAttributedString(),
avatarImage: UIImage?,
groupType: String
) {
self.unreadCount = unreadCount
self.lastMessage = lastMessage
self.lastMessageTime = lastMessageTime
self.type = type
self.title = title
self.avatar = avatar
self.conversationID = conversationID
self.userID = userID
self.groupID = groupID
self.orderKey = orderKey
self.isPinned = isPinned
self.isNotDisturb = isNotDisturb
self.isOnline = isOnline
self.draftText = draftText
self.attributedSubtitle = attributedSubtitle
self.avatarImage = avatarImage
self.groupType = groupType
}
enum CodingKeys: String, CodingKey { enum CodingKeys: String, CodingKey {
case unreadCount = "unread_count" case unreadCount = "unread_count"
case lastMessage = "last_message" case lastMessage = "last_message"
...@@ -77,6 +129,9 @@ class YHMessageInfoModel: SmartCodable { ...@@ -77,6 +129,9 @@ class YHMessageInfoModel: SmartCodable {
} else if type == YHMessageType.article.rawValue { } else if type == YHMessageType.article.rawValue {
return "银河资讯" return "银河资讯"
} else if type == YHMessageType.txIM.rawValue {
return title
} }
return "" return ""
} }
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
// //
import UIKit import UIKit
import TUICore
class YHMessageSessionCell: UITableViewCell { class YHMessageSessionCell: UITableViewCell {
...@@ -69,6 +70,9 @@ class YHMessageSessionCell: UITableViewCell { ...@@ -69,6 +70,9 @@ class YHMessageSessionCell: UITableViewCell {
self.iconImgView.image = UIImage(named: "msg_icon_news") self.iconImgView.image = UIImage(named: "msg_icon_news")
self.iconContentView.backgroundColor = UIColor(hex: 0xF0F5FF) self.iconContentView.backgroundColor = UIColor(hex: 0xF0F5FF)
} else if model.type == YHMessageType.txIM.rawValue {
// self.iconImgView.kf.setImage(with: URL(string: model.avatar), placeholder: model.avatarImage ?? UIImage(named: "people_head_default"))
updatePortrait(convData: model)
} }
self.badgeLabel.isHidden = model.unreadCount <= 0 self.badgeLabel.isHidden = model.unreadCount <= 0
...@@ -86,15 +90,21 @@ class YHMessageSessionCell: UITableViewCell { ...@@ -86,15 +90,21 @@ class YHMessageSessionCell: UITableViewCell {
} }
make.width.equalTo(width) make.width.equalTo(width)
} }
let isBigIcon = model.type == YHMessageType.yinheManager.rawValue || model.type == YHMessageType.txIM.rawValue
self.iconImgView.snp.updateConstraints { make in self.iconImgView.snp.updateConstraints { make in
let width = model.type == YHMessageType.yinheManager.rawValue ? 44.0 : 21.0 let width = isBigIcon ? 44.0 : 21.0
let height = model.type == YHMessageType.yinheManager.rawValue ? 44.0 : 21.0 let height = isBigIcon ? 44.0 : 21.0
make.width.equalTo(width) make.width.equalTo(width)
make.height.equalTo(height) make.height.equalTo(height)
} }
if model.type == YHMessageType.txIM.rawValue {
let attr = NSMutableAttributedString(attributedString: model.attributedSubtitle)
attr.setAttributes([.foregroundColor: UIColor.mainTextColor50, .font: UIFont.PFSC_R(ofSize: 12)], range: NSRange(location: 0, length: attr.string.count))
self.detailLabel.attributedText = !attr.string.isEmpty ? attr : NSAttributedString(string: "暂无消息".local, attributes: [.foregroundColor: UIColor.mainTextColor50, .font: UIFont.PFSC_R(ofSize: 12)])
} else {
self.detailLabel.text = !model.lastMessage.isEmpty ? model.lastMessage : "暂无消息".local self.detailLabel.text = !model.lastMessage.isEmpty ? model.lastMessage : "暂无消息".local
}
self.timeLabel.text = formatTimestamp(Double(model.lastMessageTime)) self.timeLabel.text = formatTimestamp(Double(model.lastMessageTime))
self.timeLabel.isHidden = model.lastMessage.isEmpty self.timeLabel.isHidden = model.lastMessage.isEmpty
} }
...@@ -124,6 +134,51 @@ class YHMessageSessionCell: UITableViewCell { ...@@ -124,6 +134,51 @@ class YHMessageSessionCell: UITableViewCell {
return dateFormatter.string(from: date) return dateFormatter.string(from: date)
} }
private func updatePortrait(convData: YHMessageInfoModel) {
if !convData.groupID.isEmpty {
// Group avatar
if !convData.avatar.isEmpty {
// Group avatar has been manually set externally
self.iconImgView.kf.setImage(with: URL(string: convData.avatar), placeholder: convData.avatarImage ?? UIImage(named: "people_head_default"))
} else {
if TUIConfig.default().enableGroupGridAvatar {
// Use synthetic avatar
self.iconImgView.image = convData.avatarImage ?? UIImage(named: "people_head_default")
TUIGroupAvatar.getCacheGroupAvatar(convData.groupID) { [weak self] (avatar, callbackGroupID) in
guard let self = self else { return }
if callbackGroupID == convData.groupID {
if let avatar = avatar {
// Cache hit
self.iconImgView.image = avatar
} else {
// Need to synthesize new avatar
self.iconImgView.image = convData.avatarImage ?? UIImage(named: "people_head_default")
let placeholderImage = convData.avatarImage ?? UIImage(named: "people_head_default") ?? UIImage()
TUIGroupAvatar.fetchGroupAvatars(convData.groupID, placeholder: placeholderImage) { [weak self] (success, image, fetchGroupID) in
guard let self = self else { return }
if fetchGroupID == convData.groupID {
let placeholder = success ? image : TUIConfig.default().getGroupAvatarImage(byGroupType: convData.groupType)
self.iconImgView.image = placeholder
}
// Ignore if cell has been reused
}
}
}
// Ignore if cell has been reused
}
} else {
// Synthetic avatars not allowed, use default
self.iconImgView.image = convData.avatarImage ?? UIImage(named: "people_head_default")
}
}
} else {
self.iconImgView.kf.setImage(with: URL(string: convData.avatar), placeholder: convData.avatarImage ?? UIImage(named: "people_head_default"))
}
}
func setupUI() { func setupUI() {
self.selectionStyle = .none self.selectionStyle = .none
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment