Build

July 5, 2017 ยท View on GitHub

Messenger

Technologies:

  • Angular (4.2.5)
  • Angular/Material (2.0.0-beta.8)
  • SignalR (2.2.2)
  • Microsoft.AspNet.WebApi (5.2.3)
  • EntityFramework (6.1.3)
  • System.IdentityModel.Tokens.Jwt (5.1.3)
  • Unity.WebAPI (5.2.3)
  • Automapper (6.0.2)
Chat Profile

Build

  • Open Server in Visual Studio.
  • Build Client using angular-cli command ng build -prod.
  • Move all files from your dist folder in your Angular project to wwwroot folder in your server project.

Server

Database:

Use <connectionStrings> in Web.config to configure your database connection.

Configure JWT:

Use <appSettings> in Web.config to set AudienceSecret.

Server API:

APIDescriptionRequest bodyResponse body
POST /api/account/signupUser registrationJSON with UserName, Password, ConfirmPassword, Email, FirstName, LastName, BirthDate, SexJSON with Token, Id, UserName, FirstName, LastName, Email, BirthDate, Sex
POST /api/account/signinLogin userJSON with UserName, PasswordJSON with Token, Id, UserName, FirstName, LastName, Email, BirthDate, Sex
POST /api/account/refreshTokenRefresh TokenNoneJSON with new Token
GET /api/users/{id}Get user by IDNoneJSON with First, Second (First - JSON (array of objects) with Id, UserName, FirstName, LastName, Email, BirthDate, Sex, AvatarUrl, Online; Second - JSON (number of pages))
GET /api/users/{username}Get user by UserNameNoneJSON with First, Second (First - JSON (array of objects) with Id, UserName, FirstName, LastName, Email, BirthDate, Sex, AvatarUrl, Online; Second - JSON (number of pages))
GET /api/users?[search parameters]&p={page} (example: GET /api/users?UserName=admin&Sex=Male&p=1)Find user by some parameters such as UserName, FirstName, LastName, Email, BirthDate, Sex (any combinations, if nothing - get all users)NoneJSON with First, Second (First - JSON (array of objects) with Id, UserName, FirstName, LastName, Email, BirthDate, Sex, AvatarUrl, Online; Second - JSON (number of pages))
DELETE /api/usersDelete userNoneNone
PUT /api/usersChange userinfoJSON with FirstName, LastName, Email, BirthDate, SexJSON with FirstName, LastName, Email, BirthDate, Sex
PUT /api/users/ChangePasswordChange PasswordJSON with OldPassword, NewPassword, ConfirmPasswordJSON with new Token
PUT /api/users/ChangeUsernameChange UserNameJSON with UserNameJSON with UserName and new Token
POST /api/users/UploadAvatarUpload avatarImageJSON with AvatarUrl
POST /api/friends/add/{receiverId}Send friend request to user(receiver)NoneNone
PUT /api/friends/confirm/{senderId}Confirm friend request from user(sender)NoneNone
GET /api/friends/onlineCountGet number of online friendsNoneJSON (number of online friends)
GET /api/friends/countGet number of friendsNoneJSON (number of friends)
GET /api/friends?p={page}Get friendsNoneJSON with First, Second (First - JSON (array of objects) with Id, UserName, FirstName, LastName, Email, BirthDate, Sex, AvatarUrl, Online; Second - JSON (number of pages))
GET /api/friends/requests?p={page}Get all users, which sent requests to this userNoneJSON with First, Second (First - JSON (array of objects) with Id, UserName, FirstName, LastName, Email, BirthDate, Sex, AvatarUrl, Online; Second - JSON (number of pages))
GET /api/friends/mutual?userId={userId}&p={page}Get mutual friendsNoneJSON with First, Second (First - JSON (array of objects) with Id, UserName, FirstName, LastName, Email, BirthDate, Sex, AvatarUrl, Online; Second - JSON (number of pages))
GET /api/friends/shortestPath?userId={userId}Get shortest path between usersNoneJSON (array of objects) with Id, UserName, FirstName, LastName, Email, BirthDate, Sex, AvatarUrl, Online
DELETE /api/friends/{friendId}Delete friendshipNoneNone
GET /api/friends/areFriends?userId={userId}&friendId={friendId}Check if two users are friendsNonetrue/false
GET /api/friends/friendshipRequestAlreadyExists?senderId={senderId}&receiverId={receiverId}Check if friendship request already existsNonetrue/false
MessageHub's functionality:
Method signature (Server)DescriptionCallback (Client)Callback invocation
void SendMessage(int userId, string text)Send messageOnSendMessage([JSON with Id, DateTime, Text, FirstName, SenderId, New], [JSON (number of pages)])All this user and specified user's online clients
void MakeMessagesOld(int[] messagesIds)Make specified messages oldOnMakeMessagesOld([JSON (array of message ids)])All message sender's online clients
int GetNewMessagesCount()Get number of all this user's new messagesNoneNone
Pair<int, int> GetNewMessagesCountWith(int userId)Get number of this user and specified user's new messagesNoneNone
void GetCorrespondence(int userId, int page)Get messages between this user and the one with userIdOnGetCorrespondence([JSON (array of objects) with Id, DateTime, Text, FirstName, SenderId, New], [JSON (number of pages)])Caller
void GetConversations(int page)Get this user's conversationsOnGetConversations([JSON (array of objects) with Text, FirstName, LastName, DateTime, OtherUserId, NewMessagesCount, AvatarUrl, Online], [JSON (number of pages)])Caller
void RemoveMessage(int messageId)Remove messageOnRemoveMessage([JSON (message id)], [JSON (number of pages)])All this user and specified user's online clients
void TypeMessage(int receiverId)Notify about typing messageOnTypeMessage([JSON (sender id)])All specified receiver's online clients
void NotTypeMessage(int receiverId)Notify about stopping to type messageOnNotTypeMessage([JSON (sender id)])All specified receiver's online clients
void UserOnline()Notify that user enteredOnUserOnline([JSON (sender id)])All online users
void UserOffline()Notify that user exitedOnUserOffline([JSON (sender id)])All online users

Web Client

Development server

Run ng serve for a dev server. Navigate to http://localhost:4200/. The app will automatically reload if you change any of the source files.

Code scaffolding

Run ng generate component component-name to generate a new component. You can also use ng generate directive|pipe|service|class|module.

Build

Run ng build to build the project. The build artifacts will be stored in the dist/ directory. Use the -prod flag for a production build.

Warning!

All API (except signup and signin) need Header Authorization with user's token (use this format: Bearer <your JWT>). Token is valid for 1 hour.
Currently add token to client hub query string when calling MessageHub's methods.

License: MIT