Skip to content

Commit

Permalink
Merge branch 'notification-page'
Browse files Browse the repository at this point in the history
  • Loading branch information
williamstein committed Apr 24, 2019
2 parents b78eb3f + c92a2fc commit d989b58
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 27 deletions.
1 change: 1 addition & 0 deletions src/smc-util/client.coffee
Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions src/smc-util/db-schema.js
Expand Up @@ -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",
Expand Down Expand Up @@ -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: {...}}"
}
},

Expand Down Expand Up @@ -1843,14 +1840,15 @@ schema.mentions = {
},
project_id: "project_write",
path: true,
source: "account_id",
source: true,
target: true,
priority: true,
description: true,
users: true
},
required_fields: {
project_id: true,
source: true,
path: true,
target: true
}
Expand Down
4 changes: 1 addition & 3 deletions src/smc-util/sync/table/synctable.ts
Expand Up @@ -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}`);
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1085,7 +1084,6 @@ export class SyncTable extends EventEmitter {
}
}
}

return Map(
changes.map((value, field) => {
if (typeof field !== "string") {
Expand Down
2 changes: 1 addition & 1 deletion src/smc-webapp/app-framework/Table.ts
Expand Up @@ -37,7 +37,7 @@ export abstract class Table {

async set(
changes: object,
merge?: any,
merge?: "deep" | "shallow" | "none",
cb?: (error?: string) => void
): Promise<void> {
let e: undefined | string = undefined;
Expand Down
4 changes: 4 additions & 0 deletions src/smc-webapp/chat/actions.coffee
Expand Up @@ -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
Expand All @@ -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())
Expand Down
3 changes: 1 addition & 2 deletions src/smc-webapp/file-use/viewer.tsx
Expand Up @@ -220,8 +220,7 @@ export class FileUseViewer extends Component<Props, State> {
}

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 (
<div className={"smc-file-use-viewer"}>
<Row key="top">
Expand Down
12 changes: 2 additions & 10 deletions 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);
}
16 changes: 10 additions & 6 deletions src/smc-webapp/notifications/mentions/actions.ts
Expand Up @@ -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");

Expand Down Expand Up @@ -38,7 +38,7 @@ export class MentionsActions extends Actions<MentionsState> {
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 => {
Expand All @@ -53,7 +53,7 @@ export class MentionsActions extends Actions<MentionsState> {
);

this.update_mention(adjusted_mention, id);
this.set(adjusted_mention.toJS());
this.set(adjusted_mention);
};

mark_saved = (mention: MentionInfo, id: string): void => {
Expand All @@ -68,7 +68,7 @@ export class MentionsActions extends Actions<MentionsState> {
);

this.update_mention(adjusted_mention, id);
this.set(adjusted_mention.toJS());
this.set(adjusted_mention);
};

mark_unsaved = (mention: MentionInfo, id: string): void => {
Expand All @@ -83,15 +83,19 @@ export class MentionsActions extends Actions<MentionsState> {
);

this.update_mention(adjusted_mention, id);
this.set(adjusted_mention.toJS());
this.set(adjusted_mention);
};

private async set(obj) {
try {
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);
Expand Down
1 change: 1 addition & 0 deletions 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";
Expand Down
14 changes: 14 additions & 0 deletions 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);
}

0 comments on commit d989b58

Please sign in to comment.