📜 ⬆️ ⬇️

As we developed "Spetskor" - a super-custom mobile application for civilian reporters

We are pleased to present habrasoobshchestvu mobile application for civilian journalists "Spetskor", with which you can take photos and video reports and promote them under the auspices of "Komsomolskaya Pravda". The main creator is Komsomolskaya Pravda Publishing House, IT minions and developers are we, EastBanc Technologies. The project was announced by Komsomolskaya Pravda at the end of April 2014, at the same time the first competitions were launched. For our part, we decided to share the technical details of the implementation of the application. In our opinion, it will be interesting for readers, because rarely in one project there are so many non-trivial technological and business problems at the same time.

"Spetskor" refers to a multi-platform client-server applications with an administrative interface. The client part is implemented on iOS and Android mobile platforms and contains the following functionality:


The server part consists of the following parts:
')

The business goal of the project is the creation of a managed network of civilian reporters using an application that will allow journalists and editors of Komsomolskaya Pravda to interact effectively. To achieve this goal, it was necessary to give an opportunity to target and segment information by categories and topics, and users - by regions of Russia.

Initially, the following requirements for the server part were formulated:


Additional technical requirements:


How the application works


Administrative Interface Sections:


The process in terms of "Komsomolskaya Pravda"


KP employees who are responsible for the operation of the “Specialcore” application are called managers. Each manager is responsible for a specific geographic region.

The main responsibilities of Komsomolskaya Pravda managers are creating content for a mobile application. Through the administrative panel, managers add tasks and rubrics, fill them with skins. For customization of skins, they can add different fonts.
When there is at least one skin in a rubric or task, it becomes available in the mobile application, and users create their own reports using existing skins.
Reportings are sent to the server, processed and fall into the tape available to the manager. Depending on the task or heading that may be tied to a specific region, as well as from the geographical coordinates of the reportage for headings that have no geographic restrictions, the reportage will be checked by the manager who is responsible for the corresponding region.

The manager plays the role of moderator of reports, publishing the best in the general tape and awarding awards. Reports that have been published are made available in the feed in a mobile application.

Information about the award comes to the author of the report in the form of news, as well as in the form of a push-notification, if the appropriate type of notification is enabled in the settings of the mobile application.

In addition to skins and headings, managers can create news to talk about important events and the results of competitions. In addition, news is automatically generated for awarding and awarding titles to reporters.

One of the interesting tasks in creating an administrative interface for Komsomolskaya Pravda managers was the implementation of the ability to create and edit a skin. To do this, our colleagues developed a fully-featured WYSIWYG editor: all changes in properties are immediately displayed on the edit page as a skin preview. Using Javascript and CSS, the skin is displayed exactly as it will appear on mobile devices.

The process from the point of view of users of "Spetskor"


The user takes a photo or video, selects which category he wants to publish the report in, selects the desired skin in the category, fills in the report fields (title, subtitle, city, comment) and presses the “Publish” button. Before publication, the user can select the list of social networks in which he wants to additionally publish his report.

The user does not need to register in the application, and if he does not want to share the report in his accounts on social networks, he does not need to login even in them. In the application "Spetskor" user can upload videos and photos completely anonymously. If the user is logged in to a social network, then the server will receive information about his account, and the author’s name and avatar will be displayed in the general tape of the published reports.

To make a report for the task, the user must first open the task, and press the “Participate” button in it, then in the list of available skins when creating the report, only skins from the selected task will be shown. Of course, the user can refuse to complete the task at any time.

Example

The administrator responsible for the Siberian Federal District creates one task for Novosibirsk, Krasnoyarsk, Omsk and Tomsk. For example, shoot a video about how the Olympic flame is carried through these cities. For each city, the time interval is indicated when this task will be relevant.



Users who will be within 50 km of the site during the task will receive a push notification of the task. A wave of tasks will travel across all programmed cities in accordance with the time zone and the time when the torch will be carried in the city.

Next, the user goes to the scene and removes the report (we will discuss this in more detail later), selects and applies the skin, optionally publishes them in his personal accounts in social networks. The report is sent to the server, where it is waiting for processing and moderation.

After processing, the report is displayed in the “My feed” report, but if the report has been moderated and approved, it becomes available in the general tape.

This is how the processes behind the scenes look approximately. Refer to the implementation details.

Server side architecture




How information storage is organized


All information from mobile devices is stored in the MongoDB database. The main tasks for which the choice of DBMS was critical in our project are:


In MongoDB, work with geoindexes is implemented, and this greatly simplified the implementation of work with geodata in our application.

One of the options for implementing a MongoDB cluster configuration is replication. This allows you to distribute the load between multiple copies of the database (meeting the requirements for scalability).

To work with binary data, we used the MongoDB part called GridFS, which allows you to store binary data inside the database. To increase the speed of working with binary data, we store them in different collections.

How clustered load


One of the customer's requirements was that the back-end for simplicity, support and expansion was secured in the OpenShift-platform, which allows you to automatically scale resources depending on the load. If the server is heavily loaded, then OpenShift itself can raise another instance of this server.

In our case, one server consists of the following parts:

Services for processing media content and sending push notifications are processes that find and process data in the database for processing. When increasing the load, OpenShift raises additional server instances, it increases the number of services, and they may try to process the same information. Using the atomic operation in MongoDB, the findAndModify process sets a special status to the content being processed, thereby prohibiting its use by other processes.

Installing an application in OpenShift occurs via a push command to the remote Git repository where the application is created. OpenShift supports hooks, for example, there is a hook called when installing an application. We use this hook so that the database does not pass the initial initialization with each update of the application.

