Skip to content

Commit

Permalink
Support emote inbox chat
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonflylee committed Apr 27, 2024
1 parent 800bcf1 commit 9086b5c
Show file tree
Hide file tree
Showing 20 changed files with 326 additions and 144 deletions.
21 changes: 12 additions & 9 deletions resources/xml/fragment/inbox_chat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@
height="auto"
width="auto">

<ButtonClose
id="button/close"
focusable="true"
positionType="absolute"
positionTop="10"
positionRight="10" />

<brls:Box
height="50">
<brls:Box>
<ButtonClose
id="inbox/back"
focusable="true"
positionType="absolute"
positionTop="10"
positionRight="10" />

<brls:Label
marginTop="20"
marginBottom="15"
marginLeft="30"
id="inbox/talker" />
</brls:Box>

<RecyclingGrid
Expand Down
2 changes: 1 addition & 1 deletion resources/xml/fragment/inbox_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
</AutoTabFrame>

<ButtonClose
id="button/close"
id="inbox/close"
focusable="true"
positionType="absolute"
positionTop="10"
Expand Down
25 changes: 9 additions & 16 deletions resources/xml/views/inbox_msg.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<brls:Box
wireframe="false"
focusable="false"
axis="column"
width="auto"
height="auto">
Expand All @@ -16,15 +17,15 @@
textColor="@theme/font/grey" />

<brls:Box
focusable="true"
wireframe="false"
paddingLeft="10"
paddingRight="10"
width="auto"
hideHighlightBackground="true"
height="auto">

<brls:Box
wireframe="false"
marginTop="5"
marginRight="15">
<brls:Image
id="avatar/talker"
Expand All @@ -44,28 +45,20 @@
backgroundColor="@theme/color/grey_1"
highlightCornerRadius="16"
cornerRadius="16"
visibility="gone"
focusable="true"
axis="column"
grow="1"
padding="15">
<TextBox
id="msg/content"
lineHeight="1.5"
width="100%" />
width="auto"
height="auto"
grow="1"
wireframe="false" />
</brls:Box>

<brls:Box
id="msg/picture_box"
visibility="gone"
grow="1">
<brls:Image
id="msg/picture"
scalingType="fit"
image="@res/pictures/video-card-bg.png" />
</brls:Box>

<brls:Box
wireframe="false"
marginTop="5"
marginLeft="15">
<brls:Image
id="avatar/mine"
Expand Down
11 changes: 10 additions & 1 deletion resources/xml/views/inbox_user.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,22 @@
cornerRadius="8"
alignItems="center"
justifyContent="spaceBetween"
paddingLeft="20"
paddingLeft="15"
paddingRight="20"
width="auto"
height="auto">

<brls:Rectangle
id="badge"
width="8"
height="8"
cornerRadius="8"
visibility="invisible"
color="@theme/color/tip/red"/>

<UserInfoView
height="100%"
grow="1"
id="chat/talker" />

<brls:Label
Expand Down
1 change: 1 addition & 0 deletions resources/xml/views/user_info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
fontSize="16"
grow="1"
marginTop="4"
autoAnimate="false"
verticalAlign="top"
wireframe="false"
textColor="@theme/font/grey"/>
Expand Down
2 changes: 1 addition & 1 deletion wiliwili/include/api/bilibili.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class BilibiliClient {
const ErrorCallback& error = nullptr);

