Esempio n. 1
0
void PeerListRow::refreshStatus() {
	if (!_initialized || _statusType == StatusType::Custom) {
		return;
	}
	_statusType = StatusType::LastSeen;
	_statusValidTill = 0;
	if (auto user = peer()->asUser()) {
		if (_isSavedMessagesChat) {
			setStatusText(lang(lng_saved_forward_here));
		} else {
			auto time = unixtime();
			setStatusText(Data::OnlineText(user, time));
			if (Data::OnlineTextActive(user, time)) {
				_statusType = StatusType::Online;
			}
			_statusValidTill = crl::now()
				+ Data::OnlineChangeTimeout(user, time);
		}
	} else if (auto chat = peer()->asChat()) {
		if (!chat->amIn()) {
			setStatusText(lang(lng_chat_status_unaccessible));
		} else if (chat->count > 0) {
			setStatusText(lng_chat_status_members(lt_count_decimal, chat->count));
		} else {
			setStatusText(lang(lng_group_status));
		}
	} else if (peer()->isMegagroup()) {
		setStatusText(lang(lng_group_status));
	} else if (peer()->isChannel()) {
		setStatusText(lang(lng_channel_status));
	}
}
Esempio n. 2
0
ConfirmInviteBox::ConfirmInviteBox(const QString &title, const MTPChatPhoto &photo, int count, const QVector<UserData*> &participants) : AbstractBox()
    , _title(this, st::confirmInviteTitle)
    , _status(this, st::confirmInviteStatus)
    , _photo(chatDefPhoto(0))
    , _participants(participants)
    , _join(this, lang(lng_group_invite_join), st::defaultBoxButton)
    , _cancel(this, lang(lng_cancel), st::cancelBoxButton) {
    if (_participants.size() > 4) {
        _participants.resize(4);
    }

    _title->setText(title);
    QString status;
    if (_participants.isEmpty() || _participants.size() >= count) {
        status = lng_chat_status_members(lt_count, count);
    } else {
        status = lng_group_invite_members(lt_count, count);
    }
    _status->setText(status);
    if (photo.type() == mtpc_chatPhoto) {
        auto &d = photo.c_chatPhoto();
        auto location = App::imageLocation(160, 160, d.vphoto_small);
        if (!location.isNull()) {
            _photo = ImagePtr(location);
            if (!_photo->loaded()) {
                subscribe(FileDownload::ImageLoaded(), [this] { update(); });
                _photo->load();
            }
        }
    }

    int h = st::confirmInviteStatusTop + _status->height() + st::boxPadding.bottom() + st::boxButtonPadding.top() + _join->height() + st::boxButtonPadding.bottom();
    if (!_participants.isEmpty()) {
        int skip = (width() - 4 * st::confirmInviteUserPhotoSize) / 5;
        int padding = skip / 2;
        _userWidth = (st::confirmInviteUserPhotoSize + 2 * padding);
        int sumWidth = _participants.size() * _userWidth;
        int left = (width() - sumWidth) / 2;
        for_const (auto user, _participants) {
            auto name = new FlatLabel(this, st::confirmInviteUserName);
            name->resizeToWidth(st::confirmInviteUserPhotoSize + padding);
            name->setText(user->firstName.isEmpty() ? App::peerName(user) : user->firstName);
            name->moveToLeft(left + (padding / 2), st::confirmInviteUserNameTop);
            left += _userWidth;
        }