Skip to content

Commit

Permalink
Merge pull request #19714 from gustavotrott/graphql-timer-stop-runnin…
Browse files Browse the repository at this point in the history
…gFlag
  • Loading branch information
gustavotrott committed Feb 29, 2024
2 parents 85a43ea + 2460fc5 commit 4d71f63
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ case class TimerDbModel(
active: Boolean,
time: Long,
accumulated: Long,
startedAt: Long,
endedAt: Long,
startedOn: Long,
endedOn: Long,
songTrack: String,
)

Expand All @@ -26,10 +26,10 @@ class TimerDbTableDef(tag: Tag) extends Table[TimerDbModel](tag, None, "timer")
val active = column[Boolean]("active")
val time = column[Long]("time")
val accumulated = column[Long]("accumulated")
val startedAt = column[Long]("startedAt")
val endedAt = column[Long]("endedAt")
val startedOn = column[Long]("startedOn")
val endedOn = column[Long]("endedOn")
val songTrack = column[String]("songTrack")
override def * = (meetingId, stopwatch, running, active, time, accumulated, startedAt, endedAt, songTrack) <> (TimerDbModel.tupled, TimerDbModel.unapply)
override def * = (meetingId, stopwatch, running, active, time, accumulated, startedOn, endedOn, songTrack) <> (TimerDbModel.tupled, TimerDbModel.unapply)
}

object TimerDAO {
Expand All @@ -43,8 +43,8 @@ object TimerDAO {
active = false,
time = 300000,
accumulated = 0,
startedAt = 0,
endedAt = 0,
startedOn = 0,
endedOn = 0,
songTrack = "noTrack",
)
)
Expand All @@ -58,7 +58,7 @@ object TimerDAO {
DatabaseConnection.db.run(
TableQuery[TimerDbTableDef]
.filter(_.meetingId === meetingId)
.map(t => (t.stopwatch, t.running, t.active, t.time, t.accumulated, t.startedAt, t.endedAt, t.songTrack))
.map(t => (t.stopwatch, t.running, t.active, t.time, t.accumulated, t.startedOn, t.endedOn, t.songTrack))
.update((getStopwatch(timerModel), getRunning(timerModel), getIsActive(timerModel), getTime(timerModel), getAccumulated(timerModel), getStartedAt(timerModel), getEndedAt(timerModel), getTrack(timerModel))
)
).onComplete {
Expand Down
26 changes: 22 additions & 4 deletions bbb-graphql-server/bbb_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1467,13 +1467,31 @@ CREATE TABLE "timer" (
"active" boolean,
"time" bigint,
"accumulated" bigint,
"startedAt" bigint,
"endedAt" bigint,
"startedOn" bigint,
"endedOn" bigint,
"songTrack" varchar(50)
);

CREATE VIEW "v_timer" AS
SELECT * FROM "timer";
ALTER TABLE "timer" ADD COLUMN "startedAt" timestamp with time zone GENERATED ALWAYS AS (to_timestamp("startedOn"::double precision / 1000)) STORED;
ALTER TABLE "timer" ADD COLUMN "endedAt" timestamp with time zone GENERATED ALWAYS AS (to_timestamp("endedOn"::double precision / 1000)) STORED;

CREATE OR REPLACE VIEW "v_timer" AS
SELECT
"meetingId",
"stopwatch",
case
when "stopwatch" is true or "running" is false then "running"
when "startedAt" + ("time" * interval '1 milliseconds') >= current_timestamp then true else false
end "running",
"active",
"time",
"accumulated",
"startedAt",
"startedOn",
"endedAt",
"endedOn",
"songTrack"
FROM "timer";

------------------------------------
----breakoutRoom
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ select_permissions:
- accumulated
- active
- endedAt
- endedOn
- running
- songTrack
- startedAt
- startedOn
- stopwatch
- time
filter:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface TimerIndicatorProps {
isModerator: boolean;
sidebarNavigationIsOpen: boolean;
sidebarContentIsOpen: boolean;
startedAt: number;
startedOn: number;
}

const TimerIndicator: React.FC<TimerIndicatorProps> = ({
Expand All @@ -36,7 +36,7 @@ const TimerIndicator: React.FC<TimerIndicatorProps> = ({
isModerator,
sidebarNavigationIsOpen,
sidebarContentIsOpen,
startedAt,
startedOn,
}) => {
const [time, setTime] = useState<number>(0);
const timeRef = useRef<HTMLSpanElement>(null);
Expand Down Expand Up @@ -110,7 +110,7 @@ const TimerIndicator: React.FC<TimerIndicatorProps> = ({
if (timePassed > prev) return timePassed;
return prev;
});
}, [passedTime, stopwatch, startedAt]);
}, [passedTime, stopwatch, startedOn]);

useEffect(() => {
if (!timeRef.current) {
Expand All @@ -121,10 +121,10 @@ const TimerIndicator: React.FC<TimerIndicatorProps> = ({
}, [time]);

useEffect(() => {
if (startedAt === 0) {
if (startedOn === 0) {
setTime(passedTime);
}
}, [startedAt]);
}, [startedOn]);

const onClick = running ? stopTimer : startTimer;

Expand Down Expand Up @@ -189,13 +189,13 @@ const TimerIndicatorContainer: React.FC = () => {
const {
accumulated,
running,
startedAt,
startedOn,
stopwatch,
songTrack,
time,
} = currentTimer;
const currentDate: Date = new Date();
const startedAtDate: Date = new Date(startedAt || Date.now());
const startedAtDate: Date = new Date(startedOn || Date.now());
const adjustedCurrent: Date = new Date(currentDate.getTime() + timeSync);
const timeDifferenceMs: number = adjustedCurrent.getTime() - startedAtDate.getTime();

Expand All @@ -214,7 +214,7 @@ const TimerIndicatorContainer: React.FC = () => {
isModerator={currentUser.isModerator ?? false}
sidebarNavigationIsOpen={sidebarNavigationIsOpen}
sidebarContentIsOpen={sidebarContentIsOpen}
startedAt={startedAt}
startedOn={startedOn}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export interface GetTimerResponse {
time: number;
stopwatch: boolean;
running: boolean;
startedAt: number;
endedAt: number;
startedOn: number;
endedOn: number;
}>;
}

Expand All @@ -22,8 +22,8 @@ export const GET_TIMER = gql`
time
stopwatch
running
startedAt
endedAt
startedOn
endedOn
}
}
`;
Expand Down

0 comments on commit 4d71f63

Please sign in to comment.