Skip to content

Commit

Permalink
Light refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
kohler committed Oct 24, 2024
1 parent 1d09b4f commit e8affb1
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 57 deletions.
47 changes: 23 additions & 24 deletions src/commentinfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,34 +220,33 @@ function set_prow(PaperInfo $prow) {
/** @param PaperInfo $prow
* @return string */
static function script($prow) {
if (Ht::mark_stash("papercomment")) {
$t = [];
$crow = new CommentInfo($prow);
$crow->commentType = self::CT_RESPONSE;
foreach ($prow->conf->response_rounds() as $rrd) {
$j = ["wl" => $rrd->wordlimit];
if ($rrd->hard_wordlimit >= $rrd->wordlimit) {
$j["hwl"] = $rrd->hard_wordlimit;
if (!Ht::mark_stash("papercomment")) {
return "";
}
$t = [];
$crow = new CommentInfo($prow);
$crow->commentType = self::CT_RESPONSE;
foreach ($prow->conf->response_rounds() as $rrd) {
$j = ["wl" => $rrd->wordlimit];
if ($rrd->hard_wordlimit >= $rrd->wordlimit) {
$j["hwl"] = $rrd->hard_wordlimit;
}
$crow->commentRound = $rrd->id;
if (Contact::$main_user->can_edit_response($prow, $crow)) {
if (($m = $rrd->instructions($prow->conf)) !== false) {
$j["instrux"] = $m;
}
$crow->commentRound = $rrd->id;
if (Contact::$main_user->can_edit_response($prow, $crow)) {
if (($m = $rrd->instructions($prow->conf)) !== false) {
$j["instrux"] = $m;
}
if ($rrd->done) {
$j["done"] = $rrd->done;
}
if ($rrd->done) {
$j["done"] = $rrd->done;
}
$t[] = "hotcrp.set_response_round(" . json_encode_browser($rrd->name) . "," . json_encode_browser($j) . ")";
}
Icons::stash_defs("tag", "attachment", "trash", "thread");
Icons::stash_licon("ui_tag"); // XXX backward compat
Icons::stash_licon("ui_attachment"); // XXX backward compat
Icons::stash_licon("ui_trash"); // XXX backward compat
return Ht::unstash_script(join(";", $t));
} else {
return "";
$t[] = "hotcrp.set_response_round(" . json_encode_browser($rrd->name) . "," . json_encode_browser($j) . ")";
}
Icons::stash_defs("tag", "attachment", "trash", "thread");
Icons::stash_licon("ui_tag"); // XXX backward compat
Icons::stash_licon("ui_attachment"); // XXX backward compat
Icons::stash_licon("ui_trash"); // XXX backward compat
return Ht::unstash_script(join(";", $t));
}

/** @param PaperInfo $prow */
Expand Down
70 changes: 37 additions & 33 deletions src/paperinfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -970,20 +970,21 @@ static private function contact_to_cid($contact) {
}

private function check_rights_version() {
if ($this->_rights_version !== Contact::$rights_version) {
if ($this->_rights_version) {
$this->_flags &= ~(self::REVIEW_FLAGS | self::HAS_PHASE);
$this->_contact_info = [];
$this->reviewSignatures = $this->_review_array = $this->_reviews_have = null;
$this->allConflictType = $this->_ctype_list = null;
$this->myContactXid = null;
++$this->_review_array_version;
}
$this->_rights_version = Contact::$rights_version;
if ($this->_author_user) {
// author_user should always be in _contact_info
$this->contact_info($this->_author_user);
}
if ($this->_rights_version === Contact::$rights_version) {
return;
}
if ($this->_rights_version) {
$this->_flags &= ~(self::REVIEW_FLAGS | self::HAS_PHASE);
$this->_contact_info = [];
$this->reviewSignatures = $this->_review_array = $this->_reviews_have = null;
$this->allConflictType = $this->_ctype_list = null;
$this->myContactXid = null;
++$this->_review_array_version;
}
$this->_rights_version = Contact::$rights_version;
if ($this->_author_user) {
// author_user should always be in _contact_info
$this->contact_info($this->_author_user);
}
}

Expand Down Expand Up @@ -1015,28 +1016,31 @@ function _set_empty_contact_info($user) {
function optional_contact_info(Contact $user) {
$this->check_rights_version();
$cid = $user->contactXid;
if (!array_key_exists($cid, $this->_contact_info)) {
if ($this->myContactXid === $cid) {
$ci = PaperContactInfo::make_my($this, $user);
$this->_contact_info[$cid] = $ci;
} else if ($this->_review_array
|| $this->reviewSignatures !== null) {
$ci = PaperContactInfo::make_user($this, $user);
if ($cid > 0) {
$ci->mark_conflict($this->conflict_type($cid));
}
foreach ($this->reviews_by_user($cid, $user->review_tokens()) as $rrow) {
$ci->mark_review($rrow);
}
$this->_contact_info[$cid] = $ci;
} else {
PaperContactInfo::load_into($this, $user);
if (array_key_exists($cid, $this->_contact_info)) {
return $this->_contact_info[$cid];
}
if ($this->myContactXid === $cid) {
$ci = PaperContactInfo::make_my($this, $user);
$this->_contact_info[$cid] = $ci;
} else if ($this->_review_array
|| $this->reviewSignatures !== null) {
$ci = PaperContactInfo::make_user($this, $user);
if ($cid > 0) {
$ci->mark_conflict($this->conflict_type($cid));
}
if ($user === $this->_author_user) {
$this->_get_contact_info($cid)->mark_conflict(CONFLICT_CONTACTAUTHOR);
foreach ($this->reviews_by_user($cid, $user->review_tokens()) as $rrow) {
$ci->mark_review($rrow);
}
$this->_contact_info[$cid] = $ci;
} else {
PaperContactInfo::load_into($this, $user);
$ci = $this->_contact_info[$cid];
}
return $this->_contact_info[$cid];
if ($user === $this->_author_user) {
$ci = $ci ?? $this->_get_contact_info($cid);
$ci->mark_conflict(CONFLICT_CONTACTAUTHOR);
}
return $ci;
}

/** @return PaperContactInfo */
Expand Down

0 comments on commit e8affb1

Please sign in to comment.