Skip to content

Commit

Permalink
创建群组功能和界面
Browse files Browse the repository at this point in the history
  • Loading branch information
xmcy0011 committed Oct 31, 2020
1 parent ad024b4 commit ee3695b
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 29 deletions.
6 changes: 5 additions & 1 deletion client/ios/Coffchat/Coffchat/CIMSdk/IMChatManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,16 @@ class IMChatManager: IMClientDelegateData {

extension IMChatManager {
// 处理数据
func onHandleData(_ header: IMHeader, _ data: Data) {
func onHandleData(_ header: IMHeader, _ data: Data) -> Bool{
if header.commandId == CIM_Def_CIMCmdID.kCimCidMsgDataAck.rawValue {
_onHandleMsgAck(data: data)
return false
} else if header.commandId == CIM_Def_CIMCmdID.kCimCidMsgData.rawValue {
_onHandleMsgData(data: data)
// msg broadcast to other modules
return false
}
return false
}

// 消息发送结果
Expand Down
15 changes: 10 additions & 5 deletions client/ios/Coffchat/Coffchat/CIMSdk/IMConversationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class IMConversationManager: IMClientDelegateData {

/// 所有的会话列表
public var allRecentSessions: [String: IMRecentSession] = [:]

init() {
delegateDic = [:]
totalUnreadCount = 0
Expand Down Expand Up @@ -126,7 +126,7 @@ class IMConversationManager: IMClientDelegateData {
func unregister(key: String) {
delegateDic.removeValue(forKey: key)
}

func unregisterAll() {
delegateDic.removeAll()
}
Expand All @@ -135,16 +135,21 @@ class IMConversationManager: IMClientDelegateData {
// MARK: IMClientDelegateData

extension IMConversationManager {
func onHandleData(_ header: IMHeader, _ data: Data) {
func onHandleData(_ header: IMHeader, _ data: Data) -> Bool {
if Int(header.commandId) == CIM_Def_CIMCmdID.kCimCidListRecentContactSessionRsp.rawValue {
_onHandleRecentSessonList(data: data)
return true
} else if Int(header.commandId) == CIM_Def_CIMCmdID.kCimCidListMsgRsp.rawValue {
_onHandleMsgList(data: data)
return true
} else if Int(header.commandId) == CIM_Def_CIMCmdID.kCimCidMsgData.rawValue {
_onHandleMsgData(data: data)
return false
} else if Int(header.commandId) == CIM_Def_CIMCmdID.kCimCidMsgDataAck.rawValue {
_onHandleMsgDataAck(data: data)
return false
}
return false
}

// 会话列表响应
Expand Down Expand Up @@ -232,11 +237,11 @@ extension IMConversationManager {
recentSession!.latestMsg = msg
recentSession!.updatedTime = UInt32(NSDate().timeIntervalSince1970)
// 不是自己发送的消息,才更新未读计数
if msg.fromUserId != IMManager.singleton.loginManager.userId{
if msg.fromUserId != IMManager.singleton.loginManager.userId {
recentSession!.unreadCnt += 1
totalUnreadCount += 1
}

// 回调,更新UI界面
for item in delegateDic {
item.value.didUpdateRecentSession(session: recentSession!, totalUnreadCount: Int32(totalUnreadCount))
Expand Down
4 changes: 3 additions & 1 deletion client/ios/Coffchat/Coffchat/CIMSdk/IMFriendManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ class IMFriendManager {

extension IMFriendManager: IMClientDelegateData {
// 处理数据
func onHandleData(_ header: IMHeader, _ data: Data) {
func onHandleData(_ header: IMHeader, _ data: Data) -> Bool {
if header.commandId == CIM_Def_CIMCmdID.kCimCidFriendQueryUserListRsp.rawValue {
_onHandleQueryUserListRsp(data: data)
return true
}
return false
}

func _onHandleQueryUserListRsp(data: Data) {
Expand Down
11 changes: 10 additions & 1 deletion client/ios/Coffchat/Coffchat/CIMSdk/IMGroupManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,24 +164,33 @@ class IMGroupManager: IMClientDelegateData {

extension IMGroupManager {
// 处理数据
func onHandleData(_ header: IMHeader, _ data: Data) {
func onHandleData(_ header: IMHeader, _ data: Data) -> Bool{
if header.commandId == CIM_Def_CIMCmdID.kCimCidGroupCreateDefaultRsp.rawValue {
_onHandleGroupCreateRsp(data: data)
return true
} else if header.commandId == CIM_Def_CIMCmdID.kCimCidGroupDisbingdingRsp.rawValue {
_onHandleGroupDisbindingRsp(data: data)
return true
} else if header.commandId == CIM_Def_CIMCmdID.kCimCidGroupExitRsp.rawValue {
_onHandleGroupExitRsp(data: data)
return true
} else if header.commandId == CIM_Def_CIMCmdID.kCimCidGroupListRsp.rawValue {
_onHandleGroupListRsp(data: data)
return true
} else if header.commandId == CIM_Def_CIMCmdID.kCimCidGroupInfoRsp.rawValue {
_onHandleGroupInfoRsp(data: data)
return true
} else if header.commandId == CIM_Def_CIMCmdID.kCimCidGroupInviteMemberRsp.rawValue {
_onHandleGroupMemberInviteRsp(data: data)
return true
} else if header.commandId == CIM_Def_CIMCmdID.kCimCidGroupKickOutMemberRsp.rawValue {
_onHandleGroupMemberKickoutRsp(data: data)
return true
} else if header.commandId == CIM_Def_CIMCmdID.kCimCidGroupMemberChangedNotify.rawValue{
_onHandleMemberChangedNotify(data: data)
return true
}
return false
}

// MARK: handle
Expand Down
5 changes: 4 additions & 1 deletion client/ios/Coffchat/Coffchat/CIMSdk/IMLoginManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,15 @@ extension IMLoginManager {
// MARK: IMClientDelegateData

extension IMLoginManager {
func onHandleData(_ header: IMHeader, _ data: Data) {
func onHandleData(_ header: IMHeader, _ data: Data) -> Bool {
if header.commandId == CIM_Def_CIMCmdID.kCimCidLoginHeartbeat.rawValue {
IMLog.debug(item: "recv hearbeat")
return true
} else if header.commandId == CIM_Def_CIMCmdID.kCimCidLoginAuthTokenRsp.rawValue {
_onHandleAuthRes(header: header, data: data)
return true
}
return false
}

// auth response
Expand Down
6 changes: 4 additions & 2 deletions client/ios/Coffchat/Coffchat/CIMSdk/core/IMClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protocol IMClientDelegateData {
/// - Parameters:
/// - header: 协议头
/// - data: 数据体(裸数据)
func onHandleData(_ header: IMHeader, _ data: Data)
func onHandleData(_ header: IMHeader, _ data: Data) -> Bool
}

let kClientVersion = "0.0.1"
Expand Down Expand Up @@ -282,7 +282,9 @@ extension IMClient {

// 回调 FIXME 非线程安全
for item in delegateDicData {
item.value.onHandleData(header, bodyData)
if item.value.onHandleData(header, bodyData) {
break
}
}

return Int(header.length)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,37 @@
// Copyright © 2020 Coffeechat Inc. All rights reserved.
//

import Chrysan
import UIKit

/// 创建群组控制器
class IMCreateGroupViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet var userTabView: UITableView!
var userList: [PeopleUserModel] = []
var group: [Character] = []

var selectMemberCount: Int = 0

override func viewDidLoad() {
super.viewDidLoad()

title = "选择联系人"

// 注册自定义的Cell的实际类型
userTabView.register(UINib(nibName: "IMPeopleViewCell", bundle: nil), forCellReuseIdentifier: "IMPeopleViewCell")
userTabView.estimatedRowHeight = 65
userTabView.tableFooterView = UIView() // 设置之后可以去除空行单元格之间的空白线
userTabView.dataSource = self
userTabView.delegate = self

// Do any additional setup after loading the view.
// 左上角取消按钮
let cancel = UIBarButtonItem(title: "取消", style: .done, target: self, action: #selector(titleBarButtonItemMethod))
let cancel = UIBarButtonItem(title: "取消", style: .done, target: self, action: #selector(titleBarCancelButtonClick))
navigationItem.leftBarButtonItem = cancel


let ok = UIBarButtonItem(title: "确定", style: .done, target: self, action: #selector(titleBarOkButtonClick))
ok.isEnabled = false
navigationItem.rightBarButtonItem = ok

IMManager.singleton.friendManager.queryUserList(callback: { rsp in
// 加载用户列表
for item in rsp.userInfoList {
Expand Down Expand Up @@ -61,17 +67,34 @@ class IMCreateGroupViewController: UIViewController, UITableViewDelegate, UITabl
}

@objc
func titleBarButtonItemMethod() {}
func titleBarCancelButtonClick() {
navigationController?.popViewController(animated: true)
}

/*
// MARK: - Navigation
@objc
func titleBarOkButtonClick() {
// 菊花
chrysan.show()

// 选择的群成员
var ids: [UInt64] = []
for item in userList {
if item.check == true {
ids.append(item.userInfo.userID)
}
}

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
// 创建群组
IMManager.singleton.groupManager.createGroup(memberIdList: ids, groupName: "", callback: { _ in
// 成功,跳转聊天界面
// FIXME
self.chrysan.hide()
self.navigationController?.popViewController(animated: true)
}) {
self.chrysan.hide()
IMLog.warn(item: "titleBarOkButtonClick createGroup timeout")
}
}
}

// MARK: UITableViewDelegate
Expand All @@ -88,9 +111,38 @@ extension IMCreateGroupViewController {
// 取消选择
userTabView.deselectRow(at: indexPath, animated: true)

// 点击某一行,选中或反选
let cell = userTabView.cellForRow(at: indexPath)
let cell2 = cell as? IMPeopleViewCell
if cell2 != nil {
cell2?.on(on: !cell2!.cb.on)
onTabViewCellSelectChanged(isSelect: cell2!.cb.on)
}

// let user = userList[indexPath.row]
// let chatContentView = IMChatContentViewController(session: sessionInfo)
}

func onTabViewCellSelectChanged(isSelect: Bool) {
if isSelect {
selectMemberCount += 1

} else {
selectMemberCount -= 1
}

if selectMemberCount < 0 {
selectMemberCount = 0
}

if selectMemberCount == 0 {
title = "选择联系人"
navigationItem.rightBarButtonItem?.isEnabled = false
} else {
title = "选择联系人(\(selectMemberCount))"
navigationItem.rightBarButtonItem?.isEnabled = true
}
}
}

// MARK: UITableViewDataSource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class IMPeopleViewCell: UITableViewCell {

override func awakeFromNib() {
super.awakeFromNib()

cb.onAnimationType = .fade
// Initialization code
}

Expand All @@ -60,6 +62,11 @@ class IMPeopleViewCell: UITableViewCell {
// headImage.image = UIImage(named: "icon_avatar")
}

func on(on: Bool) {
cb.on = on
userModel?.check = on
}

@IBAction func cbValueChanged(_ sender: Any) {
userModel?.check = cb.isSelected
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" text="10.0.107.244" borderStyle="roundedRect" placeholder="Server" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="Sdp-rg-Lxg">
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" text="192.168.1.3" borderStyle="roundedRect" placeholder="Server" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="Sdp-rg-Lxg">
<rect key="frame" x="0.0" y="165" width="200" height="34"/>
<constraints>
<constraint firstAttribute="width" constant="200" id="Tnh-H3-mrP"/>
Expand Down
1 change: 1 addition & 0 deletions client/ios/Coffchat/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ target 'Coffchat' do
pod 'RxSwift', '~> 5' # 一个组合异步和事件驱动编程的库
pod 'RxCocoa', '~> 5' # iOS响应式编程中的两个主流框架(RxSwift+RxCocoa)
pod 'BEMCheckBox' # 高雅的iOS复选框
pod 'Chrysan' # 菊花组件
end
4 changes: 2 additions & 2 deletions server/src/internal/gate/tcpserver/conn_tcp_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (tcp *TcpConn) onHandleCreateGroupReq(header *cim.ImHeader, buff []byte) {
return
}

logger.Sugar.Info("onHandleCreateGroup group_name=%s,member_id_list_len=%d", req.GroupName, len(req.MemberIdList))
logger.Sugar.Infof("onHandleCreateGroup group_name=%s,member_id_list_len=%d", req.GroupName, len(req.MemberIdList))

conn := GetMessageConn()
ctx, cancelFun := context.WithTimeout(context.Background(), time.Second*kBusinessTimeOut)
Expand All @@ -28,7 +28,7 @@ func (tcp *TcpConn) onHandleCreateGroupReq(header *cim.ImHeader, buff []byte) {
if err != nil {
logger.Sugar.Warnf("onHandleCreateGroup CreateGroup(gRPC) err:", err.Error(), "user_id:", req.UserId)
} else {
_, err = tcp.Send(header.SeqNum, uint16(cim.CIMCmdID_kCIM_CID_GROUP_CREATE_DEFAULT_REQ), rsp)
_, err = tcp.Send(header.SeqNum, uint16(cim.CIMCmdID_kCIM_CID_GROUP_CREATE_DEFAULT_RSP), rsp)
logger.Sugar.Infof("onHandleCreateGroup CreateGroup(gRPC) res,user_id:%d,result_code:%d,"+
"group_id=%d,group_name=%s,member_id_list_len=%d",
rsp.UserId, rsp.ResultCode, rsp.GroupInfo.GroupId, rsp.GroupInfo.GroupName, len(rsp.MemberIdList))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ import (

// 创建群
func (s *LogicServer) CreateGroup(ctx context.Context, in *cim.CIMGroupCreateReq) (*cim.CIMGroupCreateRsp, error) {
logger.Sugar.Infof("CreateGroup userId=%d,groupName=%s", in.UserId, in.GroupName)
logger.Sugar.Infof("CreateGroup userId=%d,groupName=%s,memberIdListLen=%d", in.UserId, in.GroupName, len(in.MemberIdList))

rsp := &cim.CIMGroupCreateRsp{}
rsp.UserId = in.UserId
rsp.MemberIdList = in.MemberIdList

if in.GroupName == ""{
in.GroupName = "未命名群"
}

// create group
info, err := dao.DefaultGroup.Add(in.GroupName, in.UserId)
if err != nil {
Expand Down

0 comments on commit ee3695b

Please sign in to comment.