Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.
Go dockerfossgomarkdownmemomicroblognote-takingnotesopen-sourceown-your-datareactself-hostedsqlitetimeline
feat: display memo with updated ts (#1760)
boojacke0e59c583180
diff --git a/api/memo.go b/api/memo.goindex 579d65ee4..71bd72582 100644--- a/api/memo.go+++ b/api/memo.go@@ -34,6 +34,7 @@ type MemoResponse struct {UpdatedTs int64 `json:"updatedTs"`// Domain specific fields+ DisplayTs int64 `json:"displayTs"`Content string `json:"content"`Visibility Visibility `json:"visibility"`Pinned bool `json:"pinned"`diff --git a/api/system.go b/api/system.goindex 1c5966b77..a916e8320 100644--- a/api/system.go+++ b/api/system.go@@ -24,6 +24,8 @@ type SystemStatus struct {CustomizedProfile CustomizedProfile `json:"customizedProfile"`// Storage service ID.StorageServiceID int `json:"storageServiceId"`- // Local storage path+ // Local storage path.LocalStoragePath string `json:"localStoragePath"`+ // Memo display with updated timestamp.+ MemoDisplayWithUpdatedTs bool `json:"memoDisplayWithUpdatedTs"`}diff --git a/api/system_setting.go b/api/system_setting.goindex 522fda8eb..f89351aa1 100644--- a/api/system_setting.go+++ b/api/system_setting.go@@ -36,7 +36,8 @@ const (// SystemSettingOpenAIConfigName is the name of OpenAI config.SystemSettingOpenAIConfigName SystemSettingName = "openai-config"// SystemSettingTelegramRobotToken is the name of Telegram Robot Token.- SystemSettingTelegramRobotTokenName SystemSettingName = "telegram-robot-token"+ SystemSettingTelegramRobotTokenName SystemSettingName = "telegram-robot-token"+ SystemSettingMemoDisplayWithUpdatedTsName SystemSettingName = "memo-display-with-updated-ts")// CustomizedProfile is the struct definition for SystemSettingCustomizedProfileName system setting item.@@ -88,6 +89,8 @@ func (key SystemSettingName) String() string {return "openai-config"case SystemSettingTelegramRobotTokenName:return "telegram-robot-token"+ case SystemSettingMemoDisplayWithUpdatedTsName:+ return "memo-display-with-updated-ts"}return ""}@@ -111,43 +114,36 @@ func (upsert SystemSettingUpsert) Validate() error {switch settingName := upsert.Name; settingName {case SystemSettingServerIDName:return fmt.Errorf("updating %v is not allowed", settingName)-case SystemSettingAllowSignUpName:var value boolif err := json.Unmarshal([]byte(upsert.Value), &value); err != nil {return fmt.Errorf(systemSettingUnmarshalError, settingName)}-case SystemSettingIgnoreUpgradeName:var value boolif err := json.Unmarshal([]byte(upsert.Value), &value); err != nil {return fmt.Errorf(systemSettingUnmarshalError, settingName)}-case SystemSettingDisablePublicMemosName:var value boolif err := json.Unmarshal([]byte(upsert.Value), &value); err != nil {return fmt.Errorf(systemSettingUnmarshalError, settingName)}-case SystemSettingMaxUploadSizeMiBName:var value intif err := json.Unmarshal([]byte(upsert.Value), &value); err != nil {return fmt.Errorf(systemSettingUnmarshalError, settingName)}-case SystemSettingAdditionalStyleName:var value stringif err := json.Unmarshal([]byte(upsert.Value), &value); err != nil {return fmt.Errorf(systemSettingUnmarshalError, settingName)}-case SystemSettingAdditionalScriptName:var value stringif err := json.Unmarshal([]byte(upsert.Value), &value); err != nil {return fmt.Errorf(systemSettingUnmarshalError, settingName)}-case SystemSettingCustomizedProfileName:customizedProfile := CustomizedProfile{Name: "memos",@@ -157,7 +153,6 @@ func (upsert SystemSettingUpsert) Validate() error {Appearance: "system",ExternalURL: "",}-if err := json.Unmarshal([]byte(upsert.Value), &customizedProfile); err != nil {return fmt.Errorf(systemSettingUnmarshalError, settingName)}@@ -167,26 +162,22 @@ func (upsert SystemSettingUpsert) Validate() error {if !slices.Contains(UserSettingAppearanceValue, customizedProfile.Appearance) {return fmt.Errorf(`invalid appearance value for system setting "%v"`, settingName)}-case SystemSettingStorageServiceIDName:value := DatabaseStorageif err := json.Unmarshal([]byte(upsert.Value), &value); err != nil {return fmt.Errorf(systemSettingUnmarshalError, settingName)}return nil-case SystemSettingLocalStoragePathName:value := ""if err := json.Unmarshal([]byte(upsert.Value), &value); err != nil {return fmt.Errorf(systemSettingUnmarshalError, settingName)}-case SystemSettingOpenAIConfigName:value := OpenAIConfig{}if err := json.Unmarshal([]byte(upsert.Value), &value); err != nil {return fmt.Errorf(systemSettingUnmarshalError, settingName)}-case SystemSettingTelegramRobotTokenName:if upsert.Value == "" {return nil@@ -195,11 +186,14 @@ func (upsert SystemSettingUpsert) Validate() error {if len(fragments) != 2 {return fmt.Errorf(systemSettingUnmarshalError, settingName)}-+ case SystemSettingMemoDisplayWithUpdatedTsName:+ var value bool+ if err := json.Unmarshal([]byte(upsert.Value), &value); err != nil {+ return fmt.Errorf(systemSettingUnmarshalError, settingName)+ }default:return fmt.Errorf("invalid system setting name")}-return nil}diff --git a/server/memo.go b/server/memo.goindex 41fc763f7..4920246d2 100644--- a/server/memo.go+++ b/server/memo.go@@ -609,19 +609,39 @@ func (s *Server) composeMemoMessageToMemoResponse(ctx context.Context, memoMessaPinned: memoMessage.Pinned,}+ // Compose creator name.user, err := s.Store.FindUser(ctx, &api.UserFind{ID: &memoResponse.CreatorID,})if err != nil {return nil, err}-if user.Nickname != "" {memoResponse.CreatorName = user.Nickname} else {memoResponse.CreatorName = user.Username}+ // Compose display ts.+ memoResponse.DisplayTs = memoResponse.CreatedTs+ // Find memo display with updated ts setting.+ memoDisplayWithUpdatedTsSetting, err := s.Store.FindSystemSetting(ctx, &api.SystemSettingFind{+ Name: api.SystemSettingMemoDisplayWithUpdatedTsName,+ })+ if err != nil && common.ErrorCode(err) != common.NotFound {+ return nil, errors.Wrap(err, "failed to find system setting")+ }+ if memoDisplayWithUpdatedTsSetting != nil {+ memoDisplayWithUpdatedTs := false+ err = json.Unmarshal([]byte(memoDisplayWithUpdatedTsSetting.Value), &memoDisplayWithUpdatedTs)+ if err != nil {+ return nil, errors.Wrap(err, "failed to unmarshal system setting value")+ }+ if memoDisplayWithUpdatedTs {+ memoResponse.DisplayTs = memoResponse.UpdatedTs+ }+ }+relationList := []*api.MemoRelation{}for _, relation := range memoMessage.RelationList {relationList = append(relationList, convertMemoRelationMessageToMemoRelation(relation))diff --git a/server/system.go b/server/system.goindex 76eee0d48..52c0868f6 100644--- a/server/system.go+++ b/server/system.go@@ -55,8 +55,9 @@ func (s *Server) registerSystemRoutes(g *echo.Group) {Appearance: "system",ExternalURL: "",},- StorageServiceID: api.DatabaseStorage,- LocalStoragePath: "assets/{timestamp}_{filename}",+ StorageServiceID: api.DatabaseStorage,+ LocalStoragePath: "assets/{timestamp}_{filename}",+ MemoDisplayWithUpdatedTs: false,}systemSettingList, err := s.Store.FindSystemSettingList(ctx, &api.SystemSettingFind{})@@ -78,35 +79,28 @@ func (s *Server) registerSystemRoutes(g *echo.Group) {switch systemSetting.Name {case api.SystemSettingAllowSignUpName:systemStatus.AllowSignUp = baseValue.(bool)-case api.SystemSettingIgnoreUpgradeName:systemStatus.IgnoreUpgrade = baseValue.(bool)-case api.SystemSettingDisablePublicMemosName:systemStatus.DisablePublicMemos = baseValue.(bool)-case api.SystemSettingMaxUploadSizeMiBName:systemStatus.MaxUploadSizeMiB = int(baseValue.(float64))-case api.SystemSettingAdditionalStyleName:systemStatus.AdditionalStyle = baseValue.(string)-case api.SystemSettingAdditionalScriptName:systemStatus.AdditionalScript = baseValue.(string)-case api.SystemSettingCustomizedProfileName:customizedProfile := api.CustomizedProfile{}if err := json.Unmarshal([]byte(systemSetting.Value), &customizedProfile); err != nil {return echo.NewHTTPError(http.StatusInternalServerError, "Failed to unmarshal system setting customized profile value").SetInternal(err)}systemStatus.CustomizedProfile = customizedProfile-case api.SystemSettingStorageServiceIDName:systemStatus.StorageServiceID = int(baseValue.(float64))-case api.SystemSettingLocalStoragePathName:systemStatus.LocalStoragePath = baseValue.(string)-+ case api.SystemSettingMemoDisplayWithUpdatedTsName:+ systemStatus.MemoDisplayWithUpdatedTs = baseValue.(bool)default:log.Warn("Unknown system setting name", zap.String("setting name", systemSetting.Name.String()))}diff --git a/web/src/components/DailyMemo.tsx b/web/src/components/DailyMemo.tsxindex 450d940d6..66e3286c4 100644--- a/web/src/components/DailyMemo.tsx+++ b/web/src/components/DailyMemo.tsx@@ -9,12 +9,12 @@ interface Props {const DailyMemo: React.FC<Props> = (props: Props) => {const { memo } = props;- const createdTimeStr = getTimeString(memo.createdTs);+ const displayTimeStr = getTimeString(memo.displayTs);return (<div className="daily-memo-wrapper"><div className="time-wrapper">- <span className="normal-text">{createdTimeStr}</span>+ <span className="normal-text">{displayTimeStr}</span></div><div className="memo-container"><MemoContent content={memo.content} showFull={true} />diff --git a/web/src/components/Memo.tsx b/web/src/components/Memo.tsxindex d2cb2bc3d..b5c509d33 100644--- a/web/src/components/Memo.tsx+++ b/web/src/components/Memo.tsx@@ -33,7 +33,7 @@ const Memo: React.FC<Props> = (props: Props) => {const userStore = useUserStore();const memoStore = useMemoStore();const memoCacheStore = useMemoCacheStore();- const [createdTimeStr, setCreatedTimeStr] = useState<string>(getRelativeTimeString(memo.createdTs));+ const [createdTimeStr, setCreatedTimeStr] = useState<string>(getRelativeTimeString(memo.displayTs));const [relatedMemoList, setRelatedMemoList] = useState<Memo[]>([]);const memoContainerRef = useRef<HTMLDivElement>(null);const isVisitorMode = userStore.isVisitorMode() || readonly;@@ -54,9 +54,9 @@ const Memo: React.FC<Props> = (props: Props) => {useEffect(() => {let intervalFlag: any = -1;- if (Date.now() - memo.createdTs < 1000 * 60 * 60 * 24) {+ if (Date.now() - memo.displayTs < 1000 * 60 * 60 * 24) {intervalFlag = setInterval(() => {- setCreatedTimeStr(getRelativeTimeString(memo.createdTs));+ setCreatedTimeStr(getRelativeTimeString(memo.displayTs));}, 1000 * 1);}diff --git a/web/src/components/MemoList.tsx b/web/src/components/MemoList.tsxindex eed8b1c52..a0a90de90 100644--- a/web/src/components/MemoList.tsx+++ b/web/src/components/MemoList.tsx@@ -56,7 +56,7 @@ const MemoList = () => {if (duration &&duration.from < duration.to &&- (getTimeStampByDate(memo.createdTs) < duration.from || getTimeStampByDate(memo.createdTs) > duration.to)+ (getTimeStampByDate(memo.displayTs) < duration.from || getTimeStampByDate(memo.displayTs) > duration.to)) {shouldShow = false;}@@ -82,7 +82,7 @@ const MemoList = () => {const pinnedMemos = shownMemos.filter((m) => m.pinned);const unpinnedMemos = shownMemos.filter((m) => !m.pinned);const memoSort = (mi: Memo, mj: Memo) => {- return mj.createdTs - mi.createdTs;+ return mj.displayTs - mi.displayTs;};pinnedMemos.sort(memoSort);unpinnedMemos.sort(memoSort);@@ -168,7 +168,7 @@ const MemoList = () => {return (<div className="memo-list-container">{sortedMemos.map((memo) => (- <Memo key={`${memo.id}-${memo.createdTs}`} memo={memo} />+ <Memo key={`${memo.id}-${memo.displayTs}`} memo={memo} />))}{isFetching ? (<div className="status-text-container fetching-tip">diff --git a/web/src/components/Settings/SystemSection.tsx b/web/src/components/Settings/SystemSection.tsxindex 9b29421b9..eb1666d5f 100644--- a/web/src/components/Settings/SystemSection.tsx+++ b/web/src/components/Settings/SystemSection.tsx@@ -17,6 +17,7 @@ interface State {additionalStyle: string;additionalScript: string;maxUploadSizeMiB: number;+ memoDisplayWithUpdatedTs: boolean;}const SystemSection = () => {@@ -31,6 +32,7 @@ const SystemSection = () => {additionalScript: systemStatus.additionalScript,disablePublicMemos: systemStatus.disablePublicMemos,maxUploadSizeMiB: systemStatus.maxUploadSizeMiB,+ memoDisplayWithUpdatedTs: systemStatus.memoDisplayWithUpdatedTs,});const [telegramRobotToken, setTelegramRobotToken] = useState<string>("");const [openAIConfig, setOpenAIConfig] = useState<OpenAIConfig>({@@ -65,6 +67,7 @@ const SystemSection = () => {additionalScript: systemStatus.additionalScript,disablePublicMemos: systemStatus.disablePublicMemos,maxUploadSizeMiB: systemStatus.maxUploadSizeMiB,+ memoDisplayWithUpdatedTs: systemStatus.memoDisplayWithUpdatedTs,});}, [systemStatus]);@@ -202,6 +205,18 @@ const SystemSection = () => {});};+ const handleMemoDisplayWithUpdatedTs = async (value: boolean) => {+ setState({+ ...state,+ memoDisplayWithUpdatedTs: value,+ });+ globalStore.setSystemStatus({ disablePublicMemos: value });+ await api.upsertSystemSetting({+ name: "memo-display-with-updated-ts",+ value: JSON.stringify(value),+ });+ };+const handleMaxUploadSizeChanged = async (event: React.FocusEvent<HTMLInputElement>) => {// fixes cursor skipping position on mobileevent.target.selectionEnd = event.target.value.length;@@ -254,6 +269,10 @@ const SystemSection = () => {<span className="normal-text">{t("setting.system-section.disable-public-memos")}</span><Switch checked={state.disablePublicMemos} onChange={(event) => handleDisablePublicMemosChanged(event.target.checked)} /></div>+ <div className="form-label">+ <span className="normal-text">Display with updated time</span>+ <Switch checked={state.memoDisplayWithUpdatedTs} onChange={(event) => handleMemoDisplayWithUpdatedTs(event.target.checked)} />+ </div><div className="form-label"><div className="flex flex-row items-center"><span className="text-sm mr-1">{t("setting.system-section.max-upload-size")}</span>diff --git a/web/src/components/ShareMemoDialog.tsx b/web/src/components/ShareMemoDialog.tsxindex 7bd099d0f..0355515ce 100644--- a/web/src/components/ShareMemoDialog.tsx+++ b/web/src/components/ShareMemoDialog.tsx@@ -46,7 +46,7 @@ const ShareMemoDialog: React.FC<Props> = (props: Props) => {const memoElRef = useRef<HTMLDivElement>(null);const memo = {...propsMemo,- createdAtStr: getDateTimeString(propsMemo.createdTs),+ displayTsStr: getDateTimeString(propsMemo.displayTs),};const createdDays = Math.ceil((Date.now() - getTimeStampByDate(user.createdTs)) / 1000 / 3600 / 24);@@ -174,7 +174,7 @@ const ShareMemoDialog: React.FC<Props> = (props: Props) => {className="w-full h-auto select-none relative flex flex-col justify-start items-start bg-white dark:bg-zinc-800"ref={memoElRef}>- <span className="w-full px-6 pt-5 pb-2 text-sm text-gray-500">{memo.createdAtStr}</span>+ <span className="w-full px-6 pt-5 pb-2 text-sm text-gray-500">{memo.displayTsStr}</span><div className="w-full px-6 text-base pb-4"><MemoContent content={memo.content} showFull={true} /><MemoResourceListView className="!grid-cols-2" resourceList={memo.resourceList} />diff --git a/web/src/helpers/filter.ts b/web/src/helpers/filter.tsindex 2c97498c0..e3b80ba06 100644--- a/web/src/helpers/filter.ts+++ b/web/src/helpers/filter.ts@@ -203,9 +203,9 @@ export const checkShouldShowMemo = (memo: Memo, filter: Filter) => {}} else if (type === "DISPLAY_TIME") {if (operator === "BEFORE") {- return memo.createdTs < getUnixTimeMillis(value);+ return memo.displayTs < getUnixTimeMillis(value);} else {- return memo.createdTs >= getUnixTimeMillis(value);+ return memo.displayTs >= getUnixTimeMillis(value);}} else if (type === "VISIBILITY") {let matched = memo.visibility === value;diff --git a/web/src/pages/DailyReview.tsx b/web/src/pages/DailyReview.tsxindex 70cabec96..c2616c381 100644--- a/web/src/pages/DailyReview.tsx+++ b/web/src/pages/DailyReview.tsx@@ -28,15 +28,15 @@ const DailyReview = () => {const currentDate = new Date(currentDateStamp);const dailyMemos = memos.filter((m) => {- const createdTimestamp = getTimeStampByDate(m.createdTs);+ const displayTimestamp = getTimeStampByDate(m.displayTs);const currentDateStampWithOffset = currentDateStamp + convertToMillis(localSetting);return (m.rowStatus === "NORMAL" &&- createdTimestamp >= currentDateStampWithOffset &&- createdTimestamp < currentDateStampWithOffset + DAILY_TIMESTAMP+ displayTimestamp >= currentDateStampWithOffset &&+ displayTimestamp < currentDateStampWithOffset + DAILY_TIMESTAMP);})- .sort((a, b) => getTimeStampByDate(a.createdTs) - getTimeStampByDate(b.createdTs));+ .sort((a, b) => getTimeStampByDate(a.displayTs) - getTimeStampByDate(b.displayTs));useEffect(() => {let offset = 0;@@ -46,7 +46,7 @@ const DailyReview = () => {offset += fetchedMemos.length;if (fetchedMemos.length === DEFAULT_MEMO_LIMIT) {const lastMemo = last(fetchedMemos);- if (lastMemo && lastMemo.createdTs > currentDateStamp) {+ if (lastMemo && lastMemo.displayTs > currentDateStamp) {await fetchMoreMemos();}}diff --git a/web/src/pages/EmbedMemo.tsx b/web/src/pages/EmbedMemo.tsxindex e544e8fb5..a6c4d964e 100644--- a/web/src/pages/EmbedMemo.tsx+++ b/web/src/pages/EmbedMemo.tsx@@ -45,7 +45,7 @@ const EmbedMemo = () => {<main className="w-full max-w-lg mx-auto my-auto shadow px-4 py-4 rounded-lg"><div className="w-full flex flex-col justify-start items-start"><div className="w-full mb-2 flex flex-row justify-start items-center text-sm text-gray-400 dark:text-gray-300">- <span>{getDateTimeString(state.memo.createdTs)}</span>+ <span>{getDateTimeString(state.memo.displayTs)}</span><a className="ml-2 hover:underline hover:text-green-600" href={`/u/${state.memo.creatorId}`}>@{state.memo.creatorName}</a>diff --git a/web/src/pages/Explore.tsx b/web/src/pages/Explore.tsxindex 9bed3067a..caedd9d22 100644--- a/web/src/pages/Explore.tsx+++ b/web/src/pages/Explore.tsx@@ -90,7 +90,7 @@ const Explore = () => {<main className="relative w-full h-auto flex flex-col justify-start items-start -mt-2"><MemoFilter />{sortedMemos.map((memo) => {- return <Memo key={`${memo.id}-${memo.createdTs}`} memo={memo} readonly={true} />;+ return <Memo key={`${memo.id}-${memo.displayTs}`} memo={memo} readonly={true} />;})}{isComplete ? (state.memos.length === 0 ? (diff --git a/web/src/store/module/global.ts b/web/src/store/module/global.tsindex 38c4866f2..86a7f189e 100644--- a/web/src/store/module/global.ts+++ b/web/src/store/module/global.ts@@ -16,6 +16,7 @@ export const initialGlobalState = async () => {maxUploadSizeMiB: 0,additionalStyle: "",additionalScript: "",+ memoDisplayWithUpdatedTs: false,customizedProfile: {name: "memos",logoUrl: "/logo.webp",diff --git a/web/src/store/module/memo.ts b/web/src/store/module/memo.tsindex 6252217cd..c37153d3e 100644--- a/web/src/store/module/memo.ts+++ b/web/src/store/module/memo.ts@@ -11,6 +11,7 @@ export const convertResponseModelMemo = (memo: Memo): Memo => {...memo,createdTs: memo.createdTs * 1000,updatedTs: memo.updatedTs * 1000,+ displayTs: memo.displayTs * 1000,};};diff --git a/web/src/store/reducer/global.ts b/web/src/store/reducer/global.tsindex bd201f781..e0b6e1a0e 100644--- a/web/src/store/reducer/global.ts+++ b/web/src/store/reducer/global.ts@@ -23,6 +23,7 @@ const globalSlice = createSlice({disablePublicMemos: false,additionalStyle: "",additionalScript: "",+ memoDisplayWithUpdatedTs: false,customizedProfile: {name: "memos",logoUrl: "/logo.webp",diff --git a/web/src/types/modules/memo.d.ts b/web/src/types/modules/memo.d.tsindex 6af5fe6dc..b3f95c1c9 100644--- a/web/src/types/modules/memo.d.ts+++ b/web/src/types/modules/memo.d.ts@@ -10,6 +10,7 @@ interface Memo {updatedTs: TimeStamp;rowStatus: RowStatus;+ displayTs: TimeStamp;content: string;visibility: Visibility;pinned: boolean;diff --git a/web/src/types/modules/system.d.ts b/web/src/types/modules/system.d.tsindex 3e620c6b7..fe942163f 100644--- a/web/src/types/modules/system.d.ts+++ b/web/src/types/modules/system.d.ts@@ -31,6 +31,7 @@ interface SystemStatus {customizedProfile: CustomizedProfile;storageServiceId: number;localStoragePath: string;+ memoDisplayWithUpdatedTs: boolean;}interface SystemSetting {