@@ -589,25 +589,66 @@ DmMessage dmMessage({
589589 }) as Map <String , dynamic >);
590590}
591591
592- /// A GetMessagesResult the server might return on an `anchor=newest` request.
593- GetMessagesResult newestGetMessagesResult ({
594- required bool foundOldest,
592+ /// A GetMessagesResult the server might return for
593+ /// a request that sent the given [anchor] .
594+ ///
595+ /// The request's anchor controls the response's [GetMessagesResult.anchor] ,
596+ /// affects the default for [foundAnchor] ,
597+ /// and in some cases forces the value of [foundOldest] or [foundNewest] .
598+ GetMessagesResult getMessagesResult ({
599+ required Anchor anchor,
600+ bool ? foundAnchor,
601+ bool ? foundOldest,
602+ bool ? foundNewest,
595603 bool historyLimited = false ,
596604 required List <Message > messages,
597605}) {
598- return GetMessagesResult (
599- // These anchor, foundAnchor, and foundNewest values are what the server
600- // appears to always return when the request had `anchor=newest`.
601- anchor: 10000000000000000 , // that's 16 zeros
602- foundAnchor: false ,
603- foundNewest: true ,
606+ final resultAnchor = switch (anchor) {
607+ AnchorCode .oldest => 0 ,
608+ NumericAnchor (: final messageId) => messageId,
609+ AnchorCode .firstUnread =>
610+ throw ArgumentError ("firstUnread not accepted in this helper; try NumericAnchor" ),
611+ AnchorCode .newest => 10_000_000_000_000_000 , // that's 16 zeros
612+ };
604613
614+ switch (anchor) {
615+ case AnchorCode .oldest || AnchorCode .newest:
616+ assert (foundAnchor == null );
617+ foundAnchor = false ;
618+ case AnchorCode .firstUnread || NumericAnchor ():
619+ foundAnchor ?? = true ;
620+ }
621+
622+ if (anchor == AnchorCode .oldest) {
623+ assert (foundOldest == null );
624+ foundOldest = true ;
625+ } else if (anchor == AnchorCode .newest) {
626+ assert (foundNewest == null );
627+ foundNewest = true ;
628+ }
629+ if (foundOldest == null || foundNewest == null ) throw ArgumentError ();
630+
631+ return GetMessagesResult (
632+ anchor: resultAnchor,
633+ foundAnchor: foundAnchor,
605634 foundOldest: foundOldest,
635+ foundNewest: foundNewest,
606636 historyLimited: historyLimited,
607637 messages: messages,
608638 );
609639}
610640
641+ /// A GetMessagesResult the server might return on an `anchor=newest` request,
642+ /// or `anchor=first_unread` when there are no unreads.
643+ GetMessagesResult newestGetMessagesResult ({
644+ required bool foundOldest,
645+ bool historyLimited = false ,
646+ required List <Message > messages,
647+ }) {
648+ return getMessagesResult (anchor: AnchorCode .newest, foundOldest: foundOldest,
649+ historyLimited: historyLimited, messages: messages);
650+ }
651+
611652/// A GetMessagesResult the server might return on an initial request
612653/// when the anchor is in the middle of history (e.g., a /near/ link).
613654GetMessagesResult nearGetMessagesResult ({
0 commit comments