/// 批量获取用户昵称头像
static void get_user_cards(const std::vector<unsigned int> uids,
static void get_user_cards(const std::vector<std::string>& uids,
const std::function<void(UserCardListResult)>& callback = nullptr,
const ErrorCallback& error = nullptr);

Expand Down
1 change: 1 addition & 0 deletions wiliwili/include/api/bilibili/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ const std::string MsgFeedReply = _apiBase + "/x/msgfeed/reply";
const std::string UserCards = _vcBase + "/account/v1/user/cards";
const std::string UserDynamicStat = _vcBase + "/dynamic_svr/v1/dynamic_svr/space_num_ex";
const std::string ChatSessions = _vcBase + "/session_svr/v1/session_svr/new_sessions";
const std::string ChatUpdateAct = _vcBase + "/session_svr/v1/session_svr/update_ack";
const std::string ChatFetchMsgs = _vcBase + "/svr_sync/v1/svr_sync/fetch_session_msgs";
const std::string ChatSendMsg = _vcBase + "/web_im/v1/web_im/send_msg";
/// 用户追番/追剧
Expand Down
27 changes: 20 additions & 7 deletions wiliwili/include/api/bilibili/result/inbox_result.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ class MsgFeedItem {
std::string title;
std::string image;
std::string source_content;
std::string uri;
};
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(MsgFeedItem, subject_id, source_id, type, title, image, source_content);
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(MsgFeedItem, subject_id, source_id, type, title, image, source_content, uri);

class FeedReplyResult {
public:
Expand Down Expand Up @@ -116,12 +117,17 @@ class InboxMessageResult {
uint64_t sender_uid, receiver_id;
uint64_t msg_seqno;
std::vector<uint64_t> at_uids;
int receiver_type, msg_type;
std::string content;
int msg_type, msg_source;
nlohmann::json content;
time_t timestamp;
};
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(InboxMessageResult, sender_uid, receiver_id, receiver_type, msg_seqno, at_uids,
msg_type, content, timestamp);
inline void from_json(const nlohmann::json& nlohmann_json_j, InboxMessageResult& nlohmann_json_t) {
if (nlohmann_json_j.contains("content") && nlohmann_json_j.at("content").is_string()) {
nlohmann::json::parse(nlohmann_json_j.at("content").get<std::string>()).get_to(nlohmann_json_t.content);
}
NLOHMANN_JSON_EXPAND(
NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, sender_uid, receiver_id, msg_seqno, msg_type, msg_source, timestamp));
}

typedef std::vector<InboxMessageResult> InboxMessageListResult;

Expand Down Expand Up @@ -162,11 +168,18 @@ class InboxChatResult {
uint64_t talker_id;
int session_type;
time_t session_ts;
uint64_t max_seqno;
int unread_count;
InboxAccountInfo account_info;
InboxMessageResult last_msg;
};
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(InboxChatResult, talker_id, session_type, session_ts, account_info,
last_msg);
inline void from_json(const nlohmann::json& nlohmann_json_j, InboxChatResult& nlohmann_json_t) {
if (nlohmann_json_j.contains("last_msg") && nlohmann_json_j.at("last_msg").is_object()) {
nlohmann_json_j.at("last_msg").get_to(nlohmann_json_t.last_msg);
}
NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, talker_id, session_type, session_ts, max_seqno,
unread_count, account_info));
}

typedef std::vector<InboxChatResult> InboxChatListResult;

Expand Down
6 changes: 5 additions & 1 deletion wiliwili/include/fragment/inbox_chat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@

#include "presenter/inbox_msg.hpp"

namespace brls {
class Label;
};
class RecyclingGrid;

class InboxChat : public brls::Box, public InboxMsgRequest {
public:
InboxChat(uint64_t talker_id, int session_type);
InboxChat(const bilibili::InboxChatResult& r);

~InboxChat() override;

Expand All @@ -19,4 +22,5 @@ class InboxChat : public brls::Box, public InboxMsgRequest {

private:
BRLS_BIND(RecyclingGrid, recyclingGrid, "inbox/msgList");
BRLS_BIND(brls::Label, labelTalker, "inbox/talker");
};
4 changes: 2 additions & 2 deletions wiliwili/include/fragment/inbox_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class InboxView : public brls::Box, public InboxChatRequest {
void onError(const std::string& error) override;

private:
BRLS_BIND(ButtonClose, closebtn, "button/close");
BRLS_BIND(ButtonClose, closebtn, "inbox/close");
BRLS_BIND(brls::Box, cancel, "player/cancel");
BRLS_BIND(AutoTabFrame, inboxFrame, "inbox/tab/frame");
BRLS_BIND(AutoTabFrame, tabFrame, "inbox/tab/frame");
BRLS_BIND(RecyclingGrid, recyclingGrid, "inbox/chatList");
};
4 changes: 2 additions & 2 deletions wiliwili/include/presenter/inbox_chat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "bilibili/result/inbox_result.h"
#include "presenter.h"

typedef std::unordered_map<unsigned int, bilibili::UserCardResult> InboxUserMap;

class InboxChatRequest : public Presenter {
public:
virtual void onChatList(const bilibili::InboxChatListResult& result, bool refresh);
Expand All @@ -17,6 +19,4 @@ class InboxChatRequest : public Presenter {

protected:
time_t last_time = 0;

std::unordered_map<unsigned int, bilibili::UserCardResult> user_map;
};
27 changes: 27 additions & 0 deletions wiliwili/include/view/inbox_msg_card.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

#include "view/recycling_grid.hpp"
#include "bilibili/result/inbox_result.h"

class TextBox;

typedef std::shared_ptr<bilibili::InboxEmote> InboxEmotePtr;
typedef std::unordered_map<std::string, InboxEmotePtr> IEMap;

class InboxMsgCard : public RecyclingGridItem {
public:
InboxMsgCard();

void setCard(const bilibili::InboxMessageResult& r, const IEMap& m, uint64_t talker);

void setTime(const std::string& time_str);

void setAvatar(const std::string& face);

private:
BRLS_BIND(TextBox, textBox, "msg/content");
BRLS_BIND(brls::Box, msgBox, "msg/content_box");
BRLS_BIND(brls::Image, talker, "avatar/talker");
BRLS_BIND(brls::Image, mine, "avatar/mine");
BRLS_BIND(brls::Label, msgTime, "msg/time");
};
7 changes: 5 additions & 2 deletions wiliwili/source/activity/main_activity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "activity/main_activity.hpp"
#include "utils/activity_helper.hpp"
#include "utils/config_helper.hpp"
#include "view/custom_button.hpp"
#include "view/auto_tab_frame.hpp"
#include "view/svg_image.hpp"
Expand Down Expand Up @@ -74,8 +75,10 @@ void MainActivity::onContentAvailable() {
});
this->settingBtn->addGestureRecognizer(new brls::TapGestureRecognizer(this->settingBtn));

this->inboxBtn->registerClickAction([](brls::View* view) -> bool {
Intent::openInbox();
this->inboxBtn->registerClickAction([this](brls::View* view) -> bool {
if (ProgramConfig::instance().hasLoginInfo()) {
Intent::openInbox();
}
return true;
});

Expand Down
9 changes: 7 additions & 2 deletions wiliwili/source/api/mine_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void BilibiliClient::get_user_dynamic_count(const std::string& mid,
HTTP::getResultAsync<UserDynamicCount>(Api::UserDynamicStat, {{"uids", mid}}, callback, error);
}

void BilibiliClient::get_user_cards(const std::vector<unsigned int> uids,
void BilibiliClient::get_user_cards(const std::vector<std::string>& uids,
const std::function<void(UserCardListResult)>& callback,
const ErrorCallback& error) {
std::string mid = fmt::format("{}", fmt::join(uids, ","));
Expand All @@ -136,7 +136,10 @@ void BilibiliClient::get_user_cards(const std::vector<unsigned int> uids,
void BilibiliClient::new_inbox_sessions(time_t begin_ts,
const std::function<void(InboxChatResultWrapper)>& callback,
const ErrorCallback& error) {
HTTP::getResultAsync<InboxChatResultWrapper>(Api::ChatSessions, {{"begin_ts", std::to_string(begin_ts)}}, callback, error);
HTTP::getResultAsync<InboxChatResultWrapper>(Api::ChatSessions, {
{"begin_ts", std::to_string(begin_ts)},
{"mobi_app", "web"},
}, callback, error);
}

void BilibiliClient::fetch_inbox_msgs(const std::string& talker_id, size_t size,
Expand All @@ -145,10 +148,12 @@ void BilibiliClient::fetch_inbox_msgs(const std::string& talker_id, size_t size,
const std::function<void(InboxMessageResultWrapper)>& callback,
const ErrorCallback& error) {
HTTP::getResultAsync<InboxMessageResultWrapper>(Api::ChatFetchMsgs, {
{"sender_device_id", "1"},
{"talker_id", talker_id},
{"session_type", std::to_string(session_type)},
{"begin_seqno", begin_seqno},
{"size", std::to_string(size)},
{"mobi_app", "web"},
}, callback, error);
}

Expand Down
Loading

0 comments on commit 9086b5c

Please sign in to comment.