API and geolocation


Since tasks and rubrics in an application can often be limited to geographic regions, it is important to understand the location of a user to determine his access rights, as well as to send notifications. To determine the coordinates of the user, the application requests rights to access geolocation data and, in the case of obtaining permission from the user, receives the coordinates and sends them to the server. If the user has prohibited the application from receiving geolocation information from the smartphone’s operating system, and the application cannot send data to the server, the coordinates are determined using geoip services. At the request of the application is determined by the approximate position of the user at the place of registration of his provider.

To determine the location of the user who has banned geolocation in the settings, we used 2 services:


Media Processing Service


A media content processing service is a process that runs independently of the remaining parts. The main objectives of this process are to select content from a database with a certain status, process and save the processed data back to the database. Media content processing consists of two parts: video processing and photo processing.

How video processing is implemented

Video processing is carried out using a third-party avconv program (further development of the ffmpeg application).

Reporting video may consist of several pieces. It is removed on the principle of Vine / Instagram: while you hold your finger on the screen, the shooting goes as soon as you let go - it is interrupted. Mounting the pieces directly on the device is a very resource-intensive process, so the final installation takes place on the server.







Video can be shot from two cameras - front and rear, you can switch between them in the process of shooting. The permissions of a video shot on different smartphones are different. However, when publishing, we create clips 640 * 640. The overall video processing process includes the following steps:

  1. We determine the angle of rotation of the video (information is taken from the metadata of the video file).
  2. We overturn in the necessary orientation.
  3. Apply crop (crop).
  4. Perform scaling.
  5. Overlay the skin.
  6. After processing all the pieces, we glue them together in one clip - all this is done on the server, without the “manual” work and human participation.


Everything, we publish.



How image processing is implemented


With photo processing everything is simpler: images are processed using the Pillow library.
The mobile application sends the original photo to the server, as well as information about the report. In general, the steps of processing a photo report are similar to video processing.

How is the load on the social network implemented


The application provides support for downloading reports to the main social networks: VKontakte, Odnoklassniki, Twitter, Facebook, Instagram, YouTube.



Uploading reports in the user's social network

If a user decides to share his report on social networks, he needs to select in the application which network he wants to share the report. Further, the process will be as follows:

  1. The user is authorized in the selected social network.
  2. The user is asked for permission to access the profile and publish it in his tape on behalf of the Specialcore application.
  3. If the user allows, the mobile application receives Access Token and sends it to the server
  4. The server requests a user profile for a token and stores some user data in the database: first name, last name, and a link to the avatar.

After the user uploads his report to the server and the media content of the report has been processed, the process of downloading the report in the social network is launched directly. If this is a video report, then it can be downloaded on Vkontakte, Facebook, YouTube. If the user has selected one of these social networks, and also has chosen Twitter or Odnoklassniki, then video will be uploaded to video hosting social networks, and a link to video will be uploaded to Twitter / Odnoklassniki. All networks are available for photo reporting except YouTube.

Uploading reports in the customer's social network

In addition to the publication of the report in the user accounts of social networks, the report will be uploaded to the private Twitter-and YouTube-accounts of the customer. For this, separate applications were created in social networks. To upload to Twitter, user authorization is not needed (tokens with which publications are made do not have a statute of limitations). And to upload to YouTube, you need a primary user authorization (we made it in the application’s admin panel), during which the server receives 2 keys from YouTube: access_token and refresh_token. Access Token is a key that is used to upload videos to YouTube and is valid for a certain period of time. Refresh Token is needed to generate a new Access Token when required.

Refresh Token has no statute of limitations and may become outdated only when the user withdraws the publication rights from this application. Another nuance associated with YouTube: the number of videos uploaded through the API is limited, a total of 2,000 videos. Therefore, the server maintains a publication count and organizes the ability to add multiple YouTube accounts. To publish the video server will choose the account in which the least published clips are published.

In addition to private accounts, there is the same pair of public accounts. There reports are published only after passing moderation.

In the report, you can use hashtags. Some social networks when publishing content allow you to specify them separately. The user can specify hashtags in the comments to the report, and the customer manager, in addition, can provide tags with a task or a heading.

Service for sending push notifications


Since our app is released on iOS and Android, we support both the Apple Push Notification Service and Google Cloud Messaging.

The standard practice is this: first, the application requests from the mobile device an identifier of the ability to display push notifications. At this time, the operating system itself asks the user if he wants to accept them.



We did not agree to just “off” or “on” for all app notifications. It was necessary to customize the process, because someone from the users wants to learn about new tasks, someone wants to get new reports, someone wants to get a notification that their report is published, and others do not need it.

We decided to work with the task using the settings and configuration of the server. If the user has agreed to receive push notifications, then he has the opportunity to configure which types of notifications he wants to receive:


Total


Let's be honest: it was an exciting experience in product development, not just from a technical point of view, but based on a global idea - to create a huge network of citizen journalists across the country, take civic journalism to a professional level, giving them the resources to promote Russia .

The application is running. For example, for "Night at the Museum" civilian reporters have already received fees . If you live in the capital, then right now you can compete for fame and money by creating interesting reports on the topic “Heat in Moscow” , and for Novosibirsk “Komsomolskaya Pravda” gives a chance to become rich and famous by going to a photo hunt in the city zoo (countrymen, hurry, pictures of the white bear Shilka - a safe option!).

Download "Spetskor" in Google Play and AppStore .

Source: https://habr.com/ru/post/222945/


All Articles