提交 e2680a56 编写于 作者: F fancy

多身份 多个顶层组织的问题修复

im 消息支持会话删除试试退出的等功能
上级 c956262d
......@@ -158,6 +158,8 @@ class IMChatViewController: UIViewController {
// websocket 消息监听
NotificationCenter.default.addObserver(self, selector: #selector(receiveMessageFromWs(notice:)), name: OONotification.imCreate.notificationName, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(receiveRevokeMsgFromWs(notice:)), name: OONotification.imRevoke.notificationName, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(receiveImConvUpdateFromWs(notice:)), name: OONotification.imConvUpdate.notificationName, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(receiveImConvDeleteFromWs(notice:)), name: OONotification.imConvDelete.notificationName, object: nil)
// 监听 键盘打开
NotificationCenter.default.addObserver(self, selector: #selector(openKeyboard(notification:)), name: UIResponder.keyboardWillShowNotification, object: nil)
// 监听 键盘大小变化
......@@ -217,6 +219,30 @@ class IMChatViewController: UIViewController {
}
}
}
@objc private func receiveImConvUpdateFromWs(notice: Notification) {
DDLogDebug("接收到websocket 更新会话 消息")
if let message = notice.object as? IMConversationInfo {
if message.id == self.conversation?.id {
let personList = message.personList ?? []
let currentDn = O2AuthSDK.shared.myInfo()?.distinguishedName ?? ""
if personList.contains(currentDn) {
self.conversation = message
self.title = self.conversation?.title
} else {
DDLogInfo("成员被删除")
self.popVC()
}
}
}
}
@objc private func receiveImConvDeleteFromWs(notice: Notification) {
DDLogDebug("接收到websocket 删除会话 消息")
if let message = notice.object as? IMConversationInfo {
if message.id == self.conversation?.id {
self.popVC()
}
}
}
@objc private func clickUpdate() {
var arr = [
......
......@@ -51,6 +51,9 @@ class IMConversationListViewController: UIViewController {
view.addSubview(emptyView)
NotificationCenter.default.addObserver(self, selector: #selector(receiveMessageFromWs(notice:)), name: OONotification.imCreate.notificationName, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(receiveImConvUpdateFromWs(notice:)), name: OONotification.imConvUpdate.notificationName, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(receiveImConvDeleteFromWs(notice:)), name: OONotification.imConvDelete.notificationName, object: nil)
imConfig.enableClearMsg = false
viewModel.loadImConfig().then { imConfig in
......@@ -103,6 +106,19 @@ class IMConversationListViewController: UIViewController {
}
}
}
@objc private func receiveImConvUpdateFromWs(notice: Notification) {
DDLogDebug("接收到websocket 更新会话 消息")
if let _ = notice.object as? IMConversationInfo {
self.getConversationList()
}
}
@objc private func receiveImConvDeleteFromWs(notice: Notification) {
DDLogDebug("接收到websocket 删除会话 消息")
if let _ = notice.object as? IMConversationInfo {
self.getConversationList()
}
}
//接收websocket消息
@objc private func receiveMessageFromWs(notice: Notification) {
......
......@@ -119,7 +119,7 @@ class IMUploadBackModel: NSObject, DataModel {
}
//websocket 消息对象
class WsMessage: NSObject, DataModel {
class WsImMessage: NSObject, DataModel {
@objc var type: String? //im_create
@objc var body: IMMessageInfo? //这个对象只有 type=im_create的时候才是这个对象
required override init() { }
......@@ -128,6 +128,15 @@ class WsMessage: NSObject, DataModel {
}
}
class WsImConvMessage: NSObject, DataModel {
@objc var type: String? //
@objc var body: IMConversationInfo? //
required override init() { }
func mapping(mapper: HelpingMapper) {
}
}
//其他消息
class InstantMessage: NSObject, DataModel {
......
......@@ -374,17 +374,27 @@ extension O2MainController: WebSocketDelegate {
return
}
if type == O2.O2_MESSAGE_TYPE_IM_CREATE {
if let messageInfo = WsMessage.deserialize(from: text) {
if let messageInfo = WsImMessage.deserialize(from: text) {
DDLogDebug("接收到im消息 发送通知。。")
NotificationCenter.post(customeNotification: OONotification.imCreate, object: messageInfo.body)
}
self.addUnreadNumber()
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
} else if type == O2.O2_MESSAGE_TYPE_IM_REVOKE {
if let messageInfo = WsMessage.deserialize(from: text) {
if let messageInfo = WsImMessage.deserialize(from: text) {
DDLogDebug("接收到im消息 撤回消息")
NotificationCenter.post(customeNotification: OONotification.imRevoke, object: messageInfo.body)
}
} else if type == O2.O2_MESSAGE_TYPE_IM_CONVERSATION_UPDATE {
if let messageInfo = WsImConvMessage.deserialize(from: text) {
DDLogDebug("接收到im消息 更新会话消息")
NotificationCenter.post(customeNotification: OONotification.imConvUpdate, object: messageInfo.body)
}
} else if type == O2.O2_MESSAGE_TYPE_IM_CONVERSATION_DELETE {
if let messageInfo = WsImConvMessage.deserialize(from: text) {
DDLogDebug("接收到im消息 删除消息")
NotificationCenter.post(customeNotification: OONotification.imConvDelete, object: messageInfo.body)
}
}
}
} catch { }
......
......@@ -19,6 +19,7 @@ import CocoaLumberjack
class ContactHomeViewController: UITableViewController {
var contacts:[Int:[CellViewModel]] = [0:[],1:[],2:[]]
let group = DispatchGroup()
var myDepartmentURL:String? {
let acc = O2AuthSDK.shared.myInfo()!
......@@ -354,38 +355,14 @@ class ContactHomeViewController: UITableViewController {
case .success(let val):
let objects = JSON(val)["data"]
print(objects.description)
var identity = ""
var identitys:[IdentityV2] = []
if let person = Mapper<PersonV2>().map(JSONString:objects.description) {
if let identities = person.woIdentityList, identities.count > 0 {
identity = identities[0].distinguishedName ?? ""
identitys = identities
}
}
if !identity.isEmpty {
AF.request(self.topUnitByIdentityURL!, method: .post, parameters: ["identity": identity as AnyObject, "level": 1 as AnyObject], encoding: JSONEncoding.default, headers: nil).responseJSON(completionHandler: { (res) in
switch res.result {
case .success(let val):
let objects = JSON(val)["data"]
print(objects.description)
self.contacts[order]?.removeAll()
if let unit = Mapper<OrgUnit>().map(JSONString:objects.description) {
unit.subDirectUnitCount = 1 //这个接口查询出来的组织没有下级组织的数量,假设是有下级组织的
let tile = HeadTitle(name: L10n.Contacts.orgStructre, icon: O2ThemeManager.string(for: "Icon.icon_bumen")!)
let vmt = CellViewModel(name: tile.name, sourceObject: tile)
self.contacts[order]?.append(vmt)
// 顶级组织
let vm = CellViewModel(name: unit.name,sourceObject: unit)
self.contacts[order]?.append(vm)
}
break
case .failure(let err):
DDLogError(err.localizedDescription)
}
self.hideLoading()
if self.tableView.mj_header.isRefreshing() == true {
self.tableView.mj_header.endRefreshing()
}
self.tableView.reloadData()
})
if !identitys.isEmpty {
self.loadAllTopUnitByIdentity(order: order, identitys: identitys)
}else {
self.hideLoading()
if self.tableView.mj_header.isRefreshing() == true {
......@@ -393,7 +370,6 @@ class ContactHomeViewController: UITableViewController {
}
self.tableView.reloadData()
}
case .failure(let err):
DDLogError(err.localizedDescription)
self.hideLoading()
......@@ -407,6 +383,49 @@ class ContactHomeViewController: UITableViewController {
}
}
private func loadAllTopUnitByIdentity(order: Int, identitys: [IdentityV2]) {
self.contacts[order]?.removeAll()
for identity in identitys {
self.group.enter()
// 异步处理请求
DispatchQueue.main.async(group: self.group, execute: DispatchWorkItem(block: {
AF.request(self.topUnitByIdentityURL!, method: .post, parameters: ["identity": identity.distinguishedName as AnyObject, "level": 1 as AnyObject], encoding: JSONEncoding.default, headers: nil).responseJSON(completionHandler: { (res) in
switch res.result {
case .success(let val):
let objects = JSON(val)["data"]
if let unit = Mapper<OrgUnit>().map(JSONString:objects.description) {
unit.subDirectUnitCount = 1 //这个接口查询出来的组织没有下级组织的数量,假设是有下级组织的
if (self.contacts[order]?.isEmpty == true) { // 第一次 添加头部
let tile = HeadTitle(name: L10n.Contacts.orgStructre, icon: O2ThemeManager.string(for: "Icon.icon_bumen")!)
let vmt = CellViewModel(name: tile.name, sourceObject: tile)
self.contacts[order]?.append(vmt)
}
// 顶级组织
let vm = CellViewModel(name: unit.name,sourceObject: unit)
self.contacts[order]?.append(vm)
}
self.group.leave()
break
case .failure(let err):
DDLogError(err.localizedDescription)
self.group.leave()
break
}
})
}))
}
self.group.notify(queue: DispatchQueue.main) {
// 处理结果
self.hideLoading()
if self.tableView.mj_header.isRefreshing() == true {
self.tableView.mj_header.endRefreshing()
}
self.tableView.reloadData()
}
}
}
extension ContactHomeViewController:UISearchControllerDelegate{
......
......@@ -29,6 +29,10 @@ enum OONotification:String {
case imCreate
// im消息撤回
case imRevoke
// 会话更新
case imConvUpdate
// 会话删除
case imConvDelete
//日程管理Main中使用
case calendarIds
......
......@@ -21,6 +21,8 @@ struct O2 {
public static let O2_MESSAGE_TYPE_IM_CREATE = "im_create"
public static let O2_MESSAGE_TYPE_IM_REVOKE = "im_revoke"
public static let O2_MESSAGE_TYPE_IM_CONVERSATION_UPDATE = "im_conv_update"
public static let O2_MESSAGE_TYPE_IM_CONVERSATION_DELETE = "im_conv_delete"
// 通讯录权限查询视图key
public static let CUSTOM_STYLE_CONTACT_PERMISSION_PREF_KEY = "customStyleContactPermissionViewKey"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册