Commit 1889119d by hanccc

完善account保存

1 parent 65fb54d2
...@@ -91,7 +91,7 @@ class MessageHandler ...@@ -91,7 +91,7 @@ class MessageHandler
$message = $this->sync(); $message = $this->sync();
Message::make($selector, $message); // Message::make($selector, $message);
// print_r($message); // print_r($message);
Log::echo(json_encode($message)); Log::echo(json_encode($message));
} }
......
...@@ -10,6 +10,7 @@ namespace Hanson\Robot\Message; ...@@ -10,6 +10,7 @@ namespace Hanson\Robot\Message;
use Hanson\Robot\Core\Server; use Hanson\Robot\Core\Server;
use Hanson\Robot\Models\Account;
class Message class Message
{ {
...@@ -41,13 +42,20 @@ class Message ...@@ -41,13 +42,20 @@ class Message
{ {
$msg = $message['AddMsgList'][0]; $msg = $message['AddMsgList'][0];
if($msg['MsgType'] == 51){ if ($msg['MsgType'] == 51) {
$this->sender->name = 'system'; $this->sender->name = 'system';
$this->sender->type = 0; $this->sender->type = 0;
}elseif ($msg['MsgType'] == 37){ } elseif ($msg['MsgType'] == 37) {
$this->sender->type = 37; $this->sender->type = 37;
}elseif (Server::isMyself($msg['FromUserName'])){ } elseif (Server::isMyself($msg['FromUserName'])) {
$this->sender->name = 'self';
$this->sender->type = 1;
} elseif ($msg['ToUserName'] === 'filehelper') {
$this->sender->name = 'file_helper';
$this->sender->type = 2;
} elseif (substr($msg['FromUserName'], 0, 2) === '@@'){
$this->sender->name = Account::getInstance()->getContactName($msg['FromUserName'], Account::GROUP_MEMBER, true);
$this->sender->type = 3;
} }
} }
......
...@@ -14,8 +14,15 @@ use Illuminate\Support\Collection; ...@@ -14,8 +14,15 @@ use Illuminate\Support\Collection;
class Account extends Collection class Account extends Collection
{ {
/**
* @var Account
*/
static $instance = null; static $instance = null;
const NORMAL_MEMBER = 'normal_member';
const GROUP_MEMBER = 'group_member';
/** /**
* create a single instance * create a single instance
* *
...@@ -30,4 +37,45 @@ class Account extends Collection ...@@ -30,4 +37,45 @@ class Account extends Collection
return static::$instance; return static::$instance;
} }
public function addGroupMember($groupMember)
{
$account = static::$instance->all();
$account[static::GROUP_MEMBER][] = $groupMember;
static::$instance->make($account);
}
public function addNormalMember($normalMember)
{
$account = static::$instance->all();
$account[static::NORMAL_MEMBER][] = $normalMember;
static::$instance->make($account);
}
public function getContactName($id, $type, $prefer = false)
{
$target = static::$instance->get($type);
$user = $target[$id];
$name = [];
if(isset($user['RemarkName'])){
$name['remarkName'] = $user['RemarkName'];
}
if(isset($user['NickName'])){
$name['nickName'] = $user['NickName'];
}
if(isset($user['DisplayName'])){
$name['displayName'] = $user['DisplayName'];
}
if(!$name){
return null;
}
return $prefer ? array_values($name)[0] : $name;
}
} }
\ No newline at end of file \ No newline at end of file
...@@ -65,7 +65,7 @@ class ContactFactory ...@@ -65,7 +65,7 @@ class ContactFactory
$type = 'contact'; $type = 'contact';
ContactAccount::getInstance()->put($contact['UserName'], $contact); ContactAccount::getInstance()->put($contact['UserName'], $contact);
} }
Account::getInstance()->put($contact['UserName'], ['type' => $type, 'info' => $contact]); Account::getInstance()->addNormalMember([$contact['UserName'] => ['type' => $type, 'info' => $contact]]);
} }
$this->getBatchGroupMembers(); $this->getBatchGroupMembers();
} }
...@@ -109,6 +109,9 @@ class ContactFactory ...@@ -109,6 +109,9 @@ class ContactFactory
$groupAccount['MemberList'] = $group['MemberList']; $groupAccount['MemberList'] = $group['MemberList'];
$groupAccount['ChatRoomId'] = $group['EncryChatRoomId']; $groupAccount['ChatRoomId'] = $group['EncryChatRoomId'];
GroupAccount::getInstance()->put($group['UserName'], $groupAccount); GroupAccount::getInstance()->put($group['UserName'], $groupAccount);
foreach ($group['MemberList'] as $member) {
Account::getInstance()->addGroupMember([$member['UserName'] => ['type' => 'groupMember', 'info' => $member, 'group' => $group]]);
}
} }
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!