diff --git a/src/smc-util/client.coffee b/src/smc-util/client.coffee index 2b65f1c7cb..2455153a91 100644 --- a/src/smc-util/client.coffee +++ b/src/smc-util/client.coffee @@ -2108,6 +2108,7 @@ class exports.Connection extends EventEmitter project_id : required path : required target : required # account_id (for now) + source : required # account_id priority : undefined # optional integer; larger number is higher; 0 is default. description: undefined # optional string context eg. part of the message cb : undefined diff --git a/src/smc-util/db-schema.js b/src/smc-util/db-schema.js index caf7b9661a..14e2c26420 100644 --- a/src/smc-util/db-schema.js +++ b/src/smc-util/db-schema.js @@ -1770,7 +1770,6 @@ schema.system_notifications = { schema.mentions = { primary_key: ["time", "project_id", "path", "target"], db_standby: "unsafe", - anonymous: true, // allow user *read* access, even if not signed in fields: { time: { type: "timestamp", @@ -1811,9 +1810,7 @@ schema.mentions = { }, users: { type: "map", - desc: - "{account_id1: {read: boolean, action2:timestamp2}, account_id2: {...}}", - date: "all" + desc: "{account_id1: {read: boolean, saved: boolean}, account_id2: {...}}" } }, @@ -1843,7 +1840,7 @@ schema.mentions = { }, project_id: "project_write", path: true, - source: "account_id", + source: true, target: true, priority: true, description: true, @@ -1851,6 +1848,7 @@ schema.mentions = { }, required_fields: { project_id: true, + source: true, path: true, target: true } diff --git a/src/smc-util/sync/table/synctable.ts b/src/smc-util/sync/table/synctable.ts index 327ec108ca..ccf1e6808a 100644 --- a/src/smc-util/sync/table/synctable.ts +++ b/src/smc-util/sync/table/synctable.ts @@ -339,7 +339,6 @@ export class SyncTable extends EventEmitter { // For sanity! changes = this.do_coerce_types(changes); - // Ensure that each key is allowed to be set. if (this.client_query.set == null) { throw Error(`users may not set ${this.table}`); @@ -351,7 +350,6 @@ export class SyncTable extends EventEmitter { throw Error(`users may not set ${this.table}.${k}`); } }); - // Determine the primary key's value let key: string | undefined = this.obj_to_key(changes); if (key == null) { @@ -418,6 +416,7 @@ export class SyncTable extends EventEmitter { throw Error("merge must be one of 'deep', 'shallow', 'none'"); } } + if (new_val.equals(cur)) { // nothing actually changed, so nothing further to do. return new_val; @@ -1085,7 +1084,6 @@ export class SyncTable extends EventEmitter { } } } - return Map( changes.map((value, field) => { if (typeof field !== "string") { diff --git a/src/smc-webapp/app-framework/Table.ts b/src/smc-webapp/app-framework/Table.ts index a77107b073..074186b8ba 100644 --- a/src/smc-webapp/app-framework/Table.ts +++ b/src/smc-webapp/app-framework/Table.ts @@ -37,7 +37,7 @@ export abstract class Table { async set( changes: object, - merge?: any, + merge?: "deep" | "shallow" | "none", cb?: (error?: string) => void ): Promise { let e: undefined | string = undefined; diff --git a/src/smc-webapp/chat/actions.coffee b/src/smc-webapp/chat/actions.coffee index b684b3a5d6..09dc4c0902 100644 --- a/src/smc-webapp/chat/actions.coffee +++ b/src/smc-webapp/chat/actions.coffee @@ -154,6 +154,9 @@ class ChatActions extends Actions submit_user_mentions: (project_id, path) => CONTEXT_SIZE = 80 + account_store = @redux.getStore('account') + if account_store == undefined + return @store.get('unsent_user_mentions').map((mention) => end_of_mention_index = mention.get('plainTextIndex') + mention.get('display').length end_of_context_index = end_of_mention_index + CONTEXT_SIZE @@ -172,6 +175,7 @@ class ChatActions extends Actions target: mention.get('id') priority: 2 description: description + source: account_store.get_account_id() }) ) @setState(unsent_user_mentions: immutable.List()) diff --git a/src/smc-webapp/file-use/viewer.tsx b/src/smc-webapp/file-use/viewer.tsx index 11c1562fca..1009ef5133 100644 --- a/src/smc-webapp/file-use/viewer.tsx +++ b/src/smc-webapp/file-use/viewer.tsx @@ -220,8 +220,7 @@ export class FileUseViewer extends Component { } render(): Rendered { - // const link = this.render_see_mentions_link() - const link = undefined; // mentions are currently badly broken. + const link = this.render_see_mentions_link() return (
diff --git a/src/smc-webapp/notifications/init.ts b/src/smc-webapp/notifications/init.ts index 31d544a0cb..dfae18ec9e 100644 --- a/src/smc-webapp/notifications/init.ts +++ b/src/smc-webapp/notifications/init.ts @@ -1,14 +1,6 @@ import { AppRedux } from "../app-framework"; -import { MentionsStore } from "./mentions/store"; -import { MentionsActions } from "./mentions/actions"; -import { MentionsTable } from "./mentions/table"; -import { redux_name } from "./mentions/util"; +import { init as init_mentions } from "./mentions"; export function init(redux: AppRedux) { - if (redux.getStore(redux_name) != undefined) { - return; - } - redux.createStore(redux_name, MentionsStore, { filter: "unread" }); - redux.createActions(redux_name, MentionsActions); - redux.createTable(redux_name, MentionsTable); + init_mentions(redux); } diff --git a/src/smc-webapp/notifications/mentions/actions.ts b/src/smc-webapp/notifications/mentions/actions.ts index 626f3619b4..080949d34a 100644 --- a/src/smc-webapp/notifications/mentions/actions.ts +++ b/src/smc-webapp/notifications/mentions/actions.ts @@ -2,7 +2,7 @@ import { Actions } from "../../app-framework"; import { MentionsState } from "./store"; import { MentionInfo, MentionFilter } from "./types"; -import { callback2, once } from "smc-util/async-utils"; +import { once } from "smc-util/async-utils"; const { webapp_client } = require("../../webapp_client"); @@ -38,7 +38,7 @@ export class MentionsActions extends Actions { const adjusted_mention = mention.setIn(["users", account_id, "read"], true); this.update_mention(adjusted_mention, id); - this.set(adjusted_mention.toJS()); + this.set(adjusted_mention); }; mark_unread = (mention: MentionInfo, id: string): void => { @@ -53,7 +53,7 @@ export class MentionsActions extends Actions { ); this.update_mention(adjusted_mention, id); - this.set(adjusted_mention.toJS()); + this.set(adjusted_mention); }; mark_saved = (mention: MentionInfo, id: string): void => { @@ -68,7 +68,7 @@ export class MentionsActions extends Actions { ); this.update_mention(adjusted_mention, id); - this.set(adjusted_mention.toJS()); + this.set(adjusted_mention); }; mark_unsaved = (mention: MentionInfo, id: string): void => { @@ -83,7 +83,7 @@ export class MentionsActions extends Actions { ); this.update_mention(adjusted_mention, id); - this.set(adjusted_mention.toJS()); + this.set(adjusted_mention); }; private async set(obj) { @@ -91,7 +91,11 @@ export class MentionsActions extends Actions { if (!webapp_client.is_signed_in()) { await once(webapp_client, "signed_in"); } - await callback2(webapp_client.query, { query: { mentions: obj } }); + const table = this.redux.getTable("mentions"); + if (table == undefined) { + return; + } + await table.set(obj); } catch (error) { const err = error; console.warn("WARNING: mentions error -- ", err); diff --git a/src/smc-webapp/notifications/mentions/index.ts b/src/smc-webapp/notifications/mentions/index.ts index f11d88c43d..1e94f9ea63 100644 --- a/src/smc-webapp/notifications/mentions/index.ts +++ b/src/smc-webapp/notifications/mentions/index.ts @@ -1,3 +1,4 @@ +export { init } from "./init"; export { MentionRow } from "./mention-row"; export { MentionsActions } from "./actions"; export { MentionsStore } from "./store"; diff --git a/src/smc-webapp/notifications/mentions/init.ts b/src/smc-webapp/notifications/mentions/init.ts new file mode 100644 index 0000000000..c7a19bcb46 --- /dev/null +++ b/src/smc-webapp/notifications/mentions/init.ts @@ -0,0 +1,14 @@ +import { AppRedux } from "../../app-framework"; +import { MentionsStore } from "./store"; +import { MentionsActions } from "./actions"; +import { MentionsTable } from "./table"; +import { redux_name } from "./util"; + +export function init(redux: AppRedux) { + if (redux.getStore(redux_name) != undefined) { + return; + } + redux.createStore(redux_name, MentionsStore, { filter: "unread" }); + redux.createActions(redux_name, MentionsActions); + redux.createTable(redux_name, MentionsTable); +}