修复私聊红点问题
This commit is contained in:
parent
755d25e1bd
commit
685eb839bf
@ -88,10 +88,7 @@ void ChatMgr::ProcPrivateChat(Player* hum, const cs::CMSendChatMsg& msg)
|
||||
if (!target) {
|
||||
return;
|
||||
}
|
||||
++private_msg_id_;
|
||||
|
||||
cs::MFChatMsg* p = new cs::MFChatMsg();
|
||||
p->set_msg_uuid(private_msg_id_);
|
||||
hum->FillMFUserInfo(p->mutable_sender());
|
||||
{
|
||||
TypeConvert::Convert(target->base_data, *p->mutable_receiver()->mutable_base_data());
|
||||
@ -102,13 +99,14 @@ void ChatMgr::ProcPrivateChat(Player* hum, const cs::CMSendChatMsg& msg)
|
||||
p->set_msg_body(msg.msg_body());
|
||||
p->set_send_time(time(nullptr));
|
||||
|
||||
AddChatedUser(hum->AccountId(), msg.target(), p, private_msg_id_);
|
||||
AddChatedUser(msg.target(), hum->AccountId(), p, private_msg_id_);
|
||||
|
||||
AddChatedUser(hum->AccountId(), msg.target(), p, hum->IncDBPrivateChatLastId());
|
||||
ChatMgr::Instance()->SyncPrivateChatMsg(hum);
|
||||
Player* target_hum = PlayerMgr::Instance()->GetPlayerByAccountId(msg.target());
|
||||
if (target_hum) {
|
||||
ChatMgr::Instance()->SyncPrivateChatMsg(target_hum);
|
||||
AddChatedUser(msg.target(), hum->AccountId(), p, target_hum->IncDBPrivateChatLastId());
|
||||
} else {
|
||||
AddChatedUser(msg.target(), hum->AccountId(), p, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -294,9 +292,41 @@ void ChatMgr::SyncGuildChatMsg(Player* hum)
|
||||
}
|
||||
}
|
||||
|
||||
void ChatMgr::OnPlayerOnline(Player* hum)
|
||||
{
|
||||
ChatedUserRec* user = GetChatedUser(hum->AccountId());
|
||||
if (user) {
|
||||
long long init_last_id = hum->GetDBPrivateChatLastId();
|
||||
for (auto& pair : user->users) {
|
||||
for (auto& msg : pair.second.msg_list) {
|
||||
if (msg->msg_uuid() == 0) {
|
||||
msg->set_msg_uuid(hum->IncDBPrivateChatLastId());
|
||||
} else if (msg->msg_uuid() > init_last_id){
|
||||
msg->set_msg_uuid(hum->IncDBPrivateChatLastId());
|
||||
}
|
||||
if (msg->msg_uuid() > user->last_id) {
|
||||
msg->last_id = msg->msg_uuid();
|
||||
}
|
||||
}
|
||||
//end for msg_list
|
||||
if (user->curr_id > user->last_id) {
|
||||
user->curr_id = user->last_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ChatMgr::OnPlayerOffline(Player* hum)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ChatMgr::AddChatedUser(const std::string& sender_id, const std::string& receiver_id,
|
||||
cs::MFChatMsg* chat_msg, long long last_id)
|
||||
{
|
||||
cs::MFChatMsg* chat_msg_copy = new cs::MFChatMsg;
|
||||
*chat_msg_copy = *chat_msg;
|
||||
chat_msg_copy->set_msg_uuid(last_id);
|
||||
auto itr = private_chated_users_.find(sender_id);
|
||||
if (itr == private_chated_users_.end()) {
|
||||
private_chated_users_[sender_id] = ChatedUserRec();
|
||||
@ -310,6 +340,6 @@ void ChatMgr::AddChatedUser(const std::string& sender_id, const std::string& rec
|
||||
itr2 = itr->second.users.find(receiver_id);
|
||||
}
|
||||
itr2->second.last_id = last_id;
|
||||
itr2->second.msg_list.push_back(chat_msg);
|
||||
itr2->second.msg_list.push_back(chat_msg_copy);
|
||||
itr2->second.PopAndDelete(50);
|
||||
}
|
||||
|
@ -59,19 +59,20 @@ class ChatMgr : public a8::Singleton<ChatMgr>
|
||||
void SyncPrivateChatMsg(Player* hum);
|
||||
void SyncGuildChatMsg(Player* hum);
|
||||
|
||||
void OnPlayerOnline(Player* hum);
|
||||
void OnPlayerOffline(Player* hum);
|
||||
|
||||
private:
|
||||
ChatedUserRec* GetChatedUser(const std::string& account_id);
|
||||
void AddChatedUser(const std::string& sender_id, const std::string& receiver_id,
|
||||
cs::MFChatMsg* chat_msg, long long last_id);
|
||||
|
||||
private:
|
||||
long long private_msg_id_ = 1000;
|
||||
long long world_msg_id_ = 1000;
|
||||
long long guild_msg_id_ = 1000;
|
||||
long long temp_msg_id_ = 1000;
|
||||
ChatMsgRec world_msgrec_;
|
||||
std::map<long long, ChatMsgRec> guild_msgrec_;
|
||||
std::map<long long, cs::MFChatMsg*> private_msg_hash_;
|
||||
std::map<std::string, ChatedUserRec> private_chated_users_;
|
||||
std::map<std::string, cs::MFChatMsg*> team_msg_hash_;
|
||||
ChatMsgRec bighorn_msgrec_;
|
||||
|
@ -95,10 +95,12 @@ void Player::Init()
|
||||
},
|
||||
&timer_attacher.timer_list_
|
||||
);
|
||||
ChatMgr::Instance()->OnPlayerOnline(this);
|
||||
}
|
||||
|
||||
void Player::UnInit()
|
||||
{
|
||||
ChatMgr::Instance()->OnPlayerOffline(this);
|
||||
SaveToDB(a8::XParams(), nullptr, nullptr);
|
||||
timer_attacher.ClearTimerList();
|
||||
for (auto& pair : friend_hash_) {
|
||||
@ -138,6 +140,10 @@ void Player::Deserialize(const ss::MFUserDB& user_db)
|
||||
if (GuildId() != 0) {
|
||||
applyed_guild_hash_.clear();
|
||||
}
|
||||
db_private_chat_last_id_ = user_db.private_chat_last_id();
|
||||
if (db_private_chat_last_id_ <= 10000) {
|
||||
db_private_chat_last_id_ = 10000;
|
||||
}
|
||||
}
|
||||
|
||||
void Player::Serialize(ss::MFUserDB& user_db)
|
||||
@ -163,6 +169,7 @@ void Player::Serialize(ss::MFUserDB& user_db)
|
||||
if (GuildId() != 0) {
|
||||
applyed_guild_hash_.clear();
|
||||
}
|
||||
user_db.set_private_chat_last_id(db_private_chat_last_id_);
|
||||
}
|
||||
|
||||
void Player::_CMPing(f8::MsgHdr& hdr, const cs::CMPing& msg)
|
||||
@ -1806,6 +1813,18 @@ int Player::GetFriendNum()
|
||||
return friend_hash_.size();
|
||||
}
|
||||
|
||||
long long Player::GetDBPrivateChatLastId()
|
||||
{
|
||||
return db_private_chat_last_id_;
|
||||
}
|
||||
|
||||
long long Player::IncDBPrivateChatLastId()
|
||||
{
|
||||
++db_private_chat_last_id_;
|
||||
MarkDirty();
|
||||
return db_private_chat_last_id_;
|
||||
}
|
||||
|
||||
void Player::InternalUpdateUserInfo()
|
||||
{
|
||||
ss::SS_IM_UpdateUserInfo ss_msg;
|
||||
|
@ -161,6 +161,8 @@ class Player
|
||||
int Head();
|
||||
int GuildJob();
|
||||
int GetFriendNum();
|
||||
long long GetDBPrivateChatLastId();
|
||||
long long IncDBPrivateChatLastId();
|
||||
|
||||
void SaveToDB(a8::XParams param, f8::AsyncDBOnOkFunc on_ok, f8::AsyncDBOnErrorFunc on_error);
|
||||
void MarkNewMsg();
|
||||
@ -224,6 +226,7 @@ private:
|
||||
std::set<std::string> exclude_account_ids_;
|
||||
std::string user_sign_;
|
||||
int last_create_guild_time_ = 0;
|
||||
long long db_private_chat_last_id_ = 0;
|
||||
|
||||
std::map<std::string, Friend*> friend_hash_;
|
||||
std::map<std::string, Friend*> black_hash_;
|
||||
|
Loading…
x
Reference in New Issue
Block a user