]> Untitled Git - lemmy.git/blobdiff - ui/src/components/navbar.tsx
routes.api: fix get_captcha endpoint (#1135)
[lemmy.git] / ui / src / components / navbar.tsx
index 676ab8d4f4050cd6041ef833bbff4081134738aa..4ef5276c36c9a72f030483f0a19c3aafe5ece433 100644 (file)
@@ -18,18 +18,17 @@ import {
   PrivateMessage,
   PrivateMessageResponse,
   WebSocketJsonResponse,
-} from '../interfaces';
+} from 'lemmy-js-client';
 import {
   wsJsonToRes,
   pictrsAvatarThumbnail,
   showAvatars,
   fetchLimit,
-  isCommentType,
   toast,
-  messageToastify,
-  md,
   setTheme,
   getLanguage,
+  notifyComment,
+  notifyPrivateMessage,
 } from '../utils';
 import { i18n } from '../i18next';
 
@@ -82,6 +81,7 @@ export class Navbar extends Component<any, NavbarState> {
       banned: [],
       online: null,
       version: null,
+      federated_instances: null,
     },
     searchParam: '',
     toggleSearch: false,
@@ -137,7 +137,7 @@ export class Navbar extends Component<any, NavbarState> {
       this.context.router.history.push(`/search/`);
     } else {
       this.context.router.history.push(
-        `/search/q/${searchParam}/type/all/sort/topall/page/1`
+        `/search/q/${searchParam}/type/All/sort/TopAll/page/1`
       );
     }
   }
@@ -435,7 +435,7 @@ export class Navbar extends Component<any, NavbarState> {
           this.state.unreadCount++;
           this.setState(this.state);
           this.sendUnreadCount();
-          this.notify(data.comment);
+          notifyComment(data.comment, this.context.router);
         }
       }
     } else if (res.op == UserOperation.CreatePrivateMessage) {
@@ -447,7 +447,7 @@ export class Navbar extends Component<any, NavbarState> {
           this.state.unreadCount++;
           this.setState(this.state);
           this.sendUnreadCount();
-          this.notify(data.message);
+          notifyPrivateMessage(data.message, this.context.router);
         }
       }
     } else if (res.op == UserOperation.GetSite) {
@@ -477,14 +477,14 @@ export class Navbar extends Component<any, NavbarState> {
   fetchUnreads() {
     console.log('Fetching unreads...');
     let repliesForm: GetRepliesForm = {
-      sort: SortType[SortType.New],
+      sort: SortType.New,
       unread_only: true,
       page: 1,
       limit: fetchLimit,
     };
 
     let userMentionsForm: GetUserMentionsForm = {
-      sort: SortType[SortType.New],
+      sort: SortType.New,
       unread_only: true,
       page: 1,
       limit: fetchLimit,
@@ -541,37 +541,4 @@ export class Navbar extends Component<any, NavbarState> {
       });
     }
   }
-
-  notify(reply: Comment | PrivateMessage) {
-    let creator_name = reply.creator_name;
-    let creator_avatar = reply.creator_avatar
-      ? reply.creator_avatar
-      : `${window.location.protocol}//${window.location.host}/static/assets/apple-touch-icon.png`;
-    let link = isCommentType(reply)
-      ? `/post/${reply.post_id}/comment/${reply.id}`
-      : `/inbox`;
-    let htmlBody = md.render(reply.content);
-    let body = reply.content; // Unfortunately the notifications API can't do html
-
-    messageToastify(
-      creator_name,
-      creator_avatar,
-      htmlBody,
-      link,
-      this.context.router
-    );
-
-    if (Notification.permission !== 'granted') Notification.requestPermission();
-    else {
-      var notification = new Notification(reply.creator_name, {
-        icon: creator_avatar,
-        body: body,
-      });
-
-      notification.onclick = () => {
-        event.preventDefault();
-        this.context.router.history.push(link);
-      };
-    }
-  }
 }