Skip to content
Repos

DevPlaceApp

C++ 1.6 KB33 lines Opens in site

Directory Raw Download

#include "screens/components/ConversationRow.hpp"

#include "screens/components/RelativeTime.hpp"
#include "screens/components/UserViews.hpp"
#include "spec/SocialSpec.hpp"
#include "ui/Palette.hpp"

namespace dp {

using namespace ui;

ViewPtr ConversationRow(const Conversation& c, std::function<void()> onTap) {
  using M = spec::SocialMetrics;
  ViewPtr time;
  if (auto date = DateCodec::parseIso8601(c.lastMessageAt)) {
    time = RelativeTimeLabel(*date, RelativeTime::Style::Wide);
  } else {
    time = Text(c.lastMessageAt)->font(FontSpec::caption())->foreground(Palette::fg2());
  }
  ViewPtr head = HStack({Text(c.otherUser.username)->weight(Weight::Semibold)->foreground(Palette::fg1())->lineLimit(1),
                         Spacer(M::kTimeSpacerMin), time->fixedSize(true, false)},
                        0, VAlign::Bottom);
  ViewPtr last = Text(c.lastMessage)->font(FontSpec::subheadline())->foreground(Palette::fg2())->lineLimit(1)
                     ->maxWidth(Alignment::leading());
  std::vector<ViewPtr> row{UserImage(c.otherUser),
                           VStack({head, last}, M::kRowTextSpacing, HAlign::Leading)->maxWidth(Alignment::leading())};
  if (c.unread) row.push_back(CircleShape(Palette::accent())->frame(M::kUnreadDot, M::kUnreadDot)->paddingTop(M::kUnreadDotTop));
  ViewPtr content = HStack(row, M::kRowSpacing, VAlign::Top)->padding(M::kRowPadding)
                        ->background(c.unread ? Palette::accent().opacity(M::kUnreadTint) : Color::clear());
  return Button(content, std::move(onTap), ButtonStyles::plain())->id("conversation:" + c.otherUser.id);
}

}  // namespace dp
33.7ms