@@ -530,25 +530,66 @@ DmMessage dmMessage({
530530 }) as Map <String , dynamic >);
531531}
532532
533- /// A GetMessagesResult the server might return on an `anchor=newest` request.
534- GetMessagesResult newestGetMessagesResult ({
535- required bool foundOldest,
533+ /// A GetMessagesResult the server might return for
534+ /// a request that sent the given [anchor] .
535+ ///
536+ /// The request's anchor controls the response's [GetMessagesResult.anchor] ,
537+ /// affects the default for [foundAnchor] ,
538+ /// and in some cases forces the value of [foundOldest] or [foundNewest] .
539+ GetMessagesResult getMessagesResult ({
540+ required Anchor anchor,
541+ bool ? foundAnchor,
542+ bool ? foundOldest,
543+ bool ? foundNewest,
536544 bool historyLimited = false ,
537545 required List <Message > messages,
538546}) {
539- return GetMessagesResult (
540- // These anchor, foundAnchor, and foundNewest values are what the server
541- // appears to always return when the request had `anchor=newest`.
542- anchor: 10000000000000000 , // that's 16 zeros
543- foundAnchor: false ,
544- foundNewest: true ,
547+ final resultAnchor = switch (anchor) {
548+ AnchorCode .oldest => 0 ,
549+ NumericAnchor (: final messageId) => messageId,
550+ AnchorCode .firstUnread =>
551+ throw ArgumentError ("firstUnread not accepted in this helper; try NumericAnchor" ),
552+ AnchorCode .newest => 10_000_000_000_000_000 , // that's 16 zeros
553+ };
545554
555+ switch (anchor) {
556+ case AnchorCode .oldest || AnchorCode .newest:
557+ assert (foundAnchor == null );
558+ foundAnchor = false ;
559+ case AnchorCode .firstUnread || NumericAnchor ():
560+ foundAnchor ?? = true ;
561+ }
562+
563+ if (anchor == AnchorCode .oldest) {
564+ assert (foundOldest == null );
565+ foundOldest = true ;
566+ } else if (anchor == AnchorCode .newest) {
567+ assert (foundNewest == null );
568+ foundNewest = true ;
569+ }
570+ if (foundOldest == null || foundNewest == null ) throw ArgumentError ();
571+
572+ return GetMessagesResult (
573+ anchor: resultAnchor,
574+ foundAnchor: foundAnchor,
546575 foundOldest: foundOldest,
576+ foundNewest: foundNewest,
547577 historyLimited: historyLimited,
548578 messages: messages,
549579 );
550580}
551581
582+ /// A GetMessagesResult the server might return on an `anchor=newest` request,
583+ /// or `anchor=first_unread` when there are no unreads.
584+ GetMessagesResult newestGetMessagesResult ({
585+ required bool foundOldest,
586+ bool historyLimited = false ,
587+ required List <Message > messages,
588+ }) {
589+ return getMessagesResult (anchor: AnchorCode .newest, foundOldest: foundOldest,
590+ historyLimited: historyLimited, messages: messages);
591+ }
592+
552593/// A GetMessagesResult the server might return on an initial request
553594/// when the anchor is in the middle of history (e.g., a /near/ link).
554595GetMessagesResult nearGetMessagesResult ({
0 commit